Search in sources :

Example 6 with LayoutTplElement

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement) LayoutTplDescriptorHelper(com.liferay.ide.layouttpl.core.operation.LayoutTplDescriptorHelper)

Example 7 with LayoutTplElement

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;
}
Also used : LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement)

Example 8 with LayoutTplElement

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();
}
Also used : LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement)

Example 9 with LayoutTplElement

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);
}
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) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) Element(org.eclipse.sapphire.Element) PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) Value(org.eclipse.sapphire.Value) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement)

Example 10 with LayoutTplElement

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;
}
Also used : Status(org.eclipse.sapphire.modeling.Status) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement)

Aggregations

LayoutTplElement (com.liferay.ide.layouttpl.core.model.LayoutTplElement)21 PortletColumnElement (com.liferay.ide.layouttpl.core.model.PortletColumnElement)10 PortletLayoutElement (com.liferay.ide.layouttpl.core.model.PortletLayoutElement)9 Test (org.junit.Test)7 IFile (org.eclipse.core.resources.IFile)5 Element (org.eclipse.sapphire.Element)3 Status (org.eclipse.sapphire.modeling.Status)2 ValidationService (org.eclipse.sapphire.services.ValidationService)2 LayoutTplDescriptorHelper (com.liferay.ide.layouttpl.core.operation.LayoutTplDescriptorHelper)1 IOException (java.io.IOException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Event (org.eclipse.sapphire.Event)1 Listener (org.eclipse.sapphire.Listener)1 Property (org.eclipse.sapphire.Property)1 Value (org.eclipse.sapphire.Value)1 IDataModel (org.eclipse.wst.common.frameworks.datamodel.IDataModel)1 IModelStateListener (org.eclipse.wst.sse.core.internal.provisional.IModelStateListener)1