Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaud Cuccuru2015-01-05 13:53:29 +0000
committerArnaud Cuccuru2015-01-05 13:53:29 +0000
commitfdb0c07062f3b4162ec63ff9061c4584bb7ee2f4 (patch)
treefe178c7f8fc2d889748fc92d68678e7d2a3a0c17 /examples
parent1a5fa3cdb2a62ff3a5194908db17c51deebdea3c (diff)
downloadorg.eclipse.papyrus-fdb0c07062f3b4162ec63ff9061c4584bb7ee2f4.tar.gz
org.eclipse.papyrus-fdb0c07062f3b4162ec63ff9061c4584bb7ee2f4.tar.xz
org.eclipse.papyrus-fdb0c07062f3b4162ec63ff9061c4584bb7ee2f4.zip
456677: [Moka] Moka shall provide a simple contribution example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=456677 A simple plugin contributing to the ExecutionEngine extension point of Moka, and using/contributing to the debug API. Change-Id: I9597d705a2d871526ce8f211df6849a8540abe17
Diffstat (limited to 'examples')
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/.classpath7
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/.gitignore1
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/.project28
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/.settings/.gitignore1
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/META-INF/MANIFEST.MF17
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/build.properties5
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/plugin.xml12
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/Activator.java67
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/ControlDelegate.java258
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/DummyUMLExecutionEngine.java211
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/DummyVisitor.java86
-rw-r--r--examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/PresentationUtils.java29
12 files changed, 722 insertions, 0 deletions
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/.classpath b/examples/moka/org.eclipse.papyrus.moka.dummyexample/.classpath
new file mode 100644
index 00000000000..8a8f1668cdc
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/.gitignore b/examples/moka/org.eclipse.papyrus.moka.dummyexample/.gitignore
new file mode 100644
index 00000000000..ae3c1726048
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/.project b/examples/moka/org.eclipse.papyrus.moka.dummyexample/.project
new file mode 100644
index 00000000000..8bc293b8786
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.moka.dummyexample</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/.settings/.gitignore b/examples/moka/org.eclipse.papyrus.moka.dummyexample/.settings/.gitignore
new file mode 100644
index 00000000000..3b1537c221f
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/.settings/.gitignore
@@ -0,0 +1 @@
+/org.eclipse.jdt.core.prefs
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/META-INF/MANIFEST.MF b/examples/moka/org.eclipse.papyrus.moka.dummyexample/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..926f891a9cf
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Dummyexample
+Bundle-SymbolicName: org.eclipse.papyrus.moka.dummyexample;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.moka.dummyexample.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.moka;bundle-version="1.0.0",
+ org.eclipse.debug.core;bundle-version="3.7.100",
+ org.eclipse.emf.ecore;bundle-version="2.8.1",
+ org.eclipse.uml2.uml;bundle-version="4.0.1",
+ org.eclipse.ui.console;bundle-version="3.6.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.1.0",
+ org.eclipse.papyrus.moka.ui;bundle-version="1.1.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/build.properties b/examples/moka/org.eclipse.papyrus.moka.dummyexample/build.properties
new file mode 100644
index 00000000000..6f20375d6c7
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/plugin.xml b/examples/moka/org.eclipse.papyrus.moka.dummyexample/plugin.xml
new file mode 100644
index 00000000000..d0b168221ad
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/plugin.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.moka.engine">
+ <engine
+ class="org.eclipse.papyrus.moka.dummyexample.DummyUMLExecutionEngine"
+ description="A simple execution engine, which visits elements of a model, and displays their name">
+ </engine>
+ </extension>
+
+</plugin>
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/Activator.java b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/Activator.java
new file mode 100644
index 00000000000..f9c8734df43
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/Activator.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.dummyexample;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.moka.dummyexample"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log ;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/ControlDelegate.java b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/ControlDelegate.java
new file mode 100644
index 00000000000..ab04ae2cb14
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/ControlDelegate.java
@@ -0,0 +1,258 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.dummyexample;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.moka.MokaConstants;
+import org.eclipse.papyrus.moka.communication.event.isuspendresume.Suspend_Event;
+import org.eclipse.papyrus.moka.communication.request.isuspendresume.Resume_Request;
+import org.eclipse.papyrus.moka.communication.request.isuspendresume.Suspend_Request;
+import org.eclipse.papyrus.moka.communication.request.iterminate.Terminate_Request;
+import org.eclipse.papyrus.moka.debug.MokaBreakpoint;
+import org.eclipse.papyrus.moka.debug.MokaStackFrame;
+import org.eclipse.papyrus.moka.debug.MokaThread;
+import org.eclipse.papyrus.moka.engine.AbstractExecutionEngine;
+import org.eclipse.papyrus.moka.ui.presentation.AnimationUtils;
+
+public class ControlDelegate {
+
+ /// FIXME Problem when the variable panel is visible
+
+ /**
+ * The execution engine associated with this ControlDelegate object
+ */
+ protected AbstractExecutionEngine engine;
+
+ /**
+ * The list of threads implied by current execution
+ */
+ protected List<MokaThread> threads;
+
+ /**
+ * Determines if execution is suspended
+ */
+ protected boolean suspended = false;
+
+ /**
+ * The reason for suspending execution
+ */
+ protected int reasonForSuspending = -1;
+
+ /**
+ * The reason for resuming execution
+ */
+ protected int reasonForResuming = -1;
+
+ /**
+ * The execution mode (i.e., Debug or Run)
+ */
+ protected String mode;
+
+ /**
+ * Semantic elements associated with a breakpoint
+ */
+ protected Set<EObject> elementsWithBreakpoints;
+
+ /**
+ *
+ *
+ * @param engine The engine associated with this ControlDelegate object
+ */
+ public ControlDelegate(AbstractExecutionEngine engine) {
+ this.engine = engine;
+ this.mode = this.engine.getDebugTarget().getLaunch().getLaunchMode();
+ this.elementsWithBreakpoints = new HashSet<EObject>();
+ }
+
+ /**
+ * Manages addition of a breakpoint in the course of execution
+ *
+ * @param breakpoint
+ * The added breakpoint
+ */
+ public void addBreakpoint(MokaBreakpoint breakpoint) {
+ EObject modelElement = breakpoint.getModelElement();
+ if (modelElement != null) {
+ if (modelElement.eIsProxy()) {
+ modelElement = AnimationUtils.resolve(modelElement);
+ }
+ this.elementsWithBreakpoints.add(modelElement);
+ }
+ }
+
+ /**
+ * Manages removal of a breakpoint in the course of execution
+ *
+ * @param breakpoint
+ * The removed breakpoint
+ */
+ public void removeBreakpoint(MokaBreakpoint breakpoint) {
+ EObject modelElement = breakpoint.getModelElement();
+ if (modelElement != null) {
+ if (modelElement.eIsProxy()) {
+ modelElement = AnimationUtils.resolve(modelElement);
+ }
+ this.elementsWithBreakpoints.remove(modelElement);
+ }
+ }
+
+ /**
+ * Manages resuming of execution
+ *
+ * @param request
+ * The request underlying this resume
+ */
+ public void resume(Resume_Request request) {
+ this.suspended = false;
+ this.reasonForResuming = request.getResumeDetail();
+ if (reasonForResuming != DebugEvent.CLIENT_REQUEST) {
+ reasonForResuming = DebugEvent.STEP_OVER;
+ }
+ this.getThreads()[0].setSuspended(false);
+ synchronized (this) {
+ notify();
+ this.threads.get(0).setStackFrames(new IStackFrame[] {});
+ }
+ }
+
+ /**
+ * Manages suspension of execution
+ *
+ * @param request
+ * The request underlying this suspension
+ */
+ public void suspend(Suspend_Request request) {
+ this.suspended = true;
+ this.reasonForSuspending = DebugEvent.CLIENT_REQUEST;
+ }
+
+ /**
+ * Manages termination of execution
+ *
+ * @param request
+ * The request underlying this termination
+ */
+ public void terminate(Terminate_Request request) {
+ engine.setIsTerminated(true);
+ synchronized (this) {
+ notify();
+ }
+ }
+
+ /**
+ * Returns the threads underlying this execution
+ * The semantics implemented by this engine makes the hypothesis that the execution occurs on a single thread,
+ * so that there will be only one thread visible in the thread/stack view when execution is suspended
+ *
+ * @return The threads underlying this execution
+ */
+ public MokaThread[] getThreads() {
+ if (this.threads == null) {
+ this.threads = new ArrayList<MokaThread>();
+ if (this.engine.getDebugTarget().getLaunch().getLaunchMode().equals(ILaunchManager.DEBUG_MODE)) {
+ MokaThread thread = new MokaThread(this.engine.getDebugTarget());
+ thread.setName("Main Thread");
+ thread.setStackFrames(new IStackFrame[] {});
+ this.threads.add(thread);
+ }
+ }
+ return threads.toArray(new MokaThread[threads.size()]);
+ }
+
+ /**
+ * Method that can be called by a particular execution engine to delegate control of execution flow.
+ *
+ * @param object
+ * An object from the execution flow from which control has to be delegated
+ * @return False if execution shall stop, True if execution shall continue
+ */
+ public boolean control(Object object) {
+ if (this.engine.isTerminated()) {
+ return false;
+ }
+
+ // Retrieves the semantic element
+ EObject semanticElement = ((DummyVisitor)object).currentlyVisited ;
+
+ // Manages animation
+ if (semanticElement != null && MokaConstants.MOKA_AUTOMATIC_ANIMATION && this.mode.equals(ILaunchManager.DEBUG_MODE)) {
+ this.animate(semanticElement);
+ }
+
+ if (this.suspended) { /* Client request */
+ try {
+ synchronized (this) {
+ this.getThreads(); // To make sure that this.threads is neither null nor empty
+ MokaThread mainThread = this.threads.get(0);
+ mainThread.setSuspended(true);
+ MokaStackFrame stackFrame = PresentationUtils.getMokaStackFrame((DummyVisitor)object);
+ stackFrame.setThread(mainThread);
+ mainThread.setStackFrames(new IStackFrame[] { stackFrame });
+ Suspend_Event suspendEvent = new Suspend_Event(mainThread, DebugEvent.CLIENT_REQUEST, this.getThreads());
+ engine.sendEvent(suspendEvent);
+ wait();
+ }
+ } catch (InterruptedException e) {
+ Activator.log.error(e);
+ }
+ } else { // Tries to check if a breakpoint applies, or if execution was resumed due to a Step Over
+ if (this.elementsWithBreakpoints.contains(semanticElement) || this.reasonForResuming == DebugEvent.STEP_OVER) {
+ try {
+ synchronized (this) {
+ this.getThreads(); // To make sure that this.threads is neither null nor empty
+ MokaThread mainThread = this.threads.get(0);
+ mainThread.setSuspended(true);
+ MokaStackFrame stackFrame = PresentationUtils.getMokaStackFrame((DummyVisitor)object);
+ stackFrame.setThread(mainThread);
+ mainThread.setStackFrames(new IStackFrame[] { stackFrame });
+ Suspend_Event suspendEvent = new Suspend_Event(mainThread, DebugEvent.BREAKPOINT, this.getThreads());
+ engine.sendEvent(suspendEvent);
+ wait();
+ }
+ } catch (InterruptedException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+ return !this.engine.isTerminated();
+ }
+
+ /**
+ * A utility method to perform some animation on a model element
+ *
+ * @param element
+ */
+ protected void animate(EObject element) {
+ try {
+ // Animates the element
+ if ((AnimationUtils.getInstance().diagramsExistFor(element))) {
+ AnimationUtils.getInstance().addAnimationMarker(element);
+ Thread.sleep(MokaConstants.MOKA_ANIMATION_DELAY);
+ AnimationUtils.getInstance().removeAnimationMarker(element);
+ }
+ } catch (InterruptedException e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+}
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/DummyUMLExecutionEngine.java b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/DummyUMLExecutionEngine.java
new file mode 100644
index 00000000000..60335af304c
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/DummyUMLExecutionEngine.java
@@ -0,0 +1,211 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.dummyexample;
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.core.model.IThread;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.moka.communication.request.isuspendresume.Resume_Request;
+import org.eclipse.papyrus.moka.communication.request.isuspendresume.Suspend_Request;
+import org.eclipse.papyrus.moka.communication.request.iterminate.Terminate_Request;
+import org.eclipse.papyrus.moka.debug.MokaBreakpoint;
+import org.eclipse.papyrus.moka.debug.MokaDebugTarget;
+import org.eclipse.papyrus.moka.debug.MokaThread;
+import org.eclipse.papyrus.moka.engine.AbstractExecutionEngine;
+import org.eclipse.papyrus.moka.engine.IExecutionEngine;
+import org.eclipse.papyrus.moka.ui.presentation.AnimationUtils;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.IConsoleManager;
+import org.eclipse.ui.console.IOConsole;
+import org.eclipse.ui.console.IOConsoleOutputStream;
+import org.eclipse.uml2.uml.NamedElement;
+
+public class DummyUMLExecutionEngine extends AbstractExecutionEngine implements IExecutionEngine {
+
+ /**
+ * A static instance of this engine.
+ * This is initialized by method init.
+ */
+ public static DummyUMLExecutionEngine eInstance ;
+
+ /**
+ * A flag used to track if the execution is actually started
+ */
+ protected boolean started = false ;
+
+ /**
+ * The console associated with this engine
+ */
+ protected static IOConsole console ;
+
+ /**
+ * The output stream associated with the console of this engine
+ */
+ protected static IOConsoleOutputStream out ;
+
+ /**
+ * The name of the console associated with this engine
+ */
+ protected static final String CONSOLE_NAME = "Console";
+
+ /**
+ * The control delegate object associated with this engine
+ */
+ protected ControlDelegate controlDelegate ;
+
+ /**
+ * The DummyVisitor created for the execution of the eObjectToExecute model element
+ */
+ protected DummyVisitor visitor ;
+
+ //////////////////////////////////////
+ // Initialization
+ //////////////////////////////////////
+
+ @Override
+ public void init(EObject eObjectToExecute, String[] args, MokaDebugTarget debugTarget, int requestPort,
+ int replyPort, int eventPort) throws UnknownHostException, IOException {
+ super.init(eObjectToExecute, args, debugTarget, requestPort, replyPort, eventPort);
+ // In addition to AbsractExecutionEngine initialization:
+ // - Initializes the Animation Utils (enables a pre-execution retrieval of diagrams associated with the eObjectToExecute)
+ // - Creates a DummyVisitor for the given eObjectToExecute
+ if (eObjectToExecute instanceof NamedElement) {
+ AnimationUtils.init(eObjectToExecute);
+ if (this.debugTarget != null) {
+ this.debugTarget.setName("Dummy Example Debug Target") ;
+ }
+ visitor = new DummyVisitor((NamedElement)eObjectToExecute, this.getThreads()[0]) ;
+ }
+ DummyUMLExecutionEngine.eInstance = this ;
+ }
+
+ @Override
+ public void initializeArguments(String[] args) {
+ // not specific initialization to perform
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Implementation of the debug event processing.
+ // All debug events (except resume events) are processed by delegation to the control delegate object
+ // Reminder: These methods are automatically called by the event dispatch loop implemented by
+ // AbstractExecutionEngine
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public void addBreakpoint(MokaBreakpoint breakpoint) {
+ this.getControlDelegate().addBreakpoint(breakpoint);
+ }
+
+ @Override
+ public void removeBreakpoint(MokaBreakpoint breakpoint) {
+ this.getControlDelegate().removeBreakpoint(breakpoint);
+ }
+
+ @Override
+ public IStackFrame[] getStackFrames(IThread thread) {
+ // Never called in this implementation
+ // When the debug framework is notified, threads are already constructed with appropriate stack frames.
+ return null;
+ }
+
+ @Override
+ public MokaThread[] getThreads() {
+ return this.getControlDelegate().getThreads() ;
+ }
+
+ @Override
+ public void disconnect() {
+ // Disconnection not supported by this dummy execution engine
+ }
+
+ @Override
+ public void suspend(Suspend_Request request) {
+ this.getControlDelegate().suspend(request);
+ }
+
+ @Override
+ public void terminate(Terminate_Request request) {
+ this.getControlDelegate().terminate(request);
+ }
+
+ @Override
+ public void resume(Resume_Request request) {
+ // In the case where the execution has not yet been started, starts the visitor behavior on a new thread.
+ // Otherwise, delegates processing of the request to the control delegate object
+ if (!this.started) {
+ Runnable execution = new Runnable() {
+ public void run() {
+ if (visitor != null) {
+ try {
+ started = true ;
+ visitor.visit();
+ }
+ catch (Exception e) {
+ Activator.log.error(e);
+ }
+ if (!isTerminated()) {
+ try {
+ getDebugTarget().terminate();
+ } catch (DebugException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+ }
+ };
+ Thread mainThread = new Thread(execution);
+ mainThread.start();
+ } else {
+ this.getControlDelegate().resume(request);
+ }
+ }
+
+ //////////////////////////////////
+ // Utils
+ //////////////////////////////////
+
+ /**
+ * Returns the control delegate object associated with this engine
+ *
+ * @return The control delegate object associated with this engine
+ */
+ public ControlDelegate getControlDelegate() {
+ if (this.controlDelegate == null) {
+ this.controlDelegate = new ControlDelegate(this) ;
+ }
+ return this.controlDelegate ;
+ }
+
+ /**
+ * Returns an output stream connected to the console associated with this execution engine
+ *
+ * @return an output stream connected to the console associated with this execution engine
+ */
+ public IOConsoleOutputStream getOutputStream() {
+ if (console == null) {
+ console = new IOConsole(CONSOLE_NAME, null);
+ }
+ if (out == null) {
+ IConsoleManager conMan = ConsolePlugin.getDefault().getConsoleManager();
+ conMan.addConsoles(new IConsole[] { console });
+ out = console.newOutputStream() ;
+ }
+ return out;
+ }
+}
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/DummyVisitor.java b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/DummyVisitor.java
new file mode 100644
index 00000000000..37f9f91ea7a
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/DummyVisitor.java
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.dummyexample;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.moka.debug.MokaThread;
+import org.eclipse.uml2.uml.NamedElement;
+
+/**
+ * A simple visitor class, that simply displays the name of the model elements it visits.
+ * The visited elements are those contained in the executionRoot element, given as a parameter of the constructor.
+ *
+ */
+public class DummyVisitor {
+
+ /**
+ * The list of all the elements to be visited
+ */
+ protected List<NamedElement> elementsToVisit ;
+
+ /**
+ * The currently visited element
+ */
+ protected NamedElement currentlyVisited ;
+
+ /**
+ * The IThread associated with this visitor.
+ */
+ protected MokaThread thread ;
+
+ /**
+ * Constructor
+ *
+ * @param executionRoot The root execution element, from which elementsToVisit is determined (eAllContents)
+ * @param thread The thread to be associated with this visitor
+ */
+ public DummyVisitor(NamedElement executionRoot, MokaThread thread) {
+ this.thread = thread ;
+ this.elementsToVisit = new ArrayList<NamedElement>() ;
+ Iterator<EObject> i = executionRoot.eAllContents() ;
+ for ( ; i.hasNext() ; ) {
+ EObject o = i.next() ;
+ if (o instanceof NamedElement) {
+ elementsToVisit.add((NamedElement)o) ;
+ }
+ }
+ }
+
+ /**
+ * The visitor behavior.
+ * It consists in iterating over elementsToVisit, and display the name of the visited elements.
+ * After each visit, inside of the iteration, the control is delegated to a ControlDelegate object,
+ * in order to determine if execution can go on, or shall be suspended, or shall be terminated,
+ * or if some animation shall happen.
+ */
+ public void visit() {
+ try {
+ boolean _continue = true ;
+ for (Iterator<NamedElement> i = elementsToVisit.iterator() ; i.hasNext() && _continue ; ) {
+ currentlyVisited = i.next() ;
+ DummyUMLExecutionEngine.eInstance.getOutputStream().write("I am visiting " + currentlyVisited.getName() + "\n") ;
+ // if _continue becomes false (which means that the execution shall terminate), the loop will exit
+ _continue = DummyUMLExecutionEngine.eInstance.getControlDelegate().control(this) ;
+ }
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+
+}
diff --git a/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/PresentationUtils.java b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/PresentationUtils.java
new file mode 100644
index 00000000000..24f9219b365
--- /dev/null
+++ b/examples/moka/org.eclipse.papyrus.moka.dummyexample/src/org/eclipse/papyrus/moka/dummyexample/PresentationUtils.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.moka.dummyexample;
+
+import org.eclipse.papyrus.moka.debug.MokaDebugTarget;
+import org.eclipse.papyrus.moka.debug.MokaStackFrame;
+
+public class PresentationUtils {
+
+ public static MokaStackFrame getMokaStackFrame(DummyVisitor visitor) {
+ MokaStackFrame stackFrame = new MokaStackFrame((MokaDebugTarget)visitor.thread.getDebugTarget()) ;
+ stackFrame.setModelElement(visitor.currentlyVisited) ;
+ stackFrame.setThread(visitor.thread) ;
+ stackFrame.setName(visitor.currentlyVisited.getName()) ;
+ return stackFrame;
+ }
+
+}

Back to the top