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;
}
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;
}
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;
}
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());
}
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());
}
Aggregations