Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Preventing a node from being deleted
Preventing a node from being deleted [message #226589] Fri, 17 April 2009 14:36 Go to next message
Eclipse UserFriend
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 #226690 is a reply to message #226589] Mon, 20 April 2009 12:06 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Artur,

Are you sure you'v modified xxxSemanticEditPolicy#getDestroyElementCommand
for the element itself (not it's parent?) tru return unexecutable command
from there instead of null..

-----------------
Alex Shatalin
Re: Preventing a node from being deleted [message #227045 is a reply to message #226690] Wed, 22 April 2009 15:47 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
I tried your suggestion too, and
/**
* @generated NOT
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
return UnexecutableCommand.INSTANCE;
}
does the trick - almost.

"Delete from Model" in the right-click-menu is disabled as expected (as is
"Delete from Diagram").
Pressing DEL-button removes the node from the diagram though, while not
removing it from the model as it did before the change.
Re: Preventing a node from being deleted [message #227408 is a reply to message #227045] Sat, 25 April 2009 09:16 Go to previous messageGo to next message
govind Ra is currently offline govind RaFriend
Messages: 95
Registered: July 2009
Member
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 Go to previous messageGo to next message
Eclipse UserFriend
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
>
Re: Preventing a node from being deleted [message #489144 is a reply to message #228431] Thu, 01 October 2009 15:49 Go to previous message
ps  is currently offline ps Friend
Messages: 16
Registered: July 2009
Junior Member
Hi there,
Followed this thread, I've successfully disabled the Delete menu item. However when I press the "Del" key, my node is still get deleted. I also tried the above suggestion about adding a PreventDeleteComponentEditPolicy, still no use. Are there any other suggestions?

Thanks in advance!
Paul
Previous Topic:Trying to try out 2.2.1 update site errors
Next Topic:Find ConnectionEditPart for corresponding EObject
Goto Forum:
  


Current Time: Fri Apr 26 10:50:46 GMT 2024

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

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

Back to the top