use of com.liferay.ide.layouttpl.core.model.LayoutTplElement in project liferay-ide by liferay.
the class AddLayoutTplOperation method execute.
@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
IStatus retval = null;
IDataModel dm = getDataModel();
String diagramClassName = dm.getStringProperty(LAYOUT_TEMPLATE_ID);
LayoutTplElement diagramModel = createLayoutTplDigram(dm, _isBootstrapStyle(), _is62(), diagramClassName);
try {
IFile templateFile = null;
String templateFileName = getDataModel().getStringProperty(LAYOUT_TEMPLATE_FILE);
if (!CoreUtil.isNullOrEmpty(templateFileName)) {
templateFile = createTemplateFile(templateFileName, diagramModel);
}
getDataModel().setProperty(LAYOUT_TPL_FILE_CREATED, templateFile);
String wapTemplateFileName = getDataModel().getStringProperty(LAYOUT_WAP_TEMPLATE_FILE);
diagramModel.setClassName(diagramClassName + ".wap");
if (!CoreUtil.isNullOrEmpty(wapTemplateFileName) && _is62()) {
createTemplateFile(wapTemplateFileName, diagramModel);
}
String thumbnailFileName = getDataModel().getStringProperty(LAYOUT_THUMBNAIL_FILE);
if (!CoreUtil.isNullOrEmpty(thumbnailFileName)) {
createThumbnailFile(thumbnailFileName);
}
} catch (CoreException ce) {
LayoutTplUI.logError(ce);
return LayoutTplUI.createErrorStatus(ce);
} catch (IOException ioe) {
LayoutTplUI.logError(ioe);
return LayoutTplUI.createErrorStatus(ioe);
}
LayoutTplDescriptorHelper layoutTplDescHelper = new LayoutTplDescriptorHelper(getTargetProject());
retval = layoutTplDescHelper.addNewLayoutTemplate(dm);
return retval;
}
use of com.liferay.ide.layouttpl.core.model.LayoutTplElement in project liferay-ide by liferay.
the class AddLayoutTplOperation method createLayoutTplDigram.
protected LayoutTplElement createLayoutTplDigram(IDataModel dm, boolean bootstrapStyle, boolean is62, String className) {
LayoutTplElement layoutTpl = LayoutTplElement.TYPE.instantiate();
layoutTpl.setBootstrapStyle(bootstrapStyle);
layoutTpl.setClassName(className);
layoutTpl.setIs62(is62);
if (dm.getBooleanProperty(LAYOUT_IMAGE_1_COLUMN)) {
LayoutTemplatesFactory.add_Layout_1(layoutTpl);
} else if (dm.getBooleanProperty(LAYOUT_IMAGE_1_2_I_COLUMN)) {
LayoutTemplatesFactory.add_Layout_1_2_I(layoutTpl);
} else if (dm.getBooleanProperty(LAYOUT_IMAGE_1_2_II_COLUMN)) {
LayoutTemplatesFactory.add_Layout_1_2_II(layoutTpl);
} else if (dm.getBooleanProperty(LAYOUT_IMAGE_1_2_1_COLUMN)) {
LayoutTemplatesFactory.add_Layout_1_2_1(layoutTpl);
} else if (dm.getBooleanProperty(LAYOUT_IMAGE_2_I_COLUMN)) {
LayoutTemplatesFactory.add_Layout_2_I(layoutTpl);
} else if (dm.getBooleanProperty(LAYOUT_IMAGE_2_II_COLUMN)) {
LayoutTemplatesFactory.add_Layout_2_II(layoutTpl);
} else if (dm.getBooleanProperty(LAYOUT_IMAGE_2_III_COLUMN)) {
LayoutTemplatesFactory.add_Layout_2_III(layoutTpl);
} else if (dm.getBooleanProperty(LAYOUT_IMAGE_2_2_COLUMN)) {
LayoutTemplatesFactory.add_Layout_2_2(layoutTpl);
} else if (dm.getBooleanProperty(LAYOUT_IMAGE_3_COLUMN)) {
LayoutTemplatesFactory.add_Layout_3(layoutTpl);
}
return layoutTpl;
}
use of com.liferay.ide.layouttpl.core.model.LayoutTplElement in project liferay-ide by liferay.
the class AddRowTemplateActionHandlerFactory method init.
@Override
public void init(SapphireAction action, ActionHandlerFactoryDef def) {
super.init(action, def);
LayoutTplElement layoutElement = getModelElement().nearest(LayoutTplElement.class);
Value<Boolean> bootstrapStyle = layoutElement.getBootstrapStyle();
_bootstrapStyle = bootstrapStyle.content();
}
use of com.liferay.ide.layouttpl.core.model.LayoutTplElement 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.LayoutTplElement 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;
}
Aggregations