Search in sources :

Example 1 with PortletLayoutPanel

use of com.liferay.ide.layouttpl.ui.draw2d.PortletLayoutPanel in project liferay-ide by liferay.

the class PortletLayoutEditPart method refreshVisuals.

@Override
@SuppressWarnings("rawtypes")
protected void refreshVisuals() {
    super.refreshVisuals();
    GridData gd = createGridData();
    ((GraphicalEditPart) getParent()).setLayoutConstraint(this, layoutPanel, gd);
    List rows = getParent().getChildren();
    if (rows.size() == 1) {
        layoutPanel.setTop(true);
        layoutPanel.setBottom(true);
    } else if (equals(rows.get(0))) {
        layoutPanel.setTop(true);
        layoutPanel.setBottom(false);
    } else if (equals(rows.get(rows.size() - 1))) {
        layoutPanel.setTop(false);
        layoutPanel.setBottom(true);
    } else {
        layoutPanel.setTop(false);
        layoutPanel.setBottom(false);
    }
    PortletLayoutPanel panel = getCastedFigure();
    GridLayout gridLayout = (GridLayout) panel.getLayoutManager();
    List columns = getChildren();
    int numColumns = columns.size();
    if (numColumns > 0) {
        /*
			 * get width of our own part to calculate new width this method is
			 * invoked recursively, so it's complicated to compute the very
			 * exact width, sometimes minus 2 times of margin causes sidelines
			 * cannot be shown, minus 3 times of margin looks better
			 */
        IFigure parentFigure = getFigure().getParent();
        Dimension size = parentFigure.getSize();
        int rowWidth = size.width - (PortletLayoutEditPart.LAYOUT_MARGIN * 3);
        if (rowWidth > 0) {
            for (Object col : columns) {
                PortletColumnEditPart portletColumnPart = (PortletColumnEditPart) col;
                PortletColumnElement column = (PortletColumnElement) portletColumnPart.getModel();
                GridData rowData = portletColumnPart.createGridData();
                Value<Integer> weight = column.getWeight();
                Integer weightValue = weight.content();
                Value<Integer> fullWeight = column.getFullWeight();
                Integer fullWeightValue = fullWeight.content();
                double percent = weightValue.doubleValue() / fullWeightValue.doubleValue();
                int standardRowWidth = (int) (percent * rowWidth);
                rowData.widthHint = standardRowWidth - COLUMN_SPACING * 2;
                IFigure columnFigure = portletColumnPart.getFigure();
                columnFigure.setSize(rowData.widthHint, columnFigure.getSize().height);
                /*
					 * this.setLayoutConstraint( portletColumnPart,
					 * columnFigure, rowData );
					 */
                portletColumnPart.refresh();
            }
        }
        gridLayout.numColumns = numColumns;
        getFigure().repaint();
    }
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension) GridLayout(org.eclipse.draw2d.GridLayout) PortletLayoutPanel(com.liferay.ide.layouttpl.ui.draw2d.PortletLayoutPanel) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) GridData(org.eclipse.draw2d.GridData) List(java.util.List) ElementList(org.eclipse.sapphire.ElementList) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with PortletLayoutPanel

use of com.liferay.ide.layouttpl.ui.draw2d.PortletLayoutPanel in project liferay-ide by liferay.

the class PortletLayoutEditPart method createFigure.

@Override
protected IFigure createFigure() {
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.horizontalSpacing = COLUMN_SPACING;
    gridLayout.marginHeight = 0;
    gridLayout.verticalSpacing = 0;
    layoutPanel = new PortletLayoutPanel();
    layoutPanel.setOpaque(true);
    layoutPanel.setBorder(new MarginBorder(LAYOUT_MARGIN));
    layoutPanel.setBackgroundColor(new Color(null, 171, 171, 171));
    layoutPanel.setLayoutManager(gridLayout);
    return layoutPanel;
}
Also used : GridLayout(org.eclipse.draw2d.GridLayout) PortletLayoutPanel(com.liferay.ide.layouttpl.ui.draw2d.PortletLayoutPanel) MarginBorder(org.eclipse.draw2d.MarginBorder) Color(org.eclipse.swt.graphics.Color)

Aggregations

PortletLayoutPanel (com.liferay.ide.layouttpl.ui.draw2d.PortletLayoutPanel)2 GridLayout (org.eclipse.draw2d.GridLayout)2 PortletColumnElement (com.liferay.ide.layouttpl.core.model.PortletColumnElement)1 List (java.util.List)1 GridData (org.eclipse.draw2d.GridData)1 IFigure (org.eclipse.draw2d.IFigure)1 MarginBorder (org.eclipse.draw2d.MarginBorder)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 ElementList (org.eclipse.sapphire.ElementList)1 Color (org.eclipse.swt.graphics.Color)1