Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Initial position of nodes
Initial position of nodes [message #370967] Wed, 29 July 2009 03:59 Go to next message
Thomas Spall is currently offline Thomas SpallFriend
Messages: 29
Registered: July 2009
Junior Member
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 08:34 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
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 12:06 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
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
Previous Topic:Resizing compartments
Next Topic:Removing Copy Pasted EditPart Child Elements
Goto Forum:
  


Current Time: Wed Apr 08 09:37:00 GMT 2020

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

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

Back to the top