From e14abd9faea4fc7f6994ab10763f2374dd6fed1e Mon Sep 17 00:00:00 2001 From: Patrick Plitzner Date: Mon, 8 Feb 2016 18:02:20 +0100 Subject: [PATCH] Add possibility to specifiy multiple uuids as command parameters --- eu.etaxonomy.taxeditor.store/plugin.xml | 5 +++ .../handler/UuidsParameterTypeConverter.java | 33 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/eu.etaxonomy.taxeditor.store/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml index c3082aa12..4b8b2413b 100644 --- a/eu.etaxonomy.taxeditor.store/plugin.xml +++ b/eu.etaxonomy.taxeditor.store/plugin.xml @@ -775,6 +775,11 @@ id="eu.etaxonomy.taxeditor.uuidParameterType" type="java.util.UUID"> + + diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java index e23482714..dc8009b98 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/UuidsParameterTypeConverter.java @@ -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 uuids = new ArrayList(); + 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 -- 2.34.1