By default, GMF strangely allows compartments to be deleted.
If we take the diagram editor built in the second tutorial, we can see that it is possible to delete a compartment by (as shown below) :
Delete form model
in the popup menu
To disable this possibility, we must edit the java class named XXXXCompartmentItemSemanticEditPolicy
of the package xxx.diagram.edit.policies
and add this method :
protected Command getSemanticCommand(IEditCommandRequest request) { if (request instanceof DestroyRequest) { return null; } return super.getSemanticCommand(request); }
It is also possible to completely disable the Delete from model
popup menu item by modyfing the method getDestroyElementCommand
of the XXXBaseEditHelper
of the package xxx.diagram.edit.helpers
like this (but this is more restrictive than the previous solution) :
/** * @generated NOT */ protected ICommand getDestroyElementCommand(DestroyElementRequest req) { return UnexecutableCommand.INSTANCE; }
I hope that this material will be helpful for you. If you want to support it, your help is welcome :
Discussion