Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Command grouping in CommandStack
Command grouping in CommandStack [message #1387156] Tue, 24 June 2014 13:23 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Hi,
I need to do some housekeeping operations whenever some model classes
are destroyed.

Unfortunately operations depend on the order of deletions, so I need to
do them WHILE the deletion takes place.

Obviously this is a problem only when I delete complex objects composed
by many other EObjects.

Is there some way to "hook" to actual object deletion (if it is done
recursively and not simply relying on gc)?

Alternatively I can recourse on my model (that's what I'm doing now)
explicitly deleting depth-first all contained children.
In this case, however I have the problem undo/redo won't be atomic anymore.
I seem to recall there's a way to logically group many commands (I am
NOT speaking about CompoundCommand !) so that they are undone together,
but I couldn't find it anywhere. Perhaps I just dreamed.

Any pointer welcome
TiA
Mauro
Re: Command grouping in CommandStack [message #1387157 is a reply to message #1387156] Tue, 24 June 2014 13:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33258
Registered: July 2009
Senior Member
Mauro,

Comments below.

On 24/06/2014 3:23 PM, Mauro Condarelli wrote:
> Hi,
> I need to do some housekeeping operations whenever some model classes
> are destroyed.
Destroyed?
>
> Unfortunately operations depend on the order of deletions, so I need
> to do them WHILE the deletion takes place.
And deletion is done as a command?
>
> Obviously this is a problem only when I delete complex objects
> composed by many other EObjects.
The delete command
(org.eclipse.emf.edit.command.DeleteCommand.execute()) does visit all
objects being deleted, including contained children so it can remove all
references to them.
>
> Is there some way to "hook" to actual object deletion (if it is done
> recursively and not simply relying on gc)?
Objects used in a editor won't generally be gc'd because they have
adapters attached to them (and of course the commands reference even
deleted things so you can undo it).
>
> Alternatively I can recourse on my model (that's what I'm doing now)
> explicitly deleting depth-first all contained children.
I'm not sure how that relates to what's done as part of a command but
you can look at how a delete command produces a single compound command
to undo the delete...
> In this case, however I have the problem undo/redo won't be atomic
> anymore.
> I seem to recall there's a way to logically group many commands (I am
> NOT speaking about CompoundCommand !) so that they are undone
> together, but I couldn't find it anywhere.
At least with EMF's core command framework, compound commands are the
only way...
> Perhaps I just dreamed.
>
> Any pointer welcome
> TiA
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Command grouping in CommandStack [message #1387173 is a reply to message #1387157] Tue, 24 June 2014 15:21 Go to previous message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Hi Ed,
comments inline.

Il 24/06/2014 15:42, Ed Merks ha scritto:
> Mauro,
>
> Comments below.
>
> On 24/06/2014 3:23 PM, Mauro Condarelli wrote:
>> Hi,
>> I need to do some housekeeping operations whenever some model classes
>> are destroyed.
> Destroyed?
Yes, I am modeling a computation network, so "objects" represent
computations on data and references represent data channels.
"deleting" an element implies reconfiguring all attached "pipes", not
just destroy them.

>>
>> Unfortunately operations depend on the order of deletions, so I need
>> to do them WHILE the deletion takes place.
> And deletion is done as a command?
Actual deletion of objects is done via:

getEditingDomain().getCommandStack().execute(DeleteCommand.create(...));

>>
>> Obviously this is a problem only when I delete complex objects
>> composed by many other EObjects.
> The delete command
> (org.eclipse.emf.edit.command.DeleteCommand.execute()) does visit all
> objects being deleted, including contained children so it can remove all
> references to them.
Ok.
Is there some way I can attach a listener there?
I need something like overriding destroy() or a real Listener called
*before* removing objects ("on the way down" of the recursion).

>>
>> Is there some way to "hook" to actual object deletion (if it is done
>> recursively and not simply relying on gc)?
> Objects used in a editor won't generally be gc'd because they have
> adapters attached to them (and of course the commands reference even
> deleted things so you can undo it).
I understand. thanks.
The above question stands.

>>
>> Alternatively I can recourse on my model (that's what I'm doing now)
>> explicitly deleting depth-first all contained children.
> I'm not sure how that relates to what's done as part of a command but
> you can look at how a delete command produces a single compound command
> to undo the delete...
I'll try to follow...

>> In this case, however I have the problem undo/redo won't be atomic
>> anymore.
>> I seem to recall there's a way to logically group many commands (I am
>> NOT speaking about CompoundCommand !) so that they are undone
>> together, but I couldn't find it anywhere.
> At least with EMF's core command framework, compound commands are the
> only way...
>> Perhaps I just dreamed.
It seems I dreamed :(
I seem to remember there is some way to "mark" positions in the command
stack, so I can repeatedly undo/redo till I find a matching mark.
I think that is used at least to mark the point where last File->Save
occurred... but I cannot find it again.

Many thanks
Mauro
Previous Topic:Custom validation for ID attribute
Next Topic:[CDO] problem with CDOSession - how to close it ?
Goto Forum:
  


Current Time: Wed Dec 04 06:30:48 GMT 2024

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

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

Back to the top