use of io.jmix.ui.model.DataComponents in project jmix by jmix-framework.
the class SelectValueDialog method createEntityComboBox.
protected Field createEntityComboBox(MetaClass metaClass) {
EntityComboBox<Object> entityComboBox = uiComponents.create(EntityComboBox.NAME);
Options<Object> options;
DataComponents dataComponents = getApplicationContext().getBean(DataComponents.class);
CollectionContainer<Object> container = dataComponents.createCollectionContainer(metaClass.getJavaClass());
CollectionLoader<Object> loader = dataComponents.createCollectionLoader();
loader.setQuery("select e from " + metaClass.getName() + " e");
loader.setFetchPlan(FetchPlan.INSTANCE_NAME);
loader.setContainer(container);
loader.load();
options = new ContainerOptions<>(container);
entityComboBox.setOptions(options);
entityComboBox.setOptionCaptionProvider(((Function) context.getOptionCaptionProvider()));
entityComboBox.addValueChangeListener(event -> {
V selectedEntity = (V) event.getValue();
if (selectedEntity != null && !valueExists(selectedEntity)) {
addValueToLayout(selectedEntity);
}
entityComboBox.setValue(null);
});
return entityComboBox;
}
use of io.jmix.ui.model.DataComponents in project jmix by jmix-framework.
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.setFetchPlan(FetchPlan.INSTANCE_NAME);
loader.setContainer(container);
loader.load();
LookupPickerField<Entity> lookupPickerField = componentsFactory.create(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.create(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;
}
use of io.jmix.ui.model.DataComponents in project jmix by jmix-framework.
the class AbstractDataGrid method createInstanceContainer.
protected InstanceContainer<E> createInstanceContainer(E item) {
if (itemDatasources == null) {
itemDatasources = new WeakHashMap<>();
}
Object container = itemDatasources.get(item);
if (container instanceof InstanceContainer) {
// noinspection unchecked
return (InstanceContainer<E>) container;
}
EntityDataGridItems<E> items = getEntityDataGridItemsNN();
DataComponents factory = this.applicationContext.getBean(DataComponents.class);
FetchPlanRepository viewRepository = this.applicationContext.getBean(FetchPlanRepository.class);
MetaClass metaClass = items.getEntityMetaClass();
InstanceContainer<E> instanceContainer;
if (metaClass instanceof KeyValueMetaClass) {
// noinspection unchecked
instanceContainer = (InstanceContainer<E>) factory.createKeyValueContainer(metaClass);
} else {
instanceContainer = factory.createInstanceContainer(metaClass.getJavaClass());
}
instanceContainer.setFetchPlan(viewRepository.getFetchPlan(metaClass, FetchPlan.LOCAL));
instanceContainer.setItem(item);
itemDatasources.put(item, instanceContainer);
return instanceContainer;
}
Aggregations