Skip to main content


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 = 
				PlatformUI.getWorkbench().getActiveWorkbenchWindow()
				.getSelectionService();
		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(
			                    null,
			                    "Transform entities to...",
			                    "Customized Dialog",
			                    JOptionPane.PLAIN_MESSAGE,
			                    null,
			                    possibilities,
			                    "Term");
			
			
			// 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();
				MessageDialog.openInformation(
			         shell,
			         "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;
					break;
				case "Process":
					iElementType = OboroeditorElementTypes.Process_2009;
					break;
				case "Continuant":
					iElementType = OboroeditorElementTypes.Continuant_2011;
					break;
				case "Material":
					iElementType = OboroeditorElementTypes.Material_2007;
					break;
				case "Immaterial":
					iElementType = OboroeditorElementTypes.Immaterial_2008;
					break;
				default:
					iElementType = OboroeditorElementTypes.OboTerm_2016;
					break;
				}
				
					
				CreateViewRequest termRequest = CreateViewRequestFactory.getCreateShapeRequest(iElementType, gEditPart.getDiagramPreferencesHint());
				requestList.add(termRequest);
				Point p = gEditPart.getFigure().getBounds().getCenter().getCopy();
				termRequest.setLocation(p);
				
				//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
				cc.add(createTermCommand);
				
				
				 
			}
			//execute all commands and create items
			((IGraphicalEditPart)selectedElements.get(0)).getDiagramEditDomain().getDiagramCommandStack().execute(cc);
		
			
			// reorient all in/out connections and copy all attrributes to new elements
			// WHAT GOES HERE???
			
			// 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()));
			}

			
		}
		
	}

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

	@Override
	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: Wed Sep 26 01:46:43 GMT 2018

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

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

Back to the top