Search in sources :

Example 1 with ViewportLayout

use of org.eclipse.draw2d.ViewportLayout in project webtools.sourceediting by eclipse.

the class CategoryEditPart method createFigure.

protected IFigure createFigure() {
    outerPane = new Figure();
    outerPane.setBorder(new RoundedLineBorder(1, 6));
    createHeadingFigure();
    int minHeight = SWT.DEFAULT;
    switch(getType()) {
        case CategoryAdapter.DIRECTIVES:
            {
                minHeight = 80;
                break;
            }
        case CategoryAdapter.ATTRIBUTES:
        case CategoryAdapter.GROUPS:
            {
                minHeight = 100;
                break;
            }
    }
    final int theMinHeight = minHeight;
    ToolbarLayout outerLayout = new ToolbarLayout(false) {

        protected Dimension calculatePreferredSize(IFigure parent, int width, int height) {
            Dimension d = super.calculatePreferredSize(parent, width, height);
            d.union(new Dimension(250, theMinHeight));
            return d;
        }
    };
    outerLayout.setStretchMinorAxis(true);
    outerPane.setLayoutManager(outerLayout);
    RectangleFigure line = new RectangleFigure() {

        public Dimension getPreferredSize(int wHint, int hHint) {
            Dimension d = super.getPreferredSize(wHint, hHint);
            d.width += 20;
            d.height = 1;
            return d;
        }
    };
    ToolbarLayout lineLayout = new ToolbarLayout(false);
    lineLayout.setVertical(true);
    lineLayout.setStretchMinorAxis(true);
    line.setLayoutManager(lineLayout);
    outerPane.add(line);
    scrollpane = new ScrollPane();
    // ScrollPane.ALWAYS);
    scrollpane.setVerticalScrollBarVisibility(ScrollPane.AUTOMATIC);
    outerPane.add(scrollpane);
    Figure pane = new Figure();
    pane.setBorder(new MarginBorder(5, 8, 5, 8));
    ContainerLayout layout = new ContainerLayout();
    layout.setHorizontal(false);
    layout.setSpacing(0);
    pane.setLayoutManager(layout);
    Viewport viewport = new Viewport();
    viewport.setContentsTracksHeight(true);
    ViewportLayout viewportLayout = new ViewportLayout() {

        protected Dimension calculatePreferredSize(IFigure parent, int width, int height) {
            Dimension d = super.calculatePreferredSize(parent, width, height);
            if (theMinHeight > 0)
                d.height = Math.min(d.height, theMinHeight);
            else {
                double factor = getZoomManager().getZoom();
                // adjust for other categories and spaces
                int scaledHeight = (int) Math.round((getViewer().getControl().getBounds().height - minimumHeight) / factor);
                d.height = Math.max(250, scaledHeight);
            }
            d.width = Math.min(d.width, 300);
            return d;
        }
    };
    viewport.setLayoutManager(viewportLayout);
    scrollpane.setViewport(viewport);
    scrollpane.setContents(pane);
    return outerPane;
}
Also used : RectangleFigure(org.eclipse.draw2d.RectangleFigure) ContainerLayout(org.eclipse.wst.xsd.ui.internal.design.layouts.ContainerLayout) Viewport(org.eclipse.draw2d.Viewport) Dimension(org.eclipse.draw2d.geometry.Dimension) IFigure(org.eclipse.draw2d.IFigure) RectangleFigure(org.eclipse.draw2d.RectangleFigure) Figure(org.eclipse.draw2d.Figure) HeadingFigure(org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures.HeadingFigure) ToolbarLayout(org.eclipse.draw2d.ToolbarLayout) RoundedLineBorder(org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures.RoundedLineBorder) ScrollPane(org.eclipse.draw2d.ScrollPane) MarginBorder(org.eclipse.draw2d.MarginBorder) ViewportLayout(org.eclipse.draw2d.ViewportLayout) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

Figure (org.eclipse.draw2d.Figure)1 IFigure (org.eclipse.draw2d.IFigure)1 MarginBorder (org.eclipse.draw2d.MarginBorder)1 RectangleFigure (org.eclipse.draw2d.RectangleFigure)1 ScrollPane (org.eclipse.draw2d.ScrollPane)1 ToolbarLayout (org.eclipse.draw2d.ToolbarLayout)1 Viewport (org.eclipse.draw2d.Viewport)1 ViewportLayout (org.eclipse.draw2d.ViewportLayout)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 HeadingFigure (org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures.HeadingFigure)1 RoundedLineBorder (org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures.RoundedLineBorder)1 ContainerLayout (org.eclipse.wst.xsd.ui.internal.design.layouts.ContainerLayout)1