Search in sources :

Example 16 with FrameOwner

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

the class FormLoader method loadDataContainer.

protected void loadDataContainer(Form resultComponent, Element element) {
    String containerId = element.attributeValue("dataContainer");
    if (!Strings.isNullOrEmpty(containerId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        // noinspection unchecked
        resultComponent.setValueSourceProvider(new ContainerValueSourceProvider(container));
    }
}
Also used : ContainerValueSourceProvider(com.haulmont.cuba.gui.components.data.value.ContainerValueSourceProvider) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner)

Example 17 with FrameOwner

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

the class FragmentLoader method loadDsContext.

protected void loadDsContext(@Nullable Element dsContextElement) {
    DsContext dsContext = null;
    if (resultComponent.getFrameOwner() instanceof LegacyFrame) {
        DsContextLoader dsContextLoader;
        DsContext parentDsContext = 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(com.haulmont.cuba.gui.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 18 with FrameOwner

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

the class RuntimePropertiesFrameLoader method createComponent.

@Override
public void createComponent() {
    String src = element.attributeValue("src");
    String screenId = element.attributeValue("id");
    if (src == null) {
        src = DEFAULT_DESCRIPTOR;
    }
    String fragmentId = screenId != null ? screenId : src;
    FragmentHelper fragmentHelper = getFragmentHelper();
    WindowInfo windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
    Fragment fragment = factory.create(Fragment.NAME);
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    FrameOwner hostController = parentContext.getFrame().getFrameOwner();
    // setup screen and controller
    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, new ScreenDataImpl());
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);
    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }
        innerContext = new ComponentLoaderContext(getContext().getOptions());
        innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getContext().getParams());
        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessagesPack(messagesPack);
        }
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    this.resultComponent = fragment;
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) FragmentImplementation(com.haulmont.cuba.gui.components.sys.FragmentImplementation) Element(org.dom4j.Element) FragmentContextImpl(com.haulmont.cuba.gui.sys.FragmentContextImpl) FrameImplementation(com.haulmont.cuba.gui.components.sys.FrameImplementation) Fragment(com.haulmont.cuba.gui.components.Fragment) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenDataImpl(com.haulmont.cuba.gui.model.impl.ScreenDataImpl) FragmentHelper(com.haulmont.cuba.gui.sys.FragmentHelper) ScreenContextImpl(com.haulmont.cuba.gui.sys.ScreenContextImpl) ScreenXmlLoader(com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader)

Example 19 with FrameOwner

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

the class TokenListLoader method loadOptionsContainer.

protected void loadOptionsContainer(TokenList 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 20 with FrameOwner

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

the class TreeLoader method loadTreeChildren.

@SuppressWarnings("unchecked")
protected void loadTreeChildren() {
    Element itemsElem = element.element("treechildren");
    String containerId = element.attributeValue("dataContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        CollectionContainer collectionContainer;
        if (container instanceof CollectionContainer) {
            collectionContainer = (CollectionContainer) container;
        } else {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        String hierarchyProperty = element.attributeValue("hierarchyProperty");
        if (hierarchyProperty == null && itemsElem != null) {
            // legacy behaviour
            hierarchyProperty = itemsElem.attributeValue("hierarchyProperty");
        }
        if (Strings.isNullOrEmpty(hierarchyProperty)) {
            throw new GuiDevelopmentException("Tree doesn't have 'hierarchyProperty' attribute of the 'treechildren' element", context, "Tree ID", element.attributeValue("id"));
        }
        String showOrphansAttr = element.attributeValue("showOrphans");
        boolean showOrphans = showOrphansAttr == null || Boolean.parseBoolean(showOrphansAttr);
        resultComponent.setItems(new ContainerTreeItems(collectionContainer, hierarchyProperty, showOrphans));
    } else if (itemsElem != null) {
        String datasource = itemsElem.attributeValue("datasource");
        if (!StringUtils.isBlank(datasource)) {
            HierarchicalDatasource ds = (HierarchicalDatasource) getComponentContext().getDsContext().get(datasource);
            resultComponent.setDatasource(ds);
        }
    }
    String captionProperty = element.attributeValue("captionProperty");
    if (captionProperty == null && itemsElem != null) {
        captionProperty = itemsElem.attributeValue("captionProperty");
    }
    if (!StringUtils.isEmpty(captionProperty)) {
        resultComponent.setCaptionProperty(captionProperty);
        resultComponent.setCaptionMode(CaptionMode.PROPERTY);
    }
}
Also used : HierarchicalDatasource(com.haulmont.cuba.gui.data.HierarchicalDatasource) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Element(org.dom4j.Element) 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) ContainerTreeItems(com.haulmont.cuba.gui.components.data.tree.ContainerTreeItems)

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