Allow Anchor to "follow" the mouse [message #1186155] |
Thu, 14 November 2013 14:15 |
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 "follow" the mouse [message #1188901 is a reply to message #1187983] |
Fri, 15 November 2013 21:55 |
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 "follow" the mouse [message #1194285 is a reply to message #1187983] |
Mon, 18 November 2013 12:35 |
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
|
|
|
Powered by
FUDForum. Page generated in 0.02481 seconds