Search in sources :

Example 1 with FilterDataContext

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;
        }
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CubaProperties(com.haulmont.cuba.CubaProperties) ParamsMap(io.jmix.core.common.util.ParamsMap) EventHub(io.jmix.core.common.event.EventHub) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup) AppBeans(com.haulmont.cuba.core.global.AppBeans) StringUtils(org.apache.commons.lang3.StringUtils) EntityValues(io.jmix.core.entity.EntityValues) java.time(java.time) ListEditorHelper(com.haulmont.cuba.gui.components.listeditor.ListEditorHelper) PickerField(com.haulmont.cuba.gui.components.PickerField) ParseException(java.text.ParseException) DateInIntervalComponent(com.haulmont.cuba.gui.components.filter.dateinterval.DateInIntervalComponent) MetadataTools(io.jmix.core.MetadataTools) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) Subscription(io.jmix.core.common.event.Subscription) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Datatypes(com.haulmont.chile.core.datatypes.Datatypes) Messages(com.haulmont.cuba.core.global.Messages) Datatype(io.jmix.core.metamodel.datatype.Datatype) Collectors(java.util.stream.Collectors) ThemeConstantsManager(io.jmix.ui.theme.ThemeConstantsManager) ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) UiComponents(com.haulmont.cuba.gui.UiComponents) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) IgnoreUserTimeZone(io.jmix.core.entity.annotation.IgnoreUserTimeZone) io.jmix.ui.component(io.jmix.ui.component) NotImplementedException(org.apache.commons.lang3.NotImplementedException) CollectionLoader(io.jmix.ui.model.CollectionLoader) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) SimpleDateFormat(java.text.SimpleDateFormat) BooleanUtils(org.apache.commons.lang3.BooleanUtils) QueryTransformerFactory(io.jmix.data.QueryTransformerFactory) Scope(org.springframework.context.annotation.Scope) Metadata(com.haulmont.cuba.core.global.Metadata) UserSession(com.haulmont.cuba.security.global.UserSession) Strings(com.google.common.base.Strings) FilterDataContext(com.haulmont.cuba.gui.components.FilterDataContext) ImmutableList(com.google.common.collect.ImmutableList) DatatypeRegistry(io.jmix.core.metamodel.datatype.DatatypeRegistry) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) WindowManagerProvider(com.haulmont.cuba.gui.WindowManagerProvider) EntityClearAction(io.jmix.ui.action.entitypicker.EntityClearAction) QueryTransformer(io.jmix.data.QueryTransformer) Nullable(javax.annotation.Nullable) Actions(io.jmix.ui.Actions) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) Logger(org.slf4j.Logger) DynAttrUtils(io.jmix.dynattr.DynAttrUtils) CollectionContainer(io.jmix.ui.model.CollectionContainer) ThemeConstants(io.jmix.ui.theme.ThemeConstants) TemporalType(javax.persistence.TemporalType) FetchPlan(io.jmix.core.FetchPlan) NotificationType(com.haulmont.cuba.gui.components.Frame.NotificationType) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) ListEditor(com.haulmont.cuba.gui.components.ListEditor) ApplicationContext(org.springframework.context.ApplicationContext) Consumer(java.util.function.Consumer) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) LookupField(com.haulmont.cuba.gui.components.LookupField) Entity(io.jmix.core.Entity) Element(org.dom4j.Element) DataComponents(io.jmix.ui.model.DataComponents) ListEditor(com.haulmont.cuba.gui.components.ListEditor) Entity(io.jmix.core.Entity) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) MetaClass(io.jmix.core.metamodel.model.MetaClass) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup)

Example 2 with FilterDataContext

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"));
            }
        }
    }
}
Also used : FilterDataContext(com.haulmont.cuba.gui.components.FilterDataContext)

Aggregations

FilterDataContext (com.haulmont.cuba.gui.components.FilterDataContext)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Datatypes (com.haulmont.chile.core.datatypes.Datatypes)1 CubaProperties (com.haulmont.cuba.CubaProperties)1 PersistenceManagerClient (com.haulmont.cuba.client.sys.PersistenceManagerClient)1 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)1 LookupType (com.haulmont.cuba.core.entity.annotation.LookupType)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Messages (com.haulmont.cuba.core.global.Messages)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 UiComponents (com.haulmont.cuba.gui.UiComponents)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 WindowManagerProvider (com.haulmont.cuba.gui.WindowManagerProvider)1 LookupAction (com.haulmont.cuba.gui.actions.picker.LookupAction)1 NotificationType (com.haulmont.cuba.gui.components.Frame.NotificationType)1 ListEditor (com.haulmont.cuba.gui.components.ListEditor)1 LookupField (com.haulmont.cuba.gui.components.LookupField)1 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)1