ref #8568: performance issues for term and voc preference pages
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / handler / UuidsParameterTypeConverter.java
index e23482714f7a82b235ab79c573545ffed87b34ea..ca37917a742e4a5059c5e880453be5eaa81b7828 100644 (file)
@@ -1,12 +1,14 @@
 package eu.etaxonomy.taxeditor.handler;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 
 import org.eclipse.core.commands.AbstractParameterValueConverter;
 import org.eclipse.core.commands.ParameterValueConversionException;
 
 /**
- * Converts {@link UUID}s to a string representation
+ * Converts either a single {@link UUID} or a list of UUIDSs to a string representation
  * and vica versa.
  *
  * @author pplitzner
@@ -15,17 +17,42 @@ import org.eclipse.core.commands.ParameterValueConversionException;
  */
 public class UuidsParameterTypeConverter extends AbstractParameterValueConverter {
 
+    private static final String SEPARATOR = ",";
+
     public UuidsParameterTypeConverter() {
     }
 
     @Override
     public Object convertToObject(String parameterValue) throws ParameterValueConversionException {
-        return UUID.fromString(parameterValue);
+        if(parameterValue.endsWith(SEPARATOR)){
+            List<UUID> uuids = new ArrayList<UUID>();
+            String[] split = parameterValue.split(SEPARATOR);
+            for (String string : split) {
+                uuids.add(UUID.fromString(string));
+            }
+            return uuids;
+        }
+        else{
+            return UUID.fromString(parameterValue);
+        }
     }
 
     @Override
     public String convertToString(Object parameterValue) throws ParameterValueConversionException {
-        return parameterValue.toString();
+        if(parameterValue instanceof List){
+            List list = (List)parameterValue;
+            String stringList = "";
+            for (Object object : list) {
+                stringList += parameterValue.toString()+SEPARATOR;
+            }
+        }
+        else if(parameterValue instanceof UUID){
+            return parameterValue.toString();
+        }
+        else{
+            throw new ParameterValueConversionException("Parameter is of wrong type: "+parameterValue.getClass().toString());
+        }
+        return null;
     }
 
-}
\ No newline at end of file
+}