Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » DeleteModelCommand Problems
DeleteModelCommand Problems [message #483542] Wed, 02 September 2009 00:38 Go to next message
Eclipse UserFriend
Originally posted by: derek.pfister.gmail.com

I have the following problems when trying to delete an EObject with the
DeleteModel command:

http://sites.google.com/site/deletemodelpics/

It seems as if the framework returns a DeleteCommand that has its
isExecutable = false. Does anyone know why?

Here are some additional questions I have:

1.) Why would overriding the ItemProvider help? What are the differences
between ModelProviders and ItemProviders? How would you start going about
overriding these? How would that help with deleting an object that is
only contained within a resource? How can you tell if an object is only
contained within a resource?

2.) If I had to override the DeleteCommand, how would I override it?
What would I put in execute()? Would I always have isExecutable()
return true?
Re: DeleteModelCommand Problems [message #483664 is a reply to message #483542] Wed, 02 September 2009 14:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000900010200040707040906
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Derek,

Comments below.

Derek Pfister wrote:
> I have the following problems when trying to delete an EObject with
> the DeleteModel command:
>
> http://sites.google.com/site/deletemodelpics/
>
> It seems as if the framework returns a DeleteCommand that has its
> isExecutable = false. Does anyone know why?
I see that isPrepared is false as well though, so it seems to me it's
never been tested for executability.

/**
* Returns whether the command is valid to <code>execute</code>.
* The {@link
UnexecutableCommand#INSTANCE}.<code>canExecute()</code> always
returns <code>false</code>.
* This <b>must</b> be called before calling <code>execute</code>.
* @return whether the command is valid to <code>execute</code>.
*/
boolean canExecute();

>
> Here are some additional questions I have:
>
> 1.) Why would overriding the ItemProvider help?
Help what?
> What are the differences between ModelProviders and ItemProviders?
Reading the introductory EMF Edit paper would help, or better yet, the
EMF book...
> How would you start going about overriding these?
ItemProviderAdapter is the base class for each AbcItemProvider (for each
EClass Abc) and it has methods like createRemoveCommand and so on that
you could specialize if you want to do more than just the basic things
the base class does for you.
> How would that help with deleting an object that is only contained
> within a resource?
ResourceItemProvider doesn't by default support removing objects from
Resource.getContents().
> How can you tell if an object is only contained within a resource?
EObject.eContainer will be null. But you don't need to tell, you only
need to look at the situations where the ResourceItemProvider's
createRemoveCommand is called.
>
> 2.) If I had to override the DeleteCommand, how would I override it?
Typically you don't need to override it because it's composed from more
primitive commands, e.g., RemoveCommand in particular.
> What would I put in execute()? Would I always have isExecutable()
> return true?
You should be able to create the Remove command using this constructor:

/**
* This constructs a primitive command to remove a particular
value from the specified extent.
*/
public RemoveCommand(EditingDomain domain, EList<?> list, Object
value)
{
this(domain, list, Collections.singleton(value));
}

Passing in Resource.getContents() as the list and the thing to remove as
the value...

--------------000900010200040707040906
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Derek,<br>
<br>
Comments below.<br>
<br>
Derek Pfister wrote:
<blockquote
cite="mid:5179211e8e160d2feee8f84dc5e5f19c$1@www.eclipse.org"
type="cite">I have the following problems when trying to delete an
EObject with the DeleteModel command:
<br>
<br>
<a class="moz-txt-link-freetext" href="http://sites.google.com/site/deletemodelpics/">http://sites.google.com/site/deletemodelpics/</a>
<br>
<br>
It seems as if the framework returns a DeleteCommand that has its
isExecutable = false.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DeleteModelCommand Problems [message #483698 is a reply to message #483664] Wed, 02 September 2009 15:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: derek.pfister.gmail.com

I attempted to do what you said to do with a remove command:

http://sites.google.com/site/removecommand/

However, the command is still not executable, even when I call
canExecute() so that it is prepared. Also, the object's eContainer() is
not null, per the previous screenshots. What exactly is going on here?a
Re: DeleteModelCommand Problems [message #483700 is a reply to message #483698] Wed, 02 September 2009 15:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050901010502070600060700
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Derek,

Step through the logic that's executed during pepare(), with particular
attention to ownerList.containsAll(collection)

protected boolean prepare()
{
// This can execute if there is an owner list and a collection
and the owner list contains all the objects of the collection.
//
boolean result =
ownerList != null &&
collection != null &&
ownerList.containsAll(collection) &&
(owner == null || !domain.isReadOnly(owner.eResource()));

return result;
}


Derek Pfister wrote:
> I attempted to do what you said to do with a remove command:
>
> http://sites.google.com/site/removecommand/
>
> However, the command is still not executable, even when I call
> canExecute() so that it is prepared. Also, the object's eContainer()
> is not null, per the previous screenshots. What exactly is going on
> here?a
>

--------------050901010502070600060700
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Derek,<br>
<br>
Step through the logic that's executed during pepare(), with particular
attention to <small>ownerList.containsAll(collection) </small><br>
<small><br>
</small>
<blockquote><small>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DeleteModelCommand Problems [message #483710 is a reply to message #483700] Wed, 02 September 2009 16:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: derek.pfister.gmail.com

prepare() returns false. It appears that the ownerList does not contain
the object I want to delete. It does contain the container of the object
I want to delete, I believe:

http://sites.google.com/site/removecommand/containsall
http://sites.google.com/site/removecommand/prepare

Thanks so much for your help I have been working for over a week on this.
Re: DeleteModelCommand Problems [message #483714 is a reply to message #483710] Wed, 02 September 2009 16:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Derek,

Comments below.

Derek Pfister wrote:
> prepare() returns false. It appears that the ownerList does not
> contain the object I want to delete.
I see.
> It does contain the container of the object I want to delete, I believe:
>
> http://sites.google.com/site/removecommand/containsall
> http://sites.google.com/site/removecommand/prepare
So how is it that you're asking to be able to delete the root object
directly contained by a resource when now you're saying you're trying to
delete an object contained by another object? How do I reconcile this
apparent contradiction?
>
> Thanks so much for your help I have been working for over a week on this.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DeleteModelCommand Problems [message #483743 is a reply to message #483714] Wed, 02 September 2009 19:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: derek.pfister.gmail.com

It looks like the object is contained within another object. What I said
previously is incorrect, as this object has another object as its
container. Sorry about that. How do I go about deleting it based on the
presented evidence?
Re: DeleteModelCommand Problems [message #483874 is a reply to message #483743] Thu, 03 September 2009 12:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Derek,

Delete should just work like it does in the generated editor for the
library tutorial. I'm not sure what's different about your situation
that makes it unique...


Derek Pfister wrote:
> It looks like the object is contained within another object. What I
> said previously is incorrect, as this object has another object as its
> container. Sorry about that. How do I go about deleting it based on
> the presented evidence?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DeleteModelCommand Problems [message #483944 is a reply to message #483874] Thu, 03 September 2009 17:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: derek.pfister.gmail.com

It seems as if the ownerList that is created doesn't contain the object I
want to delete.

org.eclipse.emf.common.command.Command cmd = new
RemoveCommand(domain.getEMFEditingDomain(),
model.eResource().getContents(), model);


Is it possible that model.eResource().getContents() doesn't contain the
model object that I want to delete? Could there be another list that I
should pass instead of model.eResource().getContents() as the second
argument to the RemoveCommand?
Re: DeleteModelCommand Problems [message #483946 is a reply to message #483874] Thu, 03 September 2009 17:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: derek.pfister.gmail.com

Also, when I delete the object from another diagram, it is deleted
successfully, but in that instance it appears to be deleting an that
object which is wrapped with an ItemProvider

http://sites.google.com/site/removecommand/wrappedobject
Re: DeleteModelCommand Problems [message #484001 is a reply to message #483944] Thu, 03 September 2009 20:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Derek,

Comments below.

Derek Pfister wrote:
>
> It seems as if the ownerList that is created doesn't contain the
> object I want to delete.
> org.eclipse.emf.common.command.Command cmd = new
> RemoveCommand(domain.getEMFEditingDomain(),
> model.eResource().getContents(), model);
I think you already established that the object you're deleting isn't at
the root of the resource...
>
>
> Is it possible that model.eResource().getContents() doesn't contain
> the model object that I want to delete?
Of course. It only contains root objects.
> Could there be another list that I should pass instead of
> model.eResource().getContents() as the second argument to the
> RemoveCommand?
I'm not sure why you aren't using DeleteCommand.create passing in the
object you're trying to delete...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DeleteModelCommand Problems [message #484002 is a reply to message #483946] Thu, 03 September 2009 20:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Derek,

It's virtually impossible to help from the snips of information you
provide...


Derek Pfister wrote:
>
> Also, when I delete the object from another diagram, it is deleted
> successfully, but in that instance it appears to be deleting an that
> object which is wrapped with an ItemProvider
>
> http://sites.google.com/site/removecommand/wrappedobject
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DeleteModelCommand Problems [message #484013 is a reply to message #484001] Thu, 03 September 2009 21:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: derek.pfister.gmail.com

I don't do it that way because when I call
DeleteCommand.create(domain.getEMFEditingDomain(), model); the
RemoveCommand that is created internally returns an Unexecutable command.
Is there anything I can provide you that would help identify the problem?
Any advice?
Re: DeleteModelCommand Problems [message #484025 is a reply to message #484002] Thu, 03 September 2009 22:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: derek.pfister.gmail.com

Fixed my problem by calling EcoreUtil.remove(model); Does that sound like
a good solution to you?
Re: DeleteModelCommand Problems [message #484196 is a reply to message #484013] Fri, 04 September 2009 14:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Derek,

The debugger is your best friend and will help you discover why an
executable command cannot be created. So stepping through the process
of creating the command and stepping through the process of evaluating
canExecute will help a lot.


Derek Pfister wrote:
> I don't do it that way because when I call
> DeleteCommand.create(domain.getEMFEditingDomain(), model); the
> RemoveCommand that is created internally returns an Unexecutable
> command. Is there anything I can provide you that would help identify
> the problem? Any advice?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DeleteModelCommand Problems [message #484197 is a reply to message #484025] Fri, 04 September 2009 14:51 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Derek,

If you don't use a command, it won't be undoable and will leave the
command stack in an inconsistent state.


Derek Pfister wrote:
> Fixed my problem by calling EcoreUtil.remove(model); Does that sound
> like a good solution to you?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Setting the range of an ecore datatype
Next Topic:EMap implemention does not support inverse reference of contained entries
Goto Forum:
  


Current Time: Fri Apr 26 21:21:32 GMT 2024

Powered by FUDForum. Page generated in 0.02994 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top