Search in sources :

Example 6 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner 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 7 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner 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 8 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner 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)

Example 9 with FrameOwner

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

the class DeclarativeAction method actionPerform.

@Override
public void actionPerform(Component component) {
    if (StringUtils.isEmpty(methodName)) {
        return;
    }
    FrameOwner controller = frame.getFrameOwner();
    if (controller instanceof LegacyFragmentAdapter) {
        controller = ((LegacyFragmentAdapter) controller).getRealScreen();
    }
    Method method;
    try {
        method = controller.getClass().getMethod(methodName, Component.class);
    } catch (NoSuchMethodException e) {
        try {
            method = controller.getClass().getMethod(methodName);
        } catch (NoSuchMethodException e1) {
            throw new IllegalStateException(String.format("No suitable methods named %s for action %s", methodName, id));
        }
    }
    try {
        if (method.getParameterCount() == 1) {
            method.invoke(controller, component);
        } else {
            method.invoke(controller);
        }
    } catch (Exception e) {
        throw new RuntimeException("Exception on action handling", e);
    }
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Method(java.lang.reflect.Method) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter) Component(com.haulmont.cuba.gui.components.Component)

Example 10 with FrameOwner

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

the class DeclarativeFieldGenerator method generateField.

@Override
public Component generateField(Datasource datasource, String propertyId) {
    Frame frame = fieldGroup.getFrame();
    if (frame == null) {
        throw new IllegalStateException("Table should be attached to frame");
    }
    FrameOwner controller = frame.getFrameOwner();
    if (controller instanceof LegacyFragmentAdapter) {
        controller = ((LegacyFragmentAdapter) controller).getRealScreen();
    }
    Class<? extends FrameOwner> cCls = controller.getClass();
    Method exactMethod = getAccessibleMethod(cCls, methodName, Datasource.class, String.class);
    if (exactMethod != null) {
        checkGeneratorMethodResultType(exactMethod, frame);
        try {
            return (Component) exactMethod.invoke(controller, datasource, propertyId);
        } catch (Exception e) {
            throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
        }
    }
    Method dsMethod = getAccessibleMethod(cCls, methodName, Datasource.class);
    if (dsMethod != null) {
        checkGeneratorMethodResultType(dsMethod, frame);
        try {
            return (Component) dsMethod.invoke(controller, datasource);
        } catch (Exception e) {
            throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
        }
    }
    Method parameterLessMethod = getAccessibleMethod(cCls, methodName);
    if (parameterLessMethod != null) {
        checkGeneratorMethodResultType(parameterLessMethod, frame);
        try {
            return (Component) parameterLessMethod.invoke(controller);
        } catch (Exception e) {
            throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
        }
    }
    String fieldGroupId = fieldGroup.getId() == null ? "" : fieldGroup.getId();
    throw new IllegalStateException(String.format("No suitable method named %s for column generator of table %s", methodName, fieldGroupId));
}
Also used : Frame(com.haulmont.cuba.gui.components.Frame) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) MethodUtils.getAccessibleMethod(org.apache.commons.lang3.reflect.MethodUtils.getAccessibleMethod) Method(java.lang.reflect.Method) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter) Component(com.haulmont.cuba.gui.components.Component) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Aggregations

FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)38 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)15 ScreenData (com.haulmont.cuba.gui.model.ScreenData)9 Component (com.haulmont.cuba.gui.components.Component)7 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)7 Element (org.dom4j.Element)7 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)6 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)6 ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)6 Method (java.lang.reflect.Method)6 MetaClass (com.haulmont.chile.core.model.MetaClass)5 Frame (com.haulmont.cuba.gui.components.Frame)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)4 Screen (com.haulmont.cuba.gui.screen.Screen)4 Fragment (com.haulmont.cuba.gui.components.Fragment)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)3 Screens (com.haulmont.cuba.gui.Screens)2 FragmentImplementation (com.haulmont.cuba.gui.components.sys.FragmentImplementation)2