Search in sources :

Example 1 with CollectionLoader

use of com.haulmont.cuba.gui.model.CollectionLoader in project cuba by cuba-platform.

the class InputDialog method createEntityField.

@SuppressWarnings("unchecked")
protected Field createEntityField(InputParameter parameter) {
    MetaClass metaClass = metadata.getClassNN(parameter.getEntityClass());
    Action lookupAction = actions.create(LookupAction.ID);
    Action clearAction = actions.create(ClearAction.ID);
    if (persistenceManagerService.useLookupScreen(metaClass.getName())) {
        PickerField pickerField = uiComponents.create(PickerField.NAME);
        pickerField.setMetaClass(metadata.getClass(parameter.getEntityClass()));
        pickerField.addAction(lookupAction);
        pickerField.addAction(clearAction);
        pickerField.setWidthFull();
        return pickerField;
    } else {
        LookupPickerField lookupPickerField = uiComponents.create(LookupPickerField.NAME);
        lookupPickerField.addAction(lookupAction);
        lookupPickerField.addAction(clearAction);
        lookupPickerField.setWidthFull();
        CollectionContainer container = dataComponents.createCollectionContainer(parameter.getEntityClass());
        CollectionLoader loader = dataComponents.createCollectionLoader();
        loader.setQuery("select e from " + metaClass.getName() + " e");
        loader.setView(View.MINIMAL);
        loader.setContainer(container);
        loader.load();
        lookupPickerField.setOptions(new ContainerOptions(container));
        return lookupPickerField;
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) ClearAction(com.haulmont.cuba.gui.actions.picker.ClearAction) InputDialogAction(com.haulmont.cuba.gui.components.inputdialog.InputDialogAction) CollectionLoader(com.haulmont.cuba.gui.model.CollectionLoader) MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer)

Example 2 with CollectionLoader

use of com.haulmont.cuba.gui.model.CollectionLoader 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)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)2 ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)2 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)2 CollectionLoader (com.haulmont.cuba.gui.model.CollectionLoader)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 ValueConversionException (com.haulmont.chile.core.datatypes.ValueConversionException)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 PersistenceManagerClient (com.haulmont.cuba.client.sys.PersistenceManagerClient)1 DynamicAttributesUtils (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils)1 PropertyType (com.haulmont.cuba.core.app.dynamicattributes.PropertyType)1 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Entity (com.haulmont.cuba.core.entity.Entity)1