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;
}
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);
}
}
}
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;
}
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);
}
}
}
Aggregations