Search in sources :

Example 21 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class FormImpl method removeAll.

@Override
public void removeAll() {
    component.removeAllComponents();
    List<Component> components = new ArrayList<>(getOwnComponents());
    columnComponentMapping.clear();
    columnComponentMapping.add(new ArrayList<>());
    component.setColumns(1);
    for (Component component : components) {
        component.setParent(null);
    }
}
Also used : ArrayList(java.util.ArrayList) Component(io.jmix.ui.component.Component)

Example 22 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class DataLoadCoordinatorImpl method configureAutomatically.

private void configureAutomatically(DataLoader loader, FrameOwner frameOwner) {
    List<String> queryParameters = DataLoadersHelper.getQueryParameters(loader);
    List<String> allParameters = new ArrayList<>(queryParameters);
    allParameters.addAll(getConditionParameters(loader));
    // add triggers on container/component events
    for (String parameter : allParameters) {
        if (parameter.startsWith(containerPrefix)) {
            InstanceContainer container = UiControllerUtils.getScreenData(frameOwner).getContainer(parameter.substring(containerPrefix.length()));
            addOnContainerItemChangedLoadTrigger(loader, container, parameter);
        } else if (parameter.startsWith(componentPrefix)) {
            String componentId = parameter.substring(componentPrefix.length());
            Component component = frameOwner instanceof Screen ? ((Screen) frameOwner).getWindow().getComponentNN(componentId) : ((ScreenFragment) frameOwner).getFragment().getComponentNN(componentId);
            LikeClause likeClause = findLikeClause(loader, parameter);
            addOnComponentValueChangedLoadTrigger(loader, component, parameter, likeClause);
        }
    }
    // if the loader has no parameters in query, add trigger on BeforeShowEvent/AttachEvent
    if (queryParameters.isEmpty()) {
        Class eventClass = frameOwner instanceof Screen ? Screen.BeforeShowEvent.class : ScreenFragment.AttachEvent.class;
        addOnFrameOwnerEventLoadTrigger(loader, eventClass);
    }
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) Screen(io.jmix.ui.screen.Screen) ArrayList(java.util.ArrayList) InstanceContainer(io.jmix.ui.model.InstanceContainer) Component(io.jmix.ui.component.Component)

Example 23 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class DeclarativeTrackingAction method actionPerform.

@Override
public void actionPerform(Component component) {
    if (StringUtils.isEmpty(methodName)) {
        return;
    }
    FrameOwner controller = frame.getFrameOwner();
    if (controller instanceof LegacyFragmentAdapter) {
        controller = ((LegacyFragmentAdapter) controller).getRealScreen();
    }
    Method method;
    try {
        method = controller.getClass().getMethod(methodName, Component.class);
    } catch (NoSuchMethodException e) {
        try {
            method = controller.getClass().getMethod(methodName);
        } catch (NoSuchMethodException e1) {
            throw new IllegalStateException(String.format("No suitable methods named %s for action %s", methodName, id));
        }
    }
    try {
        if (method.getParameterCount() == 1) {
            method.invoke(controller, component);
        } else {
            method.invoke(controller);
        }
    } catch (Exception e) {
        throw new RuntimeException("Exception on action handling", e);
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) Method(java.lang.reflect.Method) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter) Component(io.jmix.ui.component.Component)

Example 24 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class FieldGroupLoader method loadComponent.

@Override
public void loadComponent() {
    assignFrame(resultComponent);
    String fieldFactoryBean = element.attributeValue("fieldFactoryBean");
    if (StringUtils.isNotEmpty(fieldFactoryBean)) {
        FieldGroupFieldFactory fieldFactory = applicationContext.getBean(fieldFactoryBean, FieldGroupFieldFactory.class);
        resultComponent.setFieldFactory(fieldFactory);
    }
    assignXmlDescriptor(resultComponent, element);
    loadVisible(resultComponent, element);
    loadWidth(resultComponent, element);
    loadEditable(resultComponent, element);
    loadEnable(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadCss(resultComponent, element);
    loadHtmlSanitizerEnabled(resultComponent, element);
    loadIcon(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadContextHelp(resultComponent, element);
    loadHeight(resultComponent, element);
    loadAlign(resultComponent, element);
    loadCaptionAlignment(resultComponent, element);
    loadFieldCaptionWidth(resultComponent, element);
    Datasource ds = loadDatasource(element);
    resultComponent.setDatasource(ds);
    if (element.elements("column").isEmpty()) {
        Iterable<FieldGroup.FieldConfig> rootFields = loadFields(resultComponent, element, ds, null);
        Iterable<FieldGroup.FieldConfig> dynamicAttributeFields = loadDynamicAttributeFields(ds);
        for (FieldGroup.FieldConfig field : dynamicAttributeFields) {
            if (resultComponent.getWidth() > 0 && field.getWidth() == null) {
                field.setWidth("100%");
            }
        }
        for (FieldGroup.FieldConfig field : Iterables.concat(rootFields, dynamicAttributeFields)) {
            resultComponent.addField(field);
        }
    } else {
        List<Element> columnElements = element.elements("column");
        List<Element> fieldElements = element.elements("field");
        if (fieldElements.size() > 0) {
            Map<String, Object> params = new HashMap<>();
            String fieldGroupId = resultComponent.getId();
            if (StringUtils.isNotEmpty(fieldGroupId)) {
                params.put("FieldGroup ID", fieldGroupId);
            }
            throw new GuiDevelopmentException("FieldGroup field elements should be placed within its column.", context, params);
        }
        resultComponent.setColumns(columnElements.size());
        int colIndex = 0;
        for (Element columnElement : columnElements) {
            String flex = columnElement.attributeValue("flex");
            if (StringUtils.isNotEmpty(flex)) {
                resultComponent.setColumnExpandRatio(colIndex, Float.parseFloat(flex));
            }
            String columnWidth = loadThemeString(columnElement.attributeValue("width"));
            Iterable<FieldGroup.FieldConfig> columnFields = loadFields(resultComponent, columnElement, ds, columnWidth);
            if (colIndex == 0) {
                columnFields = Iterables.concat(columnFields, loadDynamicAttributeFields(ds));
            }
            for (FieldGroup.FieldConfig field : columnFields) {
                resultComponent.addField(field, colIndex);
            }
            String columnFieldCaptionWidth = columnElement.attributeValue("fieldCaptionWidth");
            if (StringUtils.isNotEmpty(columnFieldCaptionWidth)) {
                if (columnFieldCaptionWidth.startsWith(MessageTools.MARK)) {
                    columnFieldCaptionWidth = loadResourceString(columnFieldCaptionWidth);
                }
                if (columnFieldCaptionWidth.endsWith("px")) {
                    columnFieldCaptionWidth = columnFieldCaptionWidth.substring(0, columnFieldCaptionWidth.indexOf("px"));
                }
                resultComponent.setFieldCaptionWidth(colIndex, Integer.parseInt(columnFieldCaptionWidth));
            }
            colIndex++;
        }
    }
    for (FieldGroup.FieldConfig field : resultComponent.getFields()) {
        if (!field.isCustom()) {
            if (!DynAttrUtils.isDynamicAttributeProperty(field.getProperty())) {
                // the following does not make sense for dynamic attributes
                loadValidators(resultComponent, field);
                loadRequired(resultComponent, field);
                loadEnable(resultComponent, field);
            }
            loadVisible(resultComponent, field);
            loadEditable(resultComponent, field);
        }
    }
    resultComponent.bind();
    ComponentContext componentContext = getComponentContext();
    for (FieldGroup.FieldConfig field : resultComponent.getFields()) {
        if (field.getXmlDescriptor() != null) {
            String generator = field.getXmlDescriptor().attributeValue("generator");
            if (generator != null) {
                componentContext.addInjectTask((boundContext, window) -> {
                    DeclarativeFieldGenerator fieldGenerator = new DeclarativeFieldGenerator(resultComponent, generator);
                    Component fieldComponent = fieldGenerator.generateField(field.getTargetDatasource(), field.getProperty());
                    field.setComponent(fieldComponent);
                });
            }
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) EmbeddedDatasource(com.haulmont.cuba.gui.data.EmbeddedDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) FieldGroup(com.haulmont.cuba.gui.components.FieldGroup) DeclarativeFieldGenerator(com.haulmont.cuba.gui.xml.DeclarativeFieldGenerator) Element(org.dom4j.Element) FieldGroupFieldFactory(com.haulmont.cuba.gui.components.FieldGroupFieldFactory) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component)

Example 25 with Component

use of io.jmix.ui.component.Component 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)

Aggregations

Component (io.jmix.ui.component.Component)81 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)16 Datasource (com.haulmont.cuba.gui.data.Datasource)12 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)11 Test (org.junit.jupiter.api.Test)11 Element (org.dom4j.Element)10 Consumer (java.util.function.Consumer)9 ListComponent (com.haulmont.cuba.gui.components.ListComponent)8 MetaClass (io.jmix.core.metamodel.model.MetaClass)7 Action (io.jmix.ui.action.Action)7 HasValue (io.jmix.ui.component.HasValue)7 FrameOwner (io.jmix.ui.screen.FrameOwner)7 ArrayList (java.util.ArrayList)7 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)6 FetchPlan (io.jmix.core.FetchPlan)6 UUID (java.util.UUID)6 Nullable (javax.annotation.Nullable)6 User (com.haulmont.cuba.core.model.common.User)5 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)5 Entity (io.jmix.core.Entity)5