Search in sources :

Example 6 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractDataGridLoader method loadColumn.

protected Column loadColumn(DataGrid component, Element element, MetaClass metaClass) {
    String id = element.attributeValue("id");
    String property = element.attributeValue("property");
    if (id == null) {
        if (property != null) {
            id = property;
        } else {
            throw new GuiDevelopmentException("A column must have whether id or property specified", context, "DataGrid ID", component.getId());
        }
    }
    Column column;
    if (property != null) {
        MetaPropertyPath metaPropertyPath = getMetadataTools().resolveMetaPropertyPathOrNull(metaClass, property);
        column = component.addColumn(id, metaPropertyPath);
    } else {
        column = component.addColumn(id, null);
    }
    String expandRatio = element.attributeValue("expandRatio");
    if (StringUtils.isNotEmpty(expandRatio)) {
        column.setExpandRatio(Integer.parseInt(expandRatio));
    }
    String collapsed = element.attributeValue("collapsed");
    if (StringUtils.isNotEmpty(collapsed)) {
        column.setCollapsed(Boolean.parseBoolean(collapsed));
    }
    String collapsible = element.attributeValue("collapsible");
    if (StringUtils.isNotEmpty(collapsible)) {
        column.setCollapsible(Boolean.parseBoolean(collapsible));
    }
    String collapsingToggleCaption = element.attributeValue("collapsingToggleCaption");
    if (StringUtils.isNotEmpty(collapsingToggleCaption)) {
        collapsingToggleCaption = loadResourceString(collapsingToggleCaption);
        column.setCollapsingToggleCaption(collapsingToggleCaption);
    }
    String sortable = element.attributeValue("sortable");
    if (StringUtils.isNotEmpty(sortable)) {
        column.setSortable(Boolean.parseBoolean(sortable));
    }
    String resizable = element.attributeValue("resizable");
    if (StringUtils.isNotEmpty(resizable)) {
        column.setResizable(Boolean.parseBoolean(resizable));
    }
    String editable = element.attributeValue("editable");
    if (StringUtils.isNotEmpty(editable)) {
        column.setEditable(Boolean.parseBoolean(editable));
    }
    String sort = element.attributeValue("sort");
    if (StringUtils.isNotBlank(sort)) {
        loadColumnSort(component, column, sort);
    }
    String caption = loadCaption(element);
    if (caption == null) {
        String columnCaption;
        if (column.getPropertyPath() != null) {
            MetaProperty metaProperty = column.getPropertyPath().getMetaProperty();
            String propertyName = metaProperty.getName();
            MetaClass propertyMetaClass = getMetadataTools().getPropertyEnclosingMetaClass(column.getPropertyPath());
            columnCaption = getMessageTools().getPropertyCaption(propertyMetaClass, propertyName);
        } else {
            Class<?> declaringClass = metaClass.getJavaClass();
            String className = declaringClass.getName();
            int i = className.lastIndexOf('.');
            if (i > -1) {
                className = className.substring(i + 1);
            }
            columnCaption = getMessages().getMessage(declaringClass, className + "." + id);
        }
        column.setCaption(columnCaption);
    } else {
        column.setCaption(caption);
    }
    ((Component.HasXmlDescriptor) column).setXmlDescriptor(element);
    Integer width = loadSizeInPx(element, "width");
    if (width != null) {
        column.setWidth(width);
    }
    Integer minimumWidth = loadSizeInPx(element, "minimumWidth");
    if (minimumWidth != null) {
        column.setMinimumWidth(minimumWidth);
    }
    Integer maximumWidth = loadSizeInPx(element, "maximumWidth");
    if (maximumWidth != null) {
        column.setMaximumWidth(maximumWidth);
    }
    loadColumnVisualDisplay(column, element);
    loadAggregation(column, element);
    return column;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) Column(io.jmix.ui.component.DataGrid.Column) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 7 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractDataGridLoader method loadStrategyClass.

protected void loadStrategyClass(AggregationInfo aggregation, Element aggregationElement) {
    String strategyClass = aggregationElement.attributeValue("strategyClass");
    if (StringUtils.isNotEmpty(strategyClass)) {
        Class<?> aggregationClass = getClassManager().findClass(strategyClass);
        if (aggregationClass == null) {
            throw new GuiDevelopmentException(String.format("Class %s is not found", strategyClass), context);
        }
        try {
            Constructor<?> constructor = aggregationClass.getDeclaredConstructor();
            AggregationStrategy customStrategy = (AggregationStrategy) constructor.newInstance();
            applicationContext.getAutowireCapableBeanFactory().autowireBean(customStrategy);
            aggregation.setStrategy(customStrategy);
        } catch (Exception e) {
            throw new RuntimeException("Unable to instantiate strategy for aggregation", e);
        }
    }
}
Also used : GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) AggregationStrategy(io.jmix.ui.component.data.aggregation.AggregationStrategy)

Example 8 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class PivotTableLoader method loadDataContainer.

protected void loadDataContainer(PivotTable pivotTable, Element element) {
    String dataContainerId = element.attributeValue("dataContainer");
    if (StringUtils.isNotEmpty(dataContainerId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        CollectionContainer dataContainer;
        InstanceContainer container = screenData.getContainer(dataContainerId);
        if (container instanceof CollectionContainer) {
            dataContainer = (CollectionContainer) container;
        } else {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + dataContainerId, context);
        }
        pivotTable.setDataProvider(new ContainerDataProvider(dataContainer));
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) CollectionContainer(io.jmix.ui.model.CollectionContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) ContainerDataProvider(io.jmix.ui.data.impl.ContainerDataProvider) ScreenData(io.jmix.ui.model.ScreenData)

Example 9 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class ScreenSettingsFacetProvider method loadComponentIds.

protected List<String> loadComponentIds(ComponentLoader.ComponentContext context, Element root) {
    Element componentsElement = root.element("components");
    if (componentsElement == null) {
        return Collections.emptyList();
    }
    List<Element> components = componentsElement.elements("component");
    List<String> result = new ArrayList<>(components.size());
    for (Element element : components) {
        String id = element.attributeValue("id");
        if (id == null) {
            throw new GuiDevelopmentException("ScreenSettings component does not define an id", context);
        }
        result.add(id);
    }
    return result;
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 10 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class TokenListLoader method loadLookup.

protected void loadLookup(TokenList component, Element element) {
    Element lookupElement = element.element("lookup");
    if (lookupElement == null) {
        throw new GuiDevelopmentException("'tokenList' must contain 'lookup' element", context, "TokenList ID", element.attributeValue("id"));
    }
    loadOptionsContainer(component, lookupElement);
    loadLookupCaptionProperty(component, lookupElement);
    String lookup = lookupElement.attributeValue("lookup");
    if (StringUtils.isNotEmpty(lookup)) {
        component.setLookup(Boolean.parseBoolean(lookup));
        if (component.isLookup()) {
            String lookupScreen = lookupElement.attributeValue("lookupScreen");
            if (StringUtils.isNotEmpty(lookupScreen)) {
                component.setLookupScreen(lookupScreen);
            }
            loadLookupOpenMode(component, lookupElement);
        }
    }
    String multiSelect = lookupElement.attributeValue("multiselect");
    if (StringUtils.isNotEmpty(multiSelect)) {
        component.setMultiSelect(Boolean.parseBoolean(multiSelect));
    }
    String inputPrompt = lookupElement.attributeValue("inputPrompt");
    if (StringUtils.isNotEmpty(inputPrompt)) {
        component.setLookupInputPrompt(loadResourceString(inputPrompt));
    }
    loadFilterMode(component, lookupElement);
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Aggregations

GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)106 Element (org.dom4j.Element)42 FrameOwner (io.jmix.ui.screen.FrameOwner)16 Component (io.jmix.ui.component.Component)13 InstanceContainer (io.jmix.ui.model.InstanceContainer)11 ScreenData (io.jmix.ui.model.ScreenData)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)9 MetaClass (io.jmix.core.metamodel.model.MetaClass)8 Action (io.jmix.ui.action.Action)7 BaseAction (io.jmix.ui.action.BaseAction)6 ParseException (java.text.ParseException)6 Date (java.util.Date)6 Nullable (javax.annotation.Nullable)6 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 ComponentLoader (io.jmix.ui.xml.layout.ComponentLoader)5 ArrayList (java.util.ArrayList)5 Datasource (com.haulmont.cuba.gui.data.Datasource)4 Formatter (io.jmix.ui.component.formatter.Formatter)4 JsonParser (com.google.gson.JsonParser)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3