Initial position of nodes [message #370967] |
Tue, 28 July 2009 23:59  |
Eclipse User |
|
|
|
I have a problem with initial positioning of nodes.
In my diagram I have a couple of diagram nodes which shall be
automatically positioned at a certain default location when the diagram is
created and opened for the first time. But afterwards these nodes shall be
freely movable by the user, i.e. the user can just drag them with the
mouse to any place on the canvas.
I first thought that in the node's XXXViewFactory overwriting the
'createLayoutConstraint()' method would be solution, but that did not do
the job:
public class XXXViewFactory extends AbstractShapeViewFactory {
/**
* @generated NOT
*/
protected LayoutConstraint createLayoutConstraint() {
Bounds bounds = NotationFactory.eINSTANCE.createBounds();
bounds.setX(100);
bounds.setY(100);
bounds.setWidth(200);
bounds.setHeight(200);
return bounds;
}
Actually the above code snippet seemed to have absolutely no effect though
it definitely is getting called as I verified with a debug run.
Any ideas how to solve this and/or why the above code has absolutely no
effect?
Thanks heaps,
Thomas
|
|
|
Re: Initial position of nodes [message #372091 is a reply to message #370967] |
Wed, 29 July 2009 04:34   |
Eclipse User |
|
|
|
Hi Thomas,
In my diagram editor, I have declared a extension
org.eclipse.gmf.runtime.diagram.ui.layoutProviders with a class which
extends
org.eclipse.gmf.runtime.diagram.ui.services.layout.AbstractL ayoutNodeProvider.
Then at opening GMF Runtime call automatically my layoutProvider to
layout my nodes.
Another method : in the XXXDiagramEditorUtil.createDiagram() method
after calling createInitialModel() method you can use ViewService GMF
singleton to create Diagram and Node corresponding to your model's
elements and use LayoutConstraint and Location to position your nodes.
One example code :
MDAProject model = createInitialModel(file);
attachModelToResource(model, diagramResource);
Diagram diagram = ViewService.createDiagram(model,
MDAProjectEditPart.MODEL_ID,
MdaDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
TargetModel targetModel = model.getTargetModels().get(0);
String type = MdaVisualIDRegistry.getType(TargetModelEditPart.VISUAL_ID);
Node targetModelNode = ViewService.createNode(diagram, targetModel,
type, PreferencesHint.USE_DEFAULTS);
LayoutConstraint layoutConstraint = targetModelNode.getLayoutConstraint();
Location location = NotationFactory.eINSTANCE.createLocation();
location.setX(190);
location.setY(290); targetModelNode.setLayoutConstraint(location);
In my GMF editors it works. hope it can help you.
Thomas Spall a écrit :
> I have a problem with initial positioning of nodes.
> In my diagram I have a couple of diagram nodes which shall be
> automatically positioned at a certain default location when the diagram
> is created and opened for the first time. But afterwards these nodes
> shall be freely movable by the user, i.e. the user can just drag them
> with the mouse to any place on the canvas.
> I first thought that in the node's XXXViewFactory overwriting the
> 'createLayoutConstraint()' method would be solution, but that did not do
> the job:
>
> public class XXXViewFactory extends AbstractShapeViewFactory {
> /**
> * @generated NOT
> */
> protected LayoutConstraint createLayoutConstraint() {
> Bounds bounds = NotationFactory.eINSTANCE.createBounds();
> bounds.setX(100);
> bounds.setY(100);
> bounds.setWidth(200);
> bounds.setHeight(200);
> return bounds;
> }
>
> Actually the above code snippet seemed to have absolutely no effect
> though it definitely is getting called as I verified with a debug run.
> Any ideas how to solve this and/or why the above code has absolutely no
> effect?
>
> Thanks heaps,
> Thomas
>
|
|
|
Re: Initial position of nodes [message #420789 is a reply to message #370967] |
Thu, 30 July 2009 08:06  |
Eclipse User |
|
|
|
Hello Thomas,
This method will be called on element creation and after this appropriate
positions (where cursor is wight now) will be set to corresponding notation
model element. So, looks like your code is doing reasonable things, but leter
result of this method will be replaces by a corresponding layout constraitn
from the creation request.
I suggest you debugging node creation process to see a place where you can
use desired positions instead of the positions from the request.
-----------------
Alex Shatalin
|
|
|
Powered by
FUDForum. Page generated in 0.02446 seconds