Search in sources :

Example 16 with GuiDevelopmentException

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

the class CubaFilterLoader method loadComponent.

@Override
public void loadComponent() {
    assignXmlDescriptor(resultComponent, element);
    assignFrame(resultComponent);
    loadAlign(resultComponent, element);
    loadVisible(resultComponent, element);
    loadEnable(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadCss(resultComponent, element);
    loadMargin(resultComponent, element);
    loadIcon(resultComponent, element);
    loadHtmlSanitizerEnabled(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadContextHelp(resultComponent, element);
    loadWidth(resultComponent, element, "100%");
    loadCollapsible(resultComponent, element, true);
    loadSettingsEnabled(resultComponent, element);
    loadBorderVisible(resultComponent, element);
    loadWindowCaptionUpdateEnabled(resultComponent, element);
    String useMaxResults = element.attributeValue("useMaxResults");
    resultComponent.setUseMaxResults(useMaxResults == null || Boolean.parseBoolean(useMaxResults));
    String textMaxResults = element.attributeValue("textMaxResults");
    resultComponent.setTextMaxResults(Boolean.parseBoolean(textMaxResults));
    final String manualApplyRequired = element.attributeValue("manualApplyRequired");
    resultComponent.setManualApplyRequired(BooleanUtils.toBooleanObject(manualApplyRequired));
    String editable = element.attributeValue("editable");
    resultComponent.setEditable(editable == null || Boolean.parseBoolean(editable));
    String columnsCount = element.attributeValue("columnsCount");
    if (!Strings.isNullOrEmpty(columnsCount)) {
        resultComponent.setColumnsCount(Integer.parseInt(columnsCount));
    }
    String folderActionsEnabled = element.attributeValue("folderActionsEnabled");
    if (folderActionsEnabled != null) {
        resultComponent.setFolderActionsEnabled(Boolean.parseBoolean(folderActionsEnabled));
    }
    String dataLoaderId = element.attributeValue("dataLoader");
    if (StringUtils.isNotBlank(dataLoaderId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        DataLoader dataLoader = screenData.getLoader(dataLoaderId);
        if (!(dataLoader instanceof CollectionLoader) && !(dataLoader instanceof KeyValueCollectionLoader)) {
            throw new IllegalStateException(String.format("Filter cannot work with %s because it is not a CollectionLoader or a KeyValueCollectionLoader", dataLoaderId));
        }
        resultComponent.setDataLoader((BaseCollectionLoader) dataLoader);
    } else {
        String datasource = element.attributeValue("datasource");
        if (StringUtils.isNotBlank(datasource)) {
            if (getComponentContext().getDsContext() == null) {
                throw new IllegalStateException("'datasource' attribute can be used only in screens with 'dsContext' element. " + "In a screen with 'data' element use 'dataContainer' attribute.");
            }
            CollectionDatasource ds = (CollectionDatasource) getComponentContext().getDsContext().get(datasource);
            if (ds == null) {
                throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context);
            }
            resultComponent.setDatasource(ds);
        }
    }
    Frame frame = getComponentContext().getFrame();
    String applyTo = element.attributeValue("applyTo");
    if (!StringUtils.isEmpty(applyTo)) {
        getComponentContext().addPostInitTask((c, w) -> {
            Component applyToComponent = frame.getComponent(applyTo);
            if (c == null) {
                throw new GuiDevelopmentException("Can't apply component to component with ID: " + applyTo, context);
            }
            resultComponent.setApplyTo(applyToComponent);
        });
    }
    String modeSwitchVisible = element.attributeValue("modeSwitchVisible");
    if (StringUtils.isNotEmpty(modeSwitchVisible)) {
        resultComponent.setModeSwitchVisible(Boolean.parseBoolean(modeSwitchVisible));
    }
    String immediatelySearch = element.attributeValue("applyImmediately");
    if (!Strings.isNullOrEmpty(immediatelySearch)) {
        resultComponent.setApplyImmediately(Boolean.parseBoolean(immediatelySearch));
    }
    getComponentContext().addPostInitTask((context1, window) -> {
        String controlsLayoutTemplate = element.attributeValue("controlsLayoutTemplate");
        if (!Strings.isNullOrEmpty(controlsLayoutTemplate)) {
            resultComponent.setControlsLayoutTemplate(controlsLayoutTemplate);
            resultComponent.createLayout();
        }
        ((FilterImplementation) resultComponent).loadFiltersAndApplyDefault();
        String defaultMode = element.attributeValue("defaultMode");
        if (FTS_MODE_VALUE.equals(defaultMode)) {
            resultComponent.switchFilterMode(FilterDelegate.FilterMode.FTS_MODE);
        }
    });
}
Also used : Frame(io.jmix.ui.component.Frame) FrameOwner(io.jmix.ui.screen.FrameOwner) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component) FilterImplementation(io.jmix.ui.component.FilterImplementation)

Example 17 with GuiDevelopmentException

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

the class LookupFieldLoader method loadNewOptionHandler.

protected void loadNewOptionHandler(LookupField component, Element element) {
    String newOptionHandlerMethod = element.attributeValue("newOptionHandler");
    if (StringUtils.isNotEmpty(newOptionHandlerMethod)) {
        FrameOwner controller = getComponentContext().getFrame().getFrameOwner();
        Class<? extends FrameOwner> windowClass = controller.getClass();
        Method newOptionHandler;
        try {
            newOptionHandler = windowClass.getMethod(newOptionHandlerMethod, ComboBox.class, String.class);
        } catch (NoSuchMethodException e) {
            Map<String, Object> params = ParamsMap.of("LookupField Id", component.getId(), "Method name", newOptionHandlerMethod);
            throw new GuiDevelopmentException("Unable to find new option handler method for lookup field", context, params);
        }
        component.setNewOptionHandler(caption -> {
            try {
                newOptionHandler.invoke(controller, component, caption);
            } catch (IllegalAccessException | InvocationTargetException e) {
                throw new RuntimeException("Unable to invoke new option handler", e);
            }
        });
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) ComboBox(io.jmix.ui.component.ComboBox) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Method(java.lang.reflect.Method) ParamsMap(io.jmix.core.common.util.ParamsMap) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with GuiDevelopmentException

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

the class BulkEditorLoader method loadComponent.

@Override
public void loadComponent() {
    assignXmlDescriptor(resultComponent, element);
    assignFrame(resultComponent);
    Window window = ComponentsHelper.getWindow(resultComponent);
    if (window != null && !(window.getFrameOwner() instanceof LegacyFrame)) {
        throw new GuiDevelopmentException("BulkEditor component can be used only in legacy screens based on AbstractWindow", context);
    }
    loadEnable(resultComponent, element);
    loadVisible(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadHtmlSanitizerEnabled(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadIcon(resultComponent, element);
    loadWidth(resultComponent, element);
    loadAlign(resultComponent, element);
    loadResponsive(resultComponent, element);
    loadCss(resultComponent, element);
    loadColumns(resultComponent, element);
    loadTabIndex(resultComponent, element);
    Security security = AppBeans.get(Security.class);
    if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
        resultComponent.setVisible(false);
    }
    String openType = element.attributeValue("openType");
    if (StringUtils.isNotEmpty(openType)) {
        resultComponent.setOpenType(OpenType.valueOf(openType));
    }
    String exclude = element.attributeValue("exclude");
    String includeProperties = element.attributeValue("includeProperties");
    if (StringUtils.isNotBlank(exclude) && StringUtils.isNotBlank(includeProperties)) {
        throw new GuiDevelopmentException("BulkEditor cannot define simultaneously exclude and includeProperties attributes", getContext());
    }
    if (StringUtils.isNotBlank(exclude)) {
        resultComponent.setExcludePropertiesRegex(exclude.replace(" ", ""));
    }
    if (StringUtils.isNotBlank(includeProperties)) {
        resultComponent.setIncludeProperties(Splitter.on(',').omitEmptyStrings().trimResults().splitToList(includeProperties));
    }
    String listComponent = element.attributeValue("for");
    if (StringUtils.isEmpty(listComponent)) {
        throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified", context, "componentId", resultComponent.getId());
    }
    String loadDynamicAttributes = element.attributeValue("loadDynamicAttributes");
    if (StringUtils.isNotEmpty(loadDynamicAttributes)) {
        resultComponent.setLoadDynamicAttributes(Boolean.parseBoolean(loadDynamicAttributes));
    }
    String useConfirmDialog = element.attributeValue("useConfirmDialog");
    if (StringUtils.isNotEmpty(useConfirmDialog)) {
        resultComponent.setUseConfirmDialog(Boolean.parseBoolean(useConfirmDialog));
    }
    getComponentContext().addPostInitTask((c, w) -> {
        if (resultComponent.getListComponent() == null) {
            Component bindComponent = resultComponent.getFrame().getComponent(listComponent);
            if (!(bindComponent instanceof ListComponent)) {
                throw new GuiDevelopmentException("Specify 'for' attribute: id of table or tree", context, "componentId", resultComponent.getId());
            }
            resultComponent.setListComponent((ListComponent) bindComponent);
        }
    });
    loadValidators(resultComponent, element);
    loadFocusable(resultComponent, element);
}
Also used : Window(io.jmix.ui.component.Window) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) ListComponent(com.haulmont.cuba.gui.components.ListComponent) Security(com.haulmont.cuba.core.global.Security) ListComponent(com.haulmont.cuba.gui.components.ListComponent) Component(io.jmix.ui.component.Component)

Example 19 with GuiDevelopmentException

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

the class CubaCalendarLoader method loadDataContainer.

@SuppressWarnings("rawtypes")
@Override
protected void loadDataContainer(Calendar component, Element element) {
    String datasource = element.attributeValue("datasource");
    ComponentLoaderContext loaderContext = (ComponentLoaderContext) getComponentContext();
    CollectionDatasource ds = (CollectionDatasource) loaderContext.getDsContext().get(datasource);
    if (ds == null) {
        throw new GuiDevelopmentException(String.format("Datasource '%s' is not defined", datasource), getContext(), "Component ID", component.getId());
    }
    ((com.haulmont.cuba.gui.components.Calendar) component).setDatasource(ds);
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Calendar(io.jmix.ui.component.Calendar) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 20 with GuiDevelopmentException

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

the class CubaRelatedEntitiesLoader method loadPropertyOption.

@Override
protected void loadPropertyOption(Element routeElement) {
    String property = loadString(routeElement, "name").orElseThrow(() -> new GuiDevelopmentException("Name attribute for related entities property is not specified", context, "componentId", resultComponent.getId()));
    String caption = loadResourceString(routeElement.attributeValue("caption"));
    String filterCaption = loadResourceString(routeElement.attributeValue("filterCaption"));
    String screen = routeElement.attributeValue("screen");
    if (StringUtils.isNotEmpty(screen)) {
        if (getWindowConfig().findWindowInfo(screen) == null) {
            throw new GuiDevelopmentException("Screen for custom route in related entities not found", context, "componentId", resultComponent.getId());
        }
    }
    resultComponent.addPropertyOption(new PropertyOption(property, screen, caption, filterCaption));
}
Also used : PropertyOption(io.jmix.ui.sys.PropertyOption) 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