mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 04:07:42 +08:00
PL-8293 Generic filter must use ListEditor for working with collections
This commit is contained in:
parent
31e0113033
commit
fe14cb3218
@ -32,7 +32,6 @@
|
||||
<permission target="filterEditor" value="1" type="10"/>
|
||||
<permission target="filterSelect" value="1" type="10"/>
|
||||
<permission target="groupConditionFrame" value="1" type="10"/>
|
||||
<permission target="inListParamEditor" value="1" type="10"/>
|
||||
<permission target="layoutAnalyzer" value="1" type="10"/>
|
||||
<permission target="mainWindow" value="1" type="10"/>
|
||||
<permission target="multiuploadDialog" value="1" type="10"/>
|
||||
|
@ -1,180 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components.filter;
|
||||
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.WindowManager.OpenType;
|
||||
import com.haulmont.cuba.gui.WindowManagerProvider;
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.config.WindowConfig;
|
||||
import com.haulmont.cuba.gui.config.WindowInfo;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.text.StrBuilder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Component for 'In list' filter condition
|
||||
*/
|
||||
public class InListParamComponent {
|
||||
|
||||
protected TextField field;
|
||||
protected Button pickerButton;
|
||||
protected Button clearButton;
|
||||
|
||||
protected Class itemClass;
|
||||
protected MetaClass metaClass;
|
||||
protected CollectionDatasource collectionDatasource;
|
||||
protected List<String> runtimeEnum;
|
||||
|
||||
protected List listValue;
|
||||
protected Map<Object, String> values = new LinkedHashMap<>();
|
||||
|
||||
protected List<InListValueListener> listeners = new LinkedList<>();
|
||||
protected BoxLayout composition;
|
||||
|
||||
public InListParamComponent(Class itemClass) {
|
||||
ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
|
||||
final WindowManager windowManager = AppBeans.get(WindowManagerProvider.class).get();
|
||||
final WindowConfig windowConfig = AppBeans.get(WindowConfig.class);
|
||||
|
||||
this.itemClass = itemClass;
|
||||
|
||||
field = componentsFactory.createComponent(TextField.class);
|
||||
field.setEditable(false);
|
||||
field.setWidth("100%");
|
||||
FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
|
||||
filterHelper.setFieldReadOnlyFocusable(field, true);
|
||||
|
||||
pickerButton = componentsFactory.createComponent(Button.class);
|
||||
pickerButton.setAction(new AbstractAction("") {
|
||||
@Override
|
||||
public void actionPerform(Component component) {
|
||||
WindowInfo windowInfo = windowConfig.getWindowInfo("inListParamEditor");
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("values", values);
|
||||
params.put("collectionDatasource", collectionDatasource);
|
||||
params.put("metaClass", metaClass);
|
||||
params.put("runtimeEnum", runtimeEnum);
|
||||
params.put("itemClass", itemClass);
|
||||
|
||||
InListParamEditor editor = (InListParamEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
|
||||
editor.addCloseListener(actionId -> {
|
||||
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
|
||||
setValues(editor.getValues());
|
||||
}
|
||||
field.requestFocus();
|
||||
});
|
||||
}
|
||||
});
|
||||
pickerButton.setIcon("components/pickerfield/images/lookup-btn.png");
|
||||
filterHelper.setComponentFocusable(pickerButton, false);
|
||||
|
||||
clearButton = componentsFactory.createComponent(Button.class);
|
||||
clearButton.setAction(new AbstractAction("") {
|
||||
@Override
|
||||
public void actionPerform(Component component) {
|
||||
setValue(null);
|
||||
values.clear();
|
||||
field.setEditable(true);
|
||||
field.setValue(null);
|
||||
field.setEditable(false);
|
||||
}
|
||||
});
|
||||
clearButton.setIcon("components/pickerfield/images/clear-btn.png");
|
||||
filterHelper.setComponentFocusable(clearButton, false);
|
||||
|
||||
composition = componentsFactory.createComponent(HBoxLayout.class);
|
||||
composition.setWidth("100%");
|
||||
|
||||
composition.add(field);
|
||||
composition.add(pickerButton);
|
||||
composition.add(clearButton);
|
||||
composition.expand(field);
|
||||
|
||||
composition.setStyleName("c-pickerfield");
|
||||
}
|
||||
|
||||
public InListParamComponent(CollectionDatasource collectionDatasource) {
|
||||
this(collectionDatasource.getMetaClass().getJavaClass());
|
||||
this.collectionDatasource = collectionDatasource;
|
||||
}
|
||||
|
||||
public InListParamComponent(MetaClass metaClass) {
|
||||
this(metaClass.getJavaClass());
|
||||
this.metaClass = metaClass;
|
||||
}
|
||||
|
||||
public InListParamComponent(List<String> values) {
|
||||
this(String.class);
|
||||
this.runtimeEnum = values;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return composition;
|
||||
}
|
||||
|
||||
public void addValueListener(InListValueListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeValueListener(InListValueListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public void setValue(Object newValue) {
|
||||
if (!ObjectUtils.equals(listValue, newValue)) {
|
||||
for (InListValueListener listener : listeners) {
|
||||
listener.valueChanged(listValue, newValue);
|
||||
}
|
||||
listValue = (List) newValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setValues(Map<Object, String> values) {
|
||||
this.values = values;
|
||||
if (values.isEmpty()) {
|
||||
setValue(null);
|
||||
} else {
|
||||
//noinspection unchecked
|
||||
setValue(new ArrayList(values.keySet()));
|
||||
}
|
||||
|
||||
String caption = new StrBuilder().appendWithSeparators(values.values(), ",").toString();
|
||||
field.setEditable(true);
|
||||
field.setValue(caption);
|
||||
field.setEditable(false);
|
||||
}
|
||||
|
||||
public Map<Object, String> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public interface InListValueListener {
|
||||
void valueChanged(@Nullable Object prevValue, @Nullable Object value);
|
||||
}
|
||||
}
|
@ -1,278 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2016 Haulmont.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.gui.components.filter;
|
||||
|
||||
import com.haulmont.chile.core.datatypes.Datatypes;
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.UserSessionSource;
|
||||
import com.haulmont.cuba.gui.AppConfig;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.theme.ThemeConstants;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Window is used for selecting multiple values for generic filter 'In list' condition
|
||||
*
|
||||
*/
|
||||
public class InListParamEditor extends AbstractWindow {
|
||||
|
||||
@Inject
|
||||
protected ThemeConstants theme;
|
||||
|
||||
@Inject
|
||||
protected ComponentsFactory componentsFactory;
|
||||
|
||||
@Inject
|
||||
protected BoxLayout componentLayout;
|
||||
|
||||
@Inject
|
||||
protected BoxLayout valuesLayout;
|
||||
|
||||
protected Map<Object, String> values;
|
||||
|
||||
protected CollectionDatasource collectionDatasource;
|
||||
|
||||
protected MetaClass metaClass;
|
||||
|
||||
protected List<String> runtimeEnum;
|
||||
|
||||
protected Class itemClass;
|
||||
|
||||
@Override
|
||||
public void init(Map<String, Object> params) {
|
||||
super.init(params);
|
||||
getDialogOptions()
|
||||
.setWidth(theme.getInt("cuba.gui.filter.FilterListParamEditor.dialog.width"))
|
||||
.setHeight(theme.getInt("cuba.gui.filter.FilterListParamEditor.dialog.height"))
|
||||
.setResizable(true);
|
||||
|
||||
values = new HashMap<>((Map<Object, String>) params.get("values"));
|
||||
collectionDatasource = (CollectionDatasource) params.get("collectionDatasource");
|
||||
metaClass = (MetaClass) params.get("metaClass");
|
||||
runtimeEnum = (List<String>) params.get("runtimeEnum");
|
||||
itemClass = (Class) params.get("itemClass");
|
||||
|
||||
for (Map.Entry<Object, String> entry : values.entrySet()) {
|
||||
addItemLayout(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
String pickerWidth = theme.get("cuba.gui.filter.FilterListParamEditor.picker.width");
|
||||
|
||||
if (collectionDatasource != null) {
|
||||
final LookupField lookup = componentsFactory.createComponent(LookupField.class);
|
||||
lookup.setWidth(pickerWidth);
|
||||
lookup.setOptionsDatasource(collectionDatasource);
|
||||
|
||||
//noinspection unchecked
|
||||
collectionDatasource.addCollectionChangeListener(e -> lookup.setValue(null));
|
||||
|
||||
lookup.addValueChangeListener(e -> {
|
||||
if (e.getValue() != null && !containsValue((Instance) e.getValue())) {
|
||||
String str = addEntityInstance((Instance) e.getValue());
|
||||
addItemLayout(e.getValue(), str);
|
||||
}
|
||||
lookup.setValue(null);
|
||||
});
|
||||
|
||||
componentLayout.add(lookup);
|
||||
lookup.requestFocus();
|
||||
|
||||
} else if (metaClass != null) {
|
||||
final PickerField picker = componentsFactory.createComponent(PickerField.class);
|
||||
picker.setWidth(pickerWidth);
|
||||
picker.setMetaClass(metaClass);
|
||||
|
||||
PickerField.LookupAction action = new PickerField.LookupAction(picker) {
|
||||
@Override
|
||||
public void afterSelect(Collection items) {
|
||||
if (!items.isEmpty()) {
|
||||
for (Object value : items) {
|
||||
if (!containsValue((Instance) value)) {
|
||||
String str = addEntityInstance((Instance) value);
|
||||
addItemLayout(value, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
picker.setValue(null);
|
||||
}
|
||||
};
|
||||
|
||||
picker.addAction(action);
|
||||
action.setLookupScreenOpenType(WindowManager.OpenType.DIALOG);
|
||||
picker.addClearAction();
|
||||
|
||||
componentLayout.add(picker);
|
||||
picker.requestFocus();
|
||||
|
||||
} else if (runtimeEnum != null) {
|
||||
final LookupField lookup = componentsFactory.createComponent(LookupField.class);
|
||||
lookup.setWidth(pickerWidth);
|
||||
lookup.setOptionsList(runtimeEnum);
|
||||
|
||||
lookup.addValueChangeListener(e -> {
|
||||
if (e.getValue() != null && !containsValue((String) e.getValue())) {
|
||||
String str = addRuntimeEnumValue((String) e.getValue());
|
||||
addItemLayout(e.getValue(), str);
|
||||
}
|
||||
lookup.setValue(null);
|
||||
});
|
||||
|
||||
componentLayout.add(lookup);
|
||||
lookup.requestFocus();
|
||||
} else if (itemClass.isEnum()) {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
for (Object obj : itemClass.getEnumConstants()) {
|
||||
options.put(messages.getMessage((Enum) obj), obj);
|
||||
}
|
||||
|
||||
final LookupField lookup = componentsFactory.createComponent(LookupField.class);
|
||||
lookup.setWidth(pickerWidth);
|
||||
lookup.setOptionsMap(options);
|
||||
|
||||
lookup.addValueChangeListener(e -> {
|
||||
if (e.getValue() != null && !containsValue((Enum) e.getValue())) {
|
||||
String str = addEnumValue((Enum) e.getValue());
|
||||
addItemLayout(e.getValue(), str);
|
||||
}
|
||||
lookup.setValue(null);
|
||||
});
|
||||
|
||||
componentLayout.add(lookup);
|
||||
lookup.requestFocus();
|
||||
|
||||
} else if (Date.class.isAssignableFrom(itemClass)) {
|
||||
final DateField dateField = componentsFactory.createComponent(DateField.class);
|
||||
|
||||
Button addButton = componentsFactory.createComponent(Button.class);
|
||||
addButton.setAction(new AbstractAction("") {
|
||||
@Override
|
||||
public void actionPerform(Component component) {
|
||||
Date date = dateField.getValue();
|
||||
if (date != null) {
|
||||
String str = addDate(date);
|
||||
addItemLayout(date, str);
|
||||
dateField.setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return messages.getMainMessage("actions.Add");
|
||||
}
|
||||
});
|
||||
|
||||
DateField.Resolution resolution;
|
||||
String dateFormat;
|
||||
if (itemClass.equals(java.sql.Date.class)) {
|
||||
resolution = DateField.Resolution.DAY;
|
||||
dateFormat = messages.getMessage(AppConfig.getMessagesPack(), "dateFormat");
|
||||
} else {
|
||||
resolution = DateField.Resolution.MIN;
|
||||
dateFormat = messages.getMessage(AppConfig.getMessagesPack(), "dateTimeFormat");
|
||||
}
|
||||
dateField.setResolution(resolution);
|
||||
dateField.setDateFormat(dateFormat);
|
||||
|
||||
componentLayout.add(dateField);
|
||||
componentLayout.add(addButton);
|
||||
dateField.requestFocus();
|
||||
|
||||
} else
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
protected boolean containsValue(String value) {
|
||||
return values.containsValue(value);
|
||||
}
|
||||
|
||||
protected boolean containsValue(Instance value) {
|
||||
return this.values.containsKey(value);
|
||||
}
|
||||
|
||||
protected boolean containsValue(Enum value) {
|
||||
return this.values.containsValue(messages.getMessage(value));
|
||||
}
|
||||
|
||||
protected String addRuntimeEnumValue(String value) {
|
||||
values.put(value, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
protected String addEnumValue(Enum en) {
|
||||
String str = messages.getMessage(en);
|
||||
values.put(en, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
protected String addEntityInstance(Instance value) {
|
||||
String str = value.getInstanceName();
|
||||
values.put(value, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
protected void addItemLayout(final Object value, String str) {
|
||||
final BoxLayout itemLayout = componentsFactory.createComponent(HBoxLayout.class);
|
||||
itemLayout.setSpacing(true);
|
||||
|
||||
Label itemLab = componentsFactory.createComponent(Label.class);
|
||||
itemLab.setValue(str);
|
||||
itemLayout.add(itemLab);
|
||||
itemLab.setAlignment(Alignment.MIDDLE_LEFT);
|
||||
|
||||
LinkButton delItemBtn = componentsFactory.createComponent(LinkButton.class);
|
||||
delItemBtn.setIcon("icons/item-remove.png");
|
||||
delItemBtn.setAction(new AbstractAction("") {
|
||||
@Override
|
||||
public void actionPerform(Component component) {
|
||||
values.remove(value);
|
||||
valuesLayout.remove(itemLayout);
|
||||
}
|
||||
});
|
||||
itemLayout.add(delItemBtn);
|
||||
delItemBtn.setAlignment(Alignment.MIDDLE_LEFT);
|
||||
|
||||
valuesLayout.add(itemLayout);
|
||||
}
|
||||
|
||||
protected String addDate(Date date) {
|
||||
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
|
||||
Locale locale = sessionSource.getUserSession().getLocale();
|
||||
String str = Datatypes.getNN(itemClass).format(date, locale);
|
||||
values.put(date, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
public Map<Object, String> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
close(COMMIT_ACTION_ID);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
close(CLOSE_ACTION_ID);
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ import com.haulmont.cuba.gui.WindowManagerProvider;
|
||||
import com.haulmont.cuba.gui.WindowParams;
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.components.filter.condition.FilterConditionUtils;
|
||||
import com.haulmont.cuba.gui.components.listeditor.ListEditorHelper;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.DsBuilder;
|
||||
@ -497,24 +498,21 @@ public class Param {
|
||||
|
||||
|
||||
protected Component createTextField(final ValueProperty valueProperty) {
|
||||
TextField field = componentsFactory.createComponent(TextField.class);
|
||||
if (inExpr) {
|
||||
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
|
||||
listEditor.setItemType(ListEditor.ItemType.STRING);
|
||||
initListEditor(listEditor, valueProperty);
|
||||
return listEditor;
|
||||
}
|
||||
|
||||
TextField field = componentsFactory.createComponent(TextField.class);
|
||||
field.setWidth(theme.get("cuba.gui.filter.Param.textComponent.width"));
|
||||
|
||||
field.addValueChangeListener(e -> {
|
||||
Object paramValue = null;
|
||||
if (!StringUtils.isBlank((String) e.getValue())) {
|
||||
if (inExpr) {
|
||||
paramValue = new ArrayList<String>();
|
||||
String[] parts = ((String) e.getValue()).split(",");
|
||||
for (String part : parts) {
|
||||
((List) paramValue).add(part.trim());
|
||||
}
|
||||
} else {
|
||||
paramValue = e.getValue();
|
||||
}
|
||||
paramValue = e.getValue();
|
||||
}
|
||||
|
||||
if (paramValue instanceof String) {
|
||||
Configuration configuration = AppBeans.get(Configuration.NAME);
|
||||
if (configuration.getConfig(ClientConfig.class).getGenericFilterTrimParamValues()) {
|
||||
@ -548,9 +546,12 @@ public class Param {
|
||||
javaClass = java.sql.Date.class;
|
||||
}
|
||||
}
|
||||
final InListParamComponent inListParamComponent = new InListParamComponent(javaClass);
|
||||
initListEdit(inListParamComponent, valueProperty);
|
||||
return inListParamComponent.getComponent();
|
||||
|
||||
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
|
||||
ListEditor.ItemType itemType = java.sql.Date.class.equals(javaClass) ? ListEditor.ItemType.DATE : ListEditor.ItemType.DATETIME;
|
||||
listEditor.setItemType(itemType);
|
||||
initListEditor(listEditor, valueProperty);
|
||||
return listEditor;
|
||||
}
|
||||
|
||||
DateField dateField = componentsFactory.createComponent(DateField.class);
|
||||
@ -583,6 +584,12 @@ public class Param {
|
||||
}
|
||||
|
||||
protected Component createNumberField(final Datatype datatype, final ValueProperty valueProperty) {
|
||||
if (inExpr) {
|
||||
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
|
||||
listEditor.setItemType(ListEditorHelper.itemTypeFromDatatype(datatype));
|
||||
initListEditor(listEditor, valueProperty);
|
||||
return listEditor;
|
||||
}
|
||||
TextField field = componentsFactory.createComponent(TextField.class);
|
||||
|
||||
field.addValueChangeListener(e -> {
|
||||
@ -592,28 +599,12 @@ public class Param {
|
||||
UserSessionSource userSessionSource1 = AppBeans.get(UserSessionSource.NAME);
|
||||
|
||||
Object v;
|
||||
if (inExpr) {
|
||||
v = new ArrayList();
|
||||
String[] parts = ((String) e.getValue()).split(",");
|
||||
for (String part : parts) {
|
||||
Object p;
|
||||
try {
|
||||
p = datatype.parse(part, userSessionSource1.getLocale());
|
||||
} catch (ParseException ex) {
|
||||
WindowManager wm = AppBeans.get(WindowManagerProvider.class).get();
|
||||
wm.showNotification(messages.getMainMessage("filter.param.numberInvalid"), Frame.NotificationType.ERROR);
|
||||
return;
|
||||
}
|
||||
((List) v).add(p);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
v = datatype.parse((String) e.getValue(), userSessionSource1.getLocale());
|
||||
} catch (ParseException ex) {
|
||||
WindowManager wm = AppBeans.get(WindowManagerProvider.class).get();
|
||||
wm.showNotification(messages.getMainMessage("filter.param.numberInvalid"), Frame.NotificationType.ERROR);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
v = datatype.parse((String) e.getValue(), userSessionSource1.getLocale());
|
||||
} catch (ParseException ex) {
|
||||
WindowManager wm = AppBeans.get(WindowManagerProvider.class).get();
|
||||
wm.showNotification(messages.getMainMessage("filter.param.numberInvalid"), Frame.NotificationType.TRAY);
|
||||
return;
|
||||
}
|
||||
_setValue(v, valueProperty);
|
||||
} else if (e.getValue() instanceof String && StringUtils.isBlank((String) e.getValue())) {
|
||||
@ -648,6 +639,13 @@ public class Param {
|
||||
}
|
||||
|
||||
protected Component createUuidField(final ValueProperty valueProperty) {
|
||||
if (inExpr) {
|
||||
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
|
||||
listEditor.setItemType(ListEditor.ItemType.UUID);
|
||||
initListEditor(listEditor, valueProperty);
|
||||
return listEditor;
|
||||
}
|
||||
|
||||
TextField field = componentsFactory.createComponent(TextField.class);
|
||||
|
||||
field.addValueChangeListener(e -> {
|
||||
@ -657,24 +655,10 @@ public class Param {
|
||||
} else if ((!StringUtils.isBlank(strValue))) {
|
||||
Messages messages1 = AppBeans.get(Messages.NAME);
|
||||
|
||||
if (inExpr) {
|
||||
List list = new ArrayList();
|
||||
String[] parts = strValue.split(",");
|
||||
try {
|
||||
for (String part : parts) {
|
||||
list.add(UUID.fromString(part.trim()));
|
||||
}
|
||||
_setValue(list, valueProperty);
|
||||
} catch (IllegalArgumentException ie) {
|
||||
AppBeans.get(WindowManagerProvider.class).get().showNotification(messages1.getMainMessage("filter.param.uuid.Err"), Frame.NotificationType.TRAY);
|
||||
_setValue(null, valueProperty);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
_setValue(UUID.fromString(strValue), valueProperty);
|
||||
} catch (IllegalArgumentException ie) {
|
||||
AppBeans.get(WindowManagerProvider.class).get().showNotification(messages1.getMainMessage("filter.param.uuid.Err"), Frame.NotificationType.TRAY);
|
||||
}
|
||||
try {
|
||||
_setValue(UUID.fromString(strValue), valueProperty);
|
||||
} catch (IllegalArgumentException ie) {
|
||||
AppBeans.get(WindowManagerProvider.class).get().showNotification(messages1.getMainMessage("filter.param.uuid.Err"), Frame.NotificationType.TRAY);
|
||||
}
|
||||
} else if (StringUtils.isBlank(strValue)) {
|
||||
_setValue(null, valueProperty);
|
||||
@ -684,14 +668,11 @@ public class Param {
|
||||
});
|
||||
|
||||
Object _value = _getValue(valueProperty);
|
||||
if (_value instanceof List) {
|
||||
field.setValue(StringUtils.join((Collection) _value, ","));
|
||||
} else if (_value instanceof String) {
|
||||
if (_value instanceof String) {
|
||||
field.setValue(_value);
|
||||
} else {
|
||||
field.setValue("");
|
||||
}
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
@ -706,9 +687,11 @@ public class Param {
|
||||
|
||||
if (useLookupScreen) {
|
||||
if (inExpr) {
|
||||
final InListParamComponent inListParamComponent = new InListParamComponent(metaClass);
|
||||
initListEdit(inListParamComponent, valueProperty);
|
||||
return inListParamComponent.getComponent();
|
||||
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
|
||||
listEditor.setItemType(ListEditor.ItemType.ENTITY);
|
||||
listEditor.setEntityName(metaClass.getName());
|
||||
initListEditor(listEditor, valueProperty);
|
||||
return listEditor;
|
||||
} else {
|
||||
PickerField picker = componentsFactory.createComponent(PickerField.class);
|
||||
picker.setMetaClass(metaClass);
|
||||
@ -727,9 +710,13 @@ public class Param {
|
||||
CollectionDatasource<Entity<Object>, Object> optionsDataSource = createOptionsDataSource(metaClass);
|
||||
|
||||
if (inExpr) {
|
||||
final InListParamComponent inListParamComponent = new InListParamComponent(optionsDataSource);
|
||||
initListEdit(inListParamComponent, valueProperty);
|
||||
return inListParamComponent.getComponent();
|
||||
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
|
||||
listEditor.setItemType(ListEditor.ItemType.ENTITY);
|
||||
listEditor.setEntityName(metaClass.getName());
|
||||
listEditor.setUseLookupField(true);
|
||||
listEditor.setEntityWhereClause(entityWhere);
|
||||
initListEditor(listEditor, valueProperty);
|
||||
return listEditor;
|
||||
} else {
|
||||
final LookupPickerField lookup = componentsFactory.createComponent(LookupPickerField.class);
|
||||
lookup.addClearAction();
|
||||
@ -776,9 +763,12 @@ public class Param {
|
||||
|
||||
protected Component createEnumLookup(final ValueProperty valueProperty) {
|
||||
if (inExpr) {
|
||||
final InListParamComponent inListParamComponent = new InListParamComponent(javaClass);
|
||||
initListEdit(inListParamComponent, valueProperty);
|
||||
return inListParamComponent.getComponent();
|
||||
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
|
||||
listEditor.setItemType(ListEditor.ItemType.ENUM);
|
||||
listEditor.setEnumClass(javaClass);
|
||||
initListEditor(listEditor, valueProperty);
|
||||
return listEditor;
|
||||
|
||||
} else {
|
||||
LookupField lookup = componentsFactory.createComponent(LookupField.class);
|
||||
List options = Arrays.asList(javaClass.getEnumConstants());
|
||||
@ -816,9 +806,11 @@ public class Param {
|
||||
}
|
||||
|
||||
if (inExpr) {
|
||||
final InListParamComponent inListParamComponent = new InListParamComponent(runtimeEnum);
|
||||
initListEdit(inListParamComponent, valueProperty);
|
||||
return inListParamComponent.getComponent();
|
||||
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
|
||||
listEditor.setItemType(ListEditor.ItemType.STRING);
|
||||
listEditor.setOptionsList(runtimeEnum);
|
||||
initListEditor(listEditor, valueProperty);
|
||||
return listEditor;
|
||||
} else {
|
||||
LookupField lookup = componentsFactory.createComponent(LookupField.class);
|
||||
lookup.setOptionsList(runtimeEnum);
|
||||
@ -833,16 +825,17 @@ public class Param {
|
||||
}
|
||||
}
|
||||
|
||||
protected void initListEdit(InListParamComponent component, ValueProperty valueProperty) {
|
||||
component.addValueListener((prevValue, value1) -> _setValue(value1, valueProperty));
|
||||
|
||||
Object _value = _getValue(valueProperty);
|
||||
if (_value != null) {
|
||||
Map<Object, String> values = new HashMap<>();
|
||||
for (Object v : (List) _value) {
|
||||
values.put(v, getValueCaption(v));
|
||||
protected void initListEditor(ListEditor listEditor, ValueProperty valueProperty) {
|
||||
listEditor.addValueChangeListener(e -> {
|
||||
Object value = e.getValue();
|
||||
if (value instanceof List && ((List) value).isEmpty()) {
|
||||
value = null;
|
||||
}
|
||||
component.setValues(values);
|
||||
_setValue(value, valueProperty);
|
||||
});
|
||||
Object value = _getValue(valueProperty);
|
||||
if (value != null) {
|
||||
listEditor.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,31 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2008-2016 Haulmont.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
-->
|
||||
|
||||
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
|
||||
class="com.haulmont.cuba.gui.components.filter.InListParamEditor"
|
||||
caption="mainMsg://filter.inListParamEditor.caption">
|
||||
<layout spacing="true" expand="scrollbox">
|
||||
<hbox id="componentLayout" spacing="true"/>
|
||||
<scrollBox id="scrollbox" scrollBars="both">
|
||||
<vbox id="valuesLayout" spacing="true"/>
|
||||
</scrollBox>
|
||||
<hbox id="buttonsPanel" spacing="true">
|
||||
<button id="commit" invoke="commit" caption="mainMsg://actions.Ok" icon="icons/ok.png"/>
|
||||
<button id="close" invoke="cancel" caption="mainMsg://actions.Cancel" icon="icons/cancel.png"/>
|
||||
</hbox>
|
||||
</layout>
|
||||
</window>
|
@ -166,9 +166,6 @@
|
||||
<screen id="saveFilter"
|
||||
template="/com/haulmont/cuba/gui/components/filter/save-filter.xml"/>
|
||||
|
||||
<screen id="inListParamEditor"
|
||||
template="/com/haulmont/cuba/gui/components/filter/in-list-param-edit.xml"/>
|
||||
|
||||
<screen id="customConditionFrame"
|
||||
template="/com/haulmont/cuba/gui/components/filter/edit/custom-condition-frame.xml"/>
|
||||
|
||||
|
@ -378,7 +378,6 @@ filter.saveFilter.name=Filter name
|
||||
filter.saveFilter.caption=Save filter
|
||||
filter.saveFilter.fillName=Fill name
|
||||
|
||||
filter.inListParamEditor.caption=Values
|
||||
filter.customCondition.new=New condition
|
||||
filter.filterSelect.caption = Select filter
|
||||
filter.filterSelect.selectFilterEntity = Select filter
|
||||
|
@ -372,7 +372,6 @@ filter.saveFilter.name=Имя фильтра
|
||||
filter.saveFilter.caption=Сохранить фильтр
|
||||
filter.saveFilter.fillName=Заполните имя
|
||||
|
||||
filter.inListParamEditor.caption=Значения
|
||||
filter.customCondition.new=Новое условие
|
||||
filter.filterSelect.caption = Выберите фильтр
|
||||
filter.filterSelect.selectFilterEntity = Выберите фильтр
|
||||
|
Loading…
Reference in New Issue
Block a user