use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.
the class InputDialog method createEntityField.
@SuppressWarnings("unchecked")
protected Field createEntityField(InputParameter parameter) {
MetaClass metaClass = metadata.getClassNN(parameter.getEntityClass());
Action lookupAction = actions.create(LookupAction.ID);
Action clearAction = actions.create(ClearAction.ID);
if (persistenceManagerService.useLookupScreen(metaClass.getName())) {
PickerField pickerField = uiComponents.create(PickerField.NAME);
pickerField.setMetaClass(metadata.getClass(parameter.getEntityClass()));
pickerField.addAction(lookupAction);
pickerField.addAction(clearAction);
pickerField.setWidthFull();
return pickerField;
} else {
LookupPickerField lookupPickerField = uiComponents.create(LookupPickerField.NAME);
lookupPickerField.addAction(lookupAction);
lookupPickerField.addAction(clearAction);
lookupPickerField.setWidthFull();
CollectionContainer container = dataComponents.createCollectionContainer(parameter.getEntityClass());
CollectionLoader loader = dataComponents.createCollectionLoader();
loader.setQuery("select e from " + metaClass.getName() + " e");
loader.setView(View.MINIMAL);
loader.setContainer(container);
loader.load();
lookupPickerField.setOptions(new ContainerOptions(container));
return lookupPickerField;
}
}
use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.
the class RefreshAction method execute.
/**
* Executes the action.
*/
@Override
public void execute() {
if (target == null) {
throw new IllegalStateException("RefreshAction target is not set");
}
if (target.getItems() instanceof EmptyDataUnit) {
return;
}
if (!(target.getItems() instanceof ContainerDataUnit)) {
throw new IllegalStateException("RefreshAction target is null or does not implement SupportsContainerBinding");
}
CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
if (container == null) {
throw new IllegalStateException("RefreshAction target is not bound to CollectionContainer");
}
DataLoader loader = null;
if (container instanceof HasLoader) {
loader = ((HasLoader) container).getLoader();
}
if (loader != null) {
DataContext dataContext = loader.getDataContext();
if (dataContext != null) {
for (Object entity : container.getItems()) {
dataContext.evict((Entity) entity);
}
}
loader.load();
} else {
log.warn("RefreshAction '{}' target container has no loader, refresh is impossible", getId());
}
}
use of com.haulmont.cuba.gui.model.CollectionContainer 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);
}
}
}
use of com.haulmont.cuba.gui.model.CollectionContainer in project cuba by cuba-platform.
the class TwinColumnLoader method loadOptionsContainer.
protected void loadOptionsContainer(TwinColumn 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 WebTableFieldFactory method findOptionsContainer.
@Nullable
protected CollectionContainer findOptionsContainer(Table.Column columnConf) {
String optDcName = columnConf.getXmlDescriptor() != null ? columnConf.getXmlDescriptor().attributeValue("optionsContainer") : null;
if (Strings.isNullOrEmpty(optDcName)) {
return null;
} else {
ScreenData screenData = UiControllerUtils.getScreenData(webTable.getFrame().getFrameOwner());
InstanceContainer container = screenData.getContainer(optDcName);
if (container instanceof CollectionContainer) {
return (CollectionContainer) container;
}
throw new IllegalStateException(String.format("'%s' is not an instance of CollectionContainer", optDcName));
}
}
Aggregations