use of io.jmix.ui.component.data.options.ContainerOptions in project jmix by jmix-framework.
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 = (PersistenceManagerClient) applicationContext.getBean(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.addAction(actions.create(LookupAction.ID));
picker.addAction(actions.create(EntityClearAction.ID));
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.addAction(actions.create(EntityClearAction.ID));
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;
}
}
}
use of io.jmix.ui.component.data.options.ContainerOptions in project jmix by jmix-framework.
the class TokenListLoader method loadOptionsContainer.
protected void loadOptionsContainer(TokenList 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));
}
if (component.getOptions() == null) {
DatasourceLoaderHelper.loadOptionsDatasource(element, (ComponentLoaderContext) getComponentContext()).ifPresent(component::setOptions);
}
}
use of io.jmix.ui.component.data.options.ContainerOptions 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.component.data.options.ContainerOptions in project jmix by jmix-framework.
the class EntityFieldCreationSupport method createFieldComponent.
protected EntityPicker createFieldComponent(MetaClass metaClass, @Nullable Options options) {
String componentName = componentProperties.getEntityFieldType().get(metaClass.getName());
EntityPicker field;
if (options != null || EntityComboBox.NAME.equals(componentName)) {
EntityComboBox entityComboBox = uiComponents.create(EntityComboBox.class);
entityComboBox.setOptions(options != null ? options : new ContainerOptions(createCollectionContainer(metaClass)));
field = entityComboBox;
} else {
if (componentName == null || EntityPicker.NAME.equals(componentName)) {
field = uiComponents.create(EntityPicker.class);
field.setMetaClass(metaClass);
} else {
EntityPicker component = uiComponents.create(componentName);
if (component instanceof OptionsField) {
((OptionsField) component).setOptions(new ContainerOptions(createCollectionContainer(metaClass)));
}
field = component;
}
}
return field;
}
use of io.jmix.ui.component.data.options.ContainerOptions in project jmix by jmix-framework.
the class TableFieldFactoryImpl method getOptions.
@SuppressWarnings("unchecked")
@Nullable
protected Options getOptions(EntityValueSource valueSource, String property) {
MetaClass metaClass = valueSource.getEntityMetaClass();
MetaPropertyPath metaPropertyPath = metadataTools.resolveMetaPropertyPathOrNull(metaClass, property);
Table.Column columnConf = webTable.getColumnsInternal().get(metaPropertyPath);
CollectionContainer collectionContainer = findOptionsContainer(columnConf);
if (collectionContainer != null) {
return new ContainerOptions(collectionContainer);
}
return null;
}
Aggregations