[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: Custom Layout in Compartment

Hi Balthasar,
I was working on the same problem recently and this is how i solved it. As you were rightly thinking it can be solved by setting custom layout to the contentPane in createFigure() method. Using StackLayout will cause ClassCastException as the ShapeCompartmentFigure expects an XYLayout. here is the code:-


public class CompartmentEditPart extends ShapeCompartmentEditPart
{
...
...
/**
* @generated
*/
public IFigure createFigure()
{
ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
result.getContentPane().setLayoutManager(new VerticalLayout());
return result;
}


 /**
 * @generated NOT
 */
 private static class VerticalLayout extends XYLayout
 {
 @Override
 public void layout(IFigure parent)
 {
 Iterator<IFigure> fIterator = parent.getChildren().iterator();
 int y = 10;
 while (fIterator.hasNext())
   {
       IFigure figure = fIterator.next();
	int height=figure.getPreferredSize().height;
	int width=figure.getPreferredSize().width;
	figure.setBounds(new Rectangle(10, 10, width,height));
	y = y + height + 30; // Spacing of 30 between children
	}
   }
 }


}//End of Class


Hope this code comes useful to you.


cheers, Srinath