Getting EditPart size in Command [message #222077] |
Thu, 24 August 2006 19:45  |
Eclipse User |
|
|
|
Originally posted by: mike.aol.com
I have an editor to display a topology diagram, and it has an underlying
model (based on EMF). One of the operations I need to implement is to
create multiple edit parts and then arrange them. The problem is that
command implementation that does the arranging needs to get the size of
the edit parts. But EditPart.getFigure() returns 0 width and height
during the command execution. After the command is finished the width
and height are initialized as expected. I've tried chaining a command
for the arrange step and executing a separate command for the
add/arrange action, to no avail.
Is there a way to get an edit part's size sometime during the lifetime
of the action that creates it?
Thanks,
Mike Gering
|
|
|
|
Re: Getting EditPart size in Command [message #222131 is a reply to message #222085] |
Fri, 25 August 2006 08:11  |
Eclipse User |
|
|
|
Originally posted by: mike.aol.com
Christian,
Thanks for your suggestions. I think I have a solution, but I suspect it
is not the best one. In a little more detail:
I have an action that, when executed, performs two things: 1) it
determines the set of objects to be placed in the editor, and 2)
rearranges all nodes in the editor (using the draw2d.DirectedGraph
functions). The figures for the edit parts representing the objects are
subclasses of org.eclipse.draw2d.Label. I have an image and text for the
Labels.
When the action executes two Commands: 1) the command that creates the
edit parts and adds them to the editor, 2) the command that rearranges
the edit parts in the editor. I chain them. When the first command is
run, it causes the EditPart.createFigure() to be called. This is where I
call Label.setIcon() and Label.setText(). After initializing the Label
with these methods, the Label.getBounds() returns (0, 0, 0, 0) -- I
don't know why it doesn't reflect the size of the image and text.
When the second command to arrange the edit parts runs, the Label
figures all still have uninitialized bounds. After both commands have
finished, and the action is finished the Label figures have correctly
initialized bounds().
My solution is to use the Figure.getPreferredSize() in the arrange
command. The initialization is far enough along to return a good value.
I'm very much a newbie to GEF, so I may be misguided with this approach
to begin with.
Thanks,
Mike Gering
|
|
|
Powered by
FUDForum. Page generated in 0.03843 seconds