|
Re: mouse location with a container drop tool [message #1401976 is a reply to message #1398678] |
Wed, 16 July 2014 10:25 |
|
Le 11/07/2014 14:19, Benoit Ries a écrit :
> Hi,
Hi Benoit,
>
> I use a java external action to manage drag&drop (in a Container Drop
> tool).
>
> In the java code, I try to retrieve the mouse location. For this I use
> SiriusLayoutDataManager.INSTANCE.getData(abstractDNode);
>
> but it always returns null.
> Any idea why, see below full code ?
It seems that the SiriusLayoutDataManager si populated after the
execution of the VSM drop tool's tasks.
Could you report a bug on the bugzilla ?
However, I am not sure you should do this in the tool, could you precise
your need, because after the tool execution, the Sirius model will be
updated and then the GMF Canonical refresh will update the GMF Notation
model. So the gmfnode you want to modify in your tool could be deleted
during the canonical refresh. The SiriusLayoutDataManager is used during
this refresh to get some layout data for the new created views. Your
external java action suggest it might require some improvements if it is
not able to handle your case.
>
> *****************************
> public void execute(Collection<? extends EObject> selections,
> Map<String, Object> parameters) {
> Object diagram = parameters.get("diagram");
> Object elementToLookFor = parameters.get("element");
> if (diagram instanceof DNodeContainer) {
> DNodeContainer dNodeContainer = (DNodeContainer) diagram;
> DDiagramElement diagElt =
> lookForElementInContainerByEObject(dNodeContainer, elementToLookFor);
> if (diagElt instanceof AbstractDNode) {
> AbstractDNode abstractDNode = (AbstractDNode) diagElt;
> //retrieve mouse drop location
> LayoutData layoutData =
> SiriusLayoutDataManager.INSTANCE.getData(abstractDNode);
>
> //set view location
> View view = SiriusGMFHelper.getGmfView(abstractDNode);
> Node gmfnode = (Node) view;
> Bounds bounds = (Bounds) gmfnode.getLayoutConstraint();
> bounds.setX(layoutData.getLocation().x);
> bounds.setY(layoutData.getLocation().y);
>
> }
> return;
> }
Regards,
Maxime
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Re: mouse location with a container drop tool [message #1402818 is a reply to message #1402681] |
Thu, 17 July 2014 15:16 |
|
Hello,
Here is a way to get your mouse location:
IEditorPart editor = EclipseUIUtil.getActiveEditor();
if (editor instanceof DiagramEditor) {
DiagramEditor diagramEditor = (DiagramEditor) editor;
DiagramEditPart diagramEditPart = diagramEditor.getDiagramEditPart();
EditPartViewer viewer = diagramEditPart.getViewer();
org.eclipse.swt.graphics.Point cursorLocation = Display.getCurrent().getCursorLocation();
final FigureCanvas control = (FigureCanvas) viewer.getControl();
final org.eclipse.swt.graphics.Point screenSWTPoint = control.toControl(cursorLocation);
final Point screenPoint = new Point(screenSWTPoint.x, screenSWTPoint.y);
}
As maxime said, could you report a bug about SiriusLayoutDataManager being set too late in the context of a drag and drop tool please?
Regards,
Steve
Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04076 seconds