Search in sources :

Example 31 with GuiDevelopmentException

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

the class MessageDialogFacetImpl method subscribeOnAction.

protected void subscribeOnAction(Frame owner) {
    Action action = ComponentsHelper.findAction(owner, actionId);
    if (!(action instanceof BaseAction)) {
        throw new GuiDevelopmentException(String.format("Unable to find Dialog target button with id '%s'", actionId), owner.getId());
    }
    ((BaseAction) action).addActionPerformedListener(e -> show());
}
Also used : Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) BaseAction(io.jmix.ui.action.BaseAction)

Example 32 with GuiDevelopmentException

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

the class NotificationFacetImpl method subscribeOnAction.

protected void subscribeOnAction(Frame owner) {
    Action action = ComponentsHelper.findAction(owner, actionId);
    if (!(action instanceof BaseAction)) {
        throw new GuiDevelopmentException(String.format("Unable to find Notification target action with id '%s'", actionId), owner.getId());
    }
    ((BaseAction) action).addActionPerformedListener(e -> show());
}
Also used : Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) BaseAction(io.jmix.ui.action.BaseAction)

Example 33 with GuiDevelopmentException

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

the class FilterLoader method loadConfigurations.

protected void loadConfigurations(Filter component, Element element) {
    Set<String> filterPaths = new HashSet<>();
    getComponentContext().addPostInitTask((context1, window) -> {
        ComponentsHelper.walkComponents(window, (visitingComponent, name) -> {
            if (visitingComponent instanceof Filter) {
                String path = FilterUtils.generateFilterPath((Filter) visitingComponent);
                if (filterPaths.contains(path)) {
                    throw new GuiDevelopmentException("Filters with the same component path should have different ids", getComponentContext());
                } else {
                    filterPaths.add(path);
                }
            }
        });
        component.loadConfigurationsAndApplyDefault();
    });
    Element configurationsElement = element.element("configurations");
    if (configurationsElement != null) {
        for (Element configurationElement : configurationsElement.elements("configuration")) {
            loadConfiguration(component, configurationElement);
        }
    }
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 34 with GuiDevelopmentException

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

the class FormLoader method loadColumns.

protected void loadColumns(Form resultComponent, Element element) {
    if (element.elements("column").isEmpty()) {
        Iterable<ComponentPosition> rootComponents = loadComponents(element, null, null);
        for (ComponentPosition component : rootComponents) {
            resultComponent.add(component.getComponent(), 0, component.getColSpan(), component.getRowSpan());
        }
    } else {
        List<Element> columnElements = element.elements("column");
        if (element.elements().size() > columnElements.size()) {
            String fieldGroupId = resultComponent.getId();
            Map<String, Object> params = Strings.isNullOrEmpty(fieldGroupId) ? Collections.emptyMap() : ParamsMap.of("Form ID", fieldGroupId);
            throw new GuiDevelopmentException("Form component elements have to be placed within its column.", context, params);
        }
        resultComponent.setColumns(columnElements.size());
        int colIndex = 0;
        for (Element columnElement : columnElements) {
            String columnWidth = loadThemeString(columnElement.attributeValue("width"));
            String flexAttr = columnElement.attributeValue("flex");
            Float flex = null;
            if (!Strings.isNullOrEmpty(flexAttr)) {
                flex = Float.parseFloat(flexAttr);
                resultComponent.setColumnFlex(colIndex, flex);
            }
            Iterable<ComponentPosition> columnComponents = loadComponents(columnElement, columnWidth, flex);
            for (ComponentPosition component : columnComponents) {
                resultComponent.add(component.getComponent(), colIndex, component.getColSpan(), component.getRowSpan());
            }
            loadChildrenCaptionAlignment(resultComponent, columnElement, colIndex);
            loadChildrenCaptionWidth(resultComponent, columnElement, colIndex);
            colIndex++;
        }
    }
}
Also used : ComponentPosition(io.jmix.ui.component.form.ComponentPosition) Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 35 with GuiDevelopmentException

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

the class AbstractTableLoader method loadColumn.

protected Table.Column loadColumn(Table component, Element element, MetaClass metaClass) {
    Object id = loadColumnId(element, metaClass);
    Table.Column column = component.addColumn(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 sortable = element.attributeValue("sortable");
    if (StringUtils.isNotEmpty(sortable)) {
        column.setSortable(Boolean.parseBoolean(sortable));
    }
    String sort = element.attributeValue("sort");
    if (StringUtils.isNotBlank(sort)) {
        loadColumnSort(column, sort);
    }
    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();
            MetaClass propertyMetaClass = getMetadataTools().getPropertyEnclosingMetaClass(mpp);
            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);
    }
    column.setXmlDescriptor(element);
    String expandRatio = element.attributeValue("expandRatio");
    String width = loadThemeString(element.attributeValue("width"));
    if (StringUtils.isNotEmpty(expandRatio)) {
        column.setExpandRatio(Float.parseFloat(expandRatio));
        if (StringUtils.isNotEmpty(width)) {
            throw new GuiDevelopmentException("Properties 'width' and 'expandRatio' cannot be used simultaneously", context);
        }
    }
    if (StringUtils.isNotEmpty(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, "width", element.attributeValue("width"));
        }
    }
    String align = element.attributeValue("align");
    if (StringUtils.isNotEmpty(align)) {
        column.setAlignment(Table.ColumnAlignment.valueOf(align));
    }
    column.setFormatter(loadFormatter(element));
    loadAggregation(column, element);
    loadMaxTextLength(column, element);
    loadCaptionAsHtml(column, element);
    return column;
}
Also used : Table(io.jmix.ui.component.Table) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) MetadataObject(io.jmix.core.metamodel.model.MetadataObject) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

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