Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Create nodes and Reorient Connections programmatically
Create nodes and Reorient Connections programmatically [message #1468655] Tue, 11 November 2014 01:30
Ricardo CaWal is currently offline Ricardo CaWalFriend
Messages: 28
Registered: January 2013
Junior Member
Hey, guys!

I'm creating an Action for a pop-up menu. The expected behaviour is that it gets a selected node of the diagram and create a new node of a chosen type. After the creation, all attributes must be copied to the new node and all connections mus be reoriented. Then, the old nod must be destroyed.

I've found a way to create the new nodes and destroy the old ones, but I didn't found a way to reorient connections and copy attributes. I'm afraid I'd oversight some important concept of the GMF runtime. Can someone put me in the right tracks?

Bellow I show the action I'm implementing. Hope it helps.

Thank you for your time!

public class OboTermTransformAction implements org.eclipse.ui.IObjectActionDelegate{
	private Shell shell;
	private oboroeditor.diagram.part.OboroeditorDiagramEditor diagramEditorPart;
	private ISelection selection;
	private IAction action;
	public void run(IAction action) {
		EditingDomain editingDomain = this.diagramEditorPart.getEditingDomain();
		ISelectionService selectionService = 
		ISelection selection = selectionService.getSelection();
		if (selection instanceof IStructuredSelection) {
			// asks the user the entity type he wants
			Object[] possibilities = {"Term", "Process", "Continuant", "Material", "Immaterial"};
			String s = (String) JOptionPane.showInputDialog(
			                    "Transform entities to...",
			                    "Customized Dialog",
			// gets the selected items
			IStructuredSelection iStructuredSelection = (IStructuredSelection) selection;
			List<EditPart> selectedElements = iStructuredSelection.toList();
			// create a compound command
			CompoundCommand cc = new CompoundCommand("Change entities types to " + s);
			List<CreateViewRequest> requestList = new ArrayList<CreateViewRequest>();
			//changes every object
			for(EditPart editPart : selectedElements){
				IGraphicalEditPart gEditPart = (IGraphicalEditPart) editPart;
				List<EditPart> a = gEditPart.getViewer().getSelectedEditParts();
			         "Readme Example",
			         "Popup Menu Action executed... I hope..." + gEditPart.getModel() + a.get(0));
				// criar um request para a criação do elemento
				IElementType iElementType = null;
				switch (s) {
				case "Term":
					iElementType = OboroeditorElementTypes.OboTerm_2016;
				case "Process":
					iElementType = OboroeditorElementTypes.Process_2009;
				case "Continuant":
					iElementType = OboroeditorElementTypes.Continuant_2011;
				case "Material":
					iElementType = OboroeditorElementTypes.Material_2007;
				case "Immaterial":
					iElementType = OboroeditorElementTypes.Immaterial_2008;
					iElementType = OboroeditorElementTypes.OboTerm_2016;
				CreateViewRequest termRequest = CreateViewRequestFactory.getCreateShapeRequest(iElementType, gEditPart.getDiagramPreferencesHint());
				Point p = gEditPart.getFigure().getBounds().getCenter().getCopy();
				//create the command to create a new term
				OboOntologyEditPart diagramEditPart = (OboOntologyEditPart) gEditPart.getParent();
				Command createTermCommand = diagramEditPart.getCommand(termRequest);
				IAdaptable topicViewAdapter = (IAdaptable) ((List) termRequest.getNewObject()).get(0);
				// adds the command to be executed
			//execute all commands and create items
			// reorient all in/out connections and copy all attrributes to new elements
			// apagar os nós antigos
			for(EditPart editPart : selectedElements){
				IGraphicalEditPart gEditPart = (IGraphicalEditPart) editPart;
				List<EditPart> a = gEditPart.getViewer().getSelectedEditParts();
				editingDomain.getCommandStack().execute(RemoveCommand.create(editingDomain, gEditPart.getModel()));


	public void selectionChanged(IAction action, ISelection selection) {
		// TODO Auto-generated method stub
		this.action = action;
		this.selection = selection;

	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		this.action = action;
		this.diagramEditorPart = (oboroeditor.diagram.part.OboroeditorDiagramEditor) targetPart;
		shell = targetPart.getSite().getShell();



Previous Topic:Notation Model from Semantic model?
Next Topic:Label focus at creation time
Goto Forum:

Current Time: Mon Jan 22 12:45:26 GMT 2018

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

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