Search in sources :

Example 16 with PortletColumnElement

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

the class PortletColumnWeightValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    PortletColumnElement portletColumn = context(PortletColumnElement.class);
    int weight = portletColumn.getWeight().content();
    LayoutTplElement layoutTpl = portletColumn.nearest(LayoutTplElement.class);
    if (layoutTpl != null) {
        if (layoutTpl.getBootstrapStyle().content()) {
            if ((weight <= 0) || (weight > 12)) {
                retval = Status.createErrorStatus("The weight value is invalid, should be in (0, 12]");
            }
        } else {
            if ((weight <= 0) || (weight > 100)) {
                retval = Status.createErrorStatus("The weight value is invalid, should be in (0, 100]");
            }
        }
    }
    return retval;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement)

Example 17 with PortletColumnElement

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

the class PortletColumnsValidtionSerivce method compute.

// store PortletColumns who have attached the listener
@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    PortletLayoutElement portletLayout = context(PortletLayoutElement.class);
    LayoutTplElement layoutTpl = portletLayout.nearest(LayoutTplElement.class);
    int actualWeightSum = 0;
    int exceptedweightSum = layoutTpl.getBootstrapStyle().content() ? 12 : 100;
    for (PortletColumnElement col : portletLayout.getPortletColumns()) {
        /*
			 * attach listener for the newly added PortletColumn there should be a better
			 * way to do this which makes more sense
			 */
        if (!_columnsAttachedListener.contains(col)) {
            col.getWeight().attach(_listener);
            _columnsAttachedListener.add(col);
        }
        Value<Integer> weight = col.getWeight();
        Integer content = weight.content();
        actualWeightSum += content.intValue();
    }
    if (!((actualWeightSum == exceptedweightSum) || ((exceptedweightSum == 100) && (actualWeightSum == 99)))) {
        retval = Status.createErrorStatus("The sum of weight of columns should be: " + exceptedweightSum);
    }
    return retval;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement)

Example 18 with PortletColumnElement

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

the class LayoutTplTestsBootstrap method createModel_132_nest.

protected LayoutTplElement createModel_132_nest(boolean isBootstrapStyle, String className, boolean is62) {
    final LayoutTplElement layoutTpl = LayoutTplElement.TYPE.instantiate();
    layoutTpl.setBootstrapStyle(isBootstrapStyle);
    layoutTpl.setClassName(className);
    layoutTpl.setIs62(is62);
    final PortletLayoutElement row1 = layoutTpl.getPortletLayouts().insert();
    final PortletColumnElement column11 = row1.getPortletColumns().insert();
    column11.setWeight(12);
    final PortletLayoutElement row2 = layoutTpl.getPortletLayouts().insert();
    final PortletColumnElement column21 = row2.getPortletColumns().insert();
    column21.setWeight(4);
    final PortletColumnElement column22 = row2.getPortletColumns().insert();
    column22.setWeight(4);
    final PortletColumnElement column23 = row2.getPortletColumns().insert();
    column23.setWeight(4);
    final PortletLayoutElement row3 = layoutTpl.getPortletLayouts().insert();
    final PortletColumnElement column31 = row3.getPortletColumns().insert();
    column31.setWeight(8);
    final PortletLayoutElement row311 = column31.getPortletLayouts().insert();
    final PortletColumnElement column3111 = row311.getPortletColumns().insert();
    column3111.setWeight(12);
    final PortletLayoutElement row312 = column31.getPortletLayouts().insert();
    final PortletColumnElement column3121 = row312.getPortletColumns().insert();
    column3121.setWeight(6);
    final PortletColumnElement column3122 = row312.getPortletColumns().insert();
    column3122.setWeight(6);
    final PortletLayoutElement row31221 = column3122.getPortletLayouts().insert();
    final PortletColumnElement column312211 = row31221.getPortletColumns().insert();
    column312211.setWeight(12);
    final PortletColumnElement column32 = row3.getPortletColumns().insert();
    column32.setWeight(4);
    return layoutTpl;
}
Also used : PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement)

Example 19 with PortletColumnElement

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

the class LayoutTplTestsBootstrap method testPorteltColumnWeightValidationService.

@Test
public void testPorteltColumnWeightValidationService() {
    final LayoutTplElement layoutTpl = LayoutTplElement.TYPE.instantiate();
    layoutTpl.setBootstrapStyle(true);
    final PortletLayoutElement row = layoutTpl.getPortletLayouts().insert();
    final PortletColumnElement column = row.getPortletColumns().insert();
    final ValidationService validationService = column.getWeight().service(ValidationService.class);
    column.setWeight(0);
    assertEquals("The weight value is invalid, should be in (0, 12]", validationService.validation().message());
    column.setWeight(-1);
    assertEquals("The weight value is invalid, should be in (0, 12]", validationService.validation().message());
    column.setWeight(13);
    assertEquals("The weight value is invalid, should be in (0, 12]", validationService.validation().message());
    column.setWeight(6);
    assertEquals("ok", validationService.validation().message());
}
Also used : PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) ValidationService(org.eclipse.sapphire.services.ValidationService) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement) Test(org.junit.Test)

Example 20 with PortletColumnElement

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

the class LayoutTplTestsBootstrap method testPortletColumnsValidationSerive.

// test sum of column weights
@Test
public void testPortletColumnsValidationSerive() {
    final LayoutTplElement layoutTpl = LayoutTplElement.TYPE.instantiate();
    layoutTpl.setBootstrapStyle(true);
    final PortletLayoutElement row = layoutTpl.getPortletLayouts().insert();
    final ElementList<PortletColumnElement> columns = row.getPortletColumns();
    final PortletColumnElement column = columns.insert();
    final ValidationService validationService = columns.service(ValidationService.class);
    assertEquals("ok", validationService.validation().message());
    column.setWeight(0);
    assertEquals("The sum of weight of columns should be: 12", validationService.validation().message());
    column.setWeight(-1);
    assertEquals("The sum of weight of columns should be: 12", validationService.validation().message());
    column.setWeight(6);
    assertEquals("The sum of weight of columns should be: 12", validationService.validation().message());
    column.setWeight(13);
    assertEquals("The sum of weight of columns should be: 12", validationService.validation().message());
    column.setWeight(12);
    assertEquals("ok", validationService.validation().message());
}
Also used : PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) ValidationService(org.eclipse.sapphire.services.ValidationService) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement) Test(org.junit.Test)

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