Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to delete Views/GraphicalEditParts from diagram programmatically?
How to delete Views/GraphicalEditParts from diagram programmatically? [message #908177] Tue, 04 September 2012 21:54 Go to next message
andrej dyck is currently offline andrej dyckFriend
Messages: 14
Registered: May 2012
Junior Member
Hello guys,

I want to delete a GraphicalEditPart (EClassEditPart) or View (GraphicalEditPart.getModel()) from a GMF diagram (not the model!), i.e., I want to execute the action "Delete from Diagram" from the context menu programmatically. I have seen, that this action creates GroupRequestViaKeyboard with RequestConstants.REQ_DELETE as parameter. So I tried the following:

import org.eclipse.emf.ecoretools.diagram.part.EcoreDiagramEditor;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
import org.eclipse.gmf.runtime.diagram.ui.requests.GroupRequestViaKeyboard;

EcoreDiagramEditor diagramEditor = ...;
IDiagramGraphicalViewer viewer = diagramEditor.getDiagramGraphicalViewer();
EClassEditPart editpart = ...; //e.g., get with viewer.findEditPartsForElement() or viewer.getEditPartRegistry()

// selecting editpart
viewer.select(editpart);

// creating the delete request
GroupRequestViaKeyboard deleteRequest = new GroupRequestViaKeyboard(RequestConstants.REQ_DELETE);
deleteRequest.setShowInformationDialog(false);

// get command
Command command = diagramEditor.getDiagramEditPart().getCommand(deleteRequest));

// execute command
diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(command);


However, I get an org.eclipse.gef.commands.UnexecutableCommand object. I debugged both the context menu (or press delete key) call and my code. The reason I get a unexecutable command, is that my code ends up in org.eclipse.gef.editpolicies.ComponentEditPolicy.getCommand() whereas the delete call get to org.eclipse.gmf.runtime.diagram.ui.editpolicies.ComponentEditPolicy.getCommand(). I do not understand why this is happening...

Is there another way to delete an element from the diagram such that the underlying model remains untouched? Please help. Thanks in advance.

Regards,
Andrej
Re: How to delete Views/GraphicalEditParts from diagram programmatically? [message #908327 is a reply to message #908177] Wed, 05 September 2012 07:11 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

you need to get the notation view from the editpart. Then you can use the EMF delete command to delete the view. This should be sufficient to delete the view and edit part.http://download.eclipse.org/modeling/emf/emf/javadoc/2.5.0/org/eclipse/emf/edit/command/RemoveCommand.html#create(org.eclipse.emf.edit.domain.EditingDomain, java.lang.Object)

Ralph
[Solved] How to delete Views/GraphicalEditParts from diagram programmatically? [message #908353 is a reply to message #908327] Wed, 05 September 2012 08:13 Go to previous message
andrej dyck is currently offline andrej dyckFriend
Messages: 14
Registered: May 2012
Junior Member
Hello Ralph,

thank you, It worked!

For whose how have not understood the post, hope this can help:

import org.eclipse.emf.edit.command.RemoveCommand;

EcoreDiagramEditor diagramEditor = ...;
IDiagramGraphicalViewer viewer = diagramEditor.getDiagramGraphicalViewer();
EClassEditPart editpart = ...; //e.g., get with viewer.findEditPartsForElement() or viewer.getEditPartRegistry()

// here the new part
EditingDomain editingDomain = diagramEditor.getEditingDomain();

editingDomain.getCommandStack().execute(RemoveCommand.create(editingDomain, editpart.getModel());


Cheers,
Andrej
Previous Topic:Change model on property change
Next Topic:NullPointerException when exiting my sample GMF editor
Goto Forum:
  


Current Time: Fri Apr 19 14:33:18 GMT 2024

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

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

Back to the top