[GEF] [Zest] problem with layouts to GEF and setLocation [message #245748] |
Fri, 10 October 2008 10:18 |
Tristan Faure Messages: 460 Registered: July 2009 |
Senior Member |
|
|
Hi I'm working on a plugin designed to apply layouts on gef diagrams and
i'm a gef newbie :(
I want to permit users to select a container and all elements inside
will be moved with zest layout information
first if this kind of plugin exists already please stop me now x/
second I success to get the edit part from the selection
for each node and connection I create an entities collection and a
relations collection and i apply the layout but the results are not very
pretty
my code is bellow if anybody can see maybe i did something wrong :/
my problem is when I apply the new locations on object my graph is
modified but when i select one element the others set location to their
previous location :/
before layout after layout I select X
----------- ----------- -----------
| | | | | |
|X | |X Y | |X |
| | | | | |
|Y | | | |Y |
----------- ----------- -----------
to modify my location i do :
part.getFigure().setLocation(new
Point((int)theNode.getX(),(int)theNode.getY()));
do you know what is my problem ? is it a edit policy problem :( ???
In my example i used topcased gef editor if it can helps
Thank you !
Collection<LayoutEntity> entities = new LinkedList<LayoutEntity>();
Collection<LayoutRelationship> relations = new
LinkedList<LayoutRelationship>();
AbstractGraphicalEditPart root = node ;
for (Object o : node.getChildren())
{
if (o instanceof AbstractGraphicalEditPart)
{
AbstractGraphicalEditPart n =
(AbstractGraphicalEditPart) o;
SimpleNode sn = getLayoutNode(entities, n);
sn.setLocation(n.getFigure().getBounds().x,
n.getFigure().getBounds().y);
for (Object e : n.getSourceConnections()){
if (e instanceof ConnectionEditPart)
{
ConnectionEditPart c = (ConnectionEditPart) e ;
SimpleNode source = getLayoutNode(entities,
c.getTarget());
SimpleRelationship r = new
SimpleRelationship(source,sn,false);
relations.add(r);
}
}
for (Object e : n.getTargetConnections()){
if (e instanceof ConnectionEditPart)
{
ConnectionEditPart c = (ConnectionEditPart) e ;
SimpleNode target = getLayoutNode(entities,
c.getSource());
SimpleRelationship r = new
SimpleRelationship(sn,target,false);
relations.add(r);
}
}
entities.add(sn);
}
}
try
{
// getAlgorithm takes a zest algo with environment preferences
getAlgorithm().addProgressListener(this);
getAlgorithm().applyLayout((LayoutEntity[])
entities.toArray(new LayoutEntity[0]),relations.toArray(new
LayoutRelationship[0]), root.getFigure().getBounds().x,
root.getFigure().getBounds().y, root.getFigure().getBounds().width,
root.getFigure().getBounds().height, true, false);
while (getAlgorithm().isRunning())
{
try
{
Thread.currentThread().sleep(10);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
for (LayoutEntity l : entities)
{
try {
SimpleNode theNode = (SimpleNode) l ;
AbstractGraphicalEditPart part =
(AbstractGraphicalEditPart) theNode.getRealObject();
part.getFigure().setLocation(new
Point((int)theNode.getX(),(int)theNode.getY()));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
catch (InvalidLayoutConfiguration e)
{
e.printStackTrace();
}
|
|
|
Re: [GEF] [Zest] problem with layouts to GEF and setLocation [message #245777 is a reply to message #245748] |
Tue, 14 October 2008 11:52 |
Eclipse User |
|
|
|
Originally posted by: shady_86.sify.com
<i>my problem is when I apply the new locations on object my graph is
modified but when i select one element the others set location to their previous location</i>
the reason for this is you are trying to set the location of the figure and not updating the model... so when you set the location it is set but later the refresh visuals is called and the location contained by your model overrides the current location...
so try to set the location in your model, for better results..,
|
|
|
|
Re: [GEF] [Zest] problem with layouts to GEF and setLocation [message #245791 is a reply to message #245782] |
Tue, 14 October 2008 20:24 |
Eclipse User |
|
|
|
Originally posted by: shady_86.sify.com
> sharad a écrit :
> > <i>my problem is when I apply the new locations on
> object my graph is
> > modified but when i select one element the others
> set location to their previous location</i>
> >
> > the reason for this is you are trying to set the
> location of the figure and not updating the model...
> so when you set the location it is set but later the
> refresh visuals is called and the location contained
> by your model overrides the current location...
> > so try to set the location in your model, for
> better results..,
>
> Thank you for your answer i've seen the model notion
> but how i can get
> it from a part ?
its very simple you need EditPart.getModel() this will return the model of your part which you might have set while creating the part in the factory
|
|
|
transparent FigureCanvas [message #246052 is a reply to message #245777] |
Mon, 03 November 2008 14:32 |
Eclipse User |
|
|
|
Originally posted by: michael.jurke.justinmind.com
Hello,
I wanted to use the GEF framework to manipulate some underlaying grafics
and for this using a transparent FigureCanvas.
Well, it took me hours to change the API (only because everything to
change is private or package), creating a own MyFigureCanvas (because it
has the method checkStyles that does not permit SWT.TRANSPARENT),
MyScrollingGraphicalViewer etc. and finally it worked out perfectly.
I just wonder why there are so many restriction. Do I have to expect
platform depency issues o other problems?
From GEF's side, it is planned to offer an alternative canvas with
transparent feature?
Greetings,
M. Jurke
|
|
|
Powered by
FUDForum. Page generated in 0.03478 seconds