Search in sources :

Example 6 with FrameOwner

use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.

the class PivotTableLoader method loadDataContainer.

protected void loadDataContainer(PivotTable pivotTable, Element element) {
    String dataContainerId = element.attributeValue("dataContainer");
    if (StringUtils.isNotEmpty(dataContainerId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        CollectionContainer dataContainer;
        InstanceContainer container = screenData.getContainer(dataContainerId);
        if (container instanceof CollectionContainer) {
            dataContainer = (CollectionContainer) container;
        } else {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + dataContainerId, context);
        }
        pivotTable.setDataProvider(new ContainerDataProvider(dataContainer));
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) CollectionContainer(io.jmix.ui.model.CollectionContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) ContainerDataProvider(io.jmix.ui.data.impl.ContainerDataProvider) ScreenData(io.jmix.ui.model.ScreenData)

Example 7 with FrameOwner

use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.

the class BulkEditors method buildEditor.

protected <E> BulkEditorWindow<E> buildEditor(BulkEditorBuilder<E> builder) {
    FrameOwner origin = builder.getOrigin();
    Screens screens = getScreenContext(origin).getScreens();
    if (CollectionUtils.isEmpty(builder.getEntities())) {
        throw new IllegalStateException(String.format("BulkEditor of %s cannot be open with no entities were set", builder.getMetaClass()));
    }
    // noinspection unchecked
    BulkEditorWindow<E> bulkEditorWindow = screens.create(BulkEditorWindow.class, builder.openMode);
    BulkEditorContext<E> context = createBulkEditorContext(builder);
    bulkEditorWindow.setBulkEditorContext(context);
    bulkEditorWindow.addAfterCloseListener(createAfterCloseHandler(builder));
    return bulkEditorWindow;
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) Screens(io.jmix.ui.Screens)

Example 8 with FrameOwner

use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.

the class EntitySuggestionFieldImpl 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(io.jmix.ui.screen.FrameOwner) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Screen(io.jmix.ui.screen.Screen)

Example 9 with FrameOwner

use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.

the class DeclarativeTrackingAction 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(io.jmix.ui.screen.FrameOwner) Method(java.lang.reflect.Method) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter) Component(io.jmix.ui.component.Component)

Example 10 with FrameOwner

use of io.jmix.ui.screen.FrameOwner in project jmix by jmix-framework.

the class CubaFilterLoader method loadComponent.

@Override
public void loadComponent() {
    assignXmlDescriptor(resultComponent, element);
    assignFrame(resultComponent);
    loadAlign(resultComponent, element);
    loadVisible(resultComponent, element);
    loadEnable(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadCss(resultComponent, element);
    loadMargin(resultComponent, element);
    loadIcon(resultComponent, element);
    loadHtmlSanitizerEnabled(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadContextHelp(resultComponent, element);
    loadWidth(resultComponent, element, "100%");
    loadCollapsible(resultComponent, element, true);
    loadSettingsEnabled(resultComponent, element);
    loadBorderVisible(resultComponent, element);
    loadWindowCaptionUpdateEnabled(resultComponent, element);
    String useMaxResults = element.attributeValue("useMaxResults");
    resultComponent.setUseMaxResults(useMaxResults == null || Boolean.parseBoolean(useMaxResults));
    String textMaxResults = element.attributeValue("textMaxResults");
    resultComponent.setTextMaxResults(Boolean.parseBoolean(textMaxResults));
    final String manualApplyRequired = element.attributeValue("manualApplyRequired");
    resultComponent.setManualApplyRequired(BooleanUtils.toBooleanObject(manualApplyRequired));
    String editable = element.attributeValue("editable");
    resultComponent.setEditable(editable == null || Boolean.parseBoolean(editable));
    String columnsCount = element.attributeValue("columnsCount");
    if (!Strings.isNullOrEmpty(columnsCount)) {
        resultComponent.setColumnsCount(Integer.parseInt(columnsCount));
    }
    String folderActionsEnabled = element.attributeValue("folderActionsEnabled");
    if (folderActionsEnabled != null) {
        resultComponent.setFolderActionsEnabled(Boolean.parseBoolean(folderActionsEnabled));
    }
    String dataLoaderId = element.attributeValue("dataLoader");
    if (StringUtils.isNotBlank(dataLoaderId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        DataLoader dataLoader = screenData.getLoader(dataLoaderId);
        if (!(dataLoader instanceof CollectionLoader) && !(dataLoader instanceof KeyValueCollectionLoader)) {
            throw new IllegalStateException(String.format("Filter cannot work with %s because it is not a CollectionLoader or a KeyValueCollectionLoader", dataLoaderId));
        }
        resultComponent.setDataLoader((BaseCollectionLoader) dataLoader);
    } else {
        String datasource = element.attributeValue("datasource");
        if (StringUtils.isNotBlank(datasource)) {
            if (getComponentContext().getDsContext() == null) {
                throw new IllegalStateException("'datasource' attribute can be used only in screens with 'dsContext' element. " + "In a screen with 'data' element use 'dataContainer' attribute.");
            }
            CollectionDatasource ds = (CollectionDatasource) getComponentContext().getDsContext().get(datasource);
            if (ds == null) {
                throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context);
            }
            resultComponent.setDatasource(ds);
        }
    }
    Frame frame = getComponentContext().getFrame();
    String applyTo = element.attributeValue("applyTo");
    if (!StringUtils.isEmpty(applyTo)) {
        getComponentContext().addPostInitTask((c, w) -> {
            Component applyToComponent = frame.getComponent(applyTo);
            if (c == null) {
                throw new GuiDevelopmentException("Can't apply component to component with ID: " + applyTo, context);
            }
            resultComponent.setApplyTo(applyToComponent);
        });
    }
    String modeSwitchVisible = element.attributeValue("modeSwitchVisible");
    if (StringUtils.isNotEmpty(modeSwitchVisible)) {
        resultComponent.setModeSwitchVisible(Boolean.parseBoolean(modeSwitchVisible));
    }
    String immediatelySearch = element.attributeValue("applyImmediately");
    if (!Strings.isNullOrEmpty(immediatelySearch)) {
        resultComponent.setApplyImmediately(Boolean.parseBoolean(immediatelySearch));
    }
    getComponentContext().addPostInitTask((context1, window) -> {
        String controlsLayoutTemplate = element.attributeValue("controlsLayoutTemplate");
        if (!Strings.isNullOrEmpty(controlsLayoutTemplate)) {
            resultComponent.setControlsLayoutTemplate(controlsLayoutTemplate);
            resultComponent.createLayout();
        }
        ((FilterImplementation) resultComponent).loadFiltersAndApplyDefault();
        String defaultMode = element.attributeValue("defaultMode");
        if (FTS_MODE_VALUE.equals(defaultMode)) {
            resultComponent.switchFilterMode(FilterDelegate.FilterMode.FTS_MODE);
        }
    });
}
Also used : Frame(io.jmix.ui.component.Frame) FrameOwner(io.jmix.ui.screen.FrameOwner) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component) FilterImplementation(io.jmix.ui.component.FilterImplementation)

Aggregations

FrameOwner (io.jmix.ui.screen.FrameOwner)51 ScreenData (io.jmix.ui.model.ScreenData)18 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)17 InstanceContainer (io.jmix.ui.model.InstanceContainer)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)9 Component (io.jmix.ui.component.Component)7 Method (java.lang.reflect.Method)6 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)5 MetaClass (io.jmix.core.metamodel.model.MetaClass)5 Screens (io.jmix.ui.Screens)5 Screen (io.jmix.ui.screen.Screen)5 ScreenFragment (io.jmix.ui.screen.ScreenFragment)5 WindowInfo (io.jmix.ui.WindowInfo)4 Frame (io.jmix.ui.component.Frame)4 Element (org.dom4j.Element)4 Fragment (io.jmix.ui.component.Fragment)3 DataUnit (io.jmix.ui.component.data.DataUnit)3 DataLoader (io.jmix.ui.model.DataLoader)3 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)2 Notifications (io.jmix.ui.Notifications)2