Search in sources :

Example 6 with ScreenData

use of com.haulmont.cuba.gui.model.ScreenData in project cuba by cuba-platform.

the class AnnotationBasedLoaderBeforeShow method loadData.

@Override
public void loadData(Screen screen) {
    LoadDataBeforeShow annotation = screen.getClass().getAnnotation(LoadDataBeforeShow.class);
    if (annotation != null && annotation.value()) {
        ScreenData screenData = UiControllerUtils.getScreenData(screen);
        screenData.loadAll();
    }
}
Also used : LoadDataBeforeShow(com.haulmont.cuba.gui.screen.LoadDataBeforeShow) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 7 with ScreenData

use of com.haulmont.cuba.gui.model.ScreenData in project cuba by cuba-platform.

the class RemoveOperation method commitIfNeeded.

protected void commitIfNeeded(Collection<? extends Entity> entitiesToRemove, CollectionContainer container, ScreenData screenData) {
    List<? extends Entity> entitiesToCommit = entitiesToRemove.stream().filter(entity -> !entityStates.isNew(entity)).collect(Collectors.toList());
    boolean needCommit = !entitiesToCommit.isEmpty();
    if (container instanceof Nested) {
        InstanceContainer masterContainer = ((Nested) container).getMaster();
        String property = ((Nested) container).getProperty();
        MetaClass masterMetaClass = masterContainer.getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getPropertyNN(property);
        needCommit = needCommit && (metaProperty.getType() != MetaProperty.Type.COMPOSITION);
    }
    if (needCommit) {
        CommitContext commitContext = new CommitContext();
        for (Entity entity : entitiesToCommit) {
            commitContext.addInstanceToRemove(entity);
        }
        dataManager.commit(commitContext);
        for (Entity entity : entitiesToRemove) {
            screenData.getDataContext().evict(entity);
        }
    } else {
        for (Entity entity : entitiesToRemove) {
            screenData.getDataContext().remove(entity);
        }
    }
}
Also used : ListComponent(com.haulmont.cuba.gui.components.ListComponent) UiControllerUtils.getScreenContext(com.haulmont.cuba.gui.screen.UiControllerUtils.getScreenContext) java.util(java.util) DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Table(com.haulmont.cuba.gui.components.Table) ScreenData(com.haulmont.cuba.gui.model.ScreenData) Focusable(com.haulmont.cuba.gui.components.Component.Focusable) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Collectors(java.util.stream.Collectors) MetaClass(com.haulmont.chile.core.model.MetaClass) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) Component(org.springframework.stereotype.Component) Nested(com.haulmont.cuba.gui.model.Nested) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) com.haulmont.cuba.gui.screen(com.haulmont.cuba.gui.screen) DataGrid(com.haulmont.cuba.gui.components.DataGrid) DialogAction(com.haulmont.cuba.gui.components.DialogAction) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) Entity(com.haulmont.cuba.core.entity.Entity) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass) Nested(com.haulmont.cuba.gui.model.Nested) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 8 with ScreenData

use of com.haulmont.cuba.gui.model.ScreenData in project cuba by cuba-platform.

the class FragmentLoader method loadScreenData.

protected void loadScreenData(Element dataEl) {
    ScreenData hostScreenData = null;
    ComponentContext parent = getComponentContext().getParent();
    while (hostScreenData == null && parent != null) {
        hostScreenData = parent.getScreenData();
        parent = parent.getParent();
    }
    ScreenDataXmlLoader screenDataXmlLoader = beanLocator.get(ScreenDataXmlLoader.class);
    ScreenData screenData = UiControllerUtils.getScreenData(resultComponent.getFrameOwner());
    screenDataXmlLoader.load(screenData, dataEl, hostScreenData);
    ((ComponentLoaderContext) context).setScreenData(screenData);
}
Also used : ScreenDataXmlLoader(com.haulmont.cuba.gui.model.impl.ScreenDataXmlLoader) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 9 with ScreenData

use of com.haulmont.cuba.gui.model.ScreenData 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 10 with ScreenData

use of com.haulmont.cuba.gui.model.ScreenData 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

ScreenData (com.haulmont.cuba.gui.model.ScreenData)17 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)9 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)9 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)8 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)8 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)2 ScreenDataXmlLoader (com.haulmont.cuba.gui.model.impl.ScreenDataXmlLoader)2 UiControllerUtils.getScreenData (com.haulmont.cuba.gui.screen.UiControllerUtils.getScreenData)2 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)2 Consumer (java.util.function.Consumer)2 Nullable (javax.annotation.Nullable)2 Element (org.dom4j.Element)2 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 ClientConfiguration (com.haulmont.cuba.client.ClientConfiguration)1 Entity (com.haulmont.cuba.core.entity.Entity)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 Focusable (com.haulmont.cuba.gui.components.Component.Focusable)1