Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Custom deletion behaviour
Custom deletion behaviour [message #173034] Tue, 19 February 2008 22:16 Go to next message
Eclipse UserFriend
Originally posted by: mlooise.planet.nl

Hello All,



I'm a relative newcomer to the GMF community, and I'm currently using GMF to
build some editors for a meta-model which I designed as a part of my
graduation project at the university. Now I'm struggling with a bit of a
problem; Adding custom deletion behaviour.



I want to change the behaviour of the 'delete-element' context-menu action.
I basically want to add some extra custom checks before an element is
actually deleted. (I'm building a requirements-traceability tool, and
requirement-elements should only be deleted if no design is attached to it
;-) ) . and no I cant do it using constraints .. design is located in
another editor and I have to do some addition checks). The problem is
however that the generator does not generate any DestroyElementCommand or
something for me to override with my own behaviour. Or maybe I'm not looking
good enough.



My question is; is it possible to add my own behaviour on pushing the
'delete element' button, and if so, where do I have to look.



Another option would be to remove the delete button (I've seen it in
(http://wiki.eclipse.org/GMF_Tutorial_Part_3), and then adding my own
actions to do the deletion. But how to go about this last step then? How do
I declare extra context-menu-items with my behaviour and also call the
original deletion action from this, after my checks are done.



If anyone could create some clarity into this puzzling question, that would
be great! Any help is appreciated.



Regards,



Martin Looise
Re: Custom deletion behaviour [message #173088 is a reply to message #173034] Wed, 20 February 2008 11:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mlooise.planet.nl

Hi,



I recently read in a presentation by IBM (GMF Best Practices) that it is
possible to create custom edit-policies. An example is given to use the
extend the OpenEditPolicy. This basically creates a custom Command, to
implement their own behaviour. In this case it displays a dialog which asks
for the attribute name, on a open-action (getOpenCommand).



I think it should be possible to maybe take a similar approach in order to
create custom edit policy which creates a custom createDeleteCommand? This
custom command could then include my own checks. This would require
extending he ComponentEditPolicy an overriding the getCommand method.



But how do I call this custom ComponentEditorPolicy via de plugin.xml? What
I've read is that I have to create a customEditroPolicyProvider which
installs my own policy. But what type of Role should I pass to the
installEditPolicy method? The example used the OPEN_ROLE, but how do I
install my policy which implements getCommand (of the ComponentEditPolicy),
instead of getOpenCommand (Of the OpenEditPolicy) which the example uses ?



Des anyone have experiences with this? Any help would be GREATLY appreciated



Thanks,



Martin Looise
Re: Custom deletion behaviour [message #173126 is a reply to message #173034] Wed, 20 February 2008 12:01 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Martin,

> element is actually deleted. (I'm building a requirements-traceability
> tool, and requirement-elements should only be deleted if no design is
> attached to it ;-) ) . and no I cant do it using constraints .. design
Isn't it better to remove corresponding "design" attached to it on deleting
requirement-element?

> The problem is however that the generator does not generate any
> DestroyElementCommand or something for me to override with my own
> behaviour. Or maybe I'm not looking good enough.
See generated xxxItemSemanticEditPolicy.getDestroyElementCommand() for requirement-element.

You can modify delete command here (or return null/UnexecutableCommand instead).

> My question is; is it possible to add my own behaviour on pushing the
> 'delete element' button, and if so, where do I have to look.
I do not suggest you to create your own EditPolicy (behaviour) for it - standard
one is already handling this situation.

-----------------
Alex Shatalin
Re: Custom deletion behaviour [message #173134 is a reply to message #173088] Wed, 20 February 2008 12:06 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Martin,

Looks like this presentation: http://www.eclipsecon.org/2007/index.php?page=sub/&id=37 39
was done by Borland guys. ;-) The rest is in my prev. answer.

-----------------
Alex Shatalin
Re: Custom deletion behaviour [message #173149 is a reply to message #173126] Wed, 20 February 2008 12:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mlooise.planet.nl

Thank you very much !



What i've done until know is just return my own custom
DestroyElementCommandWithCheck in the getDestroyElementCommand function of
the desired SemanticEditPolicy which is already there. I just overwrote the
method doExecuteWithResult and added the checks and if desired called the
parent to really do the deletion.




It works ok I think. It took me a while to really get the Command structure
into my head. I was playing with it earlier, but saw that lots and lots of
these commands get created. The trick is of course to get between the
execution of such a command, and not at its instantiation (creation). On the
doExecuteWithResult one can add its own behaviour .. changing effectively
the behaviour of the delete action.



I am thanks to you again a bit wiser in the GMF framework ! :D



Kind regards,



Martin Looise




"Alex Shatalin" <vano@borland.com> schreef in bericht
news:3c3172e61e3e38ca41d7e7dc0d9f@news.eclipse.org...
> Hello Martin,
>
>> element is actually deleted. (I'm building a requirements-traceability
>> tool, and requirement-elements should only be deleted if no design is
>> attached to it ;-) ) . and no I cant do it using constraints .. design
> Isn't it better to remove corresponding "design" attached to it on
> deleting requirement-element?
>
>> The problem is however that the generator does not generate any
>> DestroyElementCommand or something for me to override with my own
>> behaviour. Or maybe I'm not looking good enough.
> See generated xxxItemSemanticEditPolicy.getDestroyElementCommand() for
> requirement-element.
> You can modify delete command here (or return null/UnexecutableCommand
> instead).
>
>> My question is; is it possible to add my own behaviour on pushing the
>> 'delete element' button, and if so, where do I have to look.
> I do not suggest you to create your own EditPolicy (behaviour) for it -
> standard one is already handling this situation.
>
> -----------------
> Alex Shatalin
>
>
Re: Custom deletion behaviour [message #173156 is a reply to message #173134] Wed, 20 February 2008 12:49 Go to previous message
Eclipse UserFriend
Originally posted by: mlooise.planet.nl

Give Credit Where Credit is Due .. Sorry.

And in this case it is you ;-) at the EclipseCon 2007 ..

"Artem Tikhomirov and Alexander Shatalin, Borland.
GMF committers"

Thanks !

"Alex Shatalin" <vano@borland.com> schreef in bericht
news:3c3172e61e3e68ca41d87caf66bc@news.eclipse.org...
> Hello Martin,
>
> Looks like this presentation:
> http://www.eclipsecon.org/2007/index.php?page=sub/&id=37 39 was done by
> Borland guys. ;-) The rest is in my prev. answer.
>
> -----------------
> Alex Shatalin
>
>
Previous Topic:Two graphical views of the same metamodel element
Next Topic:[Announcement] Applied Metamodelling Book
Goto Forum:
  


Current Time: Tue Apr 23 10:45:01 GMT 2024

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

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

Back to the top