Search in sources :

Example 1 with PortletColumnElement

use of com.liferay.ide.layouttpl.core.model.PortletColumnElement in project liferay-ide by liferay.

the class PortletColumnEditPart method createFigureForModel.

protected Figure createFigureForModel() {
    if (getModel() instanceof PortletColumnElement) {
        RoundedRectangle rect = new ColumnFigure();
        rect.setCornerDimensions(new Dimension(10, 10));
        return rect;
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) ColumnFigure(com.liferay.ide.layouttpl.ui.draw2d.ColumnFigure) Dimension(org.eclipse.draw2d.geometry.Dimension) RoundedRectangle(org.eclipse.draw2d.RoundedRectangle)

Example 2 with PortletColumnElement

use of com.liferay.ide.layouttpl.core.model.PortletColumnElement 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 3 with PortletColumnElement

use of com.liferay.ide.layouttpl.core.model.PortletColumnElement in project liferay-ide by liferay.

the class PortletColumnsListener method updateColumns.

protected int updateColumns(CanAddPortletLayouts columnsParent, int numId) {
    for (PortletLayoutElement portletLayout : columnsParent.getPortletLayouts()) {
        ElementList<PortletColumnElement> columns = portletLayout.getPortletColumns();
        int size = columns.size();
        for (int i = 0; i < size; i++) {
            PortletColumnElement column = columns.get(i);
            if (column.getPortletLayouts().size() == 0) {
                column.setNumId(String.valueOf(numId++));
            } else if (column.getPortletLayouts().size() > 0) {
                // when new child is added, the parent column will have no numId
                column.setNumId("N/A");
                numId = updateColumns(column, numId++);
            }
            column.setOnly(false);
            column.setFirst(false);
            column.setLast(false);
            column.setColumnDescriptor("");
            column.setColumnContentDescriptor("");
            if (size == 1) {
                column.setOnly(true);
                column.setColumnDescriptor("portlet-column-only");
                column.setColumnContentDescriptor("portlet-column-content-only");
            } else if (size > 1) {
                if (i == 0) {
                    column.setFirst(true);
                    column.setColumnDescriptor("portlet-column-first");
                    column.setColumnContentDescriptor("portlet-column-content-first");
                } else if (i == (size - 1)) {
                    column.setLast(true);
                    column.setColumnDescriptor("portlet-column-last");
                    column.setColumnContentDescriptor("portlet-column-content-last");
                }
            }
        }
    }
    return numId;
}
Also used : PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement)

Example 4 with PortletColumnElement

use of com.liferay.ide.layouttpl.core.model.PortletColumnElement in project liferay-ide by liferay.

the class PortletColumnsValidtionSerivce method dispose.

@Override
public void dispose() {
    for (PortletColumnElement column : _columnsAttachedListener) {
        if ((column != null) && !column.disposed()) {
            column.detach(_listener);
        }
    }
    _listener = null;
    super.dispose();
}
Also used : PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement)

Example 5 with PortletColumnElement

use of com.liferay.ide.layouttpl.core.model.PortletColumnElement in project liferay-ide by liferay.

the class LayoutTemplatesFactory method add_Row_2_I.

public static void add_Row_2_I(CanAddPortletLayouts element) {
    PortletLayoutElement row = element.getPortletLayouts().insert();
    PortletColumnElement column1 = row.getPortletColumns().insert();
    PortletColumnElement column2 = row.getPortletColumns().insert();
    int fullWeight = column1.getFullWeight().content();
    column1.setWeight(fullWeight / 2);
    column2.setWeight(fullWeight / 2);
}
Also used : PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement)

Aggregations

PortletColumnElement (com.liferay.ide.layouttpl.core.model.PortletColumnElement)23 PortletLayoutElement (com.liferay.ide.layouttpl.core.model.PortletLayoutElement)18 LayoutTplElement (com.liferay.ide.layouttpl.core.model.LayoutTplElement)9 Test (org.junit.Test)5 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Status (org.eclipse.sapphire.modeling.Status)2 ValidationService (org.eclipse.sapphire.services.ValidationService)2 ColumnFigure (com.liferay.ide.layouttpl.ui.draw2d.ColumnFigure)1 PortletLayoutPanel (com.liferay.ide.layouttpl.ui.draw2d.PortletLayoutPanel)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 GridData (org.eclipse.draw2d.GridData)1 GridLayout (org.eclipse.draw2d.GridLayout)1 IFigure (org.eclipse.draw2d.IFigure)1 RoundedRectangle (org.eclipse.draw2d.RoundedRectangle)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 Element (org.eclipse.sapphire.Element)1 ElementList (org.eclipse.sapphire.ElementList)1 Value (org.eclipse.sapphire.Value)1