Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Create automatically an edge between two nodes
Create automatically an edge between two nodes [message #668607] Fri, 06 May 2011 12:10 Go to next message
nicolas h is currently offline nicolas hFriend
Messages: 60
Registered: February 2011
Location: Grenoble, France
Member
Hi there,

I want to create automatically an edge between the two nodes thanks to an action in a popup menu. I manage to get references of my two nodes and give its as parameters to my LinkCreateCommand. LinkCreateCommand::canExecute() return true, but when I try to execute the command, I got this error concerning the line "cmd.execute()" :

Quote:
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
at org.eclipse.emf.workspace.AbstractEMFOperation.inheritedOpti ons(AbstractEMFOperation.java:252)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:138)
at am.diagram.part.EncloseObjectAction.run(LinkAction.java:138)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginActi on.java:251)
...


Does anyone have an idea to fix it ?

My code :

public class LinkAction implements IObjectActionDelegate {
	private ISelection selectedElement = null;
	
	public void selectionChanged(IAction action, ISelection selection) {
		action.setEnabled(false);
		if (selection instanceof IStructuredSelection == false || selection.isEmpty()) {
			return;
		}
		selectedElement = selection;
		action.setEnabled(true);
	}
	
	public void run(IAction action) {
	
		EObject source = null;
		ArrayList<EObject> targets = new ArrayList<EObject>();
		
		if (selectedElement != null) {
			for (Iterator<Object> i = ((IStructuredSelection) selectedElement).iterator (); i.hasNext ();) {
				Object k = i.next ();
				if (k instanceof aaaEditPart)
					source = ((aaaEditPart)k).resolveSemanticElement();
				else if (k instanceof bbbEditPart)
					targets.add (((bbbEditPart)k).resolveSemanticElement ());
			}
			
			if (source != null && targets.size() > 0) {				
				CreateRelationshipRequest request = new CreateRelationshipRequest(xxxElementTypes.Link_4001);
				LinkCreateCommand cmd = new LinkCreateCommand(request , (EObject)source, (EObject)targets.get(0));
				if (cmd.canExecute()) {
					try {
						cmd.execute(new NullProgressMonitor(), null);
					} catch (ExecutionException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
	}
}


Best regards,

--
Nicolas
Re: Create automatically an edge between two nodes [message #669381 is a reply to message #668607] Tue, 10 May 2011 07:10 Go to previous message
nicolas h is currently offline nicolas hFriend
Messages: 60
Registered: February 2011
Location: Grenoble, France
Member
Hi,
I solved my issue by adding the two following lines :
request.setSource(source);
request.setTarget(targets.get(0));


It works but I've to refresh manually the editor to see the modification.

How can I refresh automatically my model and my editor please ?

Best regards,

--
Nicolas
Previous Topic:Diagram partitioning saving problem
Next Topic:Opening instance of .ecore in GMF diagram
Goto Forum:
  


Current Time: Fri Apr 26 09:14:54 GMT 2024

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

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

Back to the top