summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskovalsky2012-03-18 18:44:21 (EDT)
committer mgolubev2012-03-18 18:44:21 (EDT)
commitc97d2aca67e41e94ab325a2dce2a78cac8cd8a46 (patch)
tree847960a75aedb9f6aa7845a3bb2c1185ed7a1f81
parentedc795c0df2c6a547aec069b373e7c24f055c4bf (diff)
downloadorg.eclipse.gmf-tooling-c97d2aca67e41e94ab325a2dce2a78cac8cd8a46.zip
org.eclipse.gmf-tooling-c97d2aca67e41e94ab325a2dce2a78cac8cd8a46.tar.gz
org.eclipse.gmf-tooling-c97d2aca67e41e94ab325a2dce2a78cac8cd8a46.tar.bz2
[374583] - refactoring: AbstractParser split to EStructuralFeature- and
EAttribute- parts to reuse the former in EReference-parsers
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/messages.properties6
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/Messages.java6
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractAttributeParser.java227
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractFeatureParser.java145
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractParser.java418
6 files changed, 379 insertions, 424 deletions
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/META-INF/MANIFEST.MF b/plugins/org.eclipse.gmf.tooling.runtime/META-INF/MANIFEST.MF
index 0aa38bc..6b088cc 100644
--- a/plugins/org.eclipse.gmf.tooling.runtime/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.gmf.tooling.runtime/META-INF/MANIFEST.MF
@@ -16,4 +16,5 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Activator: org.eclipse.gmf.tooling.runtime.GMFToolingRuntimePlugin
+Export-Package: org.eclipse.gmf.tooling.runtime.parsers
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/messages.properties b/plugins/org.eclipse.gmf.tooling.runtime/messages.properties
index 9920f86..4f2f132 100644
--- a/plugins/org.eclipse.gmf.tooling.runtime/messages.properties
+++ b/plugins/org.eclipse.gmf.tooling.runtime/messages.properties
@@ -1,3 +1,3 @@
-AbstractParser_UnexpectedValueType=Value of type {0} is expected
-AbstractParser_WrongStringConversion=String value does not convert to {0} value
-AbstractParser_UnknownLiteral=Unknown literal: {0}
+AbstractAttributeParser_UnexpectedValueType=Value of type {0} is expected
+AbstractAttributeParser_WrongStringConversion=String value does not convert to {0} value
+AbstractAttributeParser_UnknownLiteral=Unknown literal: {0}
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/Messages.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/Messages.java
index 06b8b69..d5f38ad 100644
--- a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/Messages.java
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/Messages.java
@@ -11,9 +11,9 @@ public class Messages extends NLS {
private Messages() {
}
- public static String AbstractParser_UnexpectedValueType;
+ public static String AbstractAttributeParser_UnexpectedValueType;
- public static String AbstractParser_WrongStringConversion;
+ public static String AbstractAttributeParser_WrongStringConversion;
- public static String AbstractParser_UnknownLiteral;
+ public static String AbstractAttributeParser_UnknownLiteral;
}
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractAttributeParser.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractAttributeParser.java
new file mode 100644
index 0000000..5d6bcea
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractAttributeParser.java
@@ -0,0 +1,227 @@
+package org.eclipse.gmf.tooling.runtime.parsers;
+
+import org.eclipse.emf.ecore.EAttribute;
+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.gmf.tooling.runtime.Messages;
+import org.eclipse.osgi.util.NLS;
+
+public abstract class AbstractAttributeParser extends AbstractFeatureParser {
+
+ private String viewPattern;
+
+ private String editorPattern;
+
+ private String editPattern;
+
+ protected final EAttribute[] features;
+
+ protected final EAttribute[] editableFeatures;
+
+ public AbstractAttributeParser(EAttribute[] features) {
+ super(features);
+ this.features = this.editableFeatures = features;
+ }
+
+ public AbstractAttributeParser(EAttribute[] features, EAttribute[] editableFeatures) {
+ super(features, editableFeatures);
+ this.features = features;
+ this.editableFeatures = editableFeatures;
+ }
+
+ @Override
+ protected Object getValue(EObject element, EStructuralFeature feature) {
+ Object value = super.getValue(element, feature);
+ Class<?> iClass = ((EAttribute) feature).getEAttributeType().getInstanceClass();
+ if (String.class.equals(iClass)) {
+ if (value == null) {
+ value = ""; //$NON-NLS-1$
+ }
+ }
+ return value;
+ }
+
+ @Override
+ protected Object getValidNewValue(EStructuralFeature feature, Object value) {
+ EClassifier type = feature.getEType();
+ if (type instanceof EDataType) {
+ Class<?> iClass = type.getInstanceClass();
+ if (Boolean.TYPE.equals(iClass)) {
+ if (value instanceof Boolean) {
+ // ok
+ } else if (value instanceof String) {
+ value = Boolean.valueOf((String) value);
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, iClass.getName()));
+ }
+ } else if (Character.TYPE.equals(iClass)) {
+ if (value instanceof Character) {
+ // ok
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ value = new Character(s.charAt(0));
+ }
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, iClass.getName()));
+ }
+ } else if (Byte.TYPE.equals(iClass)) {
+ if (value instanceof Byte) {
+ // ok
+ } else if (value instanceof Number) {
+ value = new Byte(((Number) value).byteValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Byte.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_WrongStringConversion, iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, iClass.getName()));
+ }
+ } else if (Short.TYPE.equals(iClass)) {
+ if (value instanceof Short) {
+ // ok
+ } else if (value instanceof Number) {
+ value = new Short(((Number) value).shortValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Short.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_WrongStringConversion, iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, iClass.getName()));
+ }
+ } else if (Integer.TYPE.equals(iClass)) {
+ if (value instanceof Integer) {
+ // ok
+ } else if (value instanceof Number) {
+ value = new Integer(((Number) value).intValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Integer.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_WrongStringConversion, iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, iClass.getName()));
+ }
+ } else if (Long.TYPE.equals(iClass)) {
+ if (value instanceof Long) {
+ // ok
+ } else if (value instanceof Number) {
+ value = new Long(((Number) value).longValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Long.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_WrongStringConversion, iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, iClass.getName()));
+ }
+ } else if (Float.TYPE.equals(iClass)) {
+ if (value instanceof Float) {
+ // ok
+ } else if (value instanceof Number) {
+ value = new Float(((Number) value).floatValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Float.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_WrongStringConversion, iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, iClass.getName()));
+ }
+ } else if (Double.TYPE.equals(iClass)) {
+ if (value instanceof Double) {
+ // ok
+ } else if (value instanceof Number) {
+ value = new Double(((Number) value).doubleValue());
+ } else if (value instanceof String) {
+ String s = (String) value;
+ if (s.length() == 0) {
+ value = null;
+ } else {
+ try {
+ value = Double.valueOf(s);
+ } catch (NumberFormatException nfe) {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_WrongStringConversion, iClass.getName()));
+ }
+ }
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, iClass.getName()));
+ }
+ } else if (type instanceof EEnum) {
+ if (value instanceof String) {
+ EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
+ if (literal == null) {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnknownLiteral, value));
+ } else {
+ value = literal.getInstance();
+ }
+ } else {
+ value = new InvalidValue(NLS.bind(Messages.AbstractAttributeParser_UnexpectedValueType, String.class.getName()));
+ }
+ }
+ }
+ return value;
+ }
+
+ public String getViewPattern() {
+ return viewPattern;
+ }
+
+ public void setViewPattern(String viewPattern) {
+ this.viewPattern = viewPattern;
+ }
+
+ public String getEditorPattern() {
+ return editorPattern;
+ }
+
+ public void setEditorPattern(String editorPattern) {
+ this.editorPattern = editorPattern;
+ }
+
+ public String getEditPattern() {
+ return editPattern;
+ }
+
+ public void setEditPattern(String editPattern) {
+ this.editPattern = editPattern;
+ }
+}
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractFeatureParser.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractFeatureParser.java
new file mode 100644
index 0000000..c370ec3
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractFeatureParser.java
@@ -0,0 +1,145 @@
+package org.eclipse.gmf.tooling.runtime.parsers;
+
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
+import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
+import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
+import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.tooling.runtime.GMFToolingRuntimePlugin;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+
+public abstract class AbstractFeatureParser implements IParser {
+
+ private final EStructuralFeature[] features;
+
+ private final EStructuralFeature[] editableFeatures;
+
+ public AbstractFeatureParser(EStructuralFeature[] features) {
+ this(features, features);
+ }
+
+ public AbstractFeatureParser(EStructuralFeature[] features, EStructuralFeature[] editableFeatures) {
+ if (features == null || Arrays.asList(features).contains(null)) {
+ throw new IllegalArgumentException();
+ }
+ if (editableFeatures == null || Arrays.asList(editableFeatures).contains(null)) {
+ throw new IllegalArgumentException();
+ }
+ this.features = features;
+ this.editableFeatures = editableFeatures;
+ }
+
+ protected EStructuralFeature[] getFeatures() {
+ return features;
+ }
+
+ protected EStructuralFeature[] getEditableFeatures() {
+ return editableFeatures;
+ }
+
+ protected Object[] getValues(EObject element) {
+ Object[] values = new Object[features.length];
+ for (int i = 0; i < features.length; i++) {
+ values[i] = getValue(element, features[i]);
+ }
+ return values;
+ }
+
+ protected Object[] getEditableValues(EObject element) {
+ Object[] values = new Object[editableFeatures.length];
+ for (int i = 0; i < editableFeatures.length; i++) {
+ values[i] = getValue(element, editableFeatures[i]);
+ }
+ return values;
+ }
+
+ protected Object getValue(EObject element, EStructuralFeature feature) {
+ return element.eGet(feature);
+ }
+
+ protected ICommand getParseCommand(IAdaptable adapter, Object[] values, int flags) {
+ if (values == null || validateNewValues(values).getCode() != IParserEditStatus.EDITABLE) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ EObject element = (EObject) adapter.getAdapter(EObject.class);
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(element);
+ if (editingDomain == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Set Values"); //$NON-NLS-1$
+ for (int i = 0; i < values.length; i++) {
+ command.compose(getModificationCommand(element, editableFeatures[i], values[i]));
+ }
+ return command;
+ }
+
+ protected IParserEditStatus validateNewValues(Object[] values) {
+ if (values.length != editableFeatures.length) {
+ return ParserEditStatus.UNEDITABLE_STATUS;
+ }
+ for (int i = 0; i < values.length; i++) {
+ Object value = getValidNewValue(editableFeatures[i], values[i]);
+ if (value instanceof InvalidValue) {
+ return new ParserEditStatus(GMFToolingRuntimePlugin.ID, IParserEditStatus.UNEDITABLE, value.toString());
+ }
+ }
+ return ParserEditStatus.EDITABLE_STATUS;
+ }
+
+ protected Object getValidNewValue(EStructuralFeature feature, Object value) {
+ return value;
+ }
+
+ protected ICommand getModificationCommand(EObject element, EStructuralFeature feature, Object value) {
+ value = getValidNewValue(feature, value);
+ if (value instanceof InvalidValue) {
+ return UnexecutableCommand.INSTANCE;
+ }
+ SetRequest request = new SetRequest(element, feature, value);
+ return new SetValueCommand(request);
+ }
+
+ public boolean isAffectingEvent(Object event, int flags) {
+ if (event instanceof Notification) {
+ return isAffectingFeature(((Notification) event).getFeature());
+ }
+ return false;
+ }
+
+ protected boolean isAffectingFeature(Object feature) {
+ for (int i = 0; i < features.length; i++) {
+ if (features[i] == feature) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public IContentAssistProcessor getCompletionProcessor(IAdaptable element) {
+ return null;
+ }
+
+ protected class InvalidValue {
+
+ private String description;
+
+ public InvalidValue(String description) {
+ this.description = description;
+ }
+
+ public String toString() {
+ return description;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractParser.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractParser.java
deleted file mode 100644
index 778dc64..0000000
--- a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/AbstractParser.java
+++ /dev/null
@@ -1,418 +0,0 @@
-package org.eclipse.gmf.tooling.runtime.parsers;
-
-import java.util.Arrays;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EAttribute;
-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.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
-import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
-import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
-import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.gmf.tooling.runtime.GMFToolingRuntimePlugin;
-import org.eclipse.gmf.tooling.runtime.Messages;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.osgi.util.NLS;
-
-/**
- * @generated
- */
-public abstract class AbstractParser implements IParser {
-
- /**
- * @generated
- */
- protected final EAttribute[] features;
-
- /**
- * @generated
- */
- protected final EAttribute[] editableFeatures;
-
- /**
- * @generated
- */
- private String viewPattern;
-
- /**
- * @generated
- */
- private String editorPattern;
-
- /**
- * @generated
- */
- private String editPattern;
-
- /**
- * @generated
- */
- public AbstractParser(EAttribute[] features) {
- if (features == null || Arrays.asList(features).contains(null)) {
- throw new IllegalArgumentException();
- }
- this.editableFeatures = this.features = features;
- }
-
- /**
- * @generated
- */
- public AbstractParser(EAttribute[] features, EAttribute[] editableFeatures) {
- if (features == null || Arrays.asList(features).contains(null)) {
- throw new IllegalArgumentException();
- }
- this.features = features;
- if (editableFeatures == null || Arrays.asList(editableFeatures).contains(null)) {
- throw new IllegalArgumentException();
- }
- this.editableFeatures = editableFeatures;
- }
-
- /**
- * @generated
- */
- public String getViewPattern() {
- return viewPattern;
- }
-
- /**
- * @generated
- */
- public void setViewPattern(String viewPattern) {
- this.viewPattern = viewPattern;
- }
-
- /**
- * @generated
- */
- public String getEditorPattern() {
- return editorPattern;
- }
-
- /**
- * @generated
- */
- public void setEditorPattern(String editorPattern) {
- this.editorPattern = editorPattern;
- }
-
- /**
- * @generated
- */
- public String getEditPattern() {
- return editPattern;
- }
-
- /**
- * @generated
- */
- public void setEditPattern(String editPattern) {
- this.editPattern = editPattern;
- }
-
- /**
- * @generated
- */
- public boolean isAffectingEvent(Object event, int flags) {
- if (event instanceof Notification) {
- return isAffectingFeature(((Notification) event).getFeature());
- }
- return false;
- }
-
- /**
- * @generated
- */
- protected boolean isAffectingFeature(Object feature) {
- for (int i = 0; i < features.length; i++) {
- if (features[i] == feature) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * @generated
- */
- public IContentAssistProcessor getCompletionProcessor(IAdaptable element) {
- return null;
- }
-
- /**
- * @generated
- */
- protected Object[] getValues(EObject element) {
- Object[] values = new Object[features.length];
- for (int i = 0; i < features.length; i++) {
- values[i] = getValue(element, features[i]);
- }
- return values;
- }
-
- /**
- * @generated
- */
- protected Object[] getEditableValues(EObject element) {
- Object[] values = new Object[editableFeatures.length];
- for (int i = 0; i < editableFeatures.length; i++) {
- values[i] = getValue(element, editableFeatures[i]);
- }
- return values;
- }
-
- /**
- * @generated
- */
- protected Object getValue(EObject element, EAttribute feature) {
- Object value = element.eGet(feature);
- Class<?> iClass = feature.getEAttributeType().getInstanceClass();
- if (String.class.equals(iClass)) {
- if (value == null) {
- value = ""; //$NON-NLS-1$
- }
- }
- return value;
- }
-
- /**
- * @generated
- */
- protected ICommand getParseCommand(IAdaptable adapter, Object[] values, int flags) {
- if (values == null || validateNewValues(values).getCode() != IParserEditStatus.EDITABLE) {
- return UnexecutableCommand.INSTANCE;
- }
- EObject element = (EObject) adapter.getAdapter(EObject.class);
- TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(element);
- if (editingDomain == null) {
- return UnexecutableCommand.INSTANCE;
- }
- CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Set Values"); //$NON-NLS-1$
- for (int i = 0; i < values.length; i++) {
- command.compose(getModificationCommand(element, editableFeatures[i], values[i]));
- }
- return command;
- }
-
- /**
- * @generated
- */
- protected ICommand getModificationCommand(EObject element, EAttribute feature, Object value) {
- value = getValidNewValue(feature, value);
- if (value instanceof InvalidValue) {
- return UnexecutableCommand.INSTANCE;
- }
- SetRequest request = new SetRequest(element, feature, value);
- return new SetValueCommand(request);
- }
-
- /**
- * @generated
- */
- protected IParserEditStatus validateNewValues(Object[] values) {
- if (values.length != editableFeatures.length) {
- return ParserEditStatus.UNEDITABLE_STATUS;
- }
- for (int i = 0; i < values.length; i++) {
- Object value = getValidNewValue(editableFeatures[i], values[i]);
- if (value instanceof InvalidValue) {
- return new ParserEditStatus(GMFToolingRuntimePlugin.ID, IParserEditStatus.UNEDITABLE, value.toString());
- }
- }
- return ParserEditStatus.EDITABLE_STATUS;
- }
-
- /**
- * @generated
- */
- protected Object getValidNewValue(EAttribute feature, Object value) {
- EClassifier type = feature.getEType();
- if (type instanceof EDataType) {
- Class<?> iClass = type.getInstanceClass();
- if (Boolean.TYPE.equals(iClass)) {
- if (value instanceof Boolean) {
- // ok
- } else if (value instanceof String) {
- value = Boolean.valueOf((String) value);
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
- }
- } else if (Character.TYPE.equals(iClass)) {
- if (value instanceof Character) {
- // ok
- } else if (value instanceof String) {
- String s = (String) value;
- if (s.length() == 0) {
- value = null;
- } else {
- value = new Character(s.charAt(0));
- }
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
- }
- } else if (Byte.TYPE.equals(iClass)) {
- if (value instanceof Byte) {
- // ok
- } else if (value instanceof Number) {
- value = new Byte(((Number) value).byteValue());
- } else if (value instanceof String) {
- String s = (String) value;
- if (s.length() == 0) {
- value = null;
- } else {
- try {
- value = Byte.valueOf(s);
- } catch (NumberFormatException nfe) {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
- }
- }
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
- }
- } else if (Short.TYPE.equals(iClass)) {
- if (value instanceof Short) {
- // ok
- } else if (value instanceof Number) {
- value = new Short(((Number) value).shortValue());
- } else if (value instanceof String) {
- String s = (String) value;
- if (s.length() == 0) {
- value = null;
- } else {
- try {
- value = Short.valueOf(s);
- } catch (NumberFormatException nfe) {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
- }
- }
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
- }
- } else if (Integer.TYPE.equals(iClass)) {
- if (value instanceof Integer) {
- // ok
- } else if (value instanceof Number) {
- value = new Integer(((Number) value).intValue());
- } else if (value instanceof String) {
- String s = (String) value;
- if (s.length() == 0) {
- value = null;
- } else {
- try {
- value = Integer.valueOf(s);
- } catch (NumberFormatException nfe) {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
- }
- }
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
- }
- } else if (Long.TYPE.equals(iClass)) {
- if (value instanceof Long) {
- // ok
- } else if (value instanceof Number) {
- value = new Long(((Number) value).longValue());
- } else if (value instanceof String) {
- String s = (String) value;
- if (s.length() == 0) {
- value = null;
- } else {
- try {
- value = Long.valueOf(s);
- } catch (NumberFormatException nfe) {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
- }
- }
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
- }
- } else if (Float.TYPE.equals(iClass)) {
- if (value instanceof Float) {
- // ok
- } else if (value instanceof Number) {
- value = new Float(((Number) value).floatValue());
- } else if (value instanceof String) {
- String s = (String) value;
- if (s.length() == 0) {
- value = null;
- } else {
- try {
- value = Float.valueOf(s);
- } catch (NumberFormatException nfe) {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
- }
- }
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
- }
- } else if (Double.TYPE.equals(iClass)) {
- if (value instanceof Double) {
- // ok
- } else if (value instanceof Number) {
- value = new Double(((Number) value).doubleValue());
- } else if (value instanceof String) {
- String s = (String) value;
- if (s.length() == 0) {
- value = null;
- } else {
- try {
- value = Double.valueOf(s);
- } catch (NumberFormatException nfe) {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
- }
- }
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
- }
- } else if (type instanceof EEnum) {
- if (value instanceof String) {
- EEnumLiteral literal = ((EEnum) type).getEEnumLiteralByLiteral((String) value);
- if (literal == null) {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
- } else {
- value = literal.getInstance();
- }
- } else {
- value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
- }
- }
- }
- return value;
- }
-
- /**
- * @generated
- */
- protected class InvalidValue {
-
- /**
- * @generated
- */
- private String description;
-
- /**
- * @generated
- */
- public InvalidValue(String description) {
- this.description = description;
- }
-
- /**
- * @generated
- */
- public String toString() {
- return description;
- }
- }
-}