Preventing a node from being deleted [message #226589] |
Fri, 17 April 2009 14:36 |
Eclipse User |
|
|
|
Originally posted by: artur.c.ribeiro.criticalsoftware.com
Hello,
This issue is old news, but netherverless, i am having troubles to
accomplish this (to prevente a node from being deleted).
From http://wiki.eclipse.org/GMF_Newsgroup_Q_and_A:
1. You could return an unexecutable command from your
xxxSemanticEditPolicy#getDestroyElementCommand, or from your
xxxEditHelper#getDestroyElementCommand, to disable the "Delete from Model"
menu item for that kind of element.
2. You can take a look on plugin.xml generated for Ecore diagram editor - it
removes "deleteFromDiagramAction" for some elements. I think you can remove
"deleteFromModelAction" in a same way.
Tried all these options (overrided both getDestroyElementCommand methods
returning null, and added the remove contribution to the plugin.xml) and
still the nodes can be deleted. What did happen is that the
"deleteFromDiagramAction" disappeared, but the "deleteFromModelAction" is
still present and the node may be deleted through this action or by hiting
the 'del' key.
Is there any other option how to prevent a node from being deleted?
Thank you,
Artur Ribeiro
|
|
|
|
|
Re: Preventing a node from being deleted [message #227408 is a reply to message #227045] |
Sat, 25 April 2009 09:16 |
|
Hi Peter.
If u want to prevent deleting the node using del key try installing
component editpolicy of the its editpart
Soemthing like this a(add in createDefaultEditPolicies())
installEditPolicy(EditPolicy.COMPONENT_ROLE, new
PreventDeleteComponentEditPolicy());
public class PreventDeleteComponentEditPolicy extends ComponentEditPolicy
{
@Override
public Command getCommand(Request request)
{
// If the user presses the delete key, don't delete
if (request instanceof GroupRequestViaKeyboard &&
RequestConstants.REQ_DELETE.equals(request.getType()))
{
return UnexecutableCommand.INSTANCE;
}
return super.getCommand(request);
}
}
It should work
Regards
Govind R
|
|
|
Re: Preventing a node from being deleted [message #228431 is a reply to message #227408] |
Wed, 29 April 2009 16:24 |
Eclipse User |
|
|
|
Originally posted by: artur.c.ribeiro.criticalsoftware.com
Ah finally, all works fine.
Thank you Alex, it was indeed the problem to return null instead of a
UnexecutableCommand.
And also thank you Govind, tried your suggestion and it works perfectly.
So in order to fully prevent a node from being deleted one has to:
1- Ovewrite the method getDestroyElementCommand() on the respective
SemanticEditPolicy to return an UnexecutableCommand (null doesn't work).
2- [Optional] To remove the plugin.xml contribution
"deleteFromDiagramAction". (didn't work for "deleteFromModelAction").
3- To catch the RequestConstants.REQ_DELETE request and return an
UnexecutableCommand as Gonvid described.
All works fine with those steps.
Cheers!
Artur Ribeiro
"govind " <govindashrit@gmail.com> wrote in message
news:110f0e8a3c9d264b285bae15ee054839$1@www.eclipse.org...
> Hi Peter.
>
> If u want to prevent deleting the node using del key try installing
> component editpolicy of the its editpart
>
> Soemthing like this a(add in createDefaultEditPolicies())
>
> installEditPolicy(EditPolicy.COMPONENT_ROLE, new
> PreventDeleteComponentEditPolicy());
>
>
> public class PreventDeleteComponentEditPolicy extends ComponentEditPolicy
> {
> @Override
> public Command getCommand(Request request)
> {
> // If the user presses the delete key, don't delete
> if (request instanceof GroupRequestViaKeyboard &&
> RequestConstants.REQ_DELETE.equals(request.getType()))
> {
> return UnexecutableCommand.INSTANCE;
> }
>
> return super.getCommand(request);
> }
> }
>
> It should work
>
> Regards
> Govind R
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.02611 seconds