Search in sources :

Example 1 with LegacyFrame

use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.

the class EditAction method internalOpenEditor.

protected void internalOpenEditor(CollectionDatasource datasource, Entity existingItem, Datasource parentDs, Map<String, Object> params) {
    LegacyFrame frameOwner = (LegacyFrame) target.getFrame().getFrameOwner();
    AbstractEditor window = frameOwner.openEditor(getWindowId(), existingItem, getOpenType(), params, parentDs);
    if (editorCloseListener == null) {
        window.addCloseListener(actionId -> {
            // move focus to owner
            if (target instanceof Component.Focusable) {
                ((Component.Focusable) target).focus();
            }
            if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                Entity editedItem = window.getItem();
                if (editedItem != null) {
                    if (parentDs == null) {
                        editedItem = AppBeans.get(GuiActionSupport.class).reloadEntityIfNeeded(editedItem, datasource);
                        // noinspection unchecked
                        datasource.updateItem(editedItem);
                    }
                    afterCommit(editedItem);
                    if (afterCommitHandler != null) {
                        afterCommitHandler.handle(editedItem);
                    }
                }
            }
            afterWindowClosed(window);
            if (afterWindowClosedHandler != null) {
                afterWindowClosedHandler.handle(window, actionId);
            }
        });
    } else {
        window.addCloseListener(editorCloseListener);
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)

Example 2 with LegacyFrame

use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.

the class EditAction method actionPerform.

/**
 * This method is invoked by the action owner component.
 *
 * @param component component invoking the action
 */
@Override
public void actionPerform(Component component) {
    if (beforeActionPerformedHandler != null) {
        if (!beforeActionPerformedHandler.beforeActionPerformed())
            return;
    }
    final Set selected = target.getSelected();
    if (selected.size() == 1) {
        Datasource parentDs = null;
        final CollectionDatasource datasource = target.getDatasource();
        if (datasource instanceof PropertyDatasource) {
            MetaProperty metaProperty = ((PropertyDatasource) datasource).getProperty();
            if (metaProperty.getType().equals(MetaProperty.Type.COMPOSITION)) {
                parentDs = datasource;
            }
        }
        Map<String, Object> params = prepareWindowParams();
        internalOpenEditor(datasource, datasource.getItem(), parentDs, params);
    } else if (selected.size() > 1 && bulkEditorIntegration.isEnabled()) {
        UserSession userSession = AppBeans.get(UserSessionSource.class).getUserSession();
        boolean isBulkEditorPermitted = userSession.isSpecificPermitted(BulkEditor.PERMISSION);
        if (isBulkEditorPermitted) {
            // if bulk editor integration enabled and permitted for user
            Map<String, Object> params = ParamsMap.of("metaClass", target.getDatasource().getMetaClass(), "selected", selected, "exclude", bulkEditorIntegration.getExcludePropertiesRegex(), "fieldValidators", bulkEditorIntegration.getFieldValidators(), "modelValidators", bulkEditorIntegration.getModelValidators());
            LegacyFrame frameOwner = (LegacyFrame) target.getFrame().getFrameOwner();
            Window bulkEditor = frameOwner.openWindow("bulkEditor", bulkEditorIntegration.getOpenType(), params);
            bulkEditor.addCloseListener(actionId -> {
                if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                    target.getDatasource().refresh();
                }
                if (target instanceof Component.Focusable) {
                    ((Component.Focusable) target).focus();
                }
                Consumer<BulkEditorCloseEvent> afterEditorCloseHandler = bulkEditorIntegration.getAfterEditorCloseHandler();
                if (afterEditorCloseHandler != null) {
                    afterEditorCloseHandler.accept(new BulkEditorCloseEvent(this, bulkEditor, actionId));
                }
            });
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) java.util(java.util) Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ParamsMap(com.haulmont.bali.util.ParamsMap) CubaIcon(com.haulmont.cuba.gui.icons.CubaIcon) Messages(com.haulmont.cuba.core.global.Messages) AppBeans(com.haulmont.cuba.core.global.AppBeans) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Icons(com.haulmont.cuba.gui.icons.Icons) Supplier(java.util.function.Supplier) MetaClass(com.haulmont.chile.core.model.MetaClass) Scope(org.springframework.context.annotation.Scope) UserSession(com.haulmont.cuba.security.global.UserSession) Consumer(java.util.function.Consumer) EntityOp(com.haulmont.cuba.security.entity.EntityOp) Configuration(com.haulmont.cuba.core.global.Configuration) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) ClientConfig(com.haulmont.cuba.client.ClientConfig) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Consumer(java.util.function.Consumer) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) UserSession(com.haulmont.cuba.security.global.UserSession) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ParamsMap(com.haulmont.bali.util.ParamsMap)

Example 3 with LegacyFrame

use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.

the class HasWindowManager method openFrame.

/**
 * Load a frame registered in {@code screens.xml} and optionally show it inside a parent component of this
 * frame. <br> It is recommended to use {@link Fragments} bean instead.
 *
 * @param parent        if specified, all parent's sub components will be removed and the frame will be added
 * @param windowAlias   frame ID as defined in {@code screens.xml}
 * @param params        parameters to be passed into the frame's controller {@code init} method
 * @return              frame's controller instance
 */
@Deprecated
default Frame openFrame(@Nullable Component parent, String windowAlias, Map<String, Object> params) {
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    WindowInfo windowInfo = windowConfig.getWindowInfo(windowAlias);
    Frame parentFrame;
    if (this instanceof LegacyFrame) {
        parentFrame = ((LegacyFrame) this).getWrappedFrame();
    } else {
        parentFrame = ((Frame) this);
    }
    return getWindowManager().openFrame(parentFrame, parent, windowInfo, params);
}
Also used : WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo)

Example 4 with LegacyFrame

use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.

the class FilterDelegateImpl method fillTableActions.

/**
 * Adds actions of 'Entities Set' functionality to Table component
 */
protected void fillTableActions() {
    Table table;
    if ((applyTo != null) && (Table.class.isAssignableFrom(applyTo.getClass()))) {
        table = (Table) applyTo;
    } else {
        return;
    }
    ButtonsPanel buttons = table.getButtonsPanel();
    if (buttons == null) {
        // in lookup windows, there is no button panel
        return;
    }
    com.haulmont.cuba.gui.components.Button addToSetBtn = (Button) buttons.getComponent("addToSetBtn");
    com.haulmont.cuba.gui.components.Button addToCurSetBtn = (Button) buttons.getComponent("addToCurSetBtn");
    com.haulmont.cuba.gui.components.Button removeFromCurSetBtn = (Button) buttons.getComponent("removeFromCurSetBtn");
    Action addToSet = table.getAction("filter.addToSet");
    Action addToCurrSet = table.getAction("filter.addToCurSet");
    Action removeFromCurrSet = table.getAction("filter.removeFromCurSet");
    if (addToSet != null)
        table.removeAction(addToSet);
    if (addToSetBtn != null)
        addToSetBtn.setVisible(false);
    if (addToCurrSet != null) {
        table.removeAction(addToCurrSet);
    }
    if (addToCurSetBtn != null) {
        addToCurSetBtn.setVisible(false);
    }
    if (removeFromCurrSet != null) {
        table.removeAction(removeFromCurrSet);
    }
    if (removeFromCurSetBtn != null) {
        removeFromCurSetBtn.setVisible(false);
    }
    if ((filterEntity != null) && (BooleanUtils.isTrue(filterEntity.getIsSet()))) {
        addToSet = table.getAction("addToSet");
        if (addToSet != null) {
            addToSet.setVisible(false);
        }
        addToCurrSet = new AddToCurrSetAction();
        if (addToCurSetBtn == null) {
            addToCurSetBtn = uiComponents.create(Button.class);
            addToCurSetBtn.setId("addToCurSetBtn");
            addToCurSetBtn.setCaption(getMainMessage("filter.addToCurSet"));
            buttons.add(addToCurSetBtn);
        } else {
            addToCurSetBtn.setVisible(true);
        }
        if (StringUtils.isEmpty(addToCurSetBtn.getIcon())) {
            addToCurSetBtn.setIcon("icons/join-to-set.png");
        }
        addToCurSetBtn.setAction(addToCurrSet);
        table.addAction(addToCurrSet);
        removeFromCurrSet = new RemoveFromSetAction(table);
        if (removeFromCurSetBtn == null) {
            removeFromCurSetBtn = uiComponents.create(Button.class);
            removeFromCurSetBtn.setId("removeFromCurSetBtn");
            removeFromCurSetBtn.setCaption(getMainMessage("filter.removeFromCurSet"));
            buttons.add(removeFromCurSetBtn);
        } else {
            removeFromCurSetBtn.setVisible(true);
        }
        if (StringUtils.isEmpty(removeFromCurSetBtn.getIcon())) {
            removeFromCurSetBtn.setIcon("icons/delete-from-set.png");
        }
        removeFromCurSetBtn.setAction(removeFromCurrSet);
        table.addAction(removeFromCurrSet);
    } else if (filter.getFrame().getFrameOwner() instanceof LegacyFrame) {
        addToSet = new AddToSetAction(table);
        if (addToSetBtn == null) {
            addToSetBtn = uiComponents.create(Button.class);
            addToSetBtn.setId("addToSetBtn");
            addToSetBtn.setCaption(getMainMessage("filter.addToSet"));
            buttons.add(addToSetBtn);
        } else {
            addToSetBtn.setVisible(true);
        }
        if (StringUtils.isEmpty(addToSetBtn.getIcon())) {
            addToSetBtn.setIcon("icons/insert-to-set.png");
        }
        addToSetBtn.setAction(addToSet);
        table.addAction(addToSet);
    }
}
Also used : com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)

Example 5 with LegacyFrame

use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.

the class FakeFilterSupport method createFakeFilter.

public Filter createFakeFilter() {
    if (filter != null) {
        return filter;
    }
    Filter fakeFilter = AppBeans.get(ComponentsFactory.NAME, ComponentsFactory.class).createComponent(Filter.class);
    Dom4jTools dom4JTools = AppBeans.get(Dom4jTools.NAME);
    ((HasXmlDescriptor) fakeFilter).setXmlDescriptor(dom4JTools.readDocument("<filter/>").getRootElement());
    CollectionDatasourceImpl fakeDatasource = new CollectionDatasourceImpl();
    LegacyFrame legacyFrame = (LegacyFrame) this.frameOwner;
    DsContextImpl fakeDsContext = new DsContextImpl(legacyFrame.getDsContext().getDataSupplier());
    FrameContextImpl fakeFrameContext = new FrameContextImpl((Frame) legacyFrame);
    fakeDsContext.setFrameContext(fakeFrameContext);
    fakeDatasource.setDsContext(fakeDsContext);
    // Attention: this query should match the logic in com.haulmont.reports.wizard.ReportingWizardBean.createJpqlDataSet()
    fakeDatasource.setQuery("select queryEntity from " + metaClass.getName() + " queryEntity");
    fakeDatasource.setMetaClass(metaClass);
    fakeFilter.setDatasource(fakeDatasource);
    fakeFilter.setFrame(UiControllerUtils.getFrame(frameOwner));
    return fakeFilter;
}
Also used : ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Dom4jTools(com.haulmont.cuba.core.sys.xmlparsing.Dom4jTools) Filter(com.haulmont.cuba.gui.components.Filter) HasXmlDescriptor(com.haulmont.cuba.gui.components.Component.HasXmlDescriptor) FrameContextImpl(com.haulmont.cuba.gui.sys.FrameContextImpl) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) DsContextImpl(com.haulmont.cuba.gui.data.impl.DsContextImpl)

Aggregations

LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)23 Entity (com.haulmont.cuba.core.entity.Entity)5 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 DsContext (com.haulmont.cuba.gui.data.DsContext)5 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)4 MetaClass (com.haulmont.chile.core.model.MetaClass)3 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)2 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 Messages (com.haulmont.cuba.core.global.Messages)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 Component (com.haulmont.cuba.gui.components.Component)2 Filter (com.haulmont.cuba.gui.components.Filter)2 Frame (com.haulmont.cuba.gui.components.Frame)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2