use of com.haulmont.cuba.core.entity.annotation.Lookup in project cuba by cuba-platform.
the class Param method createEntityLookup.
protected Component createEntityLookup(final ValueProperty valueProperty) {
Metadata metadata = AppBeans.get(Metadata.NAME);
MetaClass metaClass = metadata.getSession().getClassNN(javaClass);
ThemeConstants theme = AppBeans.get(ThemeConstantsManager.class).getConstants();
PersistenceManagerService persistenceManager = AppBeans.get(PersistenceManagerService.NAME);
LookupType type = null;
if (property != null && property.getRange().isClass()) {
type = (LookupType) metadata.getTools().getMetaAnnotationAttributes(property.getAnnotations(), Lookup.class).get("type");
}
boolean useLookupScreen = type != null ? type == LookupType.SCREEN : persistenceManager.useLookupScreen(metaClass.getName());
if (useLookupScreen) {
if (inExpr) {
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
listEditor.setItemType(ListEditor.ItemType.ENTITY);
listEditor.setEntityName(metaClass.getName());
initListEditor(listEditor, valueProperty);
return listEditor;
} else {
PickerField picker = componentsFactory.createComponent(PickerField.class);
picker.setMetaClass(metaClass);
picker.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
picker.setFrame(datasource.getDsContext().getFrameContext().getFrame());
picker.addLookupAction();
picker.addClearAction();
picker.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
picker.setValue(_getValue(valueProperty));
return picker;
}
} else {
CollectionDatasource<Entity<Object>, Object> optionsDataSource = createOptionsDataSource(metaClass);
if (inExpr) {
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
listEditor.setItemType(ListEditor.ItemType.ENTITY);
listEditor.setEntityName(metaClass.getName());
listEditor.setUseLookupField(true);
listEditor.setEntityWhereClause(entityWhere);
initListEditor(listEditor, valueProperty);
return listEditor;
} else {
final LookupPickerField lookup = componentsFactory.createComponent(LookupPickerField.class);
lookup.addClearAction();
lookup.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
lookup.setOptionsDatasource(optionsDataSource);
// noinspection unchecked
optionsDataSource.addCollectionChangeListener(e -> lookup.setValue(null));
lookup.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
lookup.setValue(_getValue(valueProperty));
return lookup;
}
}
}
Aggregations