Add possibility to specifiy multiple uuids as command parameters
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 8 Feb 2016 17:02:20 +0000 (18:02 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 16 Feb 2016 14:14:49 +0000 (15:14 +0100)
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java

index c3082aa12c74b25edceb91b220b08972c717a84a..4b8b2413b5fe2fe1c7357fa102e772ee776b3752 100644 (file)
             id="eu.etaxonomy.taxeditor.uuidParameterType"
             type="java.util.UUID">
       </commandParameterType>
+      <commandParameterType
+            converter="eu.etaxonomy.taxeditor.handler.UuidsParameterTypeConverter"
+            id="eu.etaxonomy.taxeditor.uuidsParameterType"
+            type="java.util.List">
+      </commandParameterType>
    </extension>
    <extension
          point="org.eclipse.ui.importWizards">
index e23482714f7a82b235ab79c573545ffed87b34ea..dc8009b983d377a24459349cfac782e140bd7fa2 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