Search in sources :

Example 1 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadContainer.

protected Optional<InstanceContainer> loadContainer(Element element, @Nullable String property) {
    String containerId = element.attributeValue("dataContainer");
    // For instance, a component is placed within the Form component
    if (Strings.isNullOrEmpty(containerId) && property != null) {
        containerId = getParentDataContainer(element);
    }
    if (!Strings.isNullOrEmpty(containerId)) {
        if (property == null) {
            throw new GuiDevelopmentException(String.format("Can't set container '%s' for component '%s' because 'property' " + "attribute is not defined", containerId, element.attributeValue("id")), context);
        }
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        return Optional.of(screenData.getContainer(containerId));
    }
    return Optional.empty();
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) ScreenData(io.jmix.ui.model.ScreenData)

Example 2 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadOptionsContainer.

protected Optional<CollectionContainer> loadOptionsContainer(Element element) {
    String containerId = element.attributeValue("optionsContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        if (!(container instanceof CollectionContainer)) {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        return Optional.of((CollectionContainer) container);
    }
    return Optional.empty();
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 3 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadShortcutFromAlias.

@Nullable
protected String loadShortcutFromAlias(String shortcut) {
    if (shortcut.endsWith("_SHORTCUT}")) {
        PropertyShortcutLoader propertyShortcutLoader = applicationContext.getBean(PropertyShortcutLoader.class);
        String alias = shortcut.substring(2, shortcut.length() - 1);
        if (propertyShortcutLoader.contains(alias)) {
            return propertyShortcutLoader.getShortcut(alias);
        } else {
            String message = String.format("An error occurred while loading shortcut. " + "Can't find shortcut for alias \"%s\"", alias);
            throw new GuiDevelopmentException(message, context);
        }
    }
    return null;
}
Also used : GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) PropertyShortcutLoader(io.jmix.ui.xml.PropertyShortcutLoader) Nullable(javax.annotation.Nullable)

Example 4 with GuiDevelopmentException

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

the class AbstractComponentLoader method loadFormatter.

@Nullable
protected Formatter<?> loadFormatter(Element element) {
    Element formatterElement = element.element("formatter");
    if (formatterElement == null) {
        return null;
    }
    int size = formatterElement.elements().size();
    if (size != 1) {
        throw new GuiDevelopmentException("Only one formatter needs to be defined. " + "The current number of formatters is " + size, getContext(), "Component ID", resultComponent.getId());
    }
    Element childElement = formatterElement.elements().get(0);
    FormatterLoadFactory loadFactory = applicationContext.getBean(FormatterLoadFactory.class);
    if (loadFactory.isFormatter(childElement)) {
        return loadFactory.createFormatter(childElement);
    }
    return null;
}
Also used : Element(org.dom4j.Element) FormatterLoadFactory(io.jmix.ui.component.formatter.FormatterLoadFactory) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Nullable(javax.annotation.Nullable)

Example 5 with GuiDevelopmentException

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

the class AbstractDataGridLoader method loadAggregation.

@SuppressWarnings("unchecked")
protected void loadAggregation(DataGrid.Column column, Element columnElement) {
    Element aggregationElement = columnElement.element("aggregation");
    if (aggregationElement != null) {
        AggregationInfo aggregation = new AggregationInfo();
        aggregation.setPropertyPath(column.getPropertyPath());
        loadAggregationType(aggregation, aggregationElement);
        loadValueDescription(column, aggregationElement);
        Formatter formatter = loadFormatter(aggregationElement);
        aggregation.setFormatter(formatter == null ? (Formatter<Object>) column.getDescriptionProvider() : formatter);
        column.setAggregation(aggregation);
        loadStrategyClass(aggregation, aggregationElement);
        if (aggregation.getType() == null && aggregation.getStrategy() == null) {
            throw new GuiDevelopmentException("Incorrect aggregation - type or strategyClass is required", context);
        }
    }
}
Also used : Formatter(io.jmix.ui.component.formatter.Formatter) 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