Search in sources :

Example 11 with LegacyFrame

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

the class FragmentLoader method loadDsContext.

protected void loadDsContext(@Nullable Element dsContextElement) {
    DsContext dsContext = null;
    if (resultComponent.getFrameOwner() instanceof LegacyFrame) {
        DsContextLoader dsContextLoader;
        DsContext parentDsContext = getComponentContext().getParent().getDsContext();
        if (parentDsContext != null) {
            dsContextLoader = new DsContextLoader(parentDsContext.getDataSupplier());
        } else {
            dsContextLoader = new DsContextLoader(new GenericDataSupplier());
        }
        dsContext = dsContextLoader.loadDatasources(dsContextElement, parentDsContext, getComponentContext().getAliasesMap());
        ((ComponentLoaderContext) context).setDsContext(dsContext);
    }
    if (dsContext != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        if (frameOwner instanceof LegacyFrame) {
            LegacyFrame frame = (LegacyFrame) frameOwner;
            frame.setDsContext(dsContext);
            for (Datasource ds : dsContext.getAll()) {
                if (ds instanceof DatasourceImplementation) {
                    ((DatasourceImplementation) ds).initialized();
                }
            }
            dsContext.setFrameContext(resultComponent.getContext());
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) GenericDataSupplier(com.haulmont.cuba.gui.data.impl.GenericDataSupplier) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Example 12 with LegacyFrame

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

the class WebEntityLinkField method openEntityEditor.

protected void openEntityEditor() {
    V value = getValue();
    Entity entity = null;
    if (value instanceof Entity) {
        entity = (Entity) value;
    } else if (getValueSource() instanceof EntityValueSource) {
        entity = ((EntityValueSource) getValueSource()).getItem();
    }
    if (entity == null) {
        return;
    }
    Window window = ComponentsHelper.getWindow(this);
    if (window == null) {
        throw new IllegalStateException("Please specify Frame for EntityLinkField");
    }
    ScreenContext context = ComponentsHelper.getScreenContext(this);
    if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
        Messages messages = AppBeans.get(Messages.NAME);
        context.getNotifications().create(Notifications.NotificationType.HUMANIZED).withCaption(messages.getMainMessage("OpenAction.objectIsDeleted")).show();
        return;
    }
    if (window.getFrameOwner() instanceof LegacyFrame) {
        LegacyFrame frameOwner = (LegacyFrame) window.getFrameOwner();
        DataSupplier dataSupplier = frameOwner.getDsContext().getDataSupplier();
        entity = dataSupplier.reload(entity, View.MINIMAL);
    } else {
        DataManager dataManager = beanLocator.get(DataManager.NAME);
        entity = dataManager.reload(entity, View.MINIMAL);
    }
    String windowAlias = screen;
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    if (windowAlias == null) {
        windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
    }
    Screen screenEditor = screenBuilders.editor(entity.getMetaClass().getJavaClass(), window.getFrameOwner()).withScreenId(windowAlias).editEntity(entity).withOpenMode(screenOpenMode).withOptions(new MapScreenOptions(screenParams != null ? screenParams : new HashMap<>())).build();
    screenEditor.addAfterCloseListener(event -> {
        // move focus to component
        component.focus();
        String closeActionId = null;
        CloseAction closeAction = event.getCloseAction();
        if (closeAction instanceof StandardCloseAction) {
            closeActionId = ((StandardCloseAction) closeAction).getActionId();
        }
        Screen screenSource = null;
        if (StringUtils.isNotEmpty(closeActionId) && Window.COMMIT_ACTION_ID.equals(closeActionId)) {
            Entity item = null;
            screenSource = event.getSource();
            if (screenSource instanceof EditorScreen) {
                item = ((EditorScreen) screenSource).getEditedEntity();
            }
            if (item != null) {
                afterCommitOpenedEntity(item);
            }
        }
        fireEditorCloseEvent(screenSource == null ? null : (EditorScreen) screenSource, closeActionId);
    });
    screenEditor.show();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) HashMap(java.util.HashMap) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Example 13 with LegacyFrame

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

the class WebAccordion method initComponentTabChangeListener.

protected void initComponentTabChangeListener() {
    // after all lazy tabs listeners
    if (!componentTabChangeListenerInitialized) {
        component.addSelectedTabChangeListener(event -> {
            if (context instanceof ComponentLoader.ComponentContext) {
                ((ComponentLoader.ComponentContext) context).executeInjectTasks();
                ((ComponentLoader.ComponentContext) context).executeInitTasks();
            }
            // Fire GUI listener
            fireTabChanged();
            // We suppose that context.executePostInitTasks() executes a task once and then remove it from task list.
            if (context instanceof ComponentLoader.ComponentContext) {
                ((ComponentLoader.ComponentContext) context).executePostInitTasks();
            }
            Window window = ComponentsHelper.getWindow(WebAccordion.this);
            if (window != null) {
                if (window.getFrameOwner() instanceof LegacyFrame) {
                    DsContext dsContext = ((LegacyFrame) window.getFrameOwner()).getDsContext();
                    if (dsContext != null) {
                        ((DsContextImplementation) dsContext).resumeSuspended();
                    }
                }
            } else {
                LoggerFactory.getLogger(WebAccordion.class).warn("Please specify Frame for Accordion");
            }
        });
        componentTabChangeListenerInitialized = true;
    }
}
Also used : DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) DsContext(com.haulmont.cuba.gui.data.DsContext) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)

Example 14 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}
 * @return              frame's controller instance
 */
@Deprecated
default Frame openFrame(@Nullable Component parent, String windowAlias) {
    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);
}
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 15 with LegacyFrame

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

the class RelatedEntitiesBean method openRelatedScreen.

@Override
public void openRelatedScreen(Collection<? extends Entity> selectedEntities, MetaClass metaClass, MetaProperty metaProperty, RelatedScreenDescriptor descriptor) {
    checkNotNullArgument(metaClass, "MetaClass can't be null");
    checkNotNullArgument(metaProperty, "MetaProperty can't be null");
    WindowManager windowManager = windowManagerProvider.get();
    if (!selectedEntities.isEmpty()) {
        Map<String, Object> params = new HashMap<>();
        WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
        WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
        if (descriptor != null && descriptor.getScreenParams() != null) {
            params.putAll(descriptor.getScreenParams());
        }
        String screenId;
        if (descriptor != null && StringUtils.isNotEmpty(descriptor.getScreenId())) {
            screenId = descriptor.getScreenId();
        } else {
            screenId = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
        }
        if (StringUtils.isEmpty(screenId)) {
            String message = String.format("Can't show related entities: passed screenId is null and " + "there is no default browse screen for %s", metaClass.getName());
            throw new IllegalStateException(message);
        }
        WindowManager.OpenType openType = WindowManager.OpenType.THIS_TAB;
        if (descriptor != null) {
            openType = descriptor.getOpenType();
        }
        Screen screen = windowManager.create(screenId, openType.getOpenMode(), new MapScreenOptions(params));
        boolean found = ComponentsHelper.walkComponents(screen.getWindow(), screenComponent -> {
            if (!(screenComponent instanceof Filter)) {
                return false;
            } else {
                MetaClass actualMetaClass = ((FilterImplementation) screenComponent).getEntityMetaClass();
                MetaClass relatedMetaClass = metaProperty.getRange().asClass();
                MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
                if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
                    MetaDataDescriptor metaDataDescriptor = new MetaDataDescriptor(metaClass, metaProperty);
                    applyFilter(((Filter) screenComponent), selectedEntities, descriptor, metaDataDescriptor);
                    return true;
                }
                return false;
            }
        });
        screen.show();
        if (!found) {
            windowManager.showNotification(messages.getMainMessage("actions.Related.FilterNotFound"), Frame.NotificationType.WARNING);
        }
        if (screen instanceof LegacyFrame) {
            LegacyFrame legacyFrame = (LegacyFrame) screen;
            ((DsContextImplementation) legacyFrame.getDsContext()).resumeSuspended();
        }
    } else {
        windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), Frame.NotificationType.HUMANIZED);
    }
}
Also used : DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) FilterImplementation(com.haulmont.cuba.gui.components.FilterImplementation) MetaClass(com.haulmont.chile.core.model.MetaClass) Filter(com.haulmont.cuba.gui.components.Filter)

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