Search in sources :

Example 1 with Disposable

use of com.haulmont.cuba.gui.components.Component.Disposable in project cuba by cuba-platform.

the class WebScreens method openFrame.

@SuppressWarnings({ "deprecation", "IncorrectCreateGuiComponent" })
@Override
public Frame openFrame(Frame parentFrame, com.haulmont.cuba.gui.components.Component parent, @Nullable String id, WindowInfo windowInfo, Map<String, Object> params) {
    ScreenFragment screenFragment;
    Fragments fragments = ui.getFragments();
    if (params != null && !params.isEmpty()) {
        screenFragment = fragments.create(parentFrame.getFrameOwner(), windowInfo.getId(), new MapScreenOptions(params));
    } else {
        screenFragment = fragments.create(parentFrame.getFrameOwner(), windowInfo.getId());
    }
    if (id != null) {
        screenFragment.getFragment().setId(id);
    }
    fragments.init(screenFragment);
    if (parent instanceof ComponentContainer) {
        ComponentContainer container = (ComponentContainer) parent;
        for (com.haulmont.cuba.gui.components.Component c : container.getComponents()) {
            if (c instanceof com.haulmont.cuba.gui.components.Component.Disposable) {
                com.haulmont.cuba.gui.components.Component.Disposable disposable = (com.haulmont.cuba.gui.components.Component.Disposable) c;
                if (!disposable.isDisposed()) {
                    disposable.dispose();
                }
            }
            container.remove(c);
        }
        container.add(screenFragment.getFragment());
    }
    if (screenFragment instanceof LegacyFragmentAdapter) {
        return ((LegacyFragmentAdapter) screenFragment).getRealScreen();
    }
    return screenFragment instanceof Frame ? (Frame) screenFragment : new ScreenFragmentWrapper(screenFragment);
}
Also used : Disposable(com.haulmont.cuba.gui.components.Component.Disposable) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Disposable(com.haulmont.cuba.gui.components.Component.Disposable) com.haulmont.cuba.gui(com.haulmont.cuba.gui) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)

Example 2 with Disposable

use of com.haulmont.cuba.gui.components.Component.Disposable in project cuba by cuba-platform.

the class WebScreens method remove.

@Override
public void remove(Screen screen) {
    checkNotNullArgument(screen);
    checkOpened(screen);
    WindowImplementation windowImpl = (WindowImplementation) screen.getWindow();
    if (windowImpl instanceof Disposable) {
        ((Disposable) windowImpl).dispose();
    }
    LaunchMode launchMode = windowImpl.getContext().getLaunchMode();
    if (launchMode instanceof OpenMode) {
        OpenMode openMode = (OpenMode) launchMode;
        switch(openMode) {
            case DIALOG:
                removeDialogWindow(screen);
                break;
            case NEW_TAB:
            case NEW_WINDOW:
                removeNewTabWindow(screen);
                break;
            case ROOT:
                removeRootWindow(screen);
                break;
            case THIS_TAB:
                removeThisTabWindow(screen);
                break;
            default:
                throw new UnsupportedOperationException("Unsupported OpenMode");
        }
    }
    fireEvent(screen, AfterDetachEvent.class, new AfterDetachEvent(screen));
    events.publish(new ScreenClosedEvent(screen));
    afterScreenRemove(screen);
}
Also used : Disposable(com.haulmont.cuba.gui.components.Component.Disposable) WindowImplementation(com.haulmont.cuba.gui.components.sys.WindowImplementation) ScreenClosedEvent(com.haulmont.cuba.gui.screen.event.ScreenClosedEvent)

Aggregations

Disposable (com.haulmont.cuba.gui.components.Component.Disposable)2 com.haulmont.cuba.gui (com.haulmont.cuba.gui)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)1 WindowImplementation (com.haulmont.cuba.gui.components.sys.WindowImplementation)1 ScreenClosedEvent (com.haulmont.cuba.gui.screen.event.ScreenClosedEvent)1