Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Allow Anchor to "follow" the mouse
Allow Anchor to "follow" the mouse [message #1186155] Thu, 14 November 2013 14:15 Go to next message
Eclipse User
Hi there,

I try to dynamically move a BoxRelativeAnchor on a PictogramElement. To
do that, I implemented an addMouseMoveListener, and a customFeature
executed as a dark feature.

The implementation of the addMouseMoveListener looks like this snapshot:


graphitiEditor.getGraphicalViewer().getControl().addMouseMoveListener(new MouseMoveListener() 
{

// Some code to check the object and get its BoxRelativeAnchor...
CustomContext ctx = new CustomContext();
ctx.putProperty("anchor", anchor); // anchor is the BoxRelativeAnchor
ICustomFeature[] cfs = featureProvider.getCustomFeatures(ctx);
																										for (int i = 0; i < cfs.length; i++) {
	if (cfs[i].canExecute(ctx)) {
		cfs[i].execute(ctx);
	}
}


My customFeature looks like this snapshot:

@Override
	public boolean canExecute(ICustomContext context) {
		return true; // for simplifying purpose
	}

	@Override
	public void execute(ICustomContext context) {
		IGaService gaService = Graphiti.getGaService();
		BoxRelativeAnchor anchor = (BoxRelativeAnchor) 
context.getProperty("anchor");
		// Some test to see if the anchor is updated
		anchor.setRelativeWidth(1.0);
		anchor.getGraphicsAlgorithm().setLineWidth(5);
		anchor.setVisible(false);
		System.err.println("customFeature called");
		updatePictogramElement(anchor);
		updatePictogramElement(anchor.getParent());
updatePictogramElement(anchor.getReferencedGraphicsAlgorithm().getPictogramElement());
		this.hasDoneChanges = true;
	}
	
	@Override
	public boolean hasDoneChanges() {
		return this.hasDoneChanges;
	}


The execute method is called ("customFeature called is shown every time
I moved the mouse on my pictogramElement, but any change is done, the
editor is not dirty and there is no error display. I also tried to
encapsulate the call of the execute command inside a transaction, there
is neither change or error display.

Does anybody have an idea of what I have forgotten ?

Thanks in advance,

Yours,

--
Nicolas H
Re: Allow Anchor to &quot;follow&quot; the mouse [message #1187983 is a reply to message #1186155] Fri, 15 November 2013 11:33 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1595
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Nicolas,

how do you get the anchor instance you put into the context in your mouse
listener? Could it be that you retrieve this from another editing domain
than the diagram editor uses?

Michael
Re: Allow Anchor to &quot;follow&quot; the mouse [message #1188901 is a reply to message #1187983] Fri, 15 November 2013 21:55 Go to previous messageGo to next message
Eclipse User
Le 15/11/2013 12:33, Michael Wenz a écrit :> Nicolas,
>
> how do you get the anchor instance you put into the context in your
> mouse listener? Could it be that you retrieve this from another editing
> domain than the diagram editor uses?
>
> Michael

Well, I get the mouse coordinate with the event of my mouse listener.
Then, I use Graphiti to retrieve the pictogram element like this:

final ILocationInfo info = 
Graphiti.getPeService().getLocationInfo(diagMove, e.x, e.y);
PictogramElement pe = info.getGraphicsAlgorithm().getPictogramElement();


After that, I perform some check about the flied over object.

Finally, I get my anchor with a foreach on :
Graphiti.getPeService().getAllContainedPictogramElements(pe);


I get the editingDomain with the following code:

editingDomain = graphitiEditor.getEditingDomain();


I do not see what I am wrong.

Thanks for your quick reply :)


--
Nicolas H
Re: Allow Anchor to &quot;follow&quot; the mouse [message #1194285 is a reply to message #1187983] Mon, 18 November 2013 12:35 Go to previous message
Eclipse User
Hi again,

Le 15/11/2013 12:33, Michael Wenz a écrit :
> Nicolas,
>
> how do you get the anchor instance you put into the context in your
> mouse listener? Could it be that you retrieve this from another editing
> domain than the diagram editor uses?

Okay, I think that I used another editing domain.

I get the editing domain once before adding my graphiti editor inside my
multipage editor. I don't know why, but if I retrieve the editing domain
from the graphiti editor instance, I can see my editor is dirty :

TransactionalEditingDomain editingDomain = 
graphitiEditor.getDiagramBehavior().getEditingDomain();
editingDomain.getCommandStack().execute(new 
RecordingCommand(editingDomain) {
																	
																	@Override
																	protected void doExecute() {
																		cf.execute(ctx);
																	}
																});




But, even if my editor is dirty, and my custom feature is called, there
is no diagram modification. When I save my dirty editor, I do not see
any modification on the diagram file opened in a text editor.

Any idea ?


Regards,

--
Nicolas H
Previous Topic:freely positionable labels outside of labeled shape
Next Topic:Property sheet loses memory of selection
Goto Forum:
  


Current Time: Fri Sep 19 09:54:44 GMT 2014

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

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