Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » mouse location with a container drop tool
mouse location with a container drop tool [message #1398678] Fri, 11 July 2014 12:19 Go to next message
Benoit Ries is currently offline Benoit RiesFriend
Messages: 86
Registered: May 2013
Member
Hi,

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 ?

*****************************
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;
}
Re: mouse location with a container drop tool [message #1401976 is a reply to message #1398678] Wed, 16 July 2014 10:25 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
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 #1402681 is a reply to message #1401976] Thu, 17 July 2014 10:39 Go to previous messageGo to next message
Benoit Ries is currently offline Benoit RiesFriend
Messages: 86
Registered: May 2013
Member
Hi Maxime,

find below, further details on my need and context:

- Firstly, I create representations using the synchronized elements mode then I hide all elements in the newly created representation.

- Secondly (and here is where I use the drop tool), the user populates the representation by dragging Model Explorer view elements and dropping them in the representations. At this moment with my current code I call the reveal method from HideFilterHelper and it works well.

"HideFilterHelper.INSTANCE.reveal(myDDiagramElementRelatedToDroppedSemanticElement);"

My issue is that the element will be revealed BUT NOT at the mouse location where the element was dropped, which is what I would like !

any help on this is greatly appreciated.

regards,
Benoît

Re: mouse location with a container drop tool [message #1402818 is a reply to message #1402681] Thu, 17 July 2014 15:16 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
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
Re: mouse location with a container drop tool [message #1402929 is a reply to message #1402818] Fri, 18 July 2014 12:05 Go to previous messageGo to next message
Benoit Ries is currently offline Benoit RiesFriend
Messages: 86
Registered: May 2013
Member
thanks Steve for the mouse location code, it works Smile

I have filed a bugzilla report here :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=439877

regards,
Benoît
Re: mouse location with a container drop tool [message #1402930 is a reply to message #1402929] Fri, 18 July 2014 12:11 Go to previous message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Le 18/07/2014 14:05, Benoit Ries a écrit :
> thanks Steve for the mouse location code, it works :)
>
> I have filed a bugzilla report here :
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=439877
>
> regards,
> Benoît

Great!

Thanks for the bugzilla with the code sample. We will look into it.

Regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Reusing viewpoint descriptions
Next Topic:launch an eclipse application with an editor
Goto Forum:
  


Current Time: Tue Apr 16 15:14:10 GMT 2024

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

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

Back to the top