aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskovalsky2012-03-18 19:13:06 (EDT)
committermgolubev2012-03-18 19:13:06 (EDT)
commit9a0b6ea8d7e7ef1062090c6ce2ad40d2fe9fb51a (patch)
treef9d3b08a3d2cb3c3d7810ecf4a26d571cfd2941f
parent0d8422dbc99a849243bb52a397dd037e138386f0 (diff)
downloadorg.eclipse.gmf-tooling-9a0b6ea8d7e7ef1062090c6ce2ad40d2fe9fb51a.zip
org.eclipse.gmf-tooling-9a0b6ea8d7e7ef1062090c6ce2ad40d2fe9fb51a.tar.gz
org.eclipse.gmf-tooling-9a0b6ea8d7e7ef1062090c6ce2ad40d2fe9fb51a.tar.bz2
[158116] - EnumParser runtime support
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/ChoiceParserBase.java75
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/EnumParser.java33
3 files changed, 109 insertions, 0 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 72aed49..0b753d6 100644
--- a/plugins/org.eclipse.gmf.tooling.runtime/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.gmf.tooling.runtime/META-INF/MANIFEST.MF
@@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.gmf.runtime.common.ui.services,
org.eclipse.gmf.runtime.emf.type.core,
org.eclipse.gmf.runtime.diagram.core,
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.6.0",
org.eclipse.ocl,
org.eclipse.ocl.ecore
Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/ChoiceParserBase.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/ChoiceParserBase.java
new file mode 100644
index 0000000..3f2d727
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/ChoiceParserBase.java
@@ -0,0 +1,75 @@
+package org.eclipse.gmf.tooling.runtime.parsers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+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.diagram.ui.tools.ComboDirectEditManager;
+import org.eclipse.gmf.tooling.runtime.GMFToolingRuntimePlugin;
+
+public abstract class ChoiceParserBase extends AbstractFeatureParser implements ComboDirectEditManager.IChoiceParser {
+
+ private static final int SINGLE_FEATURE_INDEX = 0;
+
+ public ChoiceParserBase(EStructuralFeature feature) {
+ super(new EStructuralFeature[] { feature });
+ }
+
+ protected final EStructuralFeature getFeature() {
+ return getEditableFeatures()[SINGLE_FEATURE_INDEX];
+ }
+
+ @Override
+ public String getEditString(IAdaptable adapter, int flags) {
+ EObject element = (EObject) adapter.getAdapter(EObject.class);
+ return getEditChoice(element, getEditableValues(element)[SINGLE_FEATURE_INDEX]);
+ }
+
+ @Override
+ public IParserEditStatus isValidEditString(IAdaptable adapter, String editString) {
+ if (getEditChoices(adapter).contains(editString)) {
+ return ParserEditStatus.EDITABLE_STATUS;
+ }
+ return new ParserEditStatus(GMFToolingRuntimePlugin.ID, IParserEditStatus.UNEDITABLE, editString);
+ }
+
+ @Override
+ public ICommand getParseCommand(IAdaptable adapter, String newString, int flags) {
+ EObject element = (EObject) adapter.getAdapter(EObject.class);
+ return getParseCommand(adapter, new Object[] { findItem(element, newString) }, flags);
+ }
+
+ @Override
+ public String getPrintString(IAdaptable adapter, int flags) {
+ return getEditString(adapter, flags);
+ }
+
+ @Override
+ public List<String> getEditChoices(IAdaptable adapter) {
+ EObject element = (EObject) adapter.getAdapter(EObject.class);
+ List<String> result = new ArrayList<String>();
+ for (Object item : getItems(element)) {
+ result.add(getEditChoice(element, item));
+ }
+ return result;
+ }
+
+ private Object findItem(EObject element, String editChoice) {
+ for (Object item : getItems(element)) {
+ if (editChoice.equals(getEditChoice(element, item))) {
+ return item;
+ }
+ }
+ return null;
+ }
+
+ protected abstract Collection<Object> getItems(EObject element);
+
+ protected abstract String getEditChoice(EObject element, Object item);
+}
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/EnumParser.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/EnumParser.java
new file mode 100644
index 0000000..7f4e1b1
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/EnumParser.java
@@ -0,0 +1,33 @@
+package org.eclipse.gmf.tooling.runtime.parsers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EObject;
+
+public class EnumParser extends ChoiceParserBase {
+
+ public EnumParser(EAttribute enumFeature) {
+ super(enumFeature);
+ }
+
+ @Override
+ protected Collection<Object> getItems(EObject element) {
+ List<Object> result = new ArrayList<Object>();
+ EAttribute enumFeature = (EAttribute) getFeature();
+ EEnum type = (EEnum) enumFeature.getEType();
+ for (EEnumLiteral literal : type.getELiterals()) {
+ result.add(literal.getLiteral());
+ }
+ return result;
+ }
+
+ @Override
+ protected String getEditChoice(EObject element, Object item) {
+ return item.toString();
+ }
+}