Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Drop location
Drop location [message #634802] Sat, 23 October 2010 17:13 Go to next message
123star  is currently offline 123star Friend
Messages: 70
Registered: June 2010
Member
Hi,

in a Composite diagram I change the model by adding some ports to a Component and a Property inside this Component, then I try to visualize the new ports with this method:

public static void dropObject(EObject element, EObject where){
		
		DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
		dropObjectsRequest.setLocation(new Point(1, 1));
		ArrayList<Object> objectList = new ArrayList<Object>();
		objectList.add(element);
		dropObjectsRequest.setObjects(objectList);
		
		List<EditPart> eparts = getEditPart(where);
		
		org.eclipse.gef.commands.Command cmd = eparts.get(0).getCommand(dropObjectsRequest);
		
		PapyrusMultiDiagramEditor editor = (PapyrusMultiDiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		editor.getDiagramEditPart().getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
		
	}


The ports are visualized, but I have the same problem that I mentioned in my previous post: the rectangles of the ports are at the same position.

So I tried to change the location of the drop, changing:

dropObjectsRequest.setLocation(new Point(x, y));

with no results.

Why when I drop the ports manually from the model viewer they are visualized in the location of the mouse drop?
Isn't this method used in the mouse drop from the user?

Another question: I tried to drop a Connector (between a port of the Component and a port of the Property inside the Component) with the dropObject method, but doesn't work, it throws an exception; DropObjectsRequest doesn't work with Connectors?

Thanks in advance, 123star

Re: Drop location [message #634925 is a reply to message #634802] Mon, 25 October 2010 07:27 Go to previous messageGo to next message
Vincent   is currently offline Vincent Friend
Messages: 35
Registered: December 2009
Member
Hello, here are a few answers.

123star wrote on Sat, 23 October 2010 13:13

The ports are visualized, but I have the same problem that I mentioned in my previous post: the rectangles of the ports are at the same position.


By the way, have you posted a bug so that the locator handles conflicting positions as I suggested ?

123star wrote on Sat, 23 October 2010 13:13

So I tried to change the location of the drop, changing:

dropObjectsRequest.setLocation(new Point(x, y));

with no results.

Why when I drop the ports manually from the model viewer they are visualized in the location of the mouse drop?
Isn't this method used in the mouse drop from the user?


I haven't tried, but I'm pretty sure this is the correct way.
Though, the definition of a location is very often confusing betwen absolute and local locations.
So my bet is that you probably used local coordinates (relative to the target figure) whereas I think absolute coordinates shall be used (relative to the whole diagram).

I suggest you put a breakpoint at the very beginning of the method
org.eclipse.papyrus.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy.dropAffixedNode(DropObjectsRequest, Element, int)

to try and compare what the locations are in case of a manual drop and in case of a programmatic drop. You may also check that the traslation delta which is then applied later in the method is the same.

123star wrote on Sat, 23 October 2010 13:13

Another question: I tried to drop a Connector (between a port of the Component and a port of the Property inside the Component) with the dropObject method, but doesn't work, it throws an exception; DropObjectsRequest doesn't work with Connectors?


Probably a bug... There is specific code to handle this drop in the
org.eclipse.papyrus.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy.dropConnector(DropObjectsRequest, Element, int)

method. So this "should" (meaning if it doesn't, this is an unexpected behavior) work correctly. If it does not and if there is not already a bug on that subject, you may post a new bug with the complete steps to reproduce and the associated stack trace.

Best regards,
Vincent.
Re: Drop location [message #661860 is a reply to message #634925] Mon, 28 March 2011 10:18 Go to previous messageGo to next message
yangui  is currently offline yangui Friend
Messages: 2
Registered: January 2011
Junior Member
I want to visualize the ports added in the model using the method of 123star.
but I can't find "getEditPart(EObject)" used in this line
List<EditPart> eparts = getEditPart(where);


Can you help me to resolve this problem or suggest any other ideas.
Thank you in advance.
Rahma.
Re: Drop location [message #664131 is a reply to message #661860] Thu, 07 April 2011 15:01 Go to previous message
Vincent   is currently offline Vincent Friend
Messages: 35
Registered: December 2009
Member
I guess this was a method 123star implemented in his class.

If you are trying to recover the edit parts corresponding to a specific element, this can be achived in two steps :

1. recover the views referencing this element with method DiagramEditPartsUtil.getEObjectViews(EObject);

2. Find corresponding EditParts thanks to the EditPartRegistry (you can access it from any edit part or from the viewer). Views are stored as keys, and EditParts as values.
Previous Topic:How to generate Papyrus diagrams programmatically?
Next Topic:Link Lifeline to Class in Sequence Diagrams
Goto Forum:
  


Current Time: Thu Mar 28 09:05:41 GMT 2024

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

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

Back to the top