Search in sources :

Example 1 with FrameOwner

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

the class DsContextImpl method get.

@Override
public Datasource get(String id) {
    checkNotNullArgument(id, "Null datasource ID");
    id = aliasesMap.getOrDefault(id, id);
    Datasource ds = null;
    if (!id.contains(".")) {
        ds = datasourceMap.get(id);
        if (ds == null && parent != null) {
            ds = parent.get(id);
        }
    } else {
        if (windowContext != null) {
            String nestedFramePath = id.substring(0, id.indexOf("."));
            Component nestedFrame = getFrameContext().getFrame().getComponent(nestedFramePath);
            if (nestedFrame instanceof Frame) {
                String nestedDsId = id.substring(id.indexOf(".") + 1);
                FrameOwner frameOwner = ((Frame) nestedFrame).getFrameOwner();
                if (frameOwner instanceof LegacyFrame) {
                    ds = ((LegacyFrame) frameOwner).getDsContext().get(nestedDsId);
                }
            }
        }
    }
    return ds;
}
Also used : Frame(io.jmix.ui.component.Frame) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) FrameOwner(io.jmix.ui.screen.FrameOwner) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Component(io.jmix.ui.component.Component)

Example 2 with FrameOwner

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

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(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 3 with FrameOwner

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

the class AbstractComponentLoader method loadContainer.

protected Optional<InstanceContainer> loadContainer(Element element, @Nullable String property) {
    String containerId = element.attributeValue("dataContainer");
    // For instance, a component is placed within the Form component
    if (Strings.isNullOrEmpty(containerId) && property != null) {
        containerId = getParentDataContainer(element);
    }
    if (!Strings.isNullOrEmpty(containerId)) {
        if (property == null) {
            throw new GuiDevelopmentException(String.format("Can't set container '%s' for component '%s' because 'property' " + "attribute is not defined", containerId, element.attributeValue("id")), context);
        }
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        return Optional.of(screenData.getContainer(containerId));
    }
    return Optional.empty();
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) ScreenData(io.jmix.ui.model.ScreenData)

Example 4 with FrameOwner

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

the class AbstractComponentLoader method loadOptionsContainer.

protected Optional<CollectionContainer> loadOptionsContainer(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);
        }
        return Optional.of((CollectionContainer) container);
    }
    return Optional.empty();
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 5 with FrameOwner

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

the class DeclarativeColumnGenerator method generateCell.

@Override
public Component generateCell(Object entity) {
    if (unableToFindMethod) {
        return null;
    }
    FrameOwner controller = getFrameOwner();
    if (method == null) {
        method = findGeneratorMethod(controller.getClass(), methodName);
        if (method == null) {
            this.unableToFindMethod = true;
            String tableId = table.getId() == null ? "" : table.getId();
            throw new IllegalStateException(String.format("No suitable method named %s for column generator of table %s", methodName, tableId));
        }
    }
    try {
        return (Component) method.invoke(controller, entity);
    } catch (Exception e) {
        throw new RuntimeException("Exception in declarative Table column generator " + methodName, e);
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) Component(io.jmix.ui.component.Component)

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