Search in sources :

Example 11 with FrameOwner

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

the class CubaFragmentLoader method loadDsContext.

protected void loadDsContext(@Nullable Element dsContextElement) {
    DsContext dsContext = null;
    if (resultComponent.getFrameOwner() instanceof LegacyFrame) {
        DsContextLoader dsContextLoader;
        DsContext parentDsContext = ((ComponentLoaderContext) getComponentContext().getParent()).getDsContext();
        if (parentDsContext != null) {
            dsContextLoader = new DsContextLoader(parentDsContext.getDataSupplier());
        } else {
            dsContextLoader = new DsContextLoader(new GenericDataSupplier());
        }
        dsContext = dsContextLoader.loadDatasources(dsContextElement, parentDsContext, getComponentContext().getAliasesMap());
        ((ComponentLoaderContext) context).setDsContext(dsContext);
    }
    if (dsContext != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        if (frameOwner instanceof LegacyFrame) {
            LegacyFrame frame = (LegacyFrame) frameOwner;
            frame.setDsContext(dsContext);
            for (Datasource ds : dsContext.getAll()) {
                if (ds instanceof DatasourceImplementation) {
                    ((DatasourceImplementation) ds).initialized();
                }
            }
            dsContext.setFrameContext(resultComponent.getContext());
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) FrameOwner(io.jmix.ui.screen.FrameOwner) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) GenericDataSupplier(com.haulmont.cuba.gui.data.impl.GenericDataSupplier) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation)

Example 12 with FrameOwner

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

the class LookupFieldLoader method loadNewOptionHandler.

protected void loadNewOptionHandler(LookupField component, Element element) {
    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, ComboBox.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(io.jmix.ui.screen.FrameOwner) ComboBox(io.jmix.ui.component.ComboBox) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Method(java.lang.reflect.Method) ParamsMap(io.jmix.core.common.util.ParamsMap) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with FrameOwner

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

the class StockChartLoader method loadDataSet.

protected void loadDataSet(DataSet dataSet, Element dataSetElement) {
    loadFieldMappings(dataSet, dataSetElement);
    loadStockEvents(dataSet, dataSetElement);
    String id = dataSetElement.attributeValue("id");
    if (StringUtils.isNotEmpty(id)) {
        dataSet.setId(id);
    }
    checkMultipleDatasources(dataSetElement);
    String categoryField = dataSetElement.attributeValue("categoryField");
    if (StringUtils.isNotEmpty(categoryField)) {
        dataSet.setCategoryField(categoryField);
    }
    String color = dataSetElement.attributeValue("color");
    if (StringUtils.isNotEmpty(color)) {
        dataSet.setColor(Color.valueOf(color));
    }
    String compared = dataSetElement.attributeValue("compared");
    if (StringUtils.isNotEmpty(compared)) {
        dataSet.setCompared(Boolean.valueOf(compared));
    }
    String dataContainerId = dataSetElement.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);
        }
        dataSet.setDataProvider(new ContainerDataProvider(dataContainer));
    }
    String showInCompare = dataSetElement.attributeValue("showInCompare");
    if (StringUtils.isNotEmpty(showInCompare)) {
        dataSet.setShowInCompare(Boolean.valueOf(showInCompare));
    }
    String showInSelect = dataSetElement.attributeValue("showInSelect");
    if (StringUtils.isNotEmpty(showInSelect)) {
        dataSet.setShowInSelect(Boolean.valueOf(showInSelect));
    }
    String title = dataSetElement.attributeValue("title");
    if (StringUtils.isNotEmpty(title)) {
        dataSet.setTitle(title);
    }
}
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 14 with FrameOwner

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

the class RelatedEntitiesSupportImpl method createScreen.

protected Screen createScreen(RelatedEntitiesBuilder builder, MetaClass metaClass, MetaProperty metaProperty) {
    FrameOwner origin = builder.getOrigin();
    Screens screens = UiControllerUtils.getScreenContext(origin).getScreens();
    if (builder instanceof RelatedEntitiesClassBuilder) {
        return screens.create(((RelatedEntitiesClassBuilder<?>) builder).getScreenClass(), builder.getOpenMode(), builder.getOptions());
    } else {
        String screenId = builder.getScreenId();
        if (Strings.isNullOrEmpty(screenId)) {
            // try to get default browse screen id
            screenId = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
            if (Strings.isNullOrEmpty(screenId)) {
                String message = String.format("Can't create related entities screen: passed screen id is null and " + "there is no default browse screen for %s", metaClass.getName());
                throw new IllegalStateException(message);
            }
        }
        return screens.create(screenId, builder.getOpenMode(), builder.getOptions());
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) Screens(io.jmix.ui.Screens)

Example 15 with FrameOwner

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

the class AbstractSuggestionField method showSuggestions.

protected void showSuggestions(List<I> 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(io.jmix.ui.screen.FrameOwner) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Screen(io.jmix.ui.screen.Screen)

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