use of com.haulmont.cuba.gui.components.FilterDataContext 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 com.haulmont.cuba.gui.components.FilterDataContext in project jmix by jmix-framework.
the class ConditionFrame method createDefaultValueComponent.
protected void createDefaultValueComponent() {
defaultValueLayout = (BoxLayout) getComponent("defaultValueLayout");
if (defaultValueLayout != null) {
if (defaultValueComponent != null) {
defaultValueLayout.remove(defaultValueComponent);
}
if (condition.getParam() != null) {
FilterDataContext filterDataContext = new FilterDataContext(filter.getFrame());
defaultValueComponent = condition.getParam().createEditComponentForDefaultValue(filterDataContext);
// load options for lookup fields
filterDataContext.loadAll();
defaultValueLayout.add(defaultValueComponent);
defaultValueComponent.setAlignment(Alignment.MIDDLE_LEFT);
if (defaultValueComponent instanceof TextField) {
defaultValueComponent.setWidth(theme.get("cuba.gui.conditionFrame.textField.width"));
}
}
}
}
Aggregations