Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFContants.java39
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFStringValueConverter.java372
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/AbstractStringValueConverter.java71
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/ConvertedValueContainer.java75
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/IStringValueConverter.java36
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/MultiConvertedValueContainer.java39
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/StringValueConverterStatus.java60
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java40
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties6
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypesConstants.java38
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/ElementTypeUtils.java67
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF4
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/EnumerationUtil.java43
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PrimitivesTypesUtils.java6
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLStringValueConverter.java280
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/messages/Messages.java17
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/messages/messages.properties1
18 files changed, 1195 insertions, 2 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFContants.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFContants.java
new file mode 100644
index 00000000000..68545151410
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFContants.java
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.utils;
+
+/**
+ * Thyis class defines some useful constants for EMF
+ *
+ * @author vl222926
+ *
+ */
+public class EMFContants {
+
+
+ private EMFContants() {
+ //to prevent instanciation
+ }
+
+ public static final String ESTRING = "EString";
+
+ public static final String EBOOLEAN = "EBoolean";
+
+ public static final String EINT = "EInt";
+
+ public static final String EDOUBLE = "EDouble";
+
+ public static final String EENUM_LITERAL = "EENumLiteral";
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFStringValueConverter.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFStringValueConverter.java
new file mode 100644
index 00000000000..5f659d15f18
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFStringValueConverter.java
@@ -0,0 +1,372 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.infra.emf.Activator;
+import org.eclipse.papyrus.infra.tools.converter.AbstractStringValueConverter;
+import org.eclipse.papyrus.infra.tools.converter.ConvertedValueContainer;
+import org.eclipse.papyrus.infra.tools.converter.MultiConvertedValueContainer;
+import org.eclipse.papyrus.infra.tools.converter.StringValueConverterStatus;
+import org.eclipse.papyrus.infra.tools.util.BooleanHelper;
+import org.eclipse.papyrus.infra.tools.util.TypesConstants;
+
+/**
+ * Value solver for EMF
+ *
+ * WARNING : incomplete implementations
+ *
+ * @author vl222926
+ *
+ */
+
+public class EMFStringValueConverter extends AbstractStringValueConverter {
+
+
+
+ /**
+ * Context used for the resolution of the string
+ */
+ private EObject resolutionContext;
+
+ /**
+ * The separator used for multivalue
+ */
+ protected final String multiValueSeparator;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param resolutionContext
+ * the context used for the resolution of the string
+ */
+ public EMFStringValueConverter(final EObject resolutionContext, final String multiValueSeparator) {
+ this.resolutionContext = resolutionContext;
+ this.multiValueSeparator = multiValueSeparator;
+ }
+
+
+ /**
+ *
+ * @return
+ * the context to use for the resolution
+ */
+ public EObject getResolutionContext() {
+ return resolutionContext;
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.services.IDisposable#dispose()
+ *
+ */
+ public void dispose() {
+ this.resolutionContext = null;
+ }
+
+ /**
+ *
+ * @param resolutionContext
+ * the table context
+ * @param feature
+ * the feature
+ * @param valueAsString
+ * the pasted string for this feature
+ * @return
+ * the value for the pasted string or <code>null</code> if not found
+ */
+ @Override
+ protected ConvertedValueContainer<?> doDeduceValueFromString(final Object feature, final String valueAsString) {
+ final EClassifier featureType = getFeatureType(feature);
+ if(feature instanceof EStructuralFeature) {
+ return deduceValueFromString(feature, featureType, valueAsString);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param feature
+ * @param featureType
+ * @param valueAsString
+ * @return
+ */
+ protected ConvertedValueContainer<?> deduceValueFromString(final Object feature, final EClassifier featureType, final String valueAsString) {
+ ConvertedValueContainer<?> realValue = null;
+ // if(feature instanceof EStructuralFeature) {
+ final int upperbound = getFeatureUpperBound(feature);
+ boolean isMany = (upperbound > 1 || upperbound == -1);
+ if(featureType instanceof EDataType) {
+ if(featureType instanceof EEnum) {
+ realValue = deduceEEnumLiteralValue((EEnum)featureType, isMany, valueAsString);
+ }
+ final String typeName = featureType.getName();
+ if(TypesConstants.STRING.equals(typeName) || EMFContants.ESTRING.equals(typeName)) {
+ realValue = deduceStringValue(isMany, valueAsString);
+ } else if(EMFContants.EBOOLEAN.equals(typeName) || TypesConstants.BOOLEAN.equals(typeName)) {
+ realValue = deduceBooleanValue(isMany, valueAsString);
+ } else if(EMFContants.EINT.equals(typeName) || TypesConstants.INTEGER.equals(typeName)) {
+ realValue = deduceIntValue(isMany, valueAsString);
+ } else if(EMFContants.EDOUBLE.equals(typeName)) {
+ realValue = deduceDoubleValue(isMany, valueAsString);
+ }
+ } else if(featureType instanceof EClass) {
+ realValue = deduceEObjectValue((EObject)getResolutionContext(), feature, (EClass)featureType, isMany, valueAsString);
+ }
+ return realValue;
+ }
+
+ protected int getFeatureUpperBound(final Object feature) {
+ return ((EStructuralFeature)feature).getUpperBound();
+ }
+
+
+
+ /**
+ *
+ * @param resolutionContext
+ * the context used for the resolution
+ * @param feature
+ * the feature
+ * @param featureType
+ * the type of the feature
+ * @param isMany
+ * <code>true</code> if the feature isMany
+ * @param valueAsString
+ * the string value to resolve
+ * @return
+ * a value container referencing the eobject represented by the string
+ * @throws StringValueSolverException
+ */
+ protected ConvertedValueContainer<?> deduceEObjectValue(EObject resolutionContext, Object feature, EClass featureType, boolean isMany, String valueAsString) {
+ if(valueAsString == null || valueAsString.equals("")) {
+ return new ConvertedValueContainer<EObject>(null, Status.OK_STATUS);
+ }
+ final IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_STRING_VALUE_X_CANT_BE_RESOLVED, valueAsString));
+ return new ConvertedValueContainer<EObject>(null, status);
+ }
+
+ /**
+ *
+ * @param feature
+ * an object representing a feature
+ * @return
+ * the type of the feature
+ */
+ protected EClassifier getFeatureType(final Object feature) {
+ final EClassifier featureType;
+ if(feature instanceof EStructuralFeature) {
+ return ((EStructuralFeature)feature).getEType();
+ } else {
+ featureType = null;
+ }
+ return featureType;
+ }
+
+ /**
+ *
+ * @param eenum
+ * the enumeration
+ * @param isMany
+ * <code>true</code> if the feature is many
+ * @param valueAsString
+ * the value to convert
+ * @return
+ * the converted value
+ */
+ protected ConvertedValueContainer<?> deduceEEnumLiteralValue(final EEnum eenum, final boolean isMany, final String valueAsString) {
+ ConvertedValueContainer<?> returnedValue = null;
+ IStatus iStatus = Status.OK_STATUS;
+ final Collection<String> unresolvedValues = new ArrayList<String>();
+ if(isMany) {
+ final Collection<EEnumLiteral> values = new ArrayList<EEnumLiteral>();
+ for(final String str : valueAsString.split(this.multiValueSeparator)) {
+ final EEnumLiteral literal = eenum.getEEnumLiteral(str);
+ if(literal != null) {
+ values.add(literal);
+ } else {
+ unresolvedValues.add(str);
+ }
+ }
+ if(!unresolvedValues.isEmpty()) {
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, EMFContants.EENUM_LITERAL), unresolvedValues);
+ }
+ returnedValue = new MultiConvertedValueContainer<EEnumLiteral>(values, iStatus);
+ } else {
+ final EEnumLiteral literal = eenum.getEEnumLiteral(valueAsString);
+ if(literal != null) {
+ returnedValue = new ConvertedValueContainer<EEnumLiteral>(literal, iStatus);
+ } else {
+ unresolvedValues.add(valueAsString);
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_STRING_X_IS_NOT_VALID_TO_CREATE_Y, valueAsString, EMFContants.EENUM_LITERAL), unresolvedValues);
+ returnedValue = new ConvertedValueContainer<Boolean>(null, iStatus);
+ }
+ }
+ return returnedValue;
+ }
+
+ /**
+ *
+ * @param isMany
+ * <code>true</code> if the feature isMany
+ * @param valueAsString
+ * the value to parse
+ * @return
+ * the result of the parsing
+ */
+ protected ConvertedValueContainer<?> deduceBooleanValue(final boolean isMany, final String valueAsString) {
+ ConvertedValueContainer<?> returnedValue = null;
+ IStatus iStatus = Status.OK_STATUS;
+ final Collection<String> unresolvedValues = new ArrayList<String>();
+ if(isMany) {
+ final Collection<Boolean> values = new ArrayList<Boolean>();
+ for(final String str : valueAsString.split(this.multiValueSeparator)) {
+ if(BooleanHelper.isBoolean(str)) {
+ values.add(Boolean.valueOf(valueAsString));
+ } else {
+ unresolvedValues.add(str);
+ }
+ }
+ if(!unresolvedValues.isEmpty()) {
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, TypesConstants.BOOLEAN), unresolvedValues);
+ }
+ returnedValue = new MultiConvertedValueContainer<Boolean>(values, iStatus);
+ } else {
+ if(BooleanHelper.isBoolean(valueAsString)) {
+ returnedValue = new ConvertedValueContainer<Boolean>(Boolean.valueOf(valueAsString), iStatus);
+ } else {
+ unresolvedValues.add(valueAsString);
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_STRING_X_IS_NOT_VALID_TO_CREATE_Y, valueAsString, TypesConstants.BOOLEAN), unresolvedValues);
+ returnedValue = new ConvertedValueContainer<Boolean>(null, iStatus);
+ }
+ }
+ return returnedValue;
+ }
+
+ /**
+ *
+ * @param isMany
+ * <code>true</code> if the feature isMany
+ * @param valueAsString
+ * the value to parse
+ * @return
+ * the result of the parsing
+ */
+ protected ConvertedValueContainer<?> deduceDoubleValue(final boolean isMany, final String valueAsString) {
+ ConvertedValueContainer<?> returnedValue = null;
+ IStatus iStatus = Status.OK_STATUS;
+ final Collection<String> unresolvedValues = new ArrayList<String>();
+ if(isMany) {
+ final Collection<Double> values = new ArrayList<Double>();
+ for(final String str : valueAsString.split(this.multiValueSeparator)) {
+ final Double value = Double.valueOf(str);
+ if(value != null) {
+ values.add(value);
+ } else {
+ unresolvedValues.add(str);
+ }
+ }
+ if(!unresolvedValues.isEmpty()) {
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, TypesConstants.DOUBLE), unresolvedValues);
+ }
+ returnedValue = new MultiConvertedValueContainer<Double>(values, iStatus);
+ } else {
+ try {
+ returnedValue = new ConvertedValueContainer<Double>(Double.valueOf(valueAsString), iStatus);
+ } catch (final NumberFormatException e) {
+ unresolvedValues.add(valueAsString);
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_STRING_X_IS_NOT_VALID_TO_CREATE_Y, valueAsString, TypesConstants.DOUBLE), unresolvedValues);
+ returnedValue = new ConvertedValueContainer<Boolean>(null, iStatus);
+ }
+ }
+ return returnedValue;
+ }
+
+ /**
+ *
+ * @param isMany
+ * <code>true</code> if the feature isMany
+ * @param valueAsString
+ * the value to parse
+ * @return
+ * the result of the parsing
+ */
+ protected ConvertedValueContainer<?> deduceIntValue(final boolean isMany, final String valueAsString) {
+ ConvertedValueContainer<?> returnedValue = null;
+ IStatus iStatus = Status.OK_STATUS;
+ final Collection<String> unresolvedValues = new ArrayList<String>();
+ if(isMany) {
+ final Collection<Integer> values = new ArrayList<Integer>();
+ for(final String str : valueAsString.split(this.multiValueSeparator)) {
+ try {
+ values.add(Integer.valueOf(str));
+ } catch (final NumberFormatException e) {
+ unresolvedValues.add(str);
+ }
+ }
+ if(!unresolvedValues.isEmpty()) {
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, TypesConstants.INTEGER), unresolvedValues);
+ }
+ returnedValue = new MultiConvertedValueContainer<Integer>(values, iStatus);
+ } else {
+ try {
+ returnedValue = new ConvertedValueContainer<Integer>(Integer.valueOf(valueAsString), iStatus);
+ } catch (final NumberFormatException e) {
+ unresolvedValues.add(valueAsString);
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_STRING_X_IS_NOT_VALID_TO_CREATE_Y, valueAsString, TypesConstants.INTEGER), unresolvedValues);
+ returnedValue = new ConvertedValueContainer<Boolean>(null, iStatus);
+ }
+ }
+ return returnedValue;
+ }
+
+
+ /**
+ *
+ * @param isMany
+ * <code>true</code> if the feature is many
+ * @param valueAsString
+ * the value as string
+ * @return
+ * the value container with the real value(s)
+ */
+ protected ConvertedValueContainer<?> deduceStringValue(final boolean isMany, final String valueAsString) {
+ ConvertedValueContainer<?> returnedValue = null;
+ final IStatus iStatus = Status.OK_STATUS;
+ if(isMany) {
+ final Collection<String> values = new ArrayList<String>();
+ for(final String str : valueAsString.split(this.multiValueSeparator)) {
+ values.add(str);
+ }
+ returnedValue = new MultiConvertedValueContainer<String>(values, iStatus);
+ } else {
+ returnedValue = new ConvertedValueContainer<String>(valueAsString, iStatus);
+ }
+ return returnedValue;
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF b/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
index 3dd0468f2b1..38755781eeb 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
@@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.ecore.xmi;bundle-version="2.9.0",
org.eclipse.emf.edit;bundle-version="2.9.0",
org.eclipse.core.expressions;bundle-version="3.4.500"
-Export-Package: org.eclipse.papyrus.infra.tools.databinding,
+Export-Package: org.eclipse.papyrus.infra.tools.converter,
+ org.eclipse.papyrus.infra.tools.databinding,
org.eclipse.papyrus.infra.tools.util
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/AbstractStringValueConverter.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/AbstractStringValueConverter.java
new file mode 100644
index 00000000000..3d3289e4da0
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/AbstractStringValueConverter.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.converter;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.infra.tools.Activator;
+import org.eclipse.papyrus.infra.tools.messages.Messages;
+
+/**
+ * Abstract class for Stringvakue Container
+ *
+ * @author VL222926
+ *
+ */
+public abstract class AbstractStringValueConverter implements IStringValueConverter {
+
+ protected static final String THE_STRING_X_IS_NOT_VALID_TO_CREATE_Y = Messages.AbstractStringValueConverter_TheStringXIsNotValidToCreateY;
+
+ protected static final String THE_FEATURE_X_CANT_BE_RESOLVED = Messages.AbstractStringValueConverter_TheFeatureXCantBeResolved;
+
+ protected static final String THE_STRING_VALUE_X_CANT_BE_RESOLVED = Messages.AbstractStringValueConverter_TheStringValueXCantBeResolved;
+
+ protected static final String SOME_STRING_ARE_NOT_VALID_TO_CREATE_X = Messages.AbstractStringValueConverter_SomeStringsAreNotValidToCreateY;
+
+ protected static final String SOME_STRING_CANT_BE_RESOLVED_TO_FIND_X = Messages.AbstractStringValueConverter_SomeStringsCantBeResolvedToFindY;
+
+ protected static final String NO_X_REPRESENTED_BY_Y_HAVE_BEEN_FOUND = Messages.AbstractStringValueConverter_NoXReprensentedByYHaveBeenFound;
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.tools.converter.IStringValueConverter#deduceValueFromString(java.lang.Object, java.lang.String)
+ *
+ * @param type
+ * @param valueAsString
+ * @return
+ */
+ public final ConvertedValueContainer<?> deduceValueFromString(final Object type, final String valueAsString) {
+ ConvertedValueContainer<?> result = doDeduceValueFromString(type, valueAsString);
+ if(result == null) {
+ final IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_STRING_VALUE_X_CANT_BE_RESOLVED, valueAsString));
+ result = new ConvertedValueContainer<Object>(null, status);
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param type
+ * the type of the object
+ * @param valueAsString
+ * the string to resolve
+ * @return
+ * a {@link ConvertedValueContainer} with the resolved values and a status
+ */
+ protected abstract ConvertedValueContainer<?> doDeduceValueFromString(final Object type, final String valueAsString);
+
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/ConvertedValueContainer.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/ConvertedValueContainer.java
new file mode 100644
index 00000000000..c9deeeb3d65
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/ConvertedValueContainer.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.converter;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+
+
+/**
+ *
+ * This class allows to store the value created for a pasted String AND a result status associated to this pasted String
+ *
+ * @param <T>
+ */
+
+public class ConvertedValueContainer<T> {
+
+ /**
+ * this field is used when the pasted value is monovalued
+ */
+ private final T value;
+
+ /**
+ * the resulting status of the parsing
+ */
+ private final IStatus status;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param realValue
+ * a monovalued Value (can be <code>null</code>)
+ * @param realListValue
+ * a collection value (can be <code>null</code>)
+ * @param status
+ * a status (can be <code>null</code>)
+ */
+ public ConvertedValueContainer(final T realValue, final IStatus status) {
+ this.value = realValue;
+ this.status = status;
+ Assert.isNotNull(status);
+ }
+
+
+ /**
+ *
+ * @return
+ * the status of the conversion
+ */
+ public final IStatus getStatus() {
+ return this.status;
+ }
+
+ /**
+ *
+ * @return
+ * the value
+ */
+ public final T getConvertedValue() {
+ return this.value;
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/IStringValueConverter.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/IStringValueConverter.java
new file mode 100644
index 00000000000..99d5de8dc79
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/IStringValueConverter.java
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.converter;
+
+import org.eclipse.ui.services.IDisposable;
+
+/**
+ * Common interface for string converter
+ *
+ * @author VL222926
+ *
+ */
+public interface IStringValueConverter extends IDisposable {
+
+ /**
+ *
+ * @param type
+ * an object representing the type of the in which we want to convert the string
+ * @param valueAsString
+ * the value represented by a string
+ * @return
+ * a {@link ConvertedValueContainer}
+ */
+ public ConvertedValueContainer<?> deduceValueFromString(final Object type, final String valueAsString);
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/MultiConvertedValueContainer.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/MultiConvertedValueContainer.java
new file mode 100644
index 00000000000..6ec11b8c0a0
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/MultiConvertedValueContainer.java
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.converter;
+
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ *
+ * This class allows to store the value created for a pasted String AND a result status associated to this pasted String
+ *
+ * @param <T>
+ */
+public class MultiConvertedValueContainer<T> extends ConvertedValueContainer<Collection<T>> {
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param realValue
+ * @param status
+ */
+ public MultiConvertedValueContainer(final Collection<T> realValue, final IStatus status) {
+ super(realValue, status);
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/StringValueConverterStatus.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/StringValueConverterStatus.java
new file mode 100644
index 00000000000..1d8aea35871
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/converter/StringValueConverterStatus.java
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.converter;
+
+import java.util.Collection;
+
+import org.eclipse.core.runtime.Status;
+
+/**
+ * This status is used y the String Value solvers
+ *
+ * @author vl222926
+ *
+ */
+public class StringValueConverterStatus extends Status {
+
+ /**
+ * the list of the uresolved strings
+ */
+ private Collection<String> unresolvedString;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param severity
+ * the severity of the status
+ * @param pluginId
+ * the plugin id providing this status
+ * @param message
+ * the message for this status
+ * @param unresolvedString
+ * the list of the unresolved string
+ */
+ public StringValueConverterStatus(int severity, String pluginId, String message, Collection<String> unresolvedString) {
+ super(severity, pluginId, message);
+ this.unresolvedString = unresolvedString;
+ }
+
+
+ /**
+ *
+ * @return
+ * the list of the unresolved string
+ */
+ public final Collection<String> getUnresolvedString() {
+ return unresolvedString;
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java
new file mode 100644
index 00000000000..77a155d1a10
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/Messages.java
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.tools.messages.messages"; //$NON-NLS-1$
+
+ public static String AbstractStringValueConverter_NoXReprensentedByYHaveBeenFound;
+
+ public static String AbstractStringValueConverter_SomeStringsAreNotValidToCreateY;
+
+ public static String AbstractStringValueConverter_SomeStringsCantBeResolvedToFindY;
+
+ public static String AbstractStringValueConverter_TheFeatureXCantBeResolved;
+
+ public static String AbstractStringValueConverter_TheStringValueXCantBeResolved;
+
+ public static String AbstractStringValueConverter_TheStringXIsNotValidToCreateY;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties
new file mode 100644
index 00000000000..dea12a89919
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/messages/messages.properties
@@ -0,0 +1,6 @@
+AbstractStringValueConverter_NoXReprensentedByYHaveBeenFound=No {0} represented by {1} have been found
+AbstractStringValueConverter_SomeStringsAreNotValidToCreateY=Some Strings are not valid to create {0}
+AbstractStringValueConverter_SomeStringsCantBeResolvedToFindY=Some Strings can't be resolved to find {0}
+AbstractStringValueConverter_TheFeatureXCantBeResolved=The feature {0} can't be resolved
+AbstractStringValueConverter_TheStringValueXCantBeResolved=The string value {0} can't be resolved
+AbstractStringValueConverter_TheStringXIsNotValidToCreateY=The String {0} is not valid to create {1}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypesConstants.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypesConstants.java
new file mode 100644
index 00000000000..2f1ae2bd883
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/TypesConstants.java
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.util;
+
+/**
+ *
+ * This class provides some constants used to identify java types
+ *
+ * @author vl222926
+ *
+ */
+public class TypesConstants {
+
+
+ private TypesConstants() {
+ //to prevent instanciation
+ }
+
+ public static final String STRING = "String"; //$NON-NLS-1$
+
+ public static final String BOOLEAN = "Boolean"; //$NON-NLS-1$
+
+ public static final String INTEGER = "Integer"; //$NON-NLS-1$
+
+ public static final String DOUBLE = "Double"; //$NON-NLS-1$
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/ElementTypeUtils.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/ElementTypeUtils.java
new file mode 100644
index 00000000000..d0373640aa3
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/ElementTypeUtils.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.edit.utils;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.TreeSet;
+
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.edit.Activator;
+import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
+
+/**
+ * Utils class for elements types
+ *
+ * @author VL222926
+ *
+ */
+public class ElementTypeUtils {
+
+
+ private ElementTypeUtils() {
+ //to prevent instanciation
+ }
+
+ /**
+ *
+ * @return
+ * all existing elements types
+ */
+ public static final Collection<IElementType> getAllExistingElementTypes() {
+ IClientContext clientContext = null;
+ try {
+ clientContext = TypeContext.getContext();
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ final IElementType[] types = ElementTypeRegistry.getInstance().getElementTypes(clientContext);
+ return Arrays.asList(types);
+ }
+
+ /**
+ * @return
+ * all existing element type id, sorted by alphabetical order
+ */
+ public static final Collection<String> getAllExistingElementTypesIds() {
+ final Collection<String> ids = new TreeSet<String>();
+ for(final IElementType iElementType : getAllExistingElementTypes()) {
+ ids.add(iElementType.getId());
+ }
+ return ids;
+ }
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF
index cbdcf860c52..f1407440063 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF
@@ -7,7 +7,9 @@ Require-Bundle: org.eclipse.uml2.uml,
org.eclipse.gmf.runtime.notation;bundle-version="1.5.0",
org.eclipse.papyrus.infra.core;bundle-version="0.10.1",
org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.1"
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.1",
+ org.eclipse.ui.workbench;bundle-version="3.105.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="0.10.1"
Export-Package: org.eclipse.papyrus.uml.tools.utils
Bundle-Vendor: %pluginProvider
Bundle-ActivationPolicy: lazy
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/EnumerationUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/EnumerationUtil.java
index 525201c85ce..6a7e31f10c2 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/EnumerationUtil.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/EnumerationUtil.java
@@ -18,6 +18,8 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.osgi.util.NLS;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
@@ -72,4 +74,45 @@ public class EnumerationUtil {
assert returnedValue.size() == toAdapt.size();
return returnedValue;
}
+
+ /**
+ *
+ * @param eenum
+ * an eemf enumeration
+ * @param toConvert
+ * a list of enumeration literal to convert
+ * @return
+ * the list of the converted element (/!\ in case of fail, the returned list contains less elements than the initial list)
+ */
+ public static final List<Enumerator> adaptToEnumeratorList(final EEnum eenum, final Collection<?> toConvert) {
+ final List<Enumerator> convertedvalues = new ArrayList<Enumerator>();
+ for(final Object object : toConvert) {
+ if(object instanceof EnumerationLiteral) {
+ final EEnumLiteral literal = eenum.getEEnumLiteral(((EnumerationLiteral)object).getName());
+ if(literal != null) {
+ convertedvalues.add(literal.getInstance());
+ }
+ }
+ }
+ return convertedvalues;
+
+ }
+
+ /**
+ *
+ * @param eenum
+ * an emf enumeration
+ * @param umlLiteral
+ * a uml literal
+ * @return
+ * the enumerator to use for this enumeration literal (/!\ can be null in case of fail)
+ */
+ public static final Enumerator adaptToEnumerator(final EEnum eenum, final EnumerationLiteral umlLiteral) {
+ final EEnumLiteral literal = eenum.getEEnumLiteral(umlLiteral.getName());
+ if(literal != null) {
+ return literal.getInstance();
+ }
+ return null;
+ }
+
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PrimitivesTypesUtils.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PrimitivesTypesUtils.java
index e870f8353d2..8d5270fe756 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PrimitivesTypesUtils.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PrimitivesTypesUtils.java
@@ -35,5 +35,11 @@ public class PrimitivesTypesUtils {
/** the string used for uml unlimited natural */
public static final String UML_UNLIMITED_NATURAL = "UnlimitedNatural"; //$NON-NLS-1$
+ /** the string used for enumeration */
+ public static final String ENUMERATION = "Enumeration"; //$NON-NLS-1$
+
+ /** the string used for enumeration literal */
+ public static final String ENUMERATION_LITERAL = "EnumerationLiteral"; //$NON-NLS-1$
+
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLStringValueConverter.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLStringValueConverter.java
new file mode 100644
index 00000000000..509a68f8b71
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLStringValueConverter.java
@@ -0,0 +1,280 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.infra.emf.Activator;
+import org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter;
+import org.eclipse.papyrus.infra.tools.converter.ConvertedValueContainer;
+import org.eclipse.papyrus.infra.tools.converter.MultiConvertedValueContainer;
+import org.eclipse.papyrus.infra.tools.converter.StringValueConverterStatus;
+import org.eclipse.papyrus.uml.tools.utils.messages.Messages;
+import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Enumeration;
+import org.eclipse.uml2.uml.EnumerationLiteral;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Namespace;
+import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ * ULM String converter
+ *
+ * @author vl222926
+ *
+ */
+public class UMLStringValueConverter extends EMFStringValueConverter {
+
+ final protected Map<EClass, NameResolutionHelper> nameResolutionHelpers = new HashMap<EClass, NameResolutionHelper>();
+
+ public static final String THE_ENUMERATION_LITERAL_X_CANT_BE_FOUND = Messages.UMLStringValueConverter_TheEnumerationLiteralXCantBeFound;
+
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param context
+ * the context used to resolve the value
+ * @param multiValueSeparator
+ * the string used to seprate values
+ */
+ public UMLStringValueConverter(final EObject context, final String multiValueSeparator) {
+ super(context, multiValueSeparator);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ nameResolutionHelpers.clear();
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#getFeatureUpperBound(java.lang.Object)
+ *
+ * @param feature
+ * @return
+ */
+ @Override
+ protected int getFeatureUpperBound(Object feature) {
+ if(feature instanceof Property) {
+ return ((Property)feature).getUpper();
+ }
+ return super.getFeatureUpperBound(feature);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#getFeatureType(java.lang.Object)
+ *
+ * @param feature
+ * @return
+ */
+ @Override
+ protected EClassifier getFeatureType(Object feature) {
+ final EClassifier featureType;
+ if(feature instanceof Property) {
+ final Type type = ((Property)feature).getType();
+ if(type instanceof PrimitiveType) {
+ final PrimitiveType pType = (PrimitiveType)type;
+ final String name = pType.getName();
+ if(PrimitivesTypesUtils.UML_BOOLEAN.equals(name)) {
+ featureType = EcorePackage.eINSTANCE.getEBoolean();
+ } else if(PrimitivesTypesUtils.UML_INTEGER.equals(name)) {
+ featureType = EcorePackage.eINSTANCE.getEInt();
+ } else if(PrimitivesTypesUtils.UML_REAL.equals(name)) {
+ featureType = EcorePackage.eINSTANCE.getEDouble();
+ } else if(PrimitivesTypesUtils.UML_STRING.equals(name)) {
+ featureType = EcorePackage.eINSTANCE.getEString();
+ } else if(PrimitivesTypesUtils.UML_UNLIMITED_NATURAL.equals(name)) {
+ featureType = EcorePackage.eINSTANCE.getEInt();
+ } else { //custom PrimitiveType
+ featureType = EcorePackage.eINSTANCE.getEString();
+ }
+ } else if(type instanceof Enumeration) {
+ featureType = UMLPackage.eINSTANCE.getEnumeration();
+ } else if(type instanceof DataType) {//FIXME manage the data type
+ featureType = EcorePackage.eINSTANCE.getEString();
+ } else {
+ featureType = type.eClass();
+ }
+ } else {
+ featureType = super.getFeatureType(feature);
+ }
+ return featureType;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#doDeduceValueFromString(java.lang.Object, java.lang.String)
+ *
+ * @param feature
+ * @param valueAsString
+ * @return
+ */
+ @Override
+ protected ConvertedValueContainer<?> doDeduceValueFromString(Object feature, String valueAsString) {
+ final EClassifier featureType = getFeatureType(feature);
+ if(feature instanceof Property) {
+ return deduceValueFromString(feature, featureType, valueAsString);
+ }
+ return super.doDeduceValueFromString(feature, valueAsString);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#deduceValueFromString(java.lang.Object, org.eclipse.emf.ecore.EClassifier,
+ * java.lang.String)
+ *
+ * @param feature
+ * @param featureType
+ * @param valueAsString
+ * @return
+ */
+ @Override
+ protected ConvertedValueContainer<?> deduceValueFromString(Object feature, EClassifier featureType, String valueAsString) {
+ if(featureType instanceof EClass && feature instanceof Property) {
+ final int upperbound = getFeatureUpperBound(feature);
+ boolean isMany = (upperbound > 1 || upperbound == -1);
+ if(PrimitivesTypesUtils.ENUMERATION.equals(featureType.getName())) {
+ return deduceEnumerationLiteralValue(isMany, valueAsString, (Enumeration)((Property)feature).getType());
+ }
+ }
+ return super.deduceValueFromString(feature, featureType, valueAsString);
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#deduceEObjectValue(org.eclipse.emf.ecore.EObject, java.lang.Object,
+ * org.eclipse.emf.ecore.EClass, boolean, java.lang.String)
+ *
+ * @param resolutionContext
+ * @param feature
+ * @param featureType
+ * @param isMany
+ * @param valueAsString
+ * @return
+ * @throws StringValueSolverException
+ */
+ @Override
+ protected ConvertedValueContainer<?> deduceEObjectValue(EObject resolutionContext, Object feature, EClass eClass, boolean isMany, String valueAsString) {
+ final Namespace namespace;
+ if(resolutionContext instanceof Namespace) {
+ namespace = (Namespace)resolutionContext;
+ } else if(resolutionContext instanceof Element) {
+ namespace = ((Element)resolutionContext).getNearestPackage();
+ } else {
+ namespace = null;
+ }
+ if(valueAsString != null && !valueAsString.isEmpty() && namespace != null) {
+ IStatus iStatus = Status.OK_STATUS;
+ final Collection<String> unresolvedValues = new ArrayList<String>();
+ ConvertedValueContainer<?> returnedValue = null;
+ NameResolutionHelper helper = this.nameResolutionHelpers.get(eClass);
+ if(helper == null) {
+ helper = new NameResolutionHelper(namespace, eClass);
+ this.nameResolutionHelpers.put(eClass, helper);
+ }
+ if(isMany) {
+ final Collection<NamedElement> values = new HashSet<NamedElement>();
+ for(final String str : valueAsString.split(this.multiValueSeparator)) {
+ final List<NamedElement> elements = helper.getNamedElements(str);
+ if(elements.size() == 1) {
+ values.add(elements.get(0));
+ } else {
+ unresolvedValues.add(str);
+ }
+ if(!unresolvedValues.isEmpty()) {
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_CANT_BE_RESOLVED_TO_FIND_X, eClass.getName()), unresolvedValues);
+ }
+ returnedValue = new MultiConvertedValueContainer<NamedElement>(values, iStatus);
+ }
+ } else {
+ final List<NamedElement> elements = helper.getNamedElements(valueAsString);
+ if(elements.size() == 1) {
+ //it is OK
+ returnedValue = new ConvertedValueContainer<NamedElement>(elements.get(0), iStatus);
+ } else {
+ unresolvedValues.add(valueAsString);
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(NO_X_REPRESENTED_BY_Y_HAVE_BEEN_FOUND, eClass.getName(), valueAsString), unresolvedValues);
+ returnedValue = new ConvertedValueContainer<EObject>(null, iStatus);
+ }
+ }
+ return returnedValue;
+ }
+ return super.deduceEObjectValue(resolutionContext, feature, eClass, isMany, valueAsString);
+ }
+
+ /**
+ *
+ * @param isMany
+ * <code>true</code> if the feature isMany
+ * @param valueAsString
+ * the value to parse
+ * @return
+ * the result of the parsing
+ */
+ protected ConvertedValueContainer<?> deduceEnumerationLiteralValue(final boolean isMany, final String valueAsString, final Enumeration enumeration) {
+ ConvertedValueContainer<?> returnedValue = null;
+ IStatus iStatus = Status.OK_STATUS;
+ final Collection<String> unresolvedValues = new ArrayList<String>();
+ if(isMany) {
+ final Collection<EnumerationLiteral> values = new ArrayList<EnumerationLiteral>();
+ for(final String str : valueAsString.split(this.multiValueSeparator)) {
+ final EnumerationLiteral lit = (EnumerationLiteral)enumeration.getMember(str);
+ if(lit != null) {
+ values.add(lit);
+ } else {
+ unresolvedValues.add(str);
+ }
+ }
+ if(!unresolvedValues.isEmpty()) {
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, PrimitivesTypesUtils.ENUMERATION_LITERAL), unresolvedValues);
+ }
+ returnedValue = new MultiConvertedValueContainer<EnumerationLiteral>(values, iStatus);
+ } else {
+ final EnumerationLiteral lit = (EnumerationLiteral)enumeration.getMember(valueAsString);
+ if(lit == null) {
+ unresolvedValues.add(valueAsString);
+ iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_ENUMERATION_LITERAL_X_CANT_BE_FOUND, valueAsString, PrimitivesTypesUtils.ENUMERATION_LITERAL), unresolvedValues);
+ }
+ returnedValue = new ConvertedValueContainer<EnumerationLiteral>(lit, iStatus);
+ }
+ return returnedValue;
+ }
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/messages/Messages.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/messages/Messages.java
new file mode 100644
index 00000000000..d6658da0633
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/messages/Messages.java
@@ -0,0 +1,17 @@
+package org.eclipse.papyrus.uml.tools.utils.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.tools.utils.messages.messages"; //$NON-NLS-1$
+
+ public static String UMLStringValueConverter_TheEnumerationLiteralXCantBeFound;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/messages/messages.properties b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/messages/messages.properties
new file mode 100644
index 00000000000..0a7aff7db08
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/messages/messages.properties
@@ -0,0 +1 @@
+UMLStringValueConverter_TheEnumerationLiteralXCantBeFound=The enumeration literal {0} can't be found

Back to the top