use of com.haulmont.cuba.gui.model.CollectionContainer 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.CollectionContainer 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.CollectionContainer 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);
}
}
use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.
the class WebEntityLinkField method afterCommitOpenedEntity.
protected void afterCommitOpenedEntity(Entity item) {
MetaProperty metaProperty = getMetaPropertyForEditedValue();
if (metaProperty != null && metaProperty.getRange().isClass()) {
if (getValueSource() != null) {
boolean ownerDsModified = false;
boolean nonModifiedInTable = false;
DatasourceImplementation ownerDs = null;
CollectionContainer ownerCollectionCont = null;
if (getCollectionDatasourceFromOwner() != null) {
ownerDs = ((DatasourceImplementation) getCollectionDatasourceFromOwner());
nonModifiedInTable = !ownerDs.getItemsToUpdate().contains(((EntityValueSource) getValueSource()).getItem());
ownerDsModified = ownerDs.isModified();
} else if (getCollectionContainerFromOwner() != null) {
ownerCollectionCont = ((ContainerDataUnit) owner.getItems()).getContainer();
ownerCollectionCont.mute();
}
// noinspection unchecked
setValueSilently((V) item);
// remove from items to update if it was not modified before setValue
if (ownerDs != null) {
if (nonModifiedInTable) {
ownerDs.getItemsToUpdate().remove(getDatasource().getItem());
}
ownerDs.setModified(ownerDsModified);
} else if (ownerCollectionCont != null) {
ownerCollectionCont.unmute();
}
} else {
// noinspection unchecked
setValue((V) item);
}
// if we edit property with non Entity type and set ListComponent owner
} else if (owner != null) {
if (getCollectionDatasourceFromOwner() != null) {
// noinspection unchecked
getCollectionDatasourceFromOwner().updateItem(item);
} else if (getCollectionContainerFromOwner() != null) {
// do not listen changes in collection
getCollectionContainerFromOwner().mute();
// noinspection unchecked
getCollectionContainerFromOwner().replaceItem(item);
setValueSilently(item.getValueEx(getMetaPropertyPath()));
// listen changes
getCollectionContainerFromOwner().unmute();
}
if (owner instanceof Focusable) {
// focus owner
((Focusable) owner).focus();
}
// if we edit property with non Entity type
} else {
// noinspection unchecked
setValueSilently((V) item);
}
}
use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.
the class Param method createEntityLookup.
protected Component createEntityLookup(FilterDataContext filterDataContext, ValueProperty valueProperty) {
MetaClass metaClass = metadata.getSession().getClassNN(javaClass);
LookupType type = null;
if (property != null && property.getRange().isClass()) {
type = (LookupType) metadata.getTools().getMetaAnnotationAttributes(property.getAnnotations(), Lookup.class).get("type");
}
PersistenceManagerClient persistenceManager = beanLocator.get(PersistenceManagerClient.NAME);
boolean useLookupScreen = type != null ? type == LookupType.SCREEN : persistenceManager.useLookupScreen(metaClass.getName());
if (useLookupScreen) {
if (inExpr) {
ListEditor listEditor = uiComponents.create(ListEditor.class);
listEditor.setItemType(ListEditor.ItemType.ENTITY);
listEditor.setEntityName(metaClass.getName());
initListEditor(listEditor, valueProperty);
return listEditor;
} else {
PickerField<Entity> picker = uiComponents.create(PickerField.NAME);
picker.setMetaClass(metaClass);
picker.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
picker.addLookupAction();
picker.addClearAction();
picker.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
picker.setValue((Entity) _getValue(valueProperty));
return picker;
}
} else {
if (inExpr) {
CollectionLoader<Entity> loader = createEntityOptionsLoader(metaClass);
CollectionContainer<Entity> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
loader.setContainer(container);
ListEditor listEditor = uiComponents.create(ListEditor.class);
listEditor.setItemType(ListEditor.ItemType.ENTITY);
listEditor.setEntityName(metaClass.getName());
// noinspection unchecked
listEditor.setOptions(new ContainerOptions<>(container));
// noinspection unchecked
initListEditor(listEditor, valueProperty);
// noinspection unchecked
Consumer<CollectionContainer.CollectionChangeEvent<?>> listener = e -> listEditor.setValue(null);
if (filterDataContext != null) {
filterDataContext.registerCollectionLoader(this, loader);
filterDataContext.registerContainerCollectionChangeListener(this, container, listener);
}
return listEditor;
} else {
CollectionLoader<Entity> loader = createEntityOptionsLoader(metaClass);
CollectionContainer<Entity> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
loader.setContainer(container);
LookupPickerField<Entity> lookup = uiComponents.create(LookupPickerField.NAME);
lookup.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
lookup.addClearAction();
lookup.setOptions(new ContainerOptions<>(container));
Consumer<CollectionContainer.CollectionChangeEvent<?>> listener = e -> lookup.setValue(null);
lookup.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
lookup.setValue((Entity) _getValue(valueProperty));
if (filterDataContext != null) {
filterDataContext.registerCollectionLoader(this, loader);
filterDataContext.registerContainerCollectionChangeListener(this, container, listener);
}
return lookup;
}
}
}
Aggregations