-
Notifications
You must be signed in to change notification settings - Fork 188
/
SearchFilterPanel.java
131 lines (118 loc) · 6.59 KB
/
SearchFilterPanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (C) 2010-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.web.component.search;
import com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.web.component.input.CheckPanel;
import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.midpoint.web.component.prism.InputPanel;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ParameterType;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.Validate;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import javax.xml.namespace.QName;
import java.util.List;
/**
* @author Viliam Repan (lazyman)
* @author lskublik
*/
public class SearchFilterPanel extends AbstractSearchItemPanel<FilterSearchItem> {
private static final long serialVersionUID = 1L;
private static final String ID_SEARCH_ITEM_FIELD = "searchItemField";
private static final String ID_CHECK_DISABLE_FIELD = "checkDisable";
public SearchFilterPanel(String id, IModel<FilterSearchItem> model) {
super(id, model);
}
protected void initSearchItemField(WebMarkupContainer searchItemContainer) {
CheckPanel checkPanel = new CheckPanel(ID_CHECK_DISABLE_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_APPLY_FILTER));
(checkPanel).getBaseFormComponent().add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
searchPerformed(ajaxRequestTarget);
}
});
checkPanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
checkPanel.setOutputMarkupId(true);
searchItemContainer.add(checkPanel);
ParameterType functionParameter = getModelObject().getPredefinedFilter().getParameter();
QName returnType = functionParameter != null ? functionParameter.getType() : null;
Component inputPanel;
if (returnType == null) {
inputPanel = new WebMarkupContainer(ID_SEARCH_ITEM_FIELD);
} else {
Class<?> inputClass = getPrismContext().getSchemaRegistry().determineClassForType(returnType);
Validate.notNull(inputClass, "Couldn't find class for type " + returnType);
SearchItem.Type inputType = getModelObject().getInputType(inputClass, getPageBase());
IModel<List<DisplayableValue<?>>> choices = null;
switch (inputType) {
case REFERENCE:
getModelObject().setInput(new SearchValue<>(new ObjectReferenceType()));
inputPanel = new ReferenceValueSearchPanel(ID_SEARCH_ITEM_FIELD,
new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE),
null){
@Override
protected void referenceValueUpdated(ObjectReferenceType ort, AjaxRequestTarget target) {
searchPerformed(target);
}
};
break;
case BOOLEAN:
choices = (IModel) createBooleanChoices();
case ENUM:
if (choices == null) {
choices = CollectionUtils.isEmpty(getModelObject().getAllowedValues(getPageBase())) ?
createEnumChoices((Class<? extends Enum>) inputClass) : Model.ofList(getModelObject().getAllowedValues(getPageBase()));
}
if (choices != null) {
inputPanel = WebComponentUtil.createDropDownChoices(
ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), FilterSearchItem.F_INPUT), (IModel)choices, false, getPageBase());
((InputPanel) inputPanel).getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
searchPerformed(target);
}
});
break;
}
case ITEM_PATH:
inputPanel = new ItemPathSearchPanel(ID_SEARCH_ITEM_FIELD,
new PropertyModel(getModel(), FilterSearchItem.F_INPUT_VALUE));
break;
case TEXT:
LookupTableType lookupTable = getModelObject().getLookupTable(getPageBase());
if (lookupTable != null) {
inputPanel = createAutoCompetePanel(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE),
lookupTable);
break;
}
default:
inputPanel = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT_VALUE));
}
if (inputPanel instanceof InputPanel && !(inputPanel instanceof AutoCompleteTextPanel)) {
((InputPanel) inputPanel).getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
((InputPanel) inputPanel).getBaseFormComponent().add(AttributeAppender.append("style", "width: 140px; max-width: 400px !important;"));
((InputPanel) inputPanel).getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
}
inputPanel.setOutputMarkupId(true);
searchItemContainer.add(inputPanel);
}
searchItemContainer.add(inputPanel);
}
}