Search in sources :

Example 1 with FrameOwner

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

the class TwinColumnLoader method loadOptionsContainer.

protected void loadOptionsContainer(TwinColumn component, Element element) {
    String containerId = element.attributeValue("optionsContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        if (!(container instanceof CollectionContainer)) {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        // noinspection unchecked
        component.setOptions(new ContainerOptions((CollectionContainer) container));
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 2 with FrameOwner

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

the class LookupFieldLoader method loadNewOptionHandler.

protected void loadNewOptionHandler(LookupField component, Element element) {
    String newOptionAllowed = element.attributeValue("newOptionAllowed");
    if (StringUtils.isNotEmpty(newOptionAllowed)) {
        component.setNewOptionAllowed(Boolean.parseBoolean(newOptionAllowed));
    }
    String newOptionHandlerMethod = element.attributeValue("newOptionHandler");
    if (StringUtils.isNotEmpty(newOptionHandlerMethod)) {
        FrameOwner controller = getComponentContext().getFrame().getFrameOwner();
        Class<? extends FrameOwner> windowClass = controller.getClass();
        Method newOptionHandler;
        try {
            newOptionHandler = windowClass.getMethod(newOptionHandlerMethod, LookupField.class, String.class);
        } catch (NoSuchMethodException e) {
            Map<String, Object> params = ParamsMap.of("LookupField Id", component.getId(), "Method name", newOptionHandlerMethod);
            throw new GuiDevelopmentException("Unable to find new option handler method for lookup field", context, params);
        }
        component.setNewOptionHandler(caption -> {
            try {
                newOptionHandler.invoke(controller, component, caption);
            } catch (IllegalAccessException | InvocationTargetException e) {
                throw new RuntimeException("Unable to invoke new option handler", e);
            }
        });
    }
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LookupField(com.haulmont.cuba.gui.components.LookupField) Method(java.lang.reflect.Method) ParamsMap(com.haulmont.bali.util.ParamsMap) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with FrameOwner

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

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

the class DynamicAttributesPanelLoader method loadDataContainer.

protected void loadDataContainer(DynamicAttributesPanel resultComponent, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (Strings.isNullOrEmpty(containerId)) {
        throw new GuiDevelopmentException("DynamicAttributesPanel element doesn't have 'dataContainer' attribute", context, "DynamicAttributesPanel ID", element.attributeValue("id"));
    }
    FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
    ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
    InstanceContainer container = screenData.getContainer(containerId);
    // noinspection unchecked
    resultComponent.setInstanceContainer(container);
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 5 with FrameOwner

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

the class TestCommentaryPanelLoader method loadDataContainer.

@SuppressWarnings("unchecked")
private void loadDataContainer(TestCommentaryPanel resultComponent, Element element) {
    String containerId = this.element.attributeValue("dataContainer");
    if (Strings.isNullOrEmpty(containerId)) {
        throw new GuiDevelopmentException("CommentaryPanel element doesn't have 'dataContainer' attribute", context, "CommentaryPanel ID", element.attributeValue("id"));
    }
    FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
    ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
    InstanceContainer container = screenData.getContainer(containerId);
    if (container instanceof CollectionContainer) {
        resultComponent.setDataContainer((CollectionContainer) container);
    } else {
        throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
    }
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

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