Skip to main content
summaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlena Laskavaia2010-05-22 22:18:18 -0400
committerAlena Laskavaia2010-05-22 22:18:18 -0400
commit644fefb8c57f264427f1d7cadcafd67d3d2b6188 (patch)
treee5bc4501c3c71042169c1459507017e62459bc76 /codan
parent6debae007dc3e15bfc64569bc6226a3f2a390d70 (diff)
downloadorg.eclipse.cdt-644fefb8c57f264427f1d7cadcafd67d3d2b6188.tar.gz
org.eclipse.cdt-644fefb8c57f264427f1d7cadcafd67d3d2b6188.tar.xz
org.eclipse.cdt-644fefb8c57f264427f1d7cadcafd67d3d2b6188.zip
Fixed preferences of type List
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/param/ListProblemPreferenceTest.java31
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java27
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java8
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/BasicProblemPreference.java16
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeDescriptor.java2
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeValue.java2
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/ListProblemPreference.java207
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java89
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java1
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ParametersComposite.java65
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties1
11 files changed, 362 insertions, 87 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/param/ListProblemPreferenceTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/param/ListProblemPreferenceTest.java
index 6109547a9f..bb2ecc504f 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/param/ListProblemPreferenceTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/param/ListProblemPreferenceTest.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.param;
+import java.util.Arrays;
+
import junit.framework.TestCase;
import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor.PreferenceType;
@@ -37,7 +39,7 @@ public class ListProblemPreferenceTest extends TestCase {
protected BasicProblemPreference addPar(String key, Object parval) {
BasicProblemPreference str = makePar(key, parval);
list.addChildDescriptor(str);
- return str;
+ return (BasicProblemPreference) list.getChildDescriptor(key);
}
/**
@@ -100,4 +102,31 @@ public class ListProblemPreferenceTest extends TestCase {
assertEquals("a=b", list.getChildValue(PAR1)); //$NON-NLS-1$
assertEquals(p2.getValue(), list.getChildValue(PAR2));
}
+
+ public void testGetValue() {
+ list.setChildDescriptor(new BasicProblemPreference("#", "Value")); //$NON-NLS-1$//$NON-NLS-2$
+ String x[] = { "a", "b" }; //$NON-NLS-1$ //$NON-NLS-2$
+ list.addChildValue(x[0]);
+ list.addChildValue(x[1]);
+ Object[] values = list.getValues();
+ assertTrue(Arrays.deepEquals(x, values));
+ }
+
+ public void testSetValue() {
+ list.setChildDescriptor(new BasicProblemPreference("#", "Value")); //$NON-NLS-1$//$NON-NLS-2$
+ String x[] = { "a", "b" }; //$NON-NLS-1$ //$NON-NLS-2$
+ list.setValue(x);
+ Object[] values = list.getValues();
+ assertTrue(Arrays.deepEquals(x, values));
+ }
+
+ public void testSetValueImport() {
+ list.setChildDescriptor(new BasicProblemPreference("#", "Value")); //$NON-NLS-1$//$NON-NLS-2$
+ String x[] = { "a", "b" }; //$NON-NLS-1$ //$NON-NLS-2$
+ list.setValue(x);
+ list.importValue("(x)"); //$NON-NLS-1$
+ Object[] values = list.getValues();
+ assertEquals(1, values.length);
+ assertEquals("x", values[0]); //$NON-NLS-1$
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java
index 87df5fbd20..da6836e0d0 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java
@@ -13,6 +13,7 @@ package org.eclipse.cdt.codan.core.model;
import org.eclipse.cdt.codan.core.param.BasicProblemPreference;
import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor.PreferenceType;
+import org.eclipse.cdt.codan.core.param.ListProblemPreference;
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
/**
@@ -53,6 +54,30 @@ public abstract class AbstractCheckerWithProblemPreferences extends
return info;
}
+ /**
+ * Add preference of type list with default string type, list is empty by
+ * default
+ *
+ * @param problem
+ * - problem
+ * @param key
+ * - preference key
+ * @param label
+ * - preference label
+ * @return preference instance of of the list, can be used to add default
+ * values or set different element type
+ *
+ */
+ public ListProblemPreference addListPreference(IProblemWorkingCopy problem,
+ String key, String label, String itemLabel) {
+ MapProblemPreference map = getTopLevelPreferenceMap(problem);
+ ListProblemPreference list = new ListProblemPreference(key, label);
+ list.setChildDescriptor(new BasicProblemPreference(
+ ListProblemPreference.COMMON_DESCRIPTOR_KEY, itemLabel,
+ PreferenceType.TYPE_STRING));
+ return (ListProblemPreference) map.addChildDescriptor(list);
+ }
+
public IProblemPreference addPreference(IProblemWorkingCopy problem,
IProblemPreference info, Object defaultValue) {
MapProblemPreference map = getTopLevelPreferenceMap(problem);
@@ -70,7 +95,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends
String key, Object defaultValue) {
MapProblemPreference map = getTopLevelPreferenceMap(problem);
if (map.getChildValue(key) == null)
- map.addChildValue(key, defaultValue);
+ map.setChildValue(key, defaultValue);
}
/**
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java
index ed75b37f3f..a6a1e7ac9d 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java
@@ -62,6 +62,8 @@ public abstract class AbstractProblemPreference implements IProblemPreference {
int n = id.length();
if (n == 0)
return false;
+ if (id.equals("#")) //$NON-NLS-1$
+ return true;
for (int i = 0; i < n; i++)
if (!Character.isJavaIdentifierPart(id.charAt(i)))
return false;
@@ -144,4 +146,10 @@ public abstract class AbstractProblemPreference implements IProblemPreference {
return getKey();
return parent.getQualifiedKey() + "." + getKey(); //$NON-NLS-1$
}
+
+ /**
+ * @param tokenizer
+ * @return
+ */
+ public abstract void importValue(StreamTokenizer tokenizer);
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/BasicProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/BasicProblemPreference.java
index a5bcd24634..f1e40f10e2 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/BasicProblemPreference.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/BasicProblemPreference.java
@@ -129,4 +129,20 @@ public class BasicProblemPreference extends AbstractProblemPreference {
String sval = tokenizer.sval;
return sval;
}
+
+ @Override
+ public String toString() {
+ return "(" + type + ")" + key + ((value == null) ? "" : "=" + value); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
+ }
+
+ @Override
+ public void importValue(StreamTokenizer tokenizer) {
+ try {
+ tokenizer.nextToken();
+ String val = tokenizer.sval;
+ importValue(val);
+ } catch (IOException e) {
+ new IllegalArgumentException(e);
+ }
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeDescriptor.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeDescriptor.java
index 9a8b65146d..e16c377e3b 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeDescriptor.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeDescriptor.java
@@ -34,7 +34,7 @@ public interface IProblemPreferenceCompositeDescriptor {
*/
IProblemPreference[] getChildDescriptors();
- void addChildDescriptor(IProblemPreference info);
+ IProblemPreference addChildDescriptor(IProblemPreference info);
void removeChildDescriptor(IProblemPreference info);
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeValue.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeValue.java
index 3c0e8c2dec..89ce7d8862 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeValue.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/IProblemPreferenceCompositeValue.java
@@ -19,7 +19,7 @@ package org.eclipse.cdt.codan.core.param;
public interface IProblemPreferenceCompositeValue {
Object getChildValue(String key);
- void addChildValue(String key, Object value);
+ void setChildValue(String key, Object value);
void removeChildValue(String key);
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/ListProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/ListProblemPreference.java
index 3f2555ad12..48d1c15414 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/ListProblemPreference.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/ListProblemPreference.java
@@ -13,6 +13,7 @@ package org.eclipse.cdt.codan.core.param;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
/**
@@ -22,8 +23,9 @@ import java.util.Iterator;
*/
public class ListProblemPreference extends AbstractProblemPreference implements
IProblemPreferenceCompositeValue, IProblemPreferenceCompositeDescriptor {
- protected ArrayList<IProblemPreference> list = new ArrayList<IProblemPreference>(
- 1);
+ public static final String COMMON_DESCRIPTOR_KEY = "#"; //$NON-NLS-1$
+ protected ArrayList<Object> list = new ArrayList<Object>();
+ protected IProblemPreference childDescriptor;
/**
* @param key
@@ -45,42 +47,100 @@ public class ListProblemPreference extends AbstractProblemPreference implements
}
/**
- * Get parameter into for element equal to key's int value.
+ * Set child descriptor (all elements have the same)
+ *
+ * @param i
+ * @param info
+ * @return
+ */
+ public IProblemPreference setChildDescriptor(IProblemPreference info) {
+ childDescriptor = info;
+ childDescriptor.setValue(null);
+ ((AbstractProblemPreference) childDescriptor)
+ .setKey(COMMON_DESCRIPTOR_KEY);
+ return info;
+ }
+
+ /**
+ * Sets common descriptor for all elements, if value if not null sets the
+ * value for its key also. Do not make assumptions of values of desc after
+ * you pass it to this function.
+ *
+ * @return read only preference matching the key
+ */
+ public IProblemPreference addChildDescriptor(IProblemPreference desc) {
+ Object value = desc.getValue();
+ String key = desc.getKey();
+ setChildDescriptor(desc);
+ setChildValue(key, value);
+ return getChildDescriptor(key);
+ }
+
+ public IProblemPreference getChildDescriptor() {
+ return childDescriptor;
+ }
+
+ public IProblemPreference getChildDescriptor(int i) {
+ Object value = list.get(i);
+ AbstractProblemPreference desc = (AbstractProblemPreference) childDescriptor
+ .clone();
+ desc.setKey(String.valueOf(i));
+ desc.setValue(value);
+ return desc;
+ }
+
+ /**
+ * Get read only problem preference for element equal to key's int value.
+ * If key is null or # return generic descriptor with null value.
*
* @throws NumberFormatException
* if key is not number
- * @throws ArrayIndexOutOfBoundsException
- * is index is out of bound
*/
public IProblemPreference getChildDescriptor(String key)
throws NumberFormatException {
- if (key == null) {
- // special case if all element are the same return first, if key is
- // null
- return (IProblemPreference) getChildDescriptor(0).clone();
+ if (key == null || key.equals(COMMON_DESCRIPTOR_KEY)) {
+ // return common descriptor
+ return getChildDescriptor();
}
Integer iv = Integer.valueOf(key);
if (iv.intValue() >= list.size()) {
- // special case if all element are the same return first clone
- IProblemPreference childInfo = (IProblemPreference) getChildDescriptor(
- 0).clone();
- return childInfo;
+ // create one
+ AbstractProblemPreference clone = (AbstractProblemPreference) childDescriptor
+ .clone();
+ clone.setKey(key);
+ return clone;
}
return getChildDescriptor(iv.intValue());
}
+ public IProblemPreference[] getChildDescriptors() {
+ IProblemPreference[] res = new IProblemPreference[list.size()];
+ for (int i = 0; i < res.length; i++) {
+ res[i] = getChildDescriptor(i);
+ }
+ return res;
+ }
+
+ public Object getChildValue(String key) {
+ IProblemPreference childInfo = getChildDescriptor(key);
+ return childInfo.getValue();
+ }
+
+ public void setChildValue(String key, Object value) {
+ int i = Integer.valueOf(key).intValue();
+ setChildValue(i, value);
+ }
+
/**
- * Set i'th element of parameter info, if all are the same i is 0
- *
* @param i
- * @param info
+ * @param value
*/
- public void setChildDescriptor(int i, IProblemPreference info) {
- if (info != null) {
+ protected void setChildValue(int i, Object value) {
+ if (value != null) {
while (i >= list.size()) {
list.add(null);
}
- list.set(i, info);
+ list.set(i, value);
} else {
while (i == list.size() - 1) {
list.remove(i);
@@ -88,35 +148,8 @@ public class ListProblemPreference extends AbstractProblemPreference implements
}
}
- /**
- * If all list elements have same info it is enough to set only first one
- * (index 0). When value is set for the other it will be replicated.
- */
- public void addChildDescriptor(IProblemPreference info) {
- Integer iv = Integer.valueOf(info.getKey());
- IProblemPreference desc = (IProblemPreference) info.clone();
- desc.setParent(this);
- setChildDescriptor(iv, desc);
- }
-
- public IProblemPreference getChildDescriptor(int i) {
- return list.get(i);
- }
-
- public IProblemPreference[] getChildDescriptors() {
- return list.toArray(new IProblemPreference[list.size()]);
- }
-
- public Object getChildValue(String key) {
- IProblemPreference childInfo = getChildDescriptor(key);
- return childInfo.getValue();
- }
-
- public void addChildValue(String key, Object value) {
- IProblemPreference pref = getChildDescriptor(key);
- pref.setValue(value);
- // because descriptor can be phantom we have to set preference forcefully
- setChildDescriptor(Integer.parseInt(key), pref);
+ public void addChildValue(Object value) {
+ list.add(value);
}
public void removeChildValue(String key) {
@@ -128,15 +161,15 @@ public class ListProblemPreference extends AbstractProblemPreference implements
@Override
public Object clone() {
ListProblemPreference list1 = (ListProblemPreference) super.clone();
- list1.list = (ArrayList<IProblemPreference>) list.clone();
+ list1.list = (ArrayList<Object>) list.clone();
return list1;
}
public String exportValue() {
StringBuffer buf = new StringBuffer("("); //$NON-NLS-1$
- for (Iterator<IProblemPreference> iterator = list.iterator(); iterator
- .hasNext();) {
- IProblemPreference d = iterator.next();
+ for (Iterator<Object> iterator = list.iterator(); iterator.hasNext();) {
+ IProblemPreference d = (IProblemPreference) childDescriptor.clone();
+ d.setValue(iterator.next());
buf.append(d.exportValue());
if (iterator.hasNext())
buf.append(","); //$NON-NLS-1$
@@ -146,34 +179,86 @@ public class ListProblemPreference extends AbstractProblemPreference implements
public void importValue(String str) {
StreamTokenizer tokenizer = getImportTokenizer(str);
+ try {
+ importValue(tokenizer);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException(str, e);
+ }
+ }
+
+ /**
+ * @param tokenizer
+ */
+ @Override
+ public void importValue(StreamTokenizer tokenizer) {
+ clear();
int token;
int index = 0;
try {
token = tokenizer.nextToken();
+ String chara = String.valueOf((char) token);
if (token != '(')
- throw new IllegalArgumentException(str);
+ throw new IllegalArgumentException(chara);
+ token = tokenizer.nextToken();
+ if (token != ')')
+ tokenizer.pushBack();
+ else
+ return;
while (true) {
- token = tokenizer.nextToken();
- String val = tokenizer.sval;
String ik = String.valueOf(index);
IProblemPreference desc = getChildDescriptor(ik);
- if (desc != null) {
- desc.importValue(val);
- addChildValue(ik, desc.getValue());
+ if (desc != null && desc instanceof AbstractProblemPreference) {
+ ((AbstractProblemPreference) desc).importValue(tokenizer);
+ setChildValue(ik, desc.getValue());
}
token = tokenizer.nextToken();
if (token == ')')
break;
if (token != ',')
- throw new IllegalArgumentException(str);
+ throw new IllegalArgumentException(chara);
index++;
}
} catch (IOException e) {
- throw new IllegalArgumentException(str);
+ throw new IllegalArgumentException(e);
}
}
public void removeChildDescriptor(IProblemPreference info) {
- list.remove(info);
+ throw new UnsupportedOperationException();
+ }
+
+ public int size() {
+ return list.size();
+ }
+
+ public void clear() {
+ list.clear();
+ }
+
+ @Override
+ public Object getValue() {
+ return getValues();
+ }
+
+ @Override
+ public void setValue(Object value) {
+ Object[] values = (Object[]) value;
+ if (Arrays.deepEquals(getValues(), values)) {
+ return;
+ }
+ list.clear();
+ for (int i = 0; i < values.length; i++) {
+ Object object = values[i];
+ list.add(object);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return childDescriptor + ":" + list.toString(); //$NON-NLS-1$
+ }
+
+ public Object[] getValues() {
+ return list.toArray(new Object[list.size()]);
}
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java
index f57632f957..26469db51a 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java
@@ -14,6 +14,7 @@ import java.io.IOException;
import java.io.StreamTokenizer;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.Map;
import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences;
@@ -73,10 +74,10 @@ public class MapProblemPreference extends AbstractProblemPreference implements
* @param i
* @param info
*/
- public void addChildDescriptor(IProblemPreference info) {
- IProblemPreference desc = (IProblemPreference) info.clone();
+ public IProblemPreference addChildDescriptor(IProblemPreference desc) {
desc.setParent(this);
- hash.put(info.getKey(), desc);
+ hash.put(desc.getKey(), desc);
+ return desc;
}
public IProblemPreference[] getChildDescriptors() {
@@ -89,7 +90,7 @@ public class MapProblemPreference extends AbstractProblemPreference implements
return childInfo.getValue();
}
- public void addChildValue(String key, Object value) {
+ public void setChildValue(String key, Object value) {
getChildDescriptor(key).setValue(value);
}
@@ -120,40 +121,96 @@ public class MapProblemPreference extends AbstractProblemPreference implements
public void importValue(String str) {
StreamTokenizer tokenizer = getImportTokenizer(str);
+ try {
+ importValue(tokenizer);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException(str + ":" + e.toString(), e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @param tokenizer
+ */
+ @Override
+ public void importValue(StreamTokenizer tokenizer) {
int token;
try {
token = tokenizer.nextToken();
- if (token != '{')
- throw new IllegalArgumentException(str);
+ String chara = String.valueOf((char) token);
+ if (token != '{') {
+ throw new IllegalArgumentException(chara);
+ }
while (true) {
token = tokenizer.nextToken();
String key = tokenizer.sval;
token = tokenizer.nextToken();
if (token != '=')
- throw new IllegalArgumentException(str);
+ throw new IllegalArgumentException(chara);
token = tokenizer.nextToken();
if (token != '>')
- throw new IllegalArgumentException(str);
- token = tokenizer.nextToken();
- String val = tokenizer.sval;
+ throw new IllegalArgumentException(chara);
IProblemPreference desc = getChildDescriptor(key);
- if (desc != null) {
- desc.importValue(val);
- } else {
- //putChildValue(key, val);
+ if (desc != null && desc instanceof AbstractProblemPreference) {
+ ((AbstractProblemPreference) desc).importValue(tokenizer);
+ setChildValue(key, desc.getValue());
}
token = tokenizer.nextToken();
if (token == '}')
break;
if (token != ',')
- throw new IllegalArgumentException(str);
+ throw new IllegalArgumentException(chara);
}
} catch (IOException e) {
- throw new IllegalArgumentException(str);
+ throw new IllegalArgumentException(e);
}
}
public void removeChildDescriptor(IProblemPreference info) {
hash.remove(info);
}
+
+ public int size() {
+ return hash.size();
+ }
+
+ public void clear() {
+ hash.clear();
+ }
+
+ @Override
+ public String toString() {
+ return hash.values().toString();
+ }
+
+ @Override
+ public Object getValue() {
+ LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
+ for (Iterator<IProblemPreference> iterator = hash.values().iterator(); iterator
+ .hasNext();) {
+ IProblemPreference pref = iterator.next();
+ map.put(pref.getKey(), pref.getValue());
+ }
+ return map;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void setValue(Object value) {
+ Map<String, Object> map = (Map<String, Object>) value;
+ LinkedHashMap<String, IProblemPreference> hash2 = (LinkedHashMap<String, IProblemPreference>) hash
+ .clone();
+ hash.clear();
+ for (Iterator<String> iterator = map.keySet().iterator(); iterator
+ .hasNext();) {
+ String key = iterator.next();
+ Object value2 = map.get(key);
+ if (value2 instanceof IProblemPreference) {
+ hash.put(key, (IProblemPreference) value2);
+ } else {
+ IProblemPreference pref = hash2.get(key);
+ pref.setValue(value2);
+ hash.put(key, pref);
+ }
+ }
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java
index f2b43fb5e5..004530e749 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CodanUIMessages.java
@@ -39,6 +39,7 @@ public class CodanUIMessages extends NLS {
public static String CustomizeProblemDialog_Message;
public static String CustomizeProblemDialog_Title;
public static String Job_TitleRunningAnalysis;
+ public static String ParametersComposite_NewValue;
public static String ParametersComposite_None;
static {
// initialize resource bundle
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ParametersComposite.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ParametersComposite.java
index 68ef2c5845..25100c8d3e 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ParametersComposite.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/dialogs/ParametersComposite.java
@@ -16,11 +16,15 @@ import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.codan.core.param.IProblemPreference;
import org.eclipse.cdt.codan.core.param.IProblemPreferenceCompositeDescriptor;
+import org.eclipse.cdt.codan.core.param.ListProblemPreference;
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
+import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.ListEditor;
import org.eclipse.jface.preference.PreferenceStore;
import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -59,7 +63,8 @@ public class ParametersComposite extends Composite {
/**
* @param info
*/
- private void createFieldEditorsForParameters(IProblemPreference info) {
+ private void createFieldEditorsForParameters(
+ final IProblemPreference info) {
if (info == null)
return;
switch (info.getType()) {
@@ -77,7 +82,53 @@ public class ParametersComposite extends Composite {
addField(fe);
break;
}
- case TYPE_MAP: {
+ case TYPE_LIST:
+ ListEditor le = new ListEditor(info.getQualifiedKey(),
+ info.getLabel(), getFieldEditorParent()) {
+ @Override
+ protected String[] parseString(String stringList) {
+ ListProblemPreference list = (ListProblemPreference) info;
+ IProblemPreference[] childDescriptors = list
+ .getChildDescriptors();
+ if (childDescriptors.length == 0)
+ return new String[0];
+ String res[] = new String[childDescriptors.length];
+ for (int i = 0; i < childDescriptors.length; i++) {
+ IProblemPreference item = childDescriptors[i];
+ res[i] = String.valueOf(item.getValue());
+ }
+ return res;
+ }
+
+ @Override
+ protected String getNewInputObject() {
+ ListProblemPreference list = (ListProblemPreference) info;
+ String label = list
+ .getChildDescriptor()
+ .getLabel();
+ InputDialog dialog = new InputDialog(
+ getShell(), CodanUIMessages.ParametersComposite_NewValue, label, "", null); //$NON-NLS-1$
+ if (dialog.open() == Window.OK) {
+ return dialog.getValue();
+ }
+ return null;
+ }
+
+ @Override
+ protected String createList(String[] items) {
+ ListProblemPreference list = (ListProblemPreference) info
+ .clone();
+ list.clear();
+ for (int i = 0; i < items.length; i++) {
+ String val = items[i];
+ list.addChildValue(val);
+ }
+ return list.exportValue();
+ }
+ };
+ addField(le);
+ break;
+ case TYPE_MAP:
IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) info)
.getChildDescriptors();
for (int i = 0; i < childrenDescriptor.length; i++) {
@@ -85,7 +136,6 @@ public class ParametersComposite extends Composite {
createFieldEditorsForParameters(desc);
}
break;
- }
default:
throw new UnsupportedOperationException(info.getType()
.toString());
@@ -126,8 +176,10 @@ public class ParametersComposite extends Composite {
case TYPE_FILE:
desc.setValue(new File(prefStore.getString(key)));
break;
- case TYPE_MAP:
case TYPE_LIST:
+ desc.importValue(prefStore.getString(key));
+ break;
+ case TYPE_MAP:
IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) desc)
.getChildDescriptors();
for (int i = 0; i < childrenDescriptor.length; i++) {
@@ -158,8 +210,10 @@ public class ParametersComposite extends Composite {
case TYPE_FILE:
prefStore.setValue(key, ((File) desc.getValue()).getPath());
break;
+ case TYPE_LIST:
+ prefStore.setValue(key, desc.exportValue());
+ break;
case TYPE_MAP:
- case TYPE_LIST: {
IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) desc)
.getChildDescriptors();
for (int i = 0; i < childrenDescriptor.length; i++) {
@@ -167,7 +221,6 @@ public class ParametersComposite extends Composite {
initPrefStore(chi);
}
break;
- }
default:
throw new UnsupportedOperationException(desc.getType()
.toString());
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties
index a624325729..ddcfdfbfa7 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/messages.properties
@@ -13,6 +13,7 @@ CustomizeProblemComposite_TabScope=Scope
CustomizeProblemDialog_Message=Edit problem preferences, scope and launch options
CustomizeProblemDialog_Title=Customize Problem...
Job_TitleRunningAnalysis=Running Code Analysis
+ParametersComposite_NewValue=New Value
ParametersComposite_None=No extra preferences
ProblemsTreeEditor_NameColumn=Name
ProblemsTreeEditor_Problems=Problems

Back to the top