[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.gmf] Re: Custom Layout in Compartment
|
- From: Balthasar Weitzel <balthasar@xxxxxx>
- Date: Thu, 18 Jun 2009 22:03:02 +0200
- Newsgroups: eclipse.modeling.gmf
- Organization: EclipseCorner
- User-agent: Thunderbird 2.0.0.21 (Windows/20090302)
Hi Alex, Sven and Srinath,
thanks a lot for your suggestions. Finally I found a solution using all
of them:
Instead of using the ShapeCompartmentEditPart I directly used the
ResizableCompartmentEditPart, copied what I need from
ShapeCompartmentEditPart and customized it so that it has the right
LayoutEditPolicy and the right Figures.
Furthermore I let my own layout extend XYLayout.
The complete solution:
public class MyCompartmentEditPart extends ResizableCompartmentEditPart{
...
public IFigure createFigure() {
ResizableCompartmentFigure rcf;
if (getParent() == getTopGraphicEditPart()){
rcf = (ResizableCompartmentFigure) super.createFigure();
} else {
rcf = new NestedResizableCompartmentFigure(getMapMode());
}
rcf.getContentPane().setLayoutManager(new MyLayoutManager());
return rcf;
}
...
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicy.LAYOUT_ROLE,
new MyLayoutEditPolicy());
}
}
My custom layout is a bit large, it arranges the children in a grid. For
anyone who wants to do a custom layout in a compartment, too:
Take the XYLayout as a basis and look how calculatePreferredSize(..) and
layout(..) is done there. At first I made the mistake that I did not use
the constraints that the layout stores and directly called
child.getPreferredSize(..). This returns much too big values, because an
other layout manager of the child then tries to use the complete space.
Again, thank you all for your help, finally I got it working :-)
Cheers,
Balthasar