Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Position of the elements
Position of the elements [message #468282] Tue, 04 August 2009 20:22 Go to next message
Filip Sebesta is currently offline Filip SebestaFriend
Messages: 26
Registered: July 2009
Junior Member
Where is stored the position of an element on canvas. I mean a x and
y-line of the element?

Thanks
Re: Position of the elements [message #468323 is a reply to message #468282] Wed, 05 August 2009 05:40 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
It's in XxxEditPart:
getPrimaryShape().getBounds()

> Where is stored the position of an element on canvas. I mean a x and
> y-line of the element?
Re: Position of the elements [message #468375 is a reply to message #468282] Wed, 05 August 2009 10:19 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Filip,

See org.eclipse.gmf.runtime.notation.Node.getLayoutConstraint().

-----------------
Alex Shatalin
Re: Position of the elements [message #468478 is a reply to message #468375] Wed, 05 August 2009 15:49 Go to previous messageGo to next message
Filip Sebesta is currently offline Filip SebestaFriend
Messages: 26
Registered: July 2009
Junior Member
Thanks!! I tried something, but it does not work properly. I have got
EditPart class from my Canvas. It is called GraphEditPart and I want to
get information about the position of elements (nodes) on the canvas
because of drawing something depending just on the position. I made a
method in GraphEditPart which looks following:

public class GraphEditPart extends DiagramEditPart {

Graph graph = (Graph) ((View) this.getModel())
.getElement();

[generic code........]


private void showPositions(){

EList<Network_Node> nodes;
nodes = graph.getNodes();
for (Network_Node node : nodes) {

org.eclipse.gmf.runtime.notation.Node node2 =
(org.eclipse.gmf.runtime.notation.Node) node;
LayoutConstraint constraint = node2.getLayoutConstraint();

int x = ((Bounds) constraint).getX();
int y = ((Bounds) constraint).getY();

System.out.println(x + "," + y);

}
}

but when I call this method, it throw an error :
application.impl.NodeImpl cannot be cast to
org.eclipse.gmf.runtime.notation.Node
Re: Position of the elements [message #478269 is a reply to message #468478] Thu, 06 August 2009 08:58 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Filip,

instead of
> Graph graph = (Graph) ((View) this.getModel())
> .getElement();

try:
> View rootView = (View) this.getModel();
then call view.getChildren() to pass through child nodes.

-----------------
Alex Shatalin
Re: Position of the elements [message #478685 is a reply to message #478269] Thu, 06 August 2009 12:15 Go to previous messageGo to next message
Filip Sebesta is currently offline Filip SebestaFriend
Messages: 26
Registered: July 2009
Junior Member
Hello Alex,

thanks for advice. I have tried this but still the same error.
Re: Position of the elements [message #480534 is a reply to message #478685] Mon, 17 August 2009 14:43 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Filip,

> thanks for advice. I have tried this but still the same error.
application.impl.NodeImpl cannot be cast to org.eclipse.gmf.runtime.notation.Node
?...

-----------------
Alex Shatalin
Re: Position of the elements [message #480595 is a reply to message #480534] Mon, 17 August 2009 18:57 Go to previous messageGo to next message
Filip Sebesta is currently offline Filip SebestaFriend
Messages: 26
Registered: July 2009
Junior Member
yes this error
Re: Position of the elements [message #480796 is a reply to message #480595] Tue, 18 August 2009 14:10 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Filip,

I meant try:

View rootView = (View) this.getModel();
Collection<View> children = rootView.getChildren();
for (View view : children) {
org.eclipse.gmf.runtime.notation.Node node = (org.eclipse.gmf.runtime.notation.Node)
view;
LayoutConstraint constraint = node.getLayoutConstraint();

int x = ((Bounds) constraint).getX();
int y = ((Bounds) constraint).getY();
System.out.println(x + "," + y);
}

-----------------
Alex Shatalin
Re: Position of the elements [message #481778 is a reply to message #480796] Mon, 24 August 2009 09:52 Go to previous message
Filip Sebesta is currently offline Filip SebestaFriend
Messages: 26
Registered: July 2009
Junior Member
Thanks!! It works. But now I need to get not all elements bounds, but just
specific nodes bounds. Another point is that I need to get attributes from
NodemImpl.java class. So I need to get position of a node and attribute
together.
Previous Topic:Registering Ecore metamodel.
Next Topic:Resize constraint for nodes with children
Goto Forum:
  


Current Time: Fri Apr 26 00:05:08 GMT 2024

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

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

Back to the top