Search in sources :

Example 6 with ContainerOptions

use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.

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 = beanLocator.get(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.addLookupAction();
            picker.addClearAction();
            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.addClearAction();
            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 : LoggerFactory(org.slf4j.LoggerFactory) DatatypeRegistry(com.haulmont.chile.core.datatypes.DatatypeRegistry) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup) StringUtils(org.apache.commons.lang3.StringUtils) java.time(java.time) ListEditorHelper(com.haulmont.cuba.gui.components.listeditor.ListEditorHelper) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) ParseException(java.text.ParseException) DateInIntervalComponent(com.haulmont.cuba.gui.components.filter.dateinterval.DateInIntervalComponent) IgnoreUserTimeZone(com.haulmont.cuba.core.entity.annotation.IgnoreUserTimeZone) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Datatypes(com.haulmont.chile.core.datatypes.Datatypes) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) DataComponents(com.haulmont.cuba.gui.model.DataComponents) Collectors(java.util.stream.Collectors) EventHub(com.haulmont.bali.events.EventHub) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) ClientConfig(com.haulmont.cuba.client.ClientConfig) UiComponents(com.haulmont.cuba.gui.UiComponents) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException) ParamsMap(com.haulmont.bali.util.ParamsMap) SimpleDateFormat(java.text.SimpleDateFormat) DynamicAttributesUtils(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils) BooleanUtils(org.apache.commons.lang3.BooleanUtils) MetaClass(com.haulmont.chile.core.model.MetaClass) Scope(org.springframework.context.annotation.Scope) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) UserSession(com.haulmont.cuba.security.global.UserSession) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Datatype(com.haulmont.chile.core.datatypes.Datatype) ImmutableList(com.google.common.collect.ImmutableList) Subscription(com.haulmont.bali.events.Subscription) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) WindowManagerProvider(com.haulmont.cuba.gui.WindowManagerProvider) Nullable(javax.annotation.Nullable) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) Logger(org.slf4j.Logger) ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) TemporalType(javax.persistence.TemporalType) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Consumer(java.util.function.Consumer) CollectionLoader(com.haulmont.cuba.gui.model.CollectionLoader) Element(org.dom4j.Element) PropertyType(com.haulmont.cuba.core.app.dynamicattributes.PropertyType) Entity(com.haulmont.cuba.core.entity.Entity) Entity(com.haulmont.cuba.core.entity.Entity) LookupType(com.haulmont.cuba.core.entity.annotation.LookupType) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) MetaClass(com.haulmont.chile.core.model.MetaClass) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup)

Example 7 with ContainerOptions

use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.

the class DataGridEditorComponentGenerationStrategy method createEntityField.

@SuppressWarnings("unchecked")
@Override
protected Field createEntityField(ComponentGenerationContext context, MetaPropertyPath mpp) {
    Options options = context.getOptions();
    Lookup lookupAnnotation;
    if ((lookupAnnotation = mpp.getMetaProperty().getAnnotatedElement().getAnnotation(Lookup.class)) != null && lookupAnnotation.type() == LookupType.DROPDOWN) {
        MetaClass metaClass = mpp.getMetaProperty().getRange().asClass();
        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();
        options = new ContainerOptions(container);
    }
    if (DynamicAttributesUtils.isDynamicAttribute(mpp.getMetaProperty())) {
        DynamicAttributesMetaProperty metaProperty = (DynamicAttributesMetaProperty) mpp.getMetaProperty();
        CategoryAttribute attribute = metaProperty.getAttribute();
        if (Boolean.TRUE.equals(attribute.getLookup())) {
            DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.class);
            CollectionDatasource optionsDatasource = dynamicAttributesGuiTools.createOptionsDatasourceForLookup(metaProperty.getRange().asClass(), attribute.getJoinClause(), attribute.getWhereClause());
            options = new DatasourceOptions(optionsDatasource);
        }
    }
    PickerField<?> pickerField;
    if (options == null) {
        pickerField = uiComponents.create(PickerField.class);
        setValueSource(pickerField, context);
        guiActionSupport.createActionById(pickerField, PickerField.ActionType.LOOKUP.getId());
        if (DynamicAttributesUtils.isDynamicAttribute(mpp.getMetaProperty())) {
            DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.class);
            DynamicAttributesMetaProperty dynamicAttributesMetaProperty = (DynamicAttributesMetaProperty) mpp.getMetaProperty();
            dynamicAttributesGuiTools.initEntityPickerField(pickerField, dynamicAttributesMetaProperty.getAttribute());
        }
        boolean actionsByMetaAnnotations = guiActionSupport.createActionsByMetaAnnotations(pickerField);
        if (!actionsByMetaAnnotations) {
            guiActionSupport.createActionById(pickerField, PickerField.ActionType.CLEAR.getId());
        }
    } else {
        LookupPickerField<?> lookupPickerField = uiComponents.create(LookupPickerField.class);
        setValueSource(lookupPickerField, context);
        lookupPickerField.setOptions(options);
        pickerField = lookupPickerField;
        guiActionSupport.createActionsByMetaAnnotations(pickerField);
    }
    setupPickerFieldActions(pickerField);
    return pickerField;
}
Also used : MapScreenOptions(com.haulmont.cuba.gui.screen.MapScreenOptions) ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) Options(com.haulmont.cuba.gui.components.data.Options) DatasourceOptions(com.haulmont.cuba.gui.components.data.options.DatasourceOptions) Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools) ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) DynamicAttributesMetaProperty(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup) DatasourceOptions(com.haulmont.cuba.gui.components.data.options.DatasourceOptions)

Example 8 with ContainerOptions

use of com.haulmont.cuba.gui.components.data.options.ContainerOptions in project cuba by cuba-platform.

the class WebTableFieldFactory method getOptions.

@SuppressWarnings("unchecked")
@Nullable
@Override
protected Options getOptions(EntityValueSource valueSource, String property) {
    MetaClass metaClass = valueSource.getEntityMetaClass();
    MetaPropertyPath metaPropertyPath = metadataTools.resolveMetaPropertyPath(metaClass, property);
    Table.Column columnConf = webTable.getColumnsInternal().get(metaPropertyPath);
    CollectionContainer collectionContainer = findOptionsContainer(columnConf);
    if (collectionContainer != null) {
        return new ContainerOptions(collectionContainer);
    }
    CollectionDatasource ds = findOptionsDatasource(columnConf, property);
    if (ds != null) {
        return new DatasourceOptions(ds);
    }
    return null;
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) Table(com.haulmont.cuba.gui.components.Table) WebAbstractTable(com.haulmont.cuba.web.gui.components.WebAbstractTable) MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) DatasourceOptions(com.haulmont.cuba.gui.components.data.options.DatasourceOptions) Nullable(javax.annotation.Nullable)

Aggregations

ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)8 MetaClass (com.haulmont.chile.core.model.MetaClass)6 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)5 Entity (com.haulmont.cuba.core.entity.Entity)3 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)3 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)2 DatasourceOptions (com.haulmont.cuba.gui.components.data.options.DatasourceOptions)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 CollectionLoader (com.haulmont.cuba.gui.model.CollectionLoader)2 DataComponents (com.haulmont.cuba.gui.model.DataComponents)2 Nullable (javax.annotation.Nullable)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 EventHub (com.haulmont.bali.events.EventHub)1 Subscription (com.haulmont.bali.events.Subscription)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 DatatypeRegistry (com.haulmont.chile.core.datatypes.DatatypeRegistry)1 Datatypes (com.haulmont.chile.core.datatypes.Datatypes)1