Search in sources :

Example 26 with Component

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

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

the class AttributeRecalculationListener method accept.

@Override
public void accept(HasValue.ValueChangeEvent valueChangeEvent) {
    if (Boolean.TRUE.equals(recalculationInProgress.get())) {
        return;
    }
    try {
        recalculationInProgress.set(true);
        Component component = valueChangeEvent.getComponent();
        if (component instanceof HasValueSource && ((HasValueSource<?>) component).getValueSource() instanceof ContainerValueSource) {
            ContainerValueSource<?, ?> valueSource = (ContainerValueSource<?, ?>) ((HasValueSource<?>) component).getValueSource();
            InstanceContainer<?> container = valueSource.getContainer();
            Object entity = container.getItem();
            EntityValues.setValue(entity, DynAttrUtils.getPropertyFromAttributeCode(attribute.getCode()), valueChangeEvent.getValue());
            recalculationManager.recalculateByAttribute(entity, attribute);
        }
    } finally {
        recalculationInProgress.remove();
    }
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) Component(io.jmix.ui.component.Component) HasValueSource(io.jmix.ui.component.data.HasValueSource)

Example 28 with Component

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

the class StandardEditor method getEditedEntityContainer.

protected InstanceContainer<T> getEditedEntityContainer() {
    EditedEntityContainer annotation = getClass().getAnnotation(EditedEntityContainer.class);
    if (annotation == null || Strings.isNullOrEmpty(annotation.value())) {
        throw new IllegalStateException(String.format("StandardEditor %s does not declare @EditedEntityContainer", getClass()));
    }
    String[] parts = annotation.value().split("\\.");
    ScreenData screenData;
    if (parts.length == 1) {
        screenData = getScreenData();
    } else {
        Frame frame = getWindow();
        for (int i = 0; i < parts.length - 1; i++) {
            String part = parts[i];
            Component component = frame.getComponent(part);
            if (!(component instanceof Frame)) {
                throw new IllegalStateException("Path to EditedEntityContainer must include frames only");
            }
            frame = (Frame) component;
        }
        screenData = UiControllerUtils.getScreenData(frame.getFrameOwner());
    }
    return screenData.getContainer(parts[parts.length - 1]);
}
Also used : Frame(io.jmix.ui.component.Frame) Component(io.jmix.ui.component.Component)

Example 29 with Component

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

the class PresentationsFacetImpl method fillWithInnerComponents.

protected Collection<Component> fillWithInnerComponents(Collection<Component> components, HasInnerComponents hasInnerComponents) {
    Collection<Component> innerComponents = hasInnerComponents.getInnerComponents();
    components.addAll(innerComponents);
    for (Component component : innerComponents) {
        if (component instanceof HasInnerComponents) {
            fillWithInnerComponents(components, (HasInnerComponents) component);
        }
    }
    return components;
}
Also used : HasInnerComponents(io.jmix.ui.component.HasInnerComponents) Component(io.jmix.ui.component.Component)

Example 30 with Component

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

the class PresentationsFacetProvider method loadFromXml.

@Override
public void loadFromXml(PresentationsFacet facet, Element element, ComponentLoader.ComponentContext context) {
    loadId(element).ifPresent(facet::setId);
    loadAuto(element).ifPresent(facet::setAuto);
    if (!facet.isAuto()) {
        List<String> ids = loadComponentIds(context, element);
        facet.addComponentIds(ids.toArray(new String[0]));
    }
    if (isPresentationsAvailable()) {
        context.addPostInitTask((context1, window) -> {
            Collection<Component> components = facet.getComponents();
            for (Component component : components) {
                if (component instanceof HasTablePresentations) {
                    ((HasTablePresentations) component).loadPresentations();
                }
            }
        });
    }
}
Also used : Component(io.jmix.ui.component.Component) HasTablePresentations(io.jmix.ui.component.HasTablePresentations)

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