summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskovalsky2012-03-18 19:08:31 (EDT)
committer mgolubev2012-03-18 19:08:31 (EDT)
commit0d8422dbc99a849243bb52a397dd037e138386f0 (patch)
treef68157302b352391eb95ab2d61b0c50617143449
parentbe774c3621f4bbd7aa6cc72d19ddea3bb98dd46f (diff)
downloadorg.eclipse.gmf-tooling-0d8422dbc99a849243bb52a397dd037e138386f0.zip
org.eclipse.gmf-tooling-0d8422dbc99a849243bb52a397dd037e138386f0.tar.gz
org.eclipse.gmf-tooling-0d8422dbc99a849243bb52a397dd037e138386f0.tar.bz2
[374583] - common base classes for parsers that use oclTracker to
auto-update the labels defined in OCL
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/ExpressionLabelParserBase.java46
-rw-r--r--plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/OclTrackerWrapper.java41
2 files changed, 87 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/ExpressionLabelParserBase.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/ExpressionLabelParserBase.java
new file mode 100644
index 0000000..d3304da
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/ExpressionLabelParserBase.java
@@ -0,0 +1,46 @@
+package org.eclipse.gmf.tooling.runtime.parsers;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
+import org.eclipse.gmf.tooling.runtime.GMFToolingRuntimePlugin;
+import org.eclipse.gmf.tooling.runtime.ocl.tracker.HasOclTracker;
+import org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTracker;
+import org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTrackerFactory;
+
+public abstract class ExpressionLabelParserBase implements HasOclTracker, IParser {
+
+ private final OclTrackerWrapper myDelegate;
+
+ public ExpressionLabelParserBase() {
+ this(GMFToolingRuntimePlugin.getInstance().getOclTrackerFactory());
+ }
+
+ public ExpressionLabelParserBase(OclTrackerFactory.Type preferredType) {
+ this(GMFToolingRuntimePlugin.getInstance().getOclTrackerFactory(preferredType));
+ }
+
+ public ExpressionLabelParserBase(OclTrackerFactory oclTrackerFactory) {
+ myDelegate = new OclTrackerWrapper(oclTrackerFactory) {
+
+ @Override
+ protected String getExpressionBody() {
+ return ExpressionLabelParserBase.this.getExpressionBody();
+ }
+ };
+ }
+
+ @Override
+ public OclTracker getOclTracker() {
+ return myDelegate.getOclTracker();
+ }
+
+ public String getPrintString(IAdaptable element, int flags) {
+ return myDelegate.getUpdatedString(element, flags);
+ }
+
+ public boolean isAffectingEvent(Object event, int flags) {
+ return myDelegate.isAffectingEvent(event, flags);
+ }
+
+ protected abstract String getExpressionBody();
+}
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/OclTrackerWrapper.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/OclTrackerWrapper.java
new file mode 100644
index 0000000..bb96c5d
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/parsers/OclTrackerWrapper.java
@@ -0,0 +1,41 @@
+package org.eclipse.gmf.tooling.runtime.parsers;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTracker;
+import org.eclipse.gmf.tooling.runtime.ocl.tracker.OclTrackerFactory;
+
+abstract class OclTrackerWrapper {
+
+ private final OclTrackerFactory myOclTrackerFactory;
+
+ private OclTracker myOclTracker;
+
+ public OclTrackerWrapper(OclTrackerFactory oclTrackerFactory) {
+ myOclTrackerFactory = oclTrackerFactory;
+ }
+
+ public OclTracker getOclTracker() {
+ if (myOclTracker == null) {
+ myOclTracker = myOclTrackerFactory.createOclTracker(getExpressionBody(), true);
+ }
+ return myOclTracker;
+ }
+
+ public String getUpdatedString(IAdaptable element, int flags) {
+ EObject target = (EObject) element.getAdapter(EObject.class);
+ getOclTracker().initialize(target);
+ return String.valueOf(getOclTracker().getValue());
+ }
+
+ public boolean isAffectingEvent(Object event, int flags) {
+ if (event instanceof Notification) {
+ Notification notification = (Notification) event;
+ return getOclTracker().handleNotification(notification);
+ }
+ return false;
+ }
+
+ protected abstract String getExpressionBody();
+}