Custom deletion behaviour [message #173034] |
Tue, 19 February 2008 22:16 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 #173149 is a reply to message #173126] |
Wed, 20 February 2008 12:44 |
Eclipse User |
|
|
|
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
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 5.03340 seconds