use of com.haulmont.cuba.gui.model.DataComponents in project cuba by cuba-platform.
the class BulkEditorFieldFactory method createEntityField.
protected Field createEntityField(Datasource datasource, MetaProperty property) {
Lookup lookup = property.getAnnotatedElement().getAnnotation(Lookup.class);
if (lookup != null && lookup.type() == LookupType.DROPDOWN) {
DataComponents dataComponents = AppBeans.get(DataComponents.class);
Metadata metadata = AppBeans.get(Metadata.class);
MetaClass metaClass = metadata.getClassNN(property.getJavaType());
CollectionContainer<Entity> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
CollectionLoader<Entity> loader = dataComponents.createCollectionLoader();
loader.setQuery("select e from " + metaClass.getName() + " e");
loader.setView(View.MINIMAL);
loader.setContainer(container);
loader.load();
LookupPickerField<Entity> lookupPickerField = componentsFactory.createComponent(LookupPickerField.NAME);
lookupPickerField.setDatasource(datasource, property.getName());
lookupPickerField.setOptions(new ContainerOptions(container));
GuiActionSupport guiActionSupport = AppBeans.get(GuiActionSupport.NAME);
guiActionSupport.createActionsByMetaAnnotations(lookupPickerField);
return lookupPickerField;
}
PickerField<Entity> pickerField = componentsFactory.createComponent(PickerField.NAME);
pickerField.setDatasource(datasource, property.getName());
GuiActionSupport guiActionSupport = AppBeans.get(GuiActionSupport.NAME);
guiActionSupport.createActionById(pickerField, PickerField.ActionType.LOOKUP.getId());
if (lookup == null || !guiActionSupport.createActionsByMetaAnnotations(pickerField)) {
guiActionSupport.createActionById(pickerField, PickerField.ActionType.CLEAR.getId());
}
return pickerField;
}
Aggregations