Search in sources :

Example 36 with GuiDevelopmentException

use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.

the class AbstractTableLoader method loadAggregation.

protected void loadAggregation(Table.Column column, Element columnElement) {
    Element aggregationElement = columnElement.element("aggregation");
    if (aggregationElement != null) {
        final AggregationInfo aggregation = new AggregationInfo();
        aggregation.setPropertyPath((MetaPropertyPath) column.getId());
        String aggregationType = aggregationElement.attributeValue("type");
        if (StringUtils.isNotEmpty(aggregationType)) {
            aggregation.setType(AggregationInfo.Type.valueOf(aggregationType));
        }
        String valueDescription = aggregationElement.attributeValue("valueDescription");
        if (StringUtils.isNotEmpty(valueDescription)) {
            column.setValueDescription(loadResourceString(valueDescription));
        }
        Formatter formatter = loadFormatter(aggregationElement);
        aggregation.setFormatter(formatter == null ? column.getFormatter() : formatter);
        column.setAggregation(aggregation);
        String strategyClass = aggregationElement.attributeValue("strategyClass");
        if (StringUtils.isNotEmpty(strategyClass)) {
            Class<?> aggregationClass = scripting.loadClass(strategyClass);
            if (aggregationClass == null) {
                throw new GuiDevelopmentException(String.format("Class %s is not found", strategyClass), context.getFullFrameId());
            }
            try {
                AggregationStrategy customStrategy = (AggregationStrategy) aggregationClass.newInstance();
                aggregation.setStrategy(customStrategy);
            } catch (Exception e) {
                throw new RuntimeException("Unable to instantiate strategy for aggregation", e);
            }
        }
        if (aggregationType == null && strategyClass == null) {
            throw new GuiDevelopmentException("Incorrect aggregation - type or strategyClass is required", context.getFullFrameId());
        }
    }
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) AggregationStrategy(com.haulmont.cuba.gui.data.aggregation.AggregationStrategy)

Example 37 with GuiDevelopmentException

use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.

the class AbstractTableLoader method loadColumn.

protected Table.Column loadColumn(Element element, Datasource ds) {
    String id = element.attributeValue("id");
    MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class).resolveMetaPropertyPath(ds.getMetaClass(), id);
    Table.Column column = new Table.Column(metaPropertyPath != null ? metaPropertyPath : id);
    String editable = element.attributeValue("editable");
    if (StringUtils.isNotEmpty(editable)) {
        column.setEditable(Boolean.parseBoolean(editable));
    }
    String collapsed = element.attributeValue("collapsed");
    if (StringUtils.isNotEmpty(collapsed)) {
        column.setCollapsed(Boolean.parseBoolean(collapsed));
    }
    String groupAllowed = element.attributeValue("groupAllowed");
    if (StringUtils.isNotEmpty(groupAllowed)) {
        column.setGroupAllowed(Boolean.parseBoolean(groupAllowed));
    }
    String sortable = element.attributeValue("sortable");
    if (StringUtils.isNotEmpty(sortable)) {
        column.setSortable(Boolean.parseBoolean(sortable));
    }
    loadCaption(column, element);
    loadDescription(column, element);
    if (column.getCaption() == null) {
        String columnCaption;
        if (column.getId() instanceof MetaPropertyPath) {
            MetaPropertyPath mpp = (MetaPropertyPath) column.getId();
            MetaProperty metaProperty = mpp.getMetaProperty();
            String propertyName = metaProperty.getName();
            if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
                CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
                columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ? categoryAttribute.getLocaleName() : StringUtils.capitalize(categoryAttribute.getName());
            } else {
                MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(mpp);
                columnCaption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
            }
        } else {
            Class<?> declaringClass = ds.getMetaClass().getJavaClass();
            String className = declaringClass.getName();
            int i = className.lastIndexOf('.');
            if (i > -1)
                className = className.substring(i + 1);
            columnCaption = messages.getMessage(declaringClass, className + "." + id);
        }
        column.setCaption(columnCaption);
    }
    column.setXmlDescriptor(element);
    if (metaPropertyPath != null)
        column.setType(metaPropertyPath.getRangeJavaClass());
    String width = loadThemeString(element.attributeValue("width"));
    if (!StringUtils.isBlank(width)) {
        if (StringUtils.endsWith(width, "px")) {
            width = StringUtils.substring(width, 0, width.length() - 2);
        }
        try {
            column.setWidth(Integer.parseInt(width));
        } catch (NumberFormatException e) {
            throw new GuiDevelopmentException("Property 'width' must contain only numeric value", context.getCurrentFrameId(), "width", element.attributeValue("width"));
        }
    }
    String align = element.attributeValue("align");
    if (StringUtils.isNotBlank(align)) {
        column.setAlignment(Table.ColumnAlignment.valueOf(align));
    }
    column.setFormatter(loadFormatter(element));
    loadAggregation(column, element);
    loadCalculatable(column, element);
    loadMaxTextLength(column, element);
    return column;
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 38 with GuiDevelopmentException

use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.

the class AbstractTableLoader method loadComponent.

@Override
public void loadComponent() {
    assignXmlDescriptor(resultComponent, element);
    assignFrame(resultComponent);
    loadEnable(resultComponent, element);
    loadVisible(resultComponent, element);
    loadEditable(resultComponent, element);
    loadValidators(resultComponent, element);
    loadSettingsEnabled(resultComponent, element);
    loadAlign(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadHeight(resultComponent, element);
    loadWidth(resultComponent, element);
    loadIcon(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadTabIndex(resultComponent, element);
    loadSortable(resultComponent, element);
    loadReorderingAllowed(resultComponent, element);
    loadColumnControlVisible(resultComponent, element);
    loadAggregatable(resultComponent, element);
    loadAggregationStyle(resultComponent, element);
    loadPresentations(resultComponent, element);
    loadActions(resultComponent, element);
    loadContextMenuEnabled(resultComponent, element);
    loadMultiLineCells(resultComponent, element);
    loadColumnHeaderVisible(resultComponent, element);
    loadShowSelection(resultComponent, element);
    loadTextSelectionEnabled(resultComponent, element);
    loadResponsive(resultComponent, element);
    Element columnsElement = element.element("columns");
    Element rowsElement = element.element("rows");
    if (rowsElement == null) {
        throw new GuiDevelopmentException("Table doesn't have 'rows' element", context.getCurrentFrameId(), "Table ID", element.attributeValue("id"));
    }
    String rowHeaderMode = rowsElement.attributeValue("rowHeaderMode");
    if (StringUtils.isBlank(rowHeaderMode)) {
        rowHeaderMode = rowsElement.attributeValue("headerMode");
        if (StringUtils.isNotBlank(rowHeaderMode)) {
            Logger log = LoggerFactory.getLogger(AbstractTableLoader.class);
            log.warn("Attribute headerMode is deprecated. Use rowHeaderMode.");
        }
    }
    if (!StringUtils.isEmpty(rowHeaderMode)) {
        resultComponent.setRowHeaderMode(Table.RowHeaderMode.valueOf(rowHeaderMode));
    }
    loadButtonsPanel(resultComponent);
    // must be before datasource setting
    loadRowsCount(resultComponent, element);
    String datasource = rowsElement.attributeValue("datasource");
    if (StringUtils.isBlank(datasource)) {
        throw new GuiDevelopmentException("Table 'rows' element doesn't have 'datasource' attribute", context.getCurrentFrameId(), "Table ID", element.attributeValue("id"));
    }
    Datasource ds = context.getDsContext().get(datasource);
    if (ds == null) {
        throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context.getCurrentFrameId());
    }
    if (!(ds instanceof CollectionDatasource)) {
        throw new GuiDevelopmentException("Not a CollectionDatasource: " + datasource, context.getCurrentFrameId());
    }
    CollectionDatasource cds = (CollectionDatasource) ds;
    List<Table.Column> availableColumns;
    if (columnsElement != null) {
        availableColumns = loadColumns(resultComponent, columnsElement, cds);
    } else {
        availableColumns = new ArrayList<>();
    }
    for (Table.Column column : availableColumns) {
        resultComponent.addColumn(column);
        loadValidators(resultComponent, column);
        loadRequired(resultComponent, column);
    }
    addDynamicAttributes(resultComponent, ds, availableColumns);
    resultComponent.setDatasource(cds);
    for (Table.Column column : availableColumns) {
        if (column.getXmlDescriptor() != null) {
            String generatorMethod = column.getXmlDescriptor().attributeValue("generator");
            if (StringUtils.isNotEmpty(generatorMethod)) {
                // noinspection unchecked
                resultComponent.addGeneratedColumn(String.valueOf(column), new DeclarativeColumnGenerator(resultComponent, generatorMethod));
            }
        }
    }
    String multiselect = element.attributeValue("multiselect");
    if (StringUtils.isNotEmpty(multiselect)) {
        resultComponent.setMultiSelect(Boolean.parseBoolean(multiselect));
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DeclarativeColumnGenerator(com.haulmont.cuba.gui.xml.DeclarativeColumnGenerator) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Logger(org.slf4j.Logger)

Example 39 with GuiDevelopmentException

use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.

the class ActionsHolderLoader method loadDeclarativeAction.

@Override
protected Action loadDeclarativeAction(Component.ActionsHolder actionsHolder, Element element) {
    String id = element.attributeValue("id");
    if (StringUtils.isEmpty(id)) {
        throw new GuiDevelopmentException("No action id provided", context.getFullFrameId(), "ActionsHolder ID", actionsHolder.getId());
    }
    if (StringUtils.isBlank(element.attributeValue("invoke"))) {
        // Try to create a standard list action
        for (ListActionType type : ListActionType.values()) {
            if (type.getId().equals(id)) {
                Action instance = type.createAction((ListComponent) actionsHolder);
                loadStandardActionProperties(instance, element);
                loadActionOpenType(instance, element);
                loadActionConstraint(instance, element);
                loadShortcut(instance, element);
                return instance;
            }
        }
    }
    return super.loadDeclarativeAction(actionsHolder, element);
}
Also used : Action(com.haulmont.cuba.gui.components.Action) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) ListActionType(com.haulmont.cuba.gui.components.actions.ListActionType)

Example 40 with GuiDevelopmentException

use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.

the class ActionsHolderLoader method loadActionOpenType.

protected void loadActionOpenType(Action action, Element element) {
    if (action instanceof Action.HasOpenType) {
        String openTypeString = element.attributeValue("openType");
        if (StringUtils.isNotEmpty(openTypeString)) {
            WindowManager.OpenType openType;
            try {
                openType = WindowManager.OpenType.valueOf(openTypeString);
            } catch (IllegalArgumentException e) {
                throw new GuiDevelopmentException(String.format("Unknown open type: '%s' for action: '%s'", openTypeString, action.getId()), context.getFullFrameId());
            }
            ((Action.HasOpenType) action).setOpenType(openType);
        }
    }
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) WindowManager(com.haulmont.cuba.gui.WindowManager)

Aggregations

GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)55 Element (org.dom4j.Element)23 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 Component (com.haulmont.cuba.gui.components.Component)7 Datasource (com.haulmont.cuba.gui.data.Datasource)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 MetaClass (com.haulmont.chile.core.model.MetaClass)5 ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)3 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)3 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)3 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)3 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)3 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 Column (com.haulmont.cuba.gui.components.DataGrid.Column)2 ListComponent (com.haulmont.cuba.gui.components.ListComponent)2 DsContext (com.haulmont.cuba.gui.data.DsContext)2 ByteArrayDataProvider (com.haulmont.cuba.gui.export.ByteArrayDataProvider)2