Search in sources :

Example 1 with ContainerOptions

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;
        }
    }
}
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 ContainerOptions

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);
    }
}
Also used : ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) FrameOwner(io.jmix.ui.screen.FrameOwner) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) InstanceContainer(io.jmix.ui.model.InstanceContainer) CollectionContainer(io.jmix.ui.model.CollectionContainer) ScreenData(io.jmix.ui.model.ScreenData)

Example 3 with ContainerOptions

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;
}
Also used : Entity(io.jmix.core.Entity) ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) MetaClass(io.jmix.core.metamodel.model.MetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) Lookup(com.haulmont.cuba.core.entity.annotation.Lookup) GuiActionSupport(com.haulmont.cuba.gui.components.actions.GuiActionSupport) DataComponents(io.jmix.ui.model.DataComponents)

Example 4 with ContainerOptions

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;
}
Also used : ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) EntityPicker(io.jmix.ui.component.EntityPicker) EntityComboBox(io.jmix.ui.component.EntityComboBox) OptionsField(io.jmix.ui.component.OptionsField)

Example 5 with ContainerOptions

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;
}
Also used : ContainerOptions(io.jmix.ui.component.data.options.ContainerOptions) AbstractTable(io.jmix.ui.component.impl.AbstractTable) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) CollectionContainer(io.jmix.ui.model.CollectionContainer) Nullable(javax.annotation.Nullable)

Aggregations

ContainerOptions (io.jmix.ui.component.data.options.ContainerOptions)6 MetaClass (io.jmix.core.metamodel.model.MetaClass)4 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)3 CollectionContainer (io.jmix.ui.model.CollectionContainer)3 InstanceContainer (io.jmix.ui.model.InstanceContainer)3 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)2 Metadata (com.haulmont.cuba.core.global.Metadata)2 Entity (io.jmix.core.Entity)2 ScreenData (io.jmix.ui.model.ScreenData)2 FrameOwner (io.jmix.ui.screen.FrameOwner)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 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 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 UiComponents (com.haulmont.cuba.gui.UiComponents)1