Search in sources :

Example 6 with Window

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

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

the class BulkEditAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("BulkEditAction target Items is null " + "or does not implement EntityDataUnit");
    }
    MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
    if (metaClass == null) {
        throw new IllegalStateException("Target is not bound to entity");
    }
    UiBulkEditContext context = new UiBulkEditContext();
    accessManager.applyRegisteredConstraints(context);
    if (!context.isPermitted()) {
        if (target.getFrame() != null) {
            Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
            notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("accessDenied.message")).show();
        }
        return;
    }
    if (target.getSelected().isEmpty() && target.getFrame() != null) {
        Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
        notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("actions.BulkEdit.emptySelection")).show();
        return;
    }
    Window window = ComponentsHelper.getWindowNN(target);
    BulkEditorBuilder<?> builder = bulkEditors.builder(metaClass, target.getSelected(), window.getFrameOwner()).withListComponent(target);
    if (columnsMode != null) {
        builder = builder.withColumnsMode(columnsMode);
    }
    if (exclude != null) {
        builder = builder.withExclude(exclude);
    }
    if (fieldSorter != null) {
        builder = builder.withFieldSorter(fieldSorter);
    }
    if (includeProperties != null) {
        builder = builder.withIncludeProperties(includeProperties);
    }
    if (openMode != null) {
        builder = builder.withOpenMode(openMode);
    }
    if (useConfirmDialog != null) {
        builder = builder.withUseConfirmDialog(useConfirmDialog);
    }
    builder.create().show();
}
Also used : Window(io.jmix.ui.component.Window) UiBulkEditContext(io.jmix.ui.accesscontext.UiBulkEditContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) Notifications(io.jmix.ui.Notifications)

Example 8 with Window

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

the class ScreenDependencyUtils method findWindowVerticalLayout.

protected static Optional<JmixWindowVerticalLayout> findWindowVerticalLayout(FrameOwner frameOwner) {
    Window window = UiControllerUtils.getScreen(frameOwner).getWindow();
    Component vComponent = window.unwrap(Component.class);
    if (vComponent instanceof JmixWindowVerticalLayout) {
        return Optional.of(((JmixWindowVerticalLayout) vComponent));
    }
    return Optional.empty();
}
Also used : Window(io.jmix.ui.component.Window) JmixWindowVerticalLayout(io.jmix.ui.widget.JmixWindowVerticalLayout) Component(com.vaadin.ui.Component)

Example 9 with Window

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

the class FilterDelegateImpl method getDefaultFilter.

protected FilterEntity getDefaultFilter(List<FilterEntity> filters) {
    Window window = CubaComponentsHelper.getWindowImplementation(filter);
    if (window == null) {
        throw new IllegalStateException("There is no window set for filter");
    }
    // First check if there is parameter with name equal to this filter component id, containing a filter code to apply
    Map<String, Object> params = filter.getFrame().getContext().getParams();
    String code = (String) params.get(filter.getId());
    if (!StringUtils.isBlank(code)) {
        for (FilterEntity filter : filters) {
            if (code.equals(filter.getCode())) {
                return filter;
            }
        }
    }
    // No 'filter' parameter found, load default filter
    FilterEntity defaultFilter = filter.getFrame().getFrameOwner() instanceof LegacyFrame ? getDefaultFilterFromCubaSettings(filters) : getDefaultFilterFromScreenSettings(filters);
    if (defaultFilter != null) {
        return defaultFilter;
    }
    FilterEntity globalDefaultFilter = filters.stream().filter(filterEntity -> Boolean.TRUE.equals(filterEntity.getGlobalDefault())).findAny().orElse(null);
    return globalDefaultFilter;
}
Also used : Window(io.jmix.ui.component.Window) FilterSelectWindow(com.haulmont.cuba.gui.components.filter.filterselect.FilterSelectWindow) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)

Example 10 with Window

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

the class FilterDelegateImpl method getDefaultFilterFromCubaSettings.

@Nullable
protected FilterEntity getDefaultFilterFromCubaSettings(List<FilterEntity> filters) {
    Window window = CubaComponentsHelper.getWindowImplementation(filter);
    if (window == null) {
        throw new IllegalStateException("There is no window set for filter");
    }
    SettingsImpl settings = new SettingsImpl(window.getId());
    String componentPath = CubaComponentsHelper.getFilterComponentPath(filter);
    String[] strings = ValuePathHelper.parse(componentPath);
    String name = ValuePathHelper.pathSuffix(strings);
    Element e = settings.get(name).element("defaultFilter");
    if (e != null) {
        String defIdStr = e.attributeValue("id");
        Boolean applyDefault = Boolean.valueOf(e.attributeValue("applyDefault"));
        if (!StringUtils.isBlank(defIdStr)) {
            UUID defaultId = null;
            try {
                defaultId = UUID.fromString(defIdStr);
            } catch (IllegalArgumentException ex) {
            // 
            }
            if (defaultId != null) {
                for (FilterEntity filter : filters) {
                    if (defaultId.equals(filter.getId())) {
                        filter.setIsDefault(true);
                        filter.setApplyDefault(applyDefault);
                        return filter;
                    }
                }
            }
        }
    }
    return null;
}
Also used : Window(io.jmix.ui.component.Window) FilterSelectWindow(com.haulmont.cuba.gui.components.filter.filterselect.FilterSelectWindow) SettingsImpl(com.haulmont.cuba.settings.SettingsImpl) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Element(org.dom4j.Element) Nullable(javax.annotation.Nullable)

Aggregations

Window (io.jmix.ui.component.Window)29 FilterSelectWindow (com.haulmont.cuba.gui.components.filter.filterselect.FilterSelectWindow)5 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)4 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)4 MetaClass (io.jmix.core.metamodel.model.MetaClass)4 Filter (com.haulmont.cuba.gui.components.Filter)3 Action (io.jmix.ui.action.Action)3 Component (io.jmix.ui.component.Component)3 HashMap (java.util.HashMap)3 WindowManager (com.haulmont.cuba.gui.WindowManager)2 AbstractCondition (com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)2 DsContext (com.haulmont.cuba.gui.data.DsContext)2 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)2 Messages (io.jmix.core.Messages)2 UiScreenProperties (io.jmix.ui.UiScreenProperties)2 WindowInfo (io.jmix.ui.WindowInfo)2 BaseAction (io.jmix.ui.action.BaseAction)2 Frame (io.jmix.ui.component.Frame)2 Screen (io.jmix.ui.screen.Screen)2 CubaProperties (com.haulmont.cuba.CubaProperties)1