1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects.classes; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import org.apache.commons.lang3.StringUtils; |
28 |
|
import org.apache.ecs.xhtml.input; |
29 |
|
|
30 |
|
import com.xpn.xwiki.XWiki; |
31 |
|
import com.xpn.xwiki.XWikiContext; |
32 |
|
import com.xpn.xwiki.internal.xml.XMLAttributeValueFilter; |
33 |
|
import com.xpn.xwiki.objects.BaseCollection; |
34 |
|
import com.xpn.xwiki.objects.BaseProperty; |
35 |
|
import com.xpn.xwiki.objects.meta.PropertyMetaClass; |
36 |
|
|
|
|
| 96.1% |
Uncovered Elements: 3 (77) |
Complexity: 17 |
Complexity Density: 0.31 |
|
37 |
|
public class StaticListClass extends ListClass |
38 |
|
{ |
39 |
|
private static final String XCLASSNAME = "staticlist"; |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
41 |
8023 |
public StaticListClass(PropertyMetaClass wclass)... |
42 |
|
{ |
43 |
8023 |
super(XCLASSNAME, "Static List", wclass); |
44 |
8023 |
setSeparators("|, "); |
45 |
|
} |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
6997 |
public StaticListClass()... |
48 |
|
{ |
49 |
6997 |
this(null); |
50 |
|
} |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
3109 |
public String getValues()... |
53 |
|
{ |
54 |
3109 |
return getStringValue("values"); |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
2231 |
public void setValues(String values)... |
58 |
|
{ |
59 |
2231 |
setStringValue("values", values); |
60 |
|
} |
61 |
|
|
|
|
| 95% |
Uncovered Elements: 1 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
62 |
414 |
@Override... |
63 |
|
public List<String> getList(XWikiContext context) |
64 |
|
{ |
65 |
414 |
String sort = getSort(); |
66 |
414 |
if (StringUtils.isEmpty(sort) || "none".equals(sort)) { |
67 |
412 |
return getListFromString(getValues()); |
68 |
|
} |
69 |
|
|
70 |
2 |
Map<String, ListItem> valuesMap = getMap(context); |
71 |
2 |
List<ListItem> values = new ArrayList<ListItem>(valuesMap.size()); |
72 |
2 |
values.addAll(valuesMap.values()); |
73 |
|
|
74 |
2 |
if ("id".equals(sort)) { |
75 |
1 |
Collections.sort(values, ListItem.ID_COMPARATOR); |
76 |
1 |
} else if ("value".equals(sort)) { |
77 |
1 |
Collections.sort(values, ListItem.VALUE_COMPARATOR); |
78 |
|
} |
79 |
|
|
80 |
2 |
List<String> result = new ArrayList<String>(values.size()); |
81 |
2 |
for (ListItem value : values) { |
82 |
8 |
result.add(value.getId()); |
83 |
|
} |
84 |
2 |
return result; |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
87 |
2693 |
@Override... |
88 |
|
public Map<String, ListItem> getMap(XWikiContext context) |
89 |
|
{ |
90 |
2693 |
String values = getValues(); |
91 |
2693 |
return getMapFromString(values); |
92 |
|
} |
93 |
|
|
|
|
| 95.3% |
Uncovered Elements: 2 (43) |
Complexity: 7 |
Complexity Density: 0.21 |
|
94 |
273 |
@Override... |
95 |
|
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) |
96 |
|
{ |
97 |
273 |
if (getDisplayType().equals(DISPLAYTYPE_INPUT)) { |
98 |
46 |
input input = new input(); |
99 |
46 |
input.setAttributeFilter(new XMLAttributeValueFilter()); |
100 |
46 |
BaseProperty prop = (BaseProperty) object.safeget(name); |
101 |
46 |
if (prop != null) { |
102 |
29 |
input.setValue(this.toFormString(prop)); |
103 |
|
} |
104 |
46 |
input.setType("text"); |
105 |
46 |
input.setSize(getSize()); |
106 |
46 |
input.setName(prefix + name); |
107 |
46 |
input.setID(prefix + name); |
108 |
46 |
input.setDisabled(isDisabled()); |
109 |
|
|
110 |
46 |
if (isPicker()) { |
111 |
1 |
input.setClass("suggested"); |
112 |
1 |
String path = ""; |
113 |
1 |
XWiki xwiki = context.getWiki(); |
114 |
1 |
path = xwiki.getURL("Main.WebHome", "view", context); |
115 |
|
|
116 |
1 |
String classname = this.getObject().getName(); |
117 |
1 |
String fieldname = this.getName(); |
118 |
1 |
String secondCol = "-", firstCol = "-"; |
119 |
|
|
120 |
1 |
String script = |
121 |
|
"\"" + path + "?xpage=suggest&classname=" + classname + "&fieldname=" + fieldname + "&firCol=" |
122 |
|
+ firstCol + "&secCol=" + secondCol + "&\""; |
123 |
1 |
String varname = "\"input\""; |
124 |
1 |
String seps = "\"" + this.getSeparators() + "\""; |
125 |
1 |
if (isMultiSelect()) { |
126 |
0 |
input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + ", seps:" |
127 |
|
+ seps + "} )"); |
128 |
|
} else { |
129 |
1 |
input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + "} )"); |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
46 |
buffer.append(input.toString()); |
134 |
|
|
135 |
227 |
} else if (getDisplayType().equals(DISPLAYTYPE_RADIO) || getDisplayType().equals(DISPLAYTYPE_CHECKBOX)) { |
136 |
2 |
displayRadioEdit(buffer, name, prefix, object, context); |
137 |
|
} else { |
138 |
225 |
displaySelectEdit(buffer, name, prefix, object, context); |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
225 |
org.apache.ecs.xhtml.input hidden = new input(input.hidden, prefix + name, ""); |
143 |
225 |
hidden.setAttributeFilter(new XMLAttributeValueFilter()); |
144 |
225 |
hidden.setDisabled(isDisabled()); |
145 |
225 |
buffer.append(hidden); |
146 |
|
} |
147 |
|
} |
148 |
|
} |