Search in sources :

Example 1 with DatasourceOptions

use of com.haulmont.cuba.gui.components.data.options.DatasourceOptions 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 2 with DatasourceOptions

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

the class WebSearchField method executeSearch.

protected void executeSearch(final String newFilter) {
    if (optionsBinding == null || optionsBinding.getSource() == null) {
        return;
    }
    String filterForDs = newFilter;
    if (mode == Mode.LOWER_CASE) {
        filterForDs = StringUtils.lowerCase(newFilter);
    } else if (mode == Mode.UPPER_CASE) {
        filterForDs = StringUtils.upperCase(newFilter);
    }
    if (escapeValueForLike && StringUtils.isNotEmpty(filterForDs)) {
        filterForDs = QueryUtils.escapeForLike(filterForDs);
    }
    CollectionDatasource optionsDatasource = ((DatasourceOptions) optionsBinding.getSource()).getDatasource();
    if (!isRequired() && StringUtils.isEmpty(filterForDs)) {
        setValue(null);
        if (optionsDatasource.getState() == Datasource.State.VALID) {
            optionsDatasource.clear();
        }
        return;
    }
    if (StringUtils.length(filterForDs) >= minSearchStringLength) {
        optionsDatasource.refresh(Collections.singletonMap(SEARCH_STRING_PARAM, filterForDs));
        if (optionsDatasource.getState() == Datasource.State.VALID) {
            if (optionsDatasource.size() == 0) {
                if (searchNotifications != null) {
                    searchNotifications.notFoundSuggestions(newFilter);
                }
            } else if (optionsDatasource.size() == 1) {
                setValue((V) optionsDatasource.getItems().iterator().next());
            }
        }
    } else {
        if (optionsDatasource.getState() == Datasource.State.VALID) {
            optionsDatasource.clear();
        }
        if (searchNotifications != null && StringUtils.length(newFilter) > 0) {
            searchNotifications.needMinSearchStringLength(newFilter, minSearchStringLength);
        }
    }
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DatasourceOptions(com.haulmont.cuba.gui.components.data.options.DatasourceOptions)

Example 3 with DatasourceOptions

use of com.haulmont.cuba.gui.components.data.options.DatasourceOptions 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)

Example 4 with DatasourceOptions

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

the class WebSearchPickerField method executeSearch.

protected void executeSearch(final String newFilter) {
    if (optionsBinding == null || optionsBinding.getSource() == null) {
        return;
    }
    String filterForDs = newFilter;
    if (mode == Mode.LOWER_CASE) {
        filterForDs = StringUtils.lowerCase(newFilter);
    } else if (mode == Mode.UPPER_CASE) {
        filterForDs = StringUtils.upperCase(newFilter);
    }
    if (escapeValueForLike && StringUtils.isNotEmpty(filterForDs)) {
        filterForDs = QueryUtils.escapeForLike(filterForDs);
    }
    CollectionDatasource optionsDatasource = ((DatasourceOptions) optionsBinding.getSource()).getDatasource();
    if (!isRequired() && StringUtils.isEmpty(filterForDs)) {
        setValue(null);
        if (optionsDatasource.getState() == Datasource.State.VALID) {
            optionsDatasource.clear();
        }
        return;
    }
    if (StringUtils.length(filterForDs) >= minSearchStringLength) {
        optionsDatasource.refresh(Collections.singletonMap(SEARCH_STRING_PARAM, filterForDs));
        if (optionsDatasource.getState() == Datasource.State.VALID) {
            if (optionsDatasource.size() == 0) {
                if (searchNotifications != null) {
                    searchNotifications.notFoundSuggestions(newFilter);
                }
            } else if (optionsDatasource.size() == 1) {
                setValue((V) optionsDatasource.getItems().iterator().next());
            }
        }
    } else {
        if (optionsDatasource.getState() == Datasource.State.VALID) {
            optionsDatasource.clear();
        }
        if (searchNotifications != null && StringUtils.length(newFilter) > 0) {
            searchNotifications.needMinSearchStringLength(newFilter, minSearchStringLength);
        }
    }
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DatasourceOptions(com.haulmont.cuba.gui.components.data.options.DatasourceOptions)

Aggregations

DatasourceOptions (com.haulmont.cuba.gui.components.data.options.DatasourceOptions)4 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)4 MetaClass (com.haulmont.chile.core.model.MetaClass)2 ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)2 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 DynamicAttributesMetaProperty (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty)1 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Lookup (com.haulmont.cuba.core.entity.annotation.Lookup)1 Table (com.haulmont.cuba.gui.components.Table)1 Options (com.haulmont.cuba.gui.components.data.Options)1 DynamicAttributesGuiTools (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)1 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)1 MapScreenOptions (com.haulmont.cuba.gui.screen.MapScreenOptions)1 WebAbstractTable (com.haulmont.cuba.web.gui.components.WebAbstractTable)1 Nullable (javax.annotation.Nullable)1