use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class DynamicAttributesPanelLoader method loadDataContainer.
protected void loadDataContainer(DynamicAttributesPanel resultComponent, Element element) {
String containerId = element.attributeValue("dataContainer");
if (Strings.isNullOrEmpty(containerId)) {
throw new GuiDevelopmentException("DynamicAttributesPanel element doesn't have 'dataContainer' attribute", context, "DynamicAttributesPanel ID", element.attributeValue("id"));
}
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
// noinspection unchecked
resultComponent.setInstanceContainer(container);
}
use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class TestCommentaryPanelLoader method loadDataContainer.
@SuppressWarnings("unchecked")
private void loadDataContainer(TestCommentaryPanel resultComponent, Element element) {
String containerId = this.element.attributeValue("dataContainer");
if (Strings.isNullOrEmpty(containerId)) {
throw new GuiDevelopmentException("CommentaryPanel element doesn't have 'dataContainer' attribute", context, "CommentaryPanel ID", element.attributeValue("id"));
}
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
if (container instanceof CollectionContainer) {
resultComponent.setDataContainer((CollectionContainer) container);
} else {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
}
use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.
the class ValueBinder method bind.
public <V> ValueBinding<V> bind(HasValue<V> component, ValueSource<V> valueSource) {
if (valueSource instanceof BeanLocatorAware) {
((BeanLocatorAware) valueSource).setBeanLocator(beanLocator);
}
ValueBindingImpl<V> binding = new ValueBindingImpl<>(component, valueSource);
if (component instanceof Component.Editable) {
((Component.Editable) component).setEditable(!valueSource.isReadOnly());
}
if (valueSource instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueSource;
MetaPropertyPath metaPropertyPath = entityValueSource.getMetaPropertyPath();
if (component instanceof Field) {
initRequired((Field) component, metaPropertyPath);
initBeanValidator((Field<?>) component, metaPropertyPath);
}
if (entityValueSource.isDataModelSecurityEnabled()) {
if (component instanceof Component.Editable) {
MetaClass metaClass = entityValueSource.getEntityMetaClass();
boolean permittedIfEmbedded = true;
if (entityValueSource instanceof ContainerValueSource) {
InstanceContainer container = ((ContainerValueSource) entityValueSource).getContainer();
if (container instanceof Nested && metadataTools.isEmbeddable(metaClass)) {
String embeddedProperty = ((Nested) container).getProperty();
MetaClass masterMetaClass = ((Nested) container).getMaster().getEntityMetaClass();
permittedIfEmbedded = security.isEntityAttrUpdatePermitted(masterMetaClass, embeddedProperty);
}
if (permittedIfEmbedded && metaPropertyPath.length() > 1) {
for (MetaProperty property : metaPropertyPath.getMetaProperties()) {
if (metadataTools.isEmbedded(property) && !security.isEntityAttrUpdatePermitted(property.getDomain(), property.getName())) {
permittedIfEmbedded = false;
break;
}
}
}
}
if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !permittedIfEmbedded) {
((Component.Editable) component).setEditable(false);
}
}
if (!security.isEntityAttrReadPermitted(metaPropertyPath)) {
component.setVisible(false);
}
}
}
binding.bind();
return binding;
}
use of com.haulmont.cuba.gui.model.InstanceContainer 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));
}
}
use of com.haulmont.cuba.gui.model.InstanceContainer 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);
}
}
Aggregations