1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.objects.classes

File StaticListClass.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

16
54
7
1
148
107
17
0.31
7.71
7
2.43

Classes

Class Line # Actions
StaticListClass 37 54 0% 17 3
0.9610389596.1%
 

Contributing tests

This file is covered by 39 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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   
 
37    public class StaticListClass extends ListClass
38    {
39    private static final String XCLASSNAME = "staticlist";
40   
 
41  8023 toggle public StaticListClass(PropertyMetaClass wclass)
42    {
43  8023 super(XCLASSNAME, "Static List", wclass);
44  8023 setSeparators("|, ");
45    }
46   
 
47  6997 toggle public StaticListClass()
48    {
49  6997 this(null);
50    }
51   
 
52  3109 toggle public String getValues()
53    {
54  3109 return getStringValue("values");
55    }
56   
 
57  2231 toggle public void setValues(String values)
58    {
59  2231 setStringValue("values", values);
60    }
61   
 
62  414 toggle @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   
 
87  2693 toggle @Override
88    public Map<String, ListItem> getMap(XWikiContext context)
89    {
90  2693 String values = getValues();
91  2693 return getMapFromString(values);
92    }
93   
 
94  273 toggle @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    // We need a hidden input with an empty value to be able to clear the selected values from the above select
141    // when it has multiple selection enabled and no value selected.
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    }