Search in sources :

Example 6 with WindowInfo

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

the class BulkEditAction method actionPerform.

@Override
public void actionPerform(Component component) {
    if (beforeActionPerformedHandler != null && !beforeActionPerformedHandler.beforeActionPerformed()) {
        return;
    }
    Security security = AppBeans.get(Security.class);
    if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
        Messages messages = AppBeans.get(Messages.class);
        Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
        notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("accessDenied.message")).show();
        return;
    }
    if (target.getSelected().isEmpty()) {
        Messages messages = AppBeans.get(Messages.class);
        Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
        notifications.create(NotificationType.HUMANIZED).withCaption(messages.getMessage("actions.BulkEdit.emptySelection")).show();
        return;
    }
    OpenType openType = this.openType;
    if (openType.getOpenMode() == OpenMode.DIALOG) {
        ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.class);
        ThemeConstants theme = themeManager.getConstants();
        openType = openType.copy().width(theme.get("cuba.gui.BulkEditAction.editorDialog.width")).height(theme.get("cuba.gui.BulkEditAction.editorDialog.height")).resizable(true);
    }
    Map<String, Object> params = ParamsMap.of().pair("metaClass", target.getDatasource().getMetaClass()).pair("selected", target.getSelected()).pair("exclude", exclude).pair("includeProperties", includeProperties != null ? includeProperties : Collections.EMPTY_LIST).pair("fieldValidators", fieldValidators).pair("modelValidators", modelValidators).pair("loadDynamicAttributes", loadDynamicAttributes).pair("useConfirmDialog", useConfirmDialog).pair("columnsMode", columnsMode).create();
    WindowManager wm = ((WindowManager) getScreenContext(target.getFrame()).getScreens());
    WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("bulkEditor");
    Window bulkEditor = wm.openWindow(windowInfo, openType, params);
    bulkEditor.addCloseListener(actionId -> {
        if (Window.COMMIT_ACTION_ID.equals(actionId)) {
            target.getDatasource().refresh();
        }
        if (target instanceof Component.Focusable) {
            ((Component.Focusable) target).focus();
        }
    });
}
Also used : Window(com.haulmont.cuba.gui.components.Window) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Messages(io.jmix.core.Messages) ThemeConstantsManager(io.jmix.ui.theme.ThemeConstantsManager) Security(com.haulmont.cuba.core.global.Security) WindowManager(com.haulmont.cuba.gui.WindowManager) WindowInfo(io.jmix.ui.WindowInfo) WindowConfig(io.jmix.ui.WindowConfig) ThemeConstants(io.jmix.ui.theme.ThemeConstants) Notifications(io.jmix.ui.Notifications)

Example 7 with WindowInfo

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

the class AddConditionHelper method addCondition.

/**
 * Opens AddCondition window. When condition is selected/created a {@code Handler#handle} method will be called
 *
 * @param conditionsTree conditions tree is necessary for custom condition editing. It is used for suggestion of
 *                       other component names in 'param where' field.
 */
public void addCondition(final ConditionsTree conditionsTree) {
    Map<String, Object> params = new HashMap<>();
    ConditionDescriptorsTreeBuilderAPI descriptorsTreeBuilder = AppBeans.getPrototype(ConditionDescriptorsTreeBuilderAPI.NAME, filter, properties.getGenericFilterPropertiesHierarchyDepth(), hideDynamicAttributes, hideCustomConditions, conditionsTree);
    Tree<AbstractConditionDescriptor> descriptorsTree = descriptorsTreeBuilder.build();
    params.put("descriptorsTree", descriptorsTree);
    WindowInfo windowInfo = windowConfig.getWindowInfo("addCondition");
    AddConditionWindow window = (AddConditionWindow) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
    window.addCloseListener(actionId -> {
        if (Window.COMMIT_ACTION_ID.equals(actionId)) {
            Collection<AbstractConditionDescriptor> descriptors = window.getDescriptors();
            if (descriptors != null) {
                for (AbstractConditionDescriptor descriptor : descriptors) {
                    _addCondition(descriptor, conditionsTree);
                }
            }
        }
    });
}
Also used : AbstractConditionDescriptor(com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor) HashMap(java.util.HashMap) AddConditionWindow(com.haulmont.cuba.gui.components.filter.addcondition.AddConditionWindow) ConditionDescriptorsTreeBuilderAPI(com.haulmont.cuba.gui.components.filter.addcondition.ConditionDescriptorsTreeBuilderAPI) WindowInfo(io.jmix.ui.WindowInfo)

Example 8 with WindowInfo

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

the class AddConditionHelper method _addCondition.

protected void _addCondition(AbstractConditionDescriptor descriptor, ConditionsTree conditionsTree) {
    final AbstractCondition condition = descriptor.createCondition();
    if (descriptor instanceof CustomConditionCreator) {
        WindowInfo windowInfo = windowConfig.getWindowInfo("customConditionEditor");
        Map<String, Object> params = new HashMap<>();
        params.put("condition", condition);
        params.put("conditionsTree", conditionsTree);
        params.put("filter", filter);
        final CustomConditionEditor window = (CustomConditionEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
        window.addCloseListener(actionId -> {
            if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                handler.handle(condition);
            }
        });
    } else if (descriptor instanceof DynamicAttributesConditionCreator) {
        WindowInfo windowInfo = windowConfig.getWindowInfo("dynamicAttributesConditionEditor");
        Map<String, Object> params = new HashMap<>();
        params.put("condition", condition);
        params.put("filter", filter);
        DynamicAttributesConditionEditor window = (DynamicAttributesConditionEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
        window.addCloseListener(actionId -> {
            if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                handler.handle(condition);
            }
        });
    } else {
        handler.handle(condition);
    }
}
Also used : CustomConditionCreator(com.haulmont.cuba.gui.components.filter.descriptor.CustomConditionCreator) WindowManager(com.haulmont.cuba.gui.WindowManager) Collection(java.util.Collection) CubaProperties(com.haulmont.cuba.CubaProperties) AddConditionWindow(com.haulmont.cuba.gui.components.filter.addcondition.AddConditionWindow) HashMap(java.util.HashMap) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) AppBeans(com.haulmont.cuba.core.global.AppBeans) CustomConditionEditor(com.haulmont.cuba.gui.components.filter.edit.CustomConditionEditor) Tree(io.jmix.core.common.datastruct.Tree) WindowConfig(io.jmix.ui.WindowConfig) ConditionDescriptorsTreeBuilderAPI(com.haulmont.cuba.gui.components.filter.addcondition.ConditionDescriptorsTreeBuilderAPI) AbstractConditionDescriptor(com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor) DynamicAttributesConditionCreator(com.haulmont.cuba.gui.components.filter.descriptor.DynamicAttributesConditionCreator) WindowInfo(io.jmix.ui.WindowInfo) DynamicAttributesConditionEditor(com.haulmont.cuba.gui.components.filter.edit.DynamicAttributesConditionEditor) Map(java.util.Map) WindowManagerProvider(com.haulmont.cuba.gui.WindowManagerProvider) Filter(com.haulmont.cuba.gui.components.Filter) Window(io.jmix.ui.component.Window) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) CustomConditionEditor(com.haulmont.cuba.gui.components.filter.edit.CustomConditionEditor) CustomConditionCreator(com.haulmont.cuba.gui.components.filter.descriptor.CustomConditionCreator) HashMap(java.util.HashMap) WindowInfo(io.jmix.ui.WindowInfo) DynamicAttributesConditionEditor(com.haulmont.cuba.gui.components.filter.edit.DynamicAttributesConditionEditor) DynamicAttributesConditionCreator(com.haulmont.cuba.gui.components.filter.descriptor.DynamicAttributesConditionCreator) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with WindowInfo

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

the class CubaMenuItemCommands method loadParams.

protected Map<String, Object> loadParams(MenuItem item) {
    Element descriptor = item.getDescriptor();
    if (descriptor == null) {
        return Collections.emptyMap();
    }
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    for (Element element : descriptor.elements("param")) {
        String value = element.attributeValue("value");
        EntityLoadInfo info = EntityLoadInfo.parse(value);
        if (info == null) {
            if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
                Boolean booleanValue = Boolean.valueOf(value);
                builder.put(element.attributeValue("name"), booleanValue);
            } else {
                if (value.startsWith("${") && value.endsWith("}")) {
                    String property = environment.getProperty(value.substring(2, value.length() - 1));
                    if (!StringUtils.isEmpty(property)) {
                        value = property;
                    }
                }
                builder.put(element.attributeValue("name"), value);
            }
        } else {
            builder.put(element.attributeValue("name"), loadEntityInstance(info));
        }
    }
    String screen = item.getScreen();
    if (StringUtils.isNotEmpty(screen)) {
        WindowInfo windowInfo = windowConfig.getWindowInfo(screen);
        // caption is passed only for legacy screens
        if (windowInfo.getDescriptor() != null) {
            String caption = menuConfig.getItemCaption(item);
            builder.put("caption", caption);
        }
    }
    return builder.build();
}
Also used : EntityLoadInfo(com.haulmont.cuba.core.global.EntityLoadInfo) Element(org.dom4j.Element) ImmutableMap(com.google.common.collect.ImmutableMap) WindowInfo(io.jmix.ui.WindowInfo)

Example 10 with WindowInfo

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

the class FragmentComponentLoader method createComponent.

@Override
public void createComponent() {
    WindowInfo windowInfo = createWindowInfo(element);
    String fragmentId;
    if (element.attributeValue("id") != null) {
        fragmentId = element.attributeValue("id");
    } else {
        fragmentId = windowInfo.getId();
    }
    Timer.Sample createSample = Timer.start(getMeterRegistry());
    Fragment fragment = createComponentInternal();
    FragmentHelper fragmentHelper = getFragmentHelper();
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    FrameOwner hostController = parentContext.getFrame().getFrameOwner();
    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setupScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, applicationContext.getBean(ScreenData.class));
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);
    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }
        innerContext = createInnerContext();
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        innerContext.setProperties(loadProperties(element));
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = applicationContext.getBean(ScreenXmlLoader.class);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getComponentContext().getParams());
        innerContext.setMessageGroup(fragmentHelper.findMessageGroup(rootElement, windowInfo.getTemplate()));
        loadAdditionalData(rootElement);
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    createSample.stop(createScreenTimer(getMeterRegistry(), ScreenLifeCycle.CREATE, windowInfo.getId()));
    this.resultComponent = fragment;
}
Also used : FragmentImplementation(io.jmix.ui.component.impl.FragmentImplementation) Element(org.dom4j.Element) FrameImplementation(io.jmix.ui.component.impl.FrameImplementation) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) WindowInfo(io.jmix.ui.WindowInfo) Timer(io.micrometer.core.instrument.Timer) UiMonitoring.createScreenTimer(io.jmix.ui.monitoring.UiMonitoring.createScreenTimer) ScreenFragment(io.jmix.ui.screen.ScreenFragment) FrameOwner(io.jmix.ui.screen.FrameOwner) ScreenData(io.jmix.ui.model.ScreenData)

Aggregations

WindowInfo (io.jmix.ui.WindowInfo)24 WindowManager (com.haulmont.cuba.gui.WindowManager)7 WindowConfig (io.jmix.ui.WindowConfig)7 HashMap (java.util.HashMap)6 Element (org.dom4j.Element)5 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)3 Window (io.jmix.ui.component.Window)3 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 WindowManagerProvider (com.haulmont.cuba.gui.WindowManagerProvider)2 Filter (com.haulmont.cuba.gui.components.Filter)2 Window (com.haulmont.cuba.gui.components.Window)2 AddConditionWindow (com.haulmont.cuba.gui.components.filter.addcondition.AddConditionWindow)2 ConditionDescriptorsTreeBuilderAPI (com.haulmont.cuba.gui.components.filter.addcondition.ConditionDescriptorsTreeBuilderAPI)2 AbstractConditionDescriptor (com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor)2 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)2 Screens (io.jmix.ui.Screens)2 NotFoundScreen (io.jmix.ui.app.navigation.notfoundwindow.NotFoundScreen)2 Fragment (io.jmix.ui.component.Fragment)2 FragmentImplementation (io.jmix.ui.component.impl.FragmentImplementation)2 FrameImplementation (io.jmix.ui.component.impl.FrameImplementation)2