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