Skip to main content



      Home
Home » Modeling » EMF » Disallow deletion of a node in the tree
Disallow deletion of a node in the tree [message #412041] Wed, 15 August 2007 14:49 Go to next message
Eclipse UserFriend
I have modified my factory to automatically add two child nodes to a node in the editor. Now I want to disable the ability to delete these two nodes. I originally changed the model implementation so that set would immediately return on a null input. This works but I have visual side affects such as the selection changing to the parent and the save dialog coming up on close eventhough the model didn't change.

I'd like for the Delete command on the right-click menu to be disabled for these nodes in the tree and for the delete key to do nothing when pressed. Where can I check the selected node and selectively enable/disable the delete action in the generated code?
Re: Disallow deletion of a node in the tree [message #412042 is a reply to message #412041] Wed, 15 August 2007 14:52 Go to previous messageGo to next message
Eclipse UserFriend
Ben,

I think you should specialize the set command or the remove command to
created for the parent in this/these situations to be unexecutable commands.


ben dixon wrote:
> I have modified my factory to automatically add two child nodes to a node in the editor. Now I want to disable the ability to delete these two nodes. I originally changed the model implementation so that set would immediately return on a null input. This works but I have visual side affects such as the selection changing to the parent and the save dialog coming up on close eventhough the model didn't change.
>
> I'd like for the Delete command on the right-click menu to be disabled for these nodes in the tree and for the delete key to do nothing when pressed. Where can I check the selected node and selectively enable/disable the delete action in the generated code?
>
Re: Disallow deletion of a node in the tree [message #412163 is a reply to message #412042] Thu, 16 August 2007 12:36 Go to previous messageGo to next message
Eclipse UserFriend
I think I'm still missing something about how to get this working. I overrode

protected Command createRemoveCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Collection<?> collection)

In my CustomItemProviderAdapter and checked the owner and feature to be created:

if(owner instanceof SetProperty && feature == GenoaPackage.eINSTANCE.getSetProperty_PropertyPath1()){
return new NullCommand();
}

NullCommand extends AbstractCommand and is defined as an innerclass that does nothing for the interface methods. I did this because I couldn't return null, thinking that if the command did nothing then the node wouldn't be deleted.

In the debugger I can see that the if statement is satisfied and the NullCommand is returned but there is no difference in the behavior of the editor. The node is deleted just as it was before.

I had originally put the code in the createSetCommand(...) with the same result. Any other pointers to help me get this working?
Re: Disallow deletion of a node in the tree [message #412168 is a reply to message #412163] Thu, 16 August 2007 15:42 Go to previous messageGo to next message
Eclipse UserFriend
Ben,

Maybe try returning UnexecutableCommand.INSTANCE. This feature is
multi-valued right. I would have expect this to be in
SetPropertyItemProvider so you wouldn't need an instanceof check.
Accessing GenoPackage.Literals.SET_PROPERTY__PROPERTY_PATH1 might be
better too...


ben dixon wrote:
> I think I'm still missing something about how to get this working. I overrode
>
> protected Command createRemoveCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Collection<?> collection)
>
> In my CustomItemProviderAdapter and checked the owner and feature to be created:
>
> if(owner instanceof SetProperty && feature == GenoaPackage.eINSTANCE.getSetProperty_PropertyPath1()){
> return new NullCommand();
> }
>
> NullCommand extends AbstractCommand and is defined as an innerclass that does nothing for the interface methods. I did this because I couldn't return null, thinking that if the command did nothing then the node wouldn't be deleted.
>
> In the debugger I can see that the if statement is satisfied and the NullCommand is returned but there is no difference in the behavior of the editor. The node is deleted just as it was before.
>
> I had originally put the code in the createSetCommand(...) with the same result. Any other pointers to help me get this working?
>
Re: Disallow deletion of a node in the tree [message #412169 is a reply to message #412163] Thu, 16 August 2007 16:13 Go to previous messageGo to next message
Eclipse UserFriend
After some time in the debugger tracing through how things get from the editor to the model, I found a solution to my problem.

I ended up overriding init(IActionBars actionBars) in XyzActionBarContributor and creating two new Actions. One extending DeleteAction and the other extending CutAction. In the createCommand(Collection<?> selection) of each of these I check for the types of objects I want to make undeletable and if found return UnexecutableCommand.INSTANCE.

This has the effect of disabling the Delete action in the menu.

Though it works, I question whether this is the best approach to solving the problem.
Re: Disallow deletion of a node in the tree [message #412170 is a reply to message #412169] Thu, 16 August 2007 16:29 Go to previous message
Eclipse UserFriend
Ben,

Specializing the appropriate command creation in the item provider seems
better in general, but whatever works makes you happy I'm sure...


ben dixon wrote:
> After some time in the debugger tracing through how things get from the editor to the model, I found a solution to my problem.
>
> I ended up overriding init(IActionBars actionBars) in XyzActionBarContributor and creating two new Actions. One extending DeleteAction and the other extending CutAction. In the createCommand(Collection<?> selection) of each of these I check for the types of objects I want to make undeletable and if found return UnexecutableCommand.INSTANCE.
>
> This has the effect of disabling the Delete action in the menu.
>
> Though it works, I question whether this is the best approach to solving the problem.
>
Previous Topic:Dynamically loading model specific code from within generated code.
Next Topic:JMerge Support for Java5 Annotations
Goto Forum:
  


Current Time: Wed Nov 05 10:51:31 EST 2025

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

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

Back to the top