use of com.liferay.ide.layouttpl.core.model.PortletLayoutElement in project liferay-ide by liferay.
the class LayoutTemplatesFactory method add_Layout_1_2_I.
public static void add_Layout_1_2_I(LayoutTplElement layoutTpl) {
PortletLayoutElement row1 = layoutTpl.getPortletLayouts().insert();
PortletColumnElement column11 = row1.getPortletColumns().insert();
column11.setWeight(column11.getFullWeight().content());
PortletLayoutElement row2 = layoutTpl.getPortletLayouts().insert();
PortletColumnElement column21 = row2.getPortletColumns().insert();
PortletColumnElement column22 = row2.getPortletColumns().insert();
if (_isBootstrapStyle(layoutTpl)) {
column21.setWeight(4);
column22.setWeight(8);
} else {
column21.setWeight(30);
column22.setWeight(70);
}
}
use of com.liferay.ide.layouttpl.core.model.PortletLayoutElement in project liferay-ide by liferay.
the class PortletColumnWeightInitialValueService method compute.
@Override
protected String compute() {
PortletColumnElement column = (PortletColumnElement) context(Element.class);
PortletLayoutElement parentLayout = column.nearest(PortletLayoutElement.class);
LayoutTplElement layoutTpl = column.nearest(LayoutTplElement.class);
int weightSum = 0;
ElementList<PortletColumnElement> portletColumns = parentLayout.getPortletColumns();
for (PortletColumnElement col : portletColumns) {
if (col != column) {
Value<Integer> colWeight = col.getWeight();
Integer colWeightContent = colWeight.content();
weightSum += colWeightContent.intValue();
}
}
Value<Integer> columnFullWeight = column.getFullWeight();
Integer fullWeightContent = columnFullWeight.content();
int fullWeight = fullWeightContent.intValue();
int initialWeight = layoutTpl.getBootstrapStyle().content() ? 3 : 25;
if ((weightSum >= 0) && (weightSum < fullWeight)) {
initialWeight = fullWeight - weightSum;
} else if (weightSum == fullWeight) {
/*
* the index of last valid column is portletColumns.size() - 2, because
* portletColumns().size() -1 is the new inserted column
*/
PortletColumnElement lastValidColumn = portletColumns.get(portletColumns.size() - 2);
Value<Integer> lvColumnWeight = lastValidColumn.getWeight();
Integer lvWeightContent = lvColumnWeight.content();
int lastValidWeight = lvWeightContent.intValue();
if (lastValidWeight > 1) {
initialWeight = lastValidWeight / 2;
lastValidWeight = lastValidWeight - initialWeight;
lastValidColumn.setWeight(lastValidWeight);
}
}
return String.valueOf(initialWeight);
}
use of com.liferay.ide.layouttpl.core.model.PortletLayoutElement 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.PortletLayoutElement 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.PortletLayoutElement 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());
}
Aggregations