Search in sources :

Example 1 with ScreenFragment

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

the class FragmentHelper method createController.

@SuppressWarnings("unchecked")
public ScreenFragment createController(WindowInfo windowInfo, Fragment fragment) {
    Class screenClass = windowInfo.getControllerClass();
    if (AbstractWindow.class.isAssignableFrom(screenClass)) {
        AbstractWindow legacyScreen;
        try {
            legacyScreen = (AbstractWindow) invokeConstructor(screenClass);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
            throw new DevelopmentException("Unable to create " + screenClass);
        }
        LegacyFragmentAdapter adapter = new LegacyFragmentAdapter(legacyScreen);
        legacyScreen.setFrame(fragment);
        adapter.setWrappedFrame(fragment);
        log.warn("Fragment class '{}' should not be inherited from AbstractWindow. " + "It may cause problems with controller life cycle. " + "Fragment controllers should inherit ScreenFragment.", screenClass.getSimpleName());
        return adapter;
    }
    // new screens cannot be opened in fragments
    if (!ScreenFragment.class.isAssignableFrom(screenClass)) {
        throw new IllegalStateException(String.format("Fragment controllers should inherit ScreenFragment." + " UI controller is not ScreenFragment - %s %s", windowInfo.toString(), screenClass.getSimpleName()));
    }
    ScreenFragment controller;
    try {
        controller = (ScreenFragment) invokeConstructor(screenClass);
    } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException("Unable to create instance of screen class " + screenClass);
    }
    return controller;
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException) AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)

Example 2 with ScreenFragment

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

the class WebSuggestionField method showSuggestions.

protected void showSuggestions(List<V> suggestions, boolean userOriginated) {
    FrameOwner frameOwner = getFrame().getFrameOwner();
    Collection<Screen> dialogScreens = UiControllerUtils.getScreenContext(frameOwner).getScreens().getOpenedScreens().getDialogScreens();
    Screen lastDialog = null;
    for (Screen dialogScreen : dialogScreens) {
        lastDialog = dialogScreen;
    }
    if (frameOwner instanceof ScreenFragment) {
        frameOwner = ComponentsHelper.getScreen((ScreenFragment) frameOwner);
    }
    if (lastDialog == null || Objects.equals(frameOwner, lastDialog)) {
        component.showSuggestions(suggestions, userOriginated);
    }
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) Screen(com.haulmont.cuba.gui.screen.Screen)

Example 3 with ScreenFragment

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

the class UiControllerPropertyInjector method findDatasource.

@Nullable
protected Datasource findDatasource(String datasourceId) {
    Datasource datasource = null;
    if (sourceScreen instanceof LegacyFrame) {
        ((LegacyFrame) sourceScreen).getDsContext().get(datasourceId);
    }
    FrameOwner frameOwner = this.frameOwner instanceof ScreenFragment ? ((ScreenFragment) this.frameOwner).getHostController() : this.frameOwner;
    if (frameOwner instanceof LegacyFrame) {
        datasource = ((LegacyFrame) frameOwner).getDsContext().get(datasourceId);
    }
    return datasource;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Nullable(javax.annotation.Nullable)

Example 4 with ScreenFragment

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

the class UiControllerPropertyInjector method findComponent.

@Nullable
protected Component findComponent(String componentId) {
    Component component = null;
    Window window = null;
    if (sourceScreen != null) {
        window = sourceScreen.getWindow();
    } else if (frameOwner instanceof ScreenFragment) {
        FrameOwner host = ((ScreenFragment) frameOwner).getHostController();
        if (host instanceof Screen) {
            window = ((Screen) host).getWindow();
        }
    } else if (frameOwner instanceof Screen) {
        window = ((Screen) frameOwner).getWindow();
    }
    if (window != null) {
        component = window.getComponent(componentId);
    }
    return component;
}
Also used : Window(com.haulmont.cuba.gui.components.Window) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Screen(com.haulmont.cuba.gui.screen.Screen) Component(com.haulmont.cuba.gui.components.Component) Nullable(javax.annotation.Nullable)

Example 5 with ScreenFragment

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

the class WebSuggestionPickerField method showSuggestions.

protected void showSuggestions(List<V> suggestions, boolean userOriginated) {
    FrameOwner frameOwner = getFrame().getFrameOwner();
    Collection<Screen> dialogScreens = UiControllerUtils.getScreenContext(frameOwner).getScreens().getOpenedScreens().getDialogScreens();
    Screen lastDialog = null;
    for (Screen dialogScreen : dialogScreens) {
        lastDialog = dialogScreen;
    }
    if (frameOwner instanceof ScreenFragment) {
        frameOwner = ComponentsHelper.getScreen((ScreenFragment) frameOwner);
    }
    if (lastDialog == null || Objects.equals(frameOwner, lastDialog)) {
        getComponent().showSuggestions(suggestions, userOriginated);
    }
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) Screen(com.haulmont.cuba.gui.screen.Screen)

Aggregations

ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)9 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)6 Screen (com.haulmont.cuba.gui.screen.Screen)4 Element (org.dom4j.Element)3 Component (com.haulmont.cuba.gui.components.Component)2 Fragment (com.haulmont.cuba.gui.components.Fragment)2 FragmentImplementation (com.haulmont.cuba.gui.components.sys.FragmentImplementation)2 FrameImplementation (com.haulmont.cuba.gui.components.sys.FrameImplementation)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 ScreenDataImpl (com.haulmont.cuba.gui.model.impl.ScreenDataImpl)2 FragmentContextImpl (com.haulmont.cuba.gui.sys.FragmentContextImpl)2 FragmentHelper (com.haulmont.cuba.gui.sys.FragmentHelper)2 ScreenContextImpl (com.haulmont.cuba.gui.sys.ScreenContextImpl)2 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)2 ScreenXmlLoader (com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader)2 Nullable (javax.annotation.Nullable)2 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)1 Fragments (com.haulmont.cuba.gui.Fragments)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1