Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayant Gupta2014-06-21 12:03:20 +0000
committerHenrik Rentz-Reichert2014-09-18 14:21:30 +0000
commitacafec8332f7693a8de4dcfaaa31518e560f87f4 (patch)
tree16ee38dc13cfab426ea9bc73d079b8944c6808b1
parent5f386c4178e9889fadd8748ac2dd27ce2e0b46ee (diff)
downloadorg.eclipse.etrice-acafec8332f7693a8de4dcfaaa31518e560f87f4.tar.gz
org.eclipse.etrice-acafec8332f7693a8de4dcfaaa31518e560f87f4.tar.xz
org.eclipse.etrice-acafec8332f7693a8de4dcfaaa31518e560f87f4.zip
Combined commit for Project 'Target language aware action code editors'.
1. A single squash commit for complete work on the GSoC 2014 project. 2. Incorporates eTrice recent API re-factoring. 3. Refactors code for the provided editors into separate plugin. => Contributes Extension Point for contributing Action Code Editor. 1. Contributes Action Code Editor Extension Point. 2. Contributes interfaces and abstract class for Action Code Editor. 3. Contributes an example editor(extending the provided extension point) over simple SWT Text Widget. 4. Provides class for lazy-loading the extensions. => Adds feature rich SourceViewer based Action Code Editor. 1. Adds background API similar to Platform Editor framework. - Source Viewer based in-dialog editor. - Extendible Source Viewer Configurations. - Extendible Action Code Scanner and Content Assist Processor. - Extendible Color Manager used during Syntax Highlight. - Action Code Parser and Context for model aware content assist. 2. Implements a Java Action Code editor based on the API with : - Model Aware Java Syntax Highlighting. - Model Level Content Assistance. 3. Adds command, context and keybindings for Content Assist, etc. => Adds improvements in Action Code Editor. 1. Provides Undo/Redo feature in SourceViewerActionCodeEditor. 2. Uses SourceViewerActionCodeEditor for all property dialogs. 3. Adds JavaDoc comments for main API classes. => Adds Preferences, JavaDocs and other improvements to Action Code Editor. 1. Adds Preference Page to select editor for target languages. 2. Adds extensive JavaDocs & Inline comment to classes. 3. Adds user documentation to actionCodeEditor extension point. 4. Renames files for better organization. 5. Removes Appache Commons dependency by using native API. 6. Improves Content Assist when invoked for selection. 7. Corrects insertion and selection in SourceViewerActionCodeEditor. Change-Id: I7eb214365a517339ea9468df2c06294ddd25666b Signed-off-by: Jayant Gupta <gsocjayant@gmail.com>
-rw-r--r--features/org.eclipse.etrice.feature/feature.xml7
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/xtend-gen/org/eclipse/etrice/core/ui/quickfix/DetailCodeIndentHelper.java13
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/.classpath7
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/.gitignore1
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/.project28
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/META-INF/MANIFEST.MF20
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/about.html28
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/build.properties5
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/epl-v10.html262
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/plugin.xml71
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/Activator.java69
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/GeneralActionCodeColorManager.java32
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/GeneralActionCodeScanner.java75
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditor.java38
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditorConfiguration.java126
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditorFactory.java68
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/AbstractActionCodeEditor.java86
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeAssistProcessor.java246
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeColorManager.java73
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeContext.java144
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeEditorConfiguration.java192
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeParser.java295
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeScanner.java131
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/SourceViewerActionCodeEditor.java427
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/text/TextActionCodeEditor.java75
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/text/TextActionCodeEditorFactory.java73
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF6
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/build.properties3
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/plugin.xml21
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/schema/actionCodeEditor.exsd163
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/Activator.java2
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/ActionCodeEditorRegistry.java314
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/IActionCodeEditor.java49
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/IActionCodeEditorFactory.java53
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/ActionEditorPreferencePage.java87
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/PreferenceConstants.java15
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/PreferenceInitializer.java34
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/AbstractMemberAwarePropertyDialog.java200
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/schema/actionCodeEditor.exsd163
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java127
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java124
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java7
43 files changed, 3845 insertions, 122 deletions
diff --git a/features/org.eclipse.etrice.feature/feature.xml b/features/org.eclipse.etrice.feature/feature.xml
index 1307730be..5bda6b804 100644
--- a/features/org.eclipse.etrice.feature/feature.xml
+++ b/features/org.eclipse.etrice.feature/feature.xml
@@ -412,4 +412,11 @@ http://www.eclipse.org/legal/epl-v10.html
version="0.0.0"
unpack="false"/>
+ <plugin
+ id="org.eclipse.etrice.ui.behavior.actioneditor"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>
diff --git a/plugins/org.eclipse.etrice.core.room.ui/xtend-gen/org/eclipse/etrice/core/ui/quickfix/DetailCodeIndentHelper.java b/plugins/org.eclipse.etrice.core.room.ui/xtend-gen/org/eclipse/etrice/core/ui/quickfix/DetailCodeIndentHelper.java
index 5808d5870..22a1f9b6c 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/xtend-gen/org/eclipse/etrice/core/ui/quickfix/DetailCodeIndentHelper.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/xtend-gen/org/eclipse/etrice/core/ui/quickfix/DetailCodeIndentHelper.java
@@ -9,6 +9,7 @@ import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IntegerRange;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure2;
@@ -58,7 +59,12 @@ public class DetailCodeIndentHelper {
String _xifexpression_1 = null;
if ((((lineCount).intValue() != 0) && (indentCount > 0))) {
StringConcatenation _builder = new StringConcatenation();
- _builder.append("�FOR i : (1 .. indentCount)�\t�ENDFOR�");
+ {
+ IntegerRange _upTo = new IntegerRange(1, indentCount);
+ for(final Integer i : _upTo) {
+ _builder.append("\t");
+ }
+ }
_xifexpression_1 = _builder.toString();
}
String indent = _xifexpression_1;
@@ -72,7 +78,10 @@ public class DetailCodeIndentHelper {
}
String end = _xifexpression_2;
StringConcatenation _builder_1 = new StringConcatenation();
- _builder_1.append("�front��indent��noneWSLine��end�");
+ _builder_1.append(front, "");
+ _builder_1.append(indent, "");
+ _builder_1.append(noneWSLine, "");
+ _builder_1.append(end, "");
String newEditorLine = _builder_1.toString();
newEditorLines.add(newEditorLine);
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.classpath b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.classpath
new file mode 100644
index 000000000..ad32c83a7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.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/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.gitignore b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.gitignore
new file mode 100644
index 000000000..ba077a403
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.gitignore
@@ -0,0 +1 @@
+bin
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.project b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.project
new file mode 100644
index 000000000..1275912ce
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.etrice.ui.behavior.actioneditor</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/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..c537b6306
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..6d7733a76
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/META-INF/MANIFEST.MF
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: ROOM Action Code Editor
+Bundle-SymbolicName: org.eclipse.etrice.ui.behavior.actioneditor;singleton:=true
+Bundle-Version: 0.5.0.qualifier
+Bundle-Activator: org.eclipse.etrice.ui.behavior.actioneditor.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.etrice.core.room,
+ org.eclipse.emf.common,
+ org.eclipse.etrice.core.fsm,
+ org.eclipse.jface.text,
+ org.eclipse.jdt.ui,
+ org.eclipse.etrice.ui.behavior,
+ org.eclipse.etrice.ui.behavior.fsm
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.etrice.ui.behavior.actioneditor,
+ org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer
+Bundle-Vendor: eTrice (Incubation)
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/about.html b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/about.html
new file mode 100644
index 000000000..c258ef55d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/build.properties b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/build.properties
new file mode 100644
index 000000000..e9863e281
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/epl-v10.html b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/epl-v10.html
new file mode 100644
index 000000000..9e4b628d6
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/epl-v10.html
@@ -0,0 +1,262 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>Eclipse Public License - Version 1.0</title>
+<style type="text/css">
+ body {
+ size: 8.5in 11.0in;
+ margin: 0.25in 0.5in 0.25in 0.5in;
+ tab-interval: 0.5in;
+ }
+ p {
+ margin-left: auto;
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+ }
+ p.list {
+ margin-left: 0.5in;
+ margin-top: 0.05em;
+ margin-bottom: 0.05em;
+ }
+ </style>
+
+</head>
+
+<body lang="EN-US">
+
+<p align=center><b>Eclipse Public License - v 1.0</b></p>
+
+<p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE (&quot;AGREEMENT&quot;). ANY USE, REPRODUCTION OR
+DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
+AGREEMENT.</p>
+
+<p><b>1. DEFINITIONS</b></p>
+
+<p>&quot;Contribution&quot; means:</p>
+
+<p class="list">a) in the case of the initial Contributor, the initial
+code and documentation distributed under this Agreement, and</p>
+<p class="list">b) in the case of each subsequent Contributor:</p>
+
+<p class="list">i) changes to the Program, and</p>
+<p class="list">ii) additions to the Program;</p>
+<p class="list">where such changes and/or additions to the Program
+originate from and are distributed by that particular Contributor. A
+Contribution 'originates' from a Contributor if it was added to the
+Program by such Contributor itself or anyone acting on such
+Contributor's behalf. Contributions do not include additions to the
+Program which: (i) are separate modules of software distributed in
+conjunction with the Program under their own license agreement, and (ii)
+are not derivative works of the Program.</p>
+
+<p>&quot;Contributor&quot; means any person or entity that distributes
+the Program.</p>
+
+<p>&quot;Licensed Patents&quot; mean patent claims licensable by a
+Contributor which are necessarily infringed by the use or sale of its
+Contribution alone or when combined with the Program.</p>
+
+<p>&quot;Program&quot; means the Contributions distributed in accordance
+with this Agreement.</p>
+
+<p>&quot;Recipient&quot; means anyone who receives the Program under
+this Agreement, including all Contributors.</p>
+
+<p><b>2. GRANT OF RIGHTS</b></p>
+
+<p class="list">a) Subject to the terms of this Agreement, each
+Contributor hereby grants Recipient a non-exclusive, worldwide,
+royalty-free copyright license to reproduce, prepare derivative works
+of, publicly display, publicly perform, distribute and sublicense the
+Contribution of such Contributor, if any, and such derivative works, in
+source code and object code form.</p>
+
+<p class="list">b) Subject to the terms of this Agreement, each
+Contributor hereby grants Recipient a non-exclusive, worldwide,
+royalty-free patent license under Licensed Patents to make, use, sell,
+offer to sell, import and otherwise transfer the Contribution of such
+Contributor, if any, in source code and object code form. This patent
+license shall apply to the combination of the Contribution and the
+Program if, at the time the Contribution is added by the Contributor,
+such addition of the Contribution causes such combination to be covered
+by the Licensed Patents. The patent license shall not apply to any other
+combinations which include the Contribution. No hardware per se is
+licensed hereunder.</p>
+
+<p class="list">c) Recipient understands that although each Contributor
+grants the licenses to its Contributions set forth herein, no assurances
+are provided by any Contributor that the Program does not infringe the
+patent or other intellectual property rights of any other entity. Each
+Contributor disclaims any liability to Recipient for claims brought by
+any other entity based on infringement of intellectual property rights
+or otherwise. As a condition to exercising the rights and licenses
+granted hereunder, each Recipient hereby assumes sole responsibility to
+secure any other intellectual property rights needed, if any. For
+example, if a third party patent license is required to allow Recipient
+to distribute the Program, it is Recipient's responsibility to acquire
+that license before distributing the Program.</p>
+
+<p class="list">d) Each Contributor represents that to its knowledge it
+has sufficient copyright rights in its Contribution, if any, to grant
+the copyright license set forth in this Agreement.</p>
+
+<p><b>3. REQUIREMENTS</b></p>
+
+<p>A Contributor may choose to distribute the Program in object code
+form under its own license agreement, provided that:</p>
+
+<p class="list">a) it complies with the terms and conditions of this
+Agreement; and</p>
+
+<p class="list">b) its license agreement:</p>
+
+<p class="list">i) effectively disclaims on behalf of all Contributors
+all warranties and conditions, express and implied, including warranties
+or conditions of title and non-infringement, and implied warranties or
+conditions of merchantability and fitness for a particular purpose;</p>
+
+<p class="list">ii) effectively excludes on behalf of all Contributors
+all liability for damages, including direct, indirect, special,
+incidental and consequential damages, such as lost profits;</p>
+
+<p class="list">iii) states that any provisions which differ from this
+Agreement are offered by that Contributor alone and not by any other
+party; and</p>
+
+<p class="list">iv) states that source code for the Program is available
+from such Contributor, and informs licensees how to obtain it in a
+reasonable manner on or through a medium customarily used for software
+exchange.</p>
+
+<p>When the Program is made available in source code form:</p>
+
+<p class="list">a) it must be made available under this Agreement; and</p>
+
+<p class="list">b) a copy of this Agreement must be included with each
+copy of the Program.</p>
+
+<p>Contributors may not remove or alter any copyright notices contained
+within the Program.</p>
+
+<p>Each Contributor must identify itself as the originator of its
+Contribution, if any, in a manner that reasonably allows subsequent
+Recipients to identify the originator of the Contribution.</p>
+
+<p><b>4. COMMERCIAL DISTRIBUTION</b></p>
+
+<p>Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use of
+the Program, the Contributor who includes the Program in a commercial
+product offering should do so in a manner which does not create
+potential liability for other Contributors. Therefore, if a Contributor
+includes the Program in a commercial product offering, such Contributor
+(&quot;Commercial Contributor&quot;) hereby agrees to defend and
+indemnify every other Contributor (&quot;Indemnified Contributor&quot;)
+against any losses, damages and costs (collectively &quot;Losses&quot;)
+arising from claims, lawsuits and other legal actions brought by a third
+party against the Indemnified Contributor to the extent caused by the
+acts or omissions of such Commercial Contributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement. In
+order to qualify, an Indemnified Contributor must: a) promptly notify
+the Commercial Contributor in writing of such claim, and b) allow the
+Commercial Contributor to control, and cooperate with the Commercial
+Contributor in, the defense and any related settlement negotiations. The
+Indemnified Contributor may participate in any such claim at its own
+expense.</p>
+
+<p>For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those
+performance claims and warranties, and if a court requires any other
+Contributor to pay any damages as a result, the Commercial Contributor
+must pay those damages.</p>
+
+<p><b>5. NO WARRANTY</b></p>
+
+<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED ON AN &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS
+OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
+ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
+OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement , including but not limited to
+the risks and costs of program errors, compliance with applicable laws,
+damage to or loss of data, programs or equipment, and unavailability or
+interruption of operations.</p>
+
+<p><b>6. DISCLAIMER OF LIABILITY</b></p>
+
+<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
+NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
+
+<p><b>7. GENERAL</b></p>
+
+<p>If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further action
+by the parties hereto, such provision shall be reformed to the minimum
+extent necessary to make such provision valid and enforceable.</p>
+
+<p>If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that the
+Program itself (excluding combinations of the Program with other
+software or hardware) infringes such Recipient's patent(s), then such
+Recipient's rights granted under Section 2(b) shall terminate as of the
+date such litigation is filed.</p>
+
+<p>All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of time
+after becoming aware of such noncompliance. If all Recipient's rights
+under this Agreement terminate, Recipient agrees to cease use and
+distribution of the Program as soon as reasonably practicable. However,
+Recipient's obligations under this Agreement and any licenses granted by
+Recipient relating to the Program shall continue and survive.</p>
+
+<p>Everyone is permitted to copy and distribute copies of this
+Agreement, but in order to avoid inconsistency the Agreement is
+copyrighted and may only be modified in the following manner. The
+Agreement Steward reserves the right to publish new versions (including
+revisions) of this Agreement from time to time. No one other than the
+Agreement Steward has the right to modify this Agreement. The Eclipse
+Foundation is the initial Agreement Steward. The Eclipse Foundation may
+assign the responsibility to serve as the Agreement Steward to a
+suitable separate entity. Each new version of the Agreement will be
+given a distinguishing version number. The Program (including
+Contributions) may always be distributed subject to the version of the
+Agreement under which it was received. In addition, after a new version
+of the Agreement is published, Contributor may elect to distribute the
+Program (including its Contributions) under the new version. Except as
+expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
+rights or licenses to the intellectual property of any Contributor under
+this Agreement, whether expressly, by implication, estoppel or
+otherwise. All rights in the Program not expressly granted under this
+Agreement are reserved.</p>
+
+<p>This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No party
+to this Agreement will bring a legal action under this Agreement more
+than one year after the cause of action arose. Each party waives its
+rights to a jury trial in any resulting litigation.</p>
+
+</body>
+
+</html>
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/plugin.xml b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/plugin.xml
new file mode 100644
index 000000000..c0d153cc2
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/plugin.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.etrice.ui.behavior.fsm.actionCodeEditor">
+ <editor
+ class="org.eclipse.etrice.ui.behavior.actioneditor.text.TextActionCodeEditorFactory"
+ editorName="Plain Text"
+ id="org.eclipse.etrice.ui.behavior.actioneditor.textActionCodeEditor"
+ targetLanguage="ALL">
+ </editor>
+ <editor
+ class="org.eclipse.etrice.ui.behavior.actioneditor.modelaware.ModelAwareActionCodeEditorFactory"
+ editorName="Model Aware Rich Editor"
+ id="org.eclipse.etrice.ui.behavior.actioneditor.modelAwareActionCodeEditor"
+ targetLanguage="ALL">
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.contexts">
+ <context
+ description="Context in Action Code Editor"
+ id="org.eclipse.etrice.ui.behavior.actioneditor.context"
+ name="Action Editor Context"
+ parentId="org.eclipse.ui.textEditorScope">
+ </context>
+ </extension>
+ <extension
+ point="org.eclipse.ui.bindings">
+ <key
+ commandId="org.eclipse.etrice.ui.behavior.actioneditor.contentAssist"
+ contextId="org.eclipse.etrice.ui.behavior.actioneditor.context"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+SPACE">
+ </key>
+ <key
+ commandId="org.eclipse.etrice.ui.behavior.actioneditor.undo"
+ contextId="org.eclipse.etrice.ui.behavior.actioneditor.context"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+Z">
+ </key>
+ <key
+ commandId="org.eclipse.etrice.ui.behavior.actioneditor.redo"
+ contextId="org.eclipse.etrice.ui.behavior.actioneditor.context"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+SHIFT+Z">
+ </key>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.etrice.ui.commands.category"
+ description="Content Assist Command for SourceViewerActionCodeEditor"
+ id="org.eclipse.etrice.ui.behavior.actioneditor.contentAssist"
+ name="Action Editor Content Assist">
+ </command>
+ <command
+ categoryId="org.eclipse.etrice.ui.commands.category"
+ description="Undo Command for SourceViewerActionCodeEditor"
+ id="org.eclipse.etrice.ui.behavior.actioneditor.undo"
+ name="Action Editor Undo">
+ </command>
+ <command
+ categoryId="org.eclipse.etrice.ui.commands.category"
+ description="Redo Command for SourceViewerActionCodeEditor"
+ id="org.eclipse.etrice.ui.behavior.actioneditor.redo"
+ name="Action Editor Redo">
+ </command>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/Activator.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/Activator.java
new file mode 100644
index 000000000..907ae46f9
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/Activator.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor;
+
+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.etrice.ui.behavior.actioneditor"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (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/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/GeneralActionCodeColorManager.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/GeneralActionCodeColorManager.java
new file mode 100644
index 000000000..929ed0f36
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/GeneralActionCodeColorManager.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.modelaware;
+
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.ActionCodeColorManager;
+import org.eclipse.swt.graphics.RGB;
+
+/**
+ * Color Manager for general language features for Action Code Editors.
+ *
+ * @author jayant
+ */
+public class GeneralActionCodeColorManager extends ActionCodeColorManager {
+
+ public static final RGB MULTI_LINE_COMMENT = new RGB(128, 0, 0);
+ public static final RGB SINGLE_LINE_COMMENT = new RGB(128, 0, 0);
+ public static final RGB KEYWORD = new RGB(0, 0, 128);
+ public static final RGB TYPE = new RGB(0, 0, 128);
+ public static final RGB STRING = new RGB(0, 128, 0);
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/GeneralActionCodeScanner.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/GeneralActionCodeScanner.java
new file mode 100644
index 000000000..57cf8ba34
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/GeneralActionCodeScanner.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.modelaware;
+
+import java.util.List;
+
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.ActionCodeEditorConfiguration;
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.ActionCodeScanner;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.EndOfLineRule;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WordRule;
+
+/**
+ * Extends {@link ActionCodeScanner} with rules to identify general language
+ * features.
+ *
+ * @author jayant
+ */
+public class GeneralActionCodeScanner extends ActionCodeScanner {
+
+ public GeneralActionCodeScanner(ActionCodeEditorConfiguration configuration) {
+ super(configuration);
+ }
+
+ // general language keywords
+ private static String[] fgKeywords = { "while", "for", "if", "else" };
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<IRule> computeRules(
+ ActionCodeEditorConfiguration configuration) {
+ List<IRule> rules = super.computeRules(configuration);
+
+ IToken keywordToken = new Token(new TextAttribute(configuration
+ .getColorManager().getColor(
+ GeneralActionCodeColorManager.KEYWORD)));
+ IToken stringToken = new Token(new TextAttribute(configuration
+ .getColorManager().getColor(
+ GeneralActionCodeColorManager.STRING)));
+ IToken commentToken = new Token(new TextAttribute(configuration
+ .getColorManager().getColor(
+ GeneralActionCodeColorManager.SINGLE_LINE_COMMENT)));
+
+ // Add rule for single line comments.
+ rules.add(new EndOfLineRule("//", commentToken));
+
+ // Add rule for strings.
+ rules.add(new SingleLineRule("\"", "\"", stringToken, '\\'));
+ rules.add(new SingleLineRule("'", "'", stringToken, '\\'));
+
+ // Add rule for language keywords.
+ WordRule wordRule = getWordRule();
+ for (int i = 0; i < fgKeywords.length; i++)
+ wordRule.addWord(fgKeywords[i], keywordToken);
+
+ return rules;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditor.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditor.java
new file mode 100644
index 000000000..49a0298bc
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditor.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.modelaware;
+
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.ActionCodeColorManager;
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.SourceViewerActionCodeEditor;
+
+/**
+ * An extension of the {@link SourceViewerActionCodeEditor} which configures it
+ * with a model aware configuration with general language features.
+ *
+ * @author jayant
+ */
+public class ModelAwareActionCodeEditor extends SourceViewerActionCodeEditor {
+
+ /** Color Manager for this editor's configuration */
+ private ActionCodeColorManager fColorManager;
+
+ public ModelAwareActionCodeEditor(ActorClass ac, boolean useMembers,
+ boolean useMessages, boolean useRecvMessagesOnly) {
+ super();
+ fColorManager = new ActionCodeColorManager();
+ setSourceViewerConfiguration(new ModelAwareActionCodeEditorConfiguration(
+ fColorManager, ac, useMembers, useMessages, useRecvMessagesOnly));
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditorConfiguration.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditorConfiguration.java
new file mode 100644
index 000000000..54862adf3
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditorConfiguration.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.modelaware;
+
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.ActionCodeAssistProcessor;
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.ActionCodeColorManager;
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.ActionCodeEditorConfiguration;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.ITokenScanner;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+/**
+ * An extension of {@link ActionCodeEditorConfiguration} with adds to it a model
+ * cum language(general) aware scanner and model aware content assist processor.
+ *
+ * @author jayant
+ */
+public class ModelAwareActionCodeEditorConfiguration extends
+ ActionCodeEditorConfiguration {
+
+ public ModelAwareActionCodeEditorConfiguration(
+ ActionCodeColorManager colorManager) {
+ super(colorManager);
+ }
+
+ public ModelAwareActionCodeEditorConfiguration(
+ ActionCodeColorManager colorManager, ActorClass ac) {
+ super(colorManager, ac);
+ }
+
+ public ModelAwareActionCodeEditorConfiguration(
+ ActionCodeColorManager colorManager, ActorClass ac,
+ boolean useMembers, boolean useMessages, boolean useRecvMessagesOnly) {
+ super(colorManager, ac, useMembers, useMessages, useRecvMessagesOnly);
+ }
+
+ /** token scanner for syntax highlighting */
+ private GeneralActionCodeScanner generalActionCodeScanner;
+ /** content assist processor for content assistance */
+ private ActionCodeAssistProcessor actionCodeAssistProcessor;
+
+ /**
+ * Constructs and returns an instance of the {@link ITokenScanner}. Same
+ * instance of the scanner is returned on subsequent invocations.
+ *
+ * @return the token scanner for the configuration
+ */
+ private GeneralActionCodeScanner getTokenScanner() {
+ if (generalActionCodeScanner == null) {
+ generalActionCodeScanner = new GeneralActionCodeScanner(this);
+ generalActionCodeScanner.setDefaultReturnToken(new Token(
+ new TextAttribute(getColorManager().getColor(
+ ActionCodeColorManager.DEFAULT))));
+ }
+ return generalActionCodeScanner;
+ }
+
+ /**
+ * Constructs and returns an instance of the {@link IContentAssistProcessor}
+ * . Same instance of the processor is returned on subsequent invocations.
+ *
+ * @return the content assist processor for the configuration
+ */
+ private ActionCodeAssistProcessor getContextAssistProcessor() {
+ if (actionCodeAssistProcessor == null) {
+ actionCodeAssistProcessor = new ActionCodeAssistProcessor(this);
+ }
+ return actionCodeAssistProcessor;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public IPresentationReconciler getPresentationReconciler(
+ ISourceViewer sourceViewer) {
+ PresentationReconciler reconciler = new PresentationReconciler();
+
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
+ getTokenScanner());
+ reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+
+ return reconciler;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+
+ ContentAssistant assistant = new ContentAssistant();
+ assistant.setContentAssistProcessor(getContextAssistProcessor(),
+ IDocument.DEFAULT_CONTENT_TYPE);
+ assistant.setEmptyMessage("No Proposals.");
+ assistant.enableAutoActivation(true);
+ assistant.setAutoActivationDelay(500);
+
+ return assistant;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditorFactory.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditorFactory.java
new file mode 100644
index 000000000..1d74f8104
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/modelaware/ModelAwareActionCodeEditorFactory.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.modelaware;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.ui.behavior.actioneditor.Activator;
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.SourceViewerActionCodeEditor;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditor;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditorFactory;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Factory for creation of {@link ModelAwareActionCodeEditor}.
+ *
+ * @author jayant
+ */
+public class ModelAwareActionCodeEditorFactory implements
+ IActionCodeEditorFactory {
+
+ @Override
+ public IActionCodeEditor createActionCodeEditor(DetailCode detailCode,
+ Composite parent, ModelComponent mc, boolean useMembers,
+ boolean useMessages, boolean useRecvMessagesOnly) {
+
+ SourceViewerActionCodeEditor javaActionCodeEditor = null;
+
+ if (mc instanceof ActorClass) {
+ javaActionCodeEditor = new ModelAwareActionCodeEditor(
+ (ActorClass) mc, useMembers, useMessages,
+ useRecvMessagesOnly);
+ try {
+ javaActionCodeEditor.init(detailCode);
+ } catch (CoreException e) {
+ Activator.getDefault().getLog().log(e.getStatus());
+ }
+ javaActionCodeEditor.createControl(parent);
+ } else {
+ Activator
+ .getDefault()
+ .getLog()
+ .log(new Status(Status.ERROR, Activator.PLUGIN_ID,
+ "Model Componenent " + mc.getComponentName()
+ + " is not an instance of ActorClass"));
+ }
+
+ return javaActionCodeEditor;
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/AbstractActionCodeEditor.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/AbstractActionCodeEditor.java
new file mode 100644
index 000000000..10af70f5b
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/AbstractActionCodeEditor.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditor;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Abstract implementation of the {@link IActionCodeEditor} interface. Clients
+ * need to implement the following methods:
+ * <ul>
+ * <li> {@link #init(DetailCode)}</li>
+ * <li> {@link #createControl(Composite)}</li>
+ * <li> {@link #getControl()}</li>
+ * <li> {@link #insertText(String)}</li>
+ * </ul>
+ *
+ * The lifecycle of the editor requires {@code init} method to be called before
+ * the {@code createControl} method.
+ *
+ * @author jayant
+ */
+public abstract class AbstractActionCodeEditor implements IActionCodeEditor {
+
+ protected DetailCode fDetailCode;
+
+ public AbstractActionCodeEditor() {
+ fDetailCode = null;
+ }
+
+ /**
+ * Intializes the editor with the given {@link DetailCode} object. This
+ * method must be called before the {@link #createControl(Composite)} method
+ * in the editor lifecycle.
+ *
+ * @param detailCode
+ * the {@code DetailCode} object for initializing the editor
+ * @throws CoreException
+ * if the editor cannot be initialized with the given
+ * {@code DetailCode} object
+ */
+ public abstract void init(DetailCode detailCode) throws CoreException;
+
+ /**
+ * Creates the controls of the editor within the {@code parent}
+ * {@link Composite}.
+ *
+ * @param parent
+ */
+ public abstract void createControl(Composite parent);
+
+ /**
+ * Disposes all the resources allocate by the editor.
+ */
+ public void dispose() {
+ fDetailCode = null;
+ }
+
+ @Override
+ public DetailCode getDetailCode() {
+ return fDetailCode;
+ }
+
+ /**
+ * Sets the {@link DetailCode} object to be represented by the editor.
+ *
+ * @param detailCode
+ * the DetailCode object being represented by the editor.
+ */
+ public void setDetailCode(DetailCode detailCode) {
+ fDetailCode = detailCode;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeAssistProcessor.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeAssistProcessor.java
new file mode 100644
index 000000000..2bd674062
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeAssistProcessor.java
@@ -0,0 +1,246 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+/**
+ * An Action Editor specific content assist processor. The processor lexically
+ * analyzes the Action Code using {@link ActionCodeContext} and generates
+ * proposals based on this context.
+ *
+ * @author jayant
+ */
+public class ActionCodeAssistProcessor implements IContentAssistProcessor {
+
+ /** the local reference of the associated configuration */
+ private ActionCodeEditorConfiguration fConfiguration;
+
+ public ActionCodeAssistProcessor(ActionCodeEditorConfiguration configuration) {
+ super();
+ fConfiguration = configuration;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
+ int offset) {
+ List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+
+ if (fConfiguration != null) {
+ ActionCodeContext context = createContext(viewer, offset);
+ if (context.isMethodContext()) {
+ proposals.addAll(collectMethodProposals(context));
+ } else {
+ if (fConfiguration.isMemberAware())
+ proposals.addAll(collectMemberProposals(context));
+
+ if (fConfiguration.isMessageAware())
+ proposals.addAll(collectInterfaceItemProposals(context));
+ }
+ }
+
+ return proposals.toArray(new ICompletionProposal[proposals.size()]);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public IContextInformation[] computeContextInformation(ITextViewer viewer,
+ int offset) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return new char[] { ActionCodeContext.METHOD_ITEM_SEPARATOR };
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public String getErrorMessage() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+ /**
+ * Create the {@link ActionCodeContext} object for the given invocation.
+ *
+ * @author jayant
+ */
+ protected ActionCodeContext createContext(ITextViewer viewer, int offset) {
+ ActionCodeParser parser = null;
+ if (fConfiguration != null)
+ parser = fConfiguration.getActionCodeParser();
+ return new ActionCodeContext(viewer, offset, parser);
+ }
+
+ /**
+ * Collect the proposals for method completion. These would only be
+ * generated if the Interface Item has been identified in the
+ * {@code context} and is followed by
+ * {@link ActionCodeContext#METHOD_ITEM_SEPARATOR}.
+ *
+ * @author jayant
+ *
+ * @param context
+ * the {@link ActionCodeContext} object contain the context of
+ * content assist invocation
+ * @return the collection of proposals for method completion
+ */
+ private Collection<ICompletionProposal> collectMethodProposals(
+ ActionCodeContext context) {
+ Assert.isNotNull(fConfiguration);
+
+ List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+ InterfaceItem interfaceItem = context.computeInterfaceItem();
+ if (interfaceItem != null) {
+ for (String item : fConfiguration.getActionCodeParser()
+ .getInterfaceItemMethods(interfaceItem)) {
+ ICompletionProposal proposal = createPrefixCompletionProposal(
+ context, item);
+ if (proposal != null)
+ proposals.add(proposal);
+ }
+ }
+ return proposals;
+ }
+
+ /**
+ * Collect the proposals for member name completion.
+ *
+ * @author jayant
+ *
+ * @param context
+ * the {@link ActionCodeContext} object contain the context of
+ * content assist invocation
+ * @return the collection of proposals for member name completion
+ */
+ private Collection<ICompletionProposal> collectMemberProposals(
+ ActionCodeContext context) {
+ Assert.isNotNull(fConfiguration);
+
+ List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+ for (String item : fConfiguration.getActionCodeParser()
+ .getAllMemberNames()) {
+ ICompletionProposal proposal = createPrefixCompletionProposal(
+ context, item);
+ if (proposal != null)
+ proposals.add(proposal);
+ }
+ return proposals;
+ }
+
+ /**
+ * Collect the proposals for Interface Item name completion.
+ *
+ * @author jayant
+ *
+ * @param context
+ * the {@link ActionCodeContext} object contain the context of
+ * content assist invocation
+ * @return the collection of proposals for Interface Item name completion.
+ */
+ private Collection<ICompletionProposal> collectInterfaceItemProposals(
+ ActionCodeContext context) {
+ Assert.isNotNull(fConfiguration);
+
+ List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+
+ for (String item : fConfiguration.getActionCodeParser()
+ .getAllInterfaceItemNamesWithIndex()) {
+ ICompletionProposal proposal = createPrefixCompletionProposal(
+ context, item);
+ if (proposal != null)
+ proposals.add(proposal);
+ }
+ return proposals;
+ }
+
+ /**
+ * Utility method for creating proposals given {@code context} and the
+ * possible completion string. The proposal is generated only if the
+ * character sequence to be completed is a prefix of the {@code completion}
+ * string.
+ *
+ * @author jayant
+ *
+ * @param context
+ * the {@link ActionCodeContext} object contain the context of
+ * content assist invocation
+ * @param completion
+ * the completion string
+ * @return completion proposal
+ */
+ private static ICompletionProposal createPrefixCompletionProposal(
+ ActionCodeContext context, String completion) {
+
+ String prefix = context.getPrefix();
+ if (completion.startsWith(prefix))
+ // replaces the incomplete prefix + selected range with the
+ // completion string
+ return new CompletionProposal(completion,
+ context.getInvocationOffset() - prefix.length(),
+ prefix.length() + context.getViewer().getSelectedRange().y,
+ completion.length());
+
+ return null;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeColorManager.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeColorManager.java
new file mode 100644
index 000000000..22475bb1d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeColorManager.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Manages SWT color objects for the given {@code RGB} objects. Until the
+ * {@link #dispose()} method is called, the same color object is returned for
+ * equal {@code RGB} values.
+ * <p>
+ * This class may be sub-classed.
+ * </p>
+ *
+ * @author jayant
+ */
+public class ActionCodeColorManager {
+
+ /** RGB object for member color */
+ public static final RGB MEMBER = new RGB(128, 128, 0);
+ /** RGB object for interface item color */
+ public static final RGB INTERFACE_ITEM = new RGB(0, 0, 128);
+ /** Default RGB color object */
+ public static final RGB DEFAULT = new RGB(0, 0, 0);
+
+ /** Local cache mapping {@link RGB} values with {@link Color} Objects */
+ protected Map<RGB, Color> fColorTable = new HashMap<RGB, Color>(10);
+
+ /**
+ * Disposes the cached {@link Color} objects by this Color Manager.
+ */
+ public void dispose() {
+ Iterator<Color> e = fColorTable.values().iterator();
+ while (e.hasNext())
+ (e.next()).dispose();
+ }
+
+ /**
+ * Gets the SWT {@link Color} object given the {@link RGB} value. The method
+ * internally caches the {@code Color} objects to save system resources.
+ *
+ * @author jayant
+ *
+ * @param rgb
+ * the {@code RGB} object of the color
+ * @return the SWT {@code Color} object for the color
+ */
+ public Color getColor(RGB rgb) {
+ Color color = (Color) fColorTable.get(rgb);
+ if (color == null) {
+ color = new Color(Display.getCurrent(), rgb);
+ fColorTable.put(rgb, color);
+ }
+ return color;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeContext.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeContext.java
new file mode 100644
index 000000000..8831c1e38
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeContext.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer;
+
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+
+/**
+ * A class for maintaining the current context during Content Assistance in
+ * Action Code Editor. Helps in identifying the completion context (method or
+ * InterafceItem/member) and also the {@link InterfaceItem} on which the assist
+ * is invoked.
+ *
+ * @author jayant
+ */
+public class ActionCodeContext extends ContentAssistInvocationContext {
+
+ /** the character separating the method name and the interface item */
+ public static final char METHOD_ITEM_SEPARATOR = '.';
+
+ /** the associated interface item */
+ private InterfaceItem fInterfaceItem;
+ /** the action code parser object for getting the list of items */
+ private ActionCodeParser fActionCodeParser;
+ /** is method completion required or InterafceItem/member completion */
+ private boolean methodContext;
+
+ public ActionCodeContext(ActionCodeParser detailedCodeParser) {
+ super();
+ fInterfaceItem = null;
+ methodContext = false;
+ this.fActionCodeParser = detailedCodeParser;
+ }
+
+ public ActionCodeContext(IDocument document, int offset,
+ ActionCodeParser detailedCodeParser) {
+ super(document, offset);
+ this.fActionCodeParser = detailedCodeParser;
+ }
+
+ public ActionCodeContext(ITextViewer viewer, int offset,
+ ActionCodeParser detailedCodeParser) {
+ super(viewer, offset);
+ this.fActionCodeParser = detailedCodeParser;
+ }
+
+ public ActionCodeContext(ITextViewer viewer,
+ ActionCodeParser detailedCodeParser) {
+ super(viewer);
+ this.fActionCodeParser = detailedCodeParser;
+ }
+
+ /**
+ * Compute the {@link InterfaceItem} for the invocation offset.
+ *
+ * @return the associated interface item. Returns {@code null} is no
+ * interface item associated with the invocation.
+ */
+ public InterfaceItem computeInterfaceItem() {
+
+ if (fInterfaceItem == null) {
+ if (fActionCodeParser == null)
+ return null;
+
+ int newOffset;
+ try {
+ // get the position of character just before the prefix to be
+ // complete.
+ newOffset = getInvocationOffset()
+ - computeIdentifierPrefix().length() - 1;
+
+ // if the character is method separator, then proceed with
+ // identification of interafecItem.
+ if (getDocument().getChar(newOffset) == METHOD_ITEM_SEPARATOR) {
+ // method completion is required
+ methodContext = true;
+
+ // use context API to get the interface name.
+ ContentAssistInvocationContext context = new ContentAssistInvocationContext(
+ getViewer(), newOffset);
+ fInterfaceItem = fActionCodeParser
+ .getInterfaceItemfromName(context
+ .computeIdentifierPrefix().toString());
+ }
+ } catch (BadLocationException e) {
+ fInterfaceItem = null;
+ }
+ }
+ return fInterfaceItem;
+ }
+
+ /**
+ * Returns whether the required completion is for a method.
+ *
+ * @return true if the method completion is required
+ */
+ public boolean isMethodContext() {
+ computeInterfaceItem();
+ return methodContext;
+ }
+
+ /**
+ * Gets the string of the invocation context which need to be completed.
+ *
+ * @return the string to be completed (prefix for completion)
+ */
+ public String getPrefix() {
+ String prefix;
+ try {
+ prefix = computeIdentifierPrefix().toString();
+ } catch (BadLocationException e) {
+ prefix = "";
+ }
+ return prefix;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @author jayant
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (super.equals(obj) && obj instanceof ActionCodeContext) {
+ ActionCodeContext other = (ActionCodeContext) obj;
+ return fInterfaceItem.equals(other.fInterfaceItem);
+ }
+ return false;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeEditorConfiguration.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeEditorConfiguration.java
new file mode 100644
index 000000000..2f9f4fc27
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeEditorConfiguration.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+
+/**
+ * A model aware configuration for the {@link SourceViewerActionCodeEditor}.
+ * Setters within this class could only be invoked before configuring the
+ * {@link SourceViewer} with this configuration.
+ *
+ * @author jayant
+ */
+public class ActionCodeEditorConfiguration extends SourceViewerConfiguration {
+
+ /** the actor class */
+ private ActorClass fActorClass;
+ /** use members */
+ private boolean fMemberAware;
+ /** use messages or operations */
+ private boolean fMessageAware;
+ /** use receive messages only */
+ private boolean fRecvMessagesOnly;
+ /** parser for Action Code of the associated actor class */
+ private ActionCodeParser parser;
+
+ /** Color Manager for action code editor */
+ private ActionCodeColorManager fColorManager;
+
+ public ActionCodeEditorConfiguration(ActionCodeColorManager colorManager) {
+ fColorManager = colorManager;
+ fActorClass = null;
+ fMemberAware = false;
+ fMessageAware = false;
+ fRecvMessagesOnly = false;
+ }
+
+ public ActionCodeEditorConfiguration(ActionCodeColorManager colorManager,
+ ActorClass ac) {
+ super();
+ fActorClass = ac;
+ fColorManager = colorManager;
+ fMemberAware = true;
+ fMessageAware = true;
+ fRecvMessagesOnly = false;
+ }
+
+ public ActionCodeEditorConfiguration(ActionCodeColorManager colorManager,
+ ActorClass ac, boolean useMembers, boolean useMessages,
+ boolean useRecvMessagesOnly) {
+ super();
+ fActorClass = ac;
+ fColorManager = colorManager;
+ fMemberAware = useMembers;
+ fMessageAware = useMessages;
+ fRecvMessagesOnly = useRecvMessagesOnly;
+ }
+
+ /**
+ * Getter for actor class.
+ *
+ * @return the associated actor class
+ */
+ public ActorClass getActorClass() {
+ return fActorClass;
+ }
+
+ /**
+ * Getter for use members.
+ *
+ * @return true if configuration is member aware else false
+ */
+ public boolean isMemberAware() {
+ return fMemberAware;
+ }
+
+ /**
+ * Getter for use messages.
+ *
+ * @return true if configuration is message aware else false
+ */
+ public boolean isMessageAware() {
+ return fMessageAware;
+ }
+
+ /**
+ * Getter for use receive only messages.
+ *
+ * @return true if configuration handles only receive only messages else
+ * false
+ */
+ public boolean isRecvOnly() {
+ return fRecvMessagesOnly;
+ }
+
+ /**
+ * Getter for internal action code parser for the associated actor class.
+ *
+ * @return the parser for action code of the associated actor class
+ */
+ public ActionCodeParser getActionCodeParser() {
+ if (parser == null)
+ parser = new ActionCodeParser(fActorClass, fRecvMessagesOnly);
+ return parser;
+ }
+
+ /**
+ * Getter for color manager.
+ *
+ * @return the color manager for action code
+ */
+ public ActionCodeColorManager getColorManager() {
+ if (fColorManager == null)
+ fColorManager = new ActionCodeColorManager();
+ return fColorManager;
+ }
+
+ /**
+ * Setter for actor class. Invalidates the internal action code parser.
+ *
+ * @param ac
+ * the Actor Class to associate to.
+ */
+ public void setActorClass(ActorClass ac) {
+ if (!ac.equals(fActorClass)) {
+ fActorClass = ac;
+ parser = null;
+ }
+ }
+
+ /**
+ * Setter for use members.
+ *
+ * @param useMembers
+ * true to make configuration member aware
+ */
+ public void setMemberAware(boolean useMembers) {
+ fMemberAware = useMembers;
+ }
+
+ /**
+ * Setter for use messages.
+ *
+ * @param useMessages
+ * true to make configuration message & operation aware
+ */
+ public void setMessageAware(boolean useMessages) {
+ fMessageAware = useMessages;
+ }
+
+ /**
+ * Setter for use receive messages only. Invalidates the internal action
+ * code parser.
+ *
+ * @param useRecvMessagesOnly
+ * true to use receive messages only
+ */
+ public void setRecvOnly(boolean useRecvMessagesOnly) {
+ if (useRecvMessagesOnly != fRecvMessagesOnly) {
+ fRecvMessagesOnly = useRecvMessagesOnly;
+
+ // Only invalidate parser if the configuration is message aware.
+ if (fMessageAware)
+ parser = null;
+ }
+ }
+
+ /**
+ * Setter for action code Color Manager.
+ *
+ * @param colorManager
+ * the color manager to use
+ */
+ public void setColorManager(ActionCodeColorManager colorManager) {
+ Assert.isNotNull(colorManager);
+ fColorManager = colorManager;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeParser.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeParser.java
new file mode 100644
index 000000000..a0c011128
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeParser.java
@@ -0,0 +1,295 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.CommunicationType;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.Operation;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.PortClass;
+import org.eclipse.etrice.core.room.PortOperation;
+import org.eclipse.etrice.core.room.StandardOperation;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.ui.behavior.support.SupportUtil;
+
+/**
+ * A parser for action code of an actor class. Internally constructs a
+ * collection of all member objects and a collection for all available and
+ * {@code InterfaceItems} mapped to the possible messages or operations.
+ *
+ * @author jayant
+ */
+public class ActionCodeParser {
+
+ /** the actor class */
+ ActorClass ac;
+ /** use receive only messages */
+ boolean recvOnly;
+ /** map for interface items and associated messages or operations */
+ HashMap<InterfaceItem, List<MethodItemPair>> item2pairs;
+ /** array of objects for members */
+ Object[] members;
+
+ public ActionCodeParser(ActorClass ac, boolean recvOnly) {
+ this.ac = ac;
+ this.recvOnly = recvOnly;
+ }
+
+ /**
+ * Class for representing a pair of Interface Item and an associated method.
+ *
+ * @author jayant
+ */
+ public static class MethodItemPair {
+ InterfaceItem item;
+
+ public MethodItemPair(InterfaceItem item) {
+ super();
+ this.item = item;
+ }
+ }
+
+ /**
+ * Class for representing a pair of Interface Item and an associated
+ * message.
+ *
+ * @author jayant
+ */
+ public static class MsgItemPair extends MethodItemPair {
+ Message msg;
+ boolean out;
+
+ public MsgItemPair(InterfaceItem item, Message msg, boolean out) {
+ super(item);
+ this.msg = msg;
+ this.out = out;
+ }
+ }
+
+ /**
+ * Class for representing a pair of Interface Item and an associated
+ * operation.
+ *
+ * @author jayant
+ */
+ public static class OperationItemPair extends MethodItemPair {
+ PortOperation op;
+
+ public OperationItemPair(InterfaceItem item, PortOperation op) {
+ super(item);
+ this.op = op;
+ }
+ }
+
+ /**
+ * Constructs the map of Interface Items and the list of associated methods
+ * in the associated actor class.
+ *
+ * @return a HashMap of {@link InterfaceItem}s mapped to an List of
+ * {@link MethodItemPair}
+ */
+ public HashMap<InterfaceItem, List<MethodItemPair>> getInterfaceItemMethodMap() {
+
+ if (item2pairs == null) {
+ item2pairs = new HashMap<InterfaceItem, List<MethodItemPair>>();
+
+ RoomHelpers roomHelpers = SupportUtil.getInstance()
+ .getRoomHelpers();
+ List<InterfaceItem> items = roomHelpers.getAllInterfaceItems(ac);
+ for (InterfaceItem item : items) {
+ ArrayList<MethodItemPair> pairs = new ArrayList<MethodItemPair>();
+ List<Message> out = roomHelpers.getMessageListDeep(item, true);
+ if (!recvOnly) {
+ for (Message msg : out) {
+ if (!msg.isPriv())
+ pairs.add(new MsgItemPair(item, msg, true));
+ }
+ }
+ if (roomHelpers.getProtocol(item).getCommType() == CommunicationType.DATA_DRIVEN) {
+ List<Message> in = roomHelpers.getMessageListDeep(item,
+ false);
+ for (Message msg : in) {
+ if (!msg.isPriv())
+ pairs.add(new MsgItemPair(item, msg, false));
+ }
+ }
+ PortClass pcls = roomHelpers.getPortClass(item);
+ if (pcls != null) {
+ for (PortOperation op : pcls.getOperations()) {
+ if (op.getSendsMsg() != null)
+ pairs.add(new OperationItemPair(item, op));
+ }
+ for (PortOperation op : pcls.getOperations()) {
+ if (op.getSendsMsg() == null)
+ pairs.add(new OperationItemPair(item, op));
+ }
+ }
+ item2pairs.put(item, pairs);
+ }
+ }
+ return item2pairs;
+ }
+
+ /**
+ * Gets the list of all interface items in the associated actor class.
+ *
+ * @return list of {@link InterfaceItem}s
+ */
+ public List<InterfaceItem> getAllInterfaceItems() {
+ return new ArrayList<InterfaceItem>(item2pairs.keySet());
+ }
+
+ /**
+ * Constructs an array of members in the associated actor class.
+ *
+ * @return array of members
+ */
+ public Object[] getMembers() {
+ if (members == null) {
+ EList<Attribute> attributes = ac.getAttributes();
+ EList<StandardOperation> operations = ac.getOperations();
+
+ members = new Object[attributes.size() + operations.size()];
+ System.arraycopy(attributes.toArray(), 0, members, 0,
+ attributes.size());
+ System.arraycopy(operations.toArray(), 0, members,
+ attributes.size(), operations.size());
+ }
+
+ return members;
+ }
+
+ /**
+ * Gets the list of the names of all {@link InterfaceItem} in the associated
+ * actor class.
+ *
+ * @return list of names of all Interface Items.
+ */
+ public List<String> getAllInterfaceItemNames() {
+ List<String> interfaceItemList = new ArrayList<String>();
+ for (InterfaceItem interfaceItem : getInterfaceItemMethodMap().keySet()) {
+ interfaceItemList.add(interfaceItem.getName());
+ }
+ return interfaceItemList;
+ }
+
+ /**
+ * Gets the list of the names of all {@link InterfaceItem} in the associated
+ * actor class with index, i.e. the name includes an [index] bracket if an
+ * interface item is a {@link Port} and has a multiplicity greater than 1.
+ *
+ * @return list of names of all Interface Items along with index, if
+ * required
+ */
+ public List<String> getAllInterfaceItemNamesWithIndex() {
+ List<String> interfaceItemList = new ArrayList<String>();
+ for (InterfaceItem interfaceItem : getInterfaceItemMethodMap().keySet()) {
+ String index = "";
+ if (interfaceItem instanceof Port
+ && ((Port) interfaceItem).getMultiplicity() != 1)
+ index = "[idx]";
+ interfaceItemList.add(interfaceItem.getName() + index);
+ }
+ return interfaceItemList;
+ }
+
+ /**
+ * Gets a list of the name of all members in the associated actor class.
+ *
+ * @return list of member names
+ */
+ public List<String> getAllMemberNames() {
+ List<String> memberList = new ArrayList<String>();
+ for (Object member : getMembers()) {
+ if (member instanceof Attribute)
+ memberList.add(((Attribute) member).getName());
+ else if (member instanceof Operation)
+ memberList.add(((Operation) member).getName()
+ + SupportUtil.getInstance().getRoomNameProvider()
+ .getTypedArgumentList((Operation) member));
+ }
+ return memberList;
+ }
+
+ /**
+ * Find the interface item with the given name.
+ *
+ * @param itemName
+ * the name of the interface item
+ * @return the {@link InterfaceItem} object with the given name. Returns
+ * {@code null} if no such Interface Item.
+ */
+ public InterfaceItem getInterfaceItemfromName(String itemName) {
+ for (InterfaceItem interfaceItem : item2pairs.keySet()) {
+ if (interfaceItem.getName().equals(itemName))
+ return interfaceItem;
+ }
+ return null;
+ }
+
+ /**
+ * Gets the list of method names(messages & operations) along with the
+ * arguments(data) for the given {@link InterfaceItem}.
+ *
+ * @param interfaceItem
+ * the interface item
+ * @return the list of methods
+ */
+ public List<String> getInterfaceItemMethods(InterfaceItem interfaceItem) {
+ List<String> methodList = new ArrayList<String>();
+ for (MethodItemPair method : item2pairs.get(interfaceItem)) {
+ if (method != null) {
+ String methodString = null;
+ if (method instanceof MsgItemPair) {
+ MsgItemPair pair = (MsgItemPair) method;
+ if (pair.out) {
+ String data = pair.msg.getData() != null ? pair.msg
+ .getData().getName() : "";
+ methodString = pair.msg.getName() + "(" + data + ")";
+ } else
+ methodString = pair.msg.getName();
+ } else if (method instanceof OperationItemPair) {
+ OperationItemPair pair = (OperationItemPair) method;
+ String arglist = SupportUtil.getInstance()
+ .getRoomNameProvider().getArguments(pair.op);
+ methodString = pair.op.getName() + arglist;
+ }
+ if (methodString != null)
+ methodList.add(methodString);
+ }
+ }
+ return methodList;
+ }
+
+ /**
+ * Gets the list of method names(messages & operations) along with the
+ * arguments(data) for the given {@link InterfaceItem} name. Returns an
+ * empty list if no interface item with given name.
+ *
+ * @param interfaceItem
+ * the interface item name
+ * @return the list of methods
+ */
+ public List<String> getInterfaceItemMethods(String interfaceItemName) {
+ return getInterfaceItemMethods(getInterfaceItemfromName(interfaceItemName));
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeScanner.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeScanner.java
new file mode 100644
index 000000000..ff20e819a
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/ActionCodeScanner.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WordRule;
+
+/**
+ * A extension of the {@link RuleBasedScanner} for
+ * {@link ActionCodeEditorConfiguration}. Sets up rules for identifying and
+ * associating tokens with Members and InterfaceItems.
+ * <p>
+ * Sub-classes may override {@link #computeRules(ActionCodeEditorConfiguration)}
+ * to supply new rules or add to the given rules.
+ * </p>
+ *
+ * @author jayant
+ *
+ */
+public class ActionCodeScanner extends RuleBasedScanner {
+
+ /** the default word rule for the scanner */
+ WordRule wordRule;
+
+ public ActionCodeScanner(ActionCodeEditorConfiguration configuration) {
+ // form an instance of the WordRule
+ IToken defaultToken = new Token(new TextAttribute(configuration
+ .getColorManager().getColor(ActionCodeColorManager.DEFAULT)));
+ wordRule = formWordRule(defaultToken);
+
+ List<IRule> rules = computeRules(configuration);
+ setRules(rules.toArray(new IRule[rules.size()]));
+ }
+
+ /**
+ * Computes and returns a list({@code not null}) of rules for this scanner.
+ * <p>
+ * Sub-classes may override. To add new rules, append the list supplied by
+ * the superclass. To add new words to the default {@link WordRule}, the
+ * reference of the wordRule could be obtained with {@link #getWordRule()}
+ * method.
+ * </p>
+ *
+ * @param configuration
+ * the {@link ActionCodeEditorConfiguration} for this scanner
+ * @return the list of rules formed
+ */
+ protected List<IRule> computeRules(
+ ActionCodeEditorConfiguration configuration) {
+ IToken memberToken = new Token(new TextAttribute(configuration
+ .getColorManager().getColor(ActionCodeColorManager.MEMBER)));
+ IToken interfaceItemToken = new Token(new TextAttribute(configuration
+ .getColorManager().getColor(
+ ActionCodeColorManager.INTERFACE_ITEM)));
+
+ List<IRule> rules = new ArrayList<IRule>();
+
+ // Add words to wordRule for each Interface Item names.
+ if (configuration.isMessageAware())
+ for (String item : configuration.getActionCodeParser()
+ .getAllInterfaceItemNames())
+ wordRule.addWord(item, interfaceItemToken);
+
+ // Add word to wordRule rule for each Member names.
+ if (configuration.isMemberAware())
+ for (String member : configuration.getActionCodeParser()
+ .getAllMemberNames())
+ wordRule.addWord(member, memberToken);
+
+ // Add wordRule to the list of rules.
+ rules.add(wordRule);
+
+ return rules;
+ }
+
+ /**
+ * Forms the default {@link WordRule} given the defaultToken.
+ * <p>
+ * Subclasses may override to customize the formation of the default Word
+ * Rule.
+ * </p>
+ *
+ * @param defaultToken
+ * the default token to be associated with the word rule
+ * @return the constructed WordRule instance.
+ */
+ protected WordRule formWordRule(IToken defaultToken) {
+ WordRule wordRule = new WordRule(new IWordDetector() {
+
+ @Override
+ public boolean isWordStart(char c) {
+ return Character.isJavaIdentifierStart(c);
+ }
+
+ @Override
+ public boolean isWordPart(char c) {
+ return Character.isJavaIdentifierPart(c);
+ }
+ }, defaultToken);
+
+ return wordRule;
+ }
+
+ /**
+ * Get the default {@link WordRule}.
+ *
+ * @return the default word rule.
+ */
+ public WordRule getWordRule() {
+ return wordRule;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/SourceViewerActionCodeEditor.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/SourceViewerActionCodeEditor.java
new file mode 100644
index 000000000..dc47d9546
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/sourceviewer/SourceViewerActionCodeEditor.java
@@ -0,0 +1,427 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.etrice.ui.behavior.actioneditor.Activator;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditor;
+import org.eclipse.etrice.ui.behavior.support.SupportUtil;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextOperationTarget;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.contexts.IContextActivation;
+import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
+
+/**
+ * An Implementation of the {@link IActionCodeEditor} interface using the JFace
+ * {@link SourceViewer}.
+ * <p>
+ * Sub-classes may supply a custom {@link SourceViewerConfiguration} using the
+ * {@link #setSourceViewerConfiguration(SourceViewerConfiguration)} method and a
+ * custom {@link Document} creation methodology using the
+ * {@link #createDocument(DetailCode)} method.
+ * </p>
+ *
+ * @author jayant
+ */
+public class SourceViewerActionCodeEditor extends AbstractActionCodeEditor {
+
+ /**
+ * An {@link IHandler} implementation for handling the Operations in this
+ * editor.
+ *
+ * @author jayant
+ *
+ */
+ public class ActionCodeHandler extends AbstractHandler {
+
+ int fOperation;
+
+ public ActionCodeHandler(int operation) {
+ fOperation = operation;
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ fSourceViewer.getTextOperationTarget().doOperation(fOperation);
+ return null;
+ }
+ }
+
+ public static final String CONTENT_ASSIST_COMMAND_ID = "org.eclipse.etrice.ui.behavior.actioneditor.contentAssist";
+ public static final String UNDO_COMMAND_ID = "org.eclipse.etrice.ui.behavior.actioneditor.undo";
+ public static final String REDO_COMMAND_ID = "org.eclipse.etrice.ui.behavior.actioneditor.redo";
+
+ /**
+ * The Id of custom context for the Action Code Editor Key-bindings for
+ * commands
+ */
+ public static final String ACTION_EDITOR_CONTEXT_ID = "org.eclipse.etrice.ui.behavior.actioneditor.context";
+
+ /** The editor's source viewer. */
+ private ISourceViewer fSourceViewer;
+ /** The editor's source viewer configuration. */
+ private SourceViewerConfiguration fConfiguration;
+ /** The editor's document. */
+ private IDocument fDocument;
+
+ /** The activation context Token for Action Editor Context */
+ protected IContextActivation fActivation;
+ /** The collection of all active handler tokens */
+ protected Map<String, IHandlerActivation> activatedHandlers;
+
+ /**
+ * Getter for the editor's document.
+ *
+ * @return the {@link IDocument} instance of the editor
+ */
+ public IDocument getDocument() {
+ return fDocument;
+ }
+
+ /**
+ * Returns the editor's source viewer configuration. May return
+ * <code>null</code> before the editor's part has been created and after
+ * disposal.
+ *
+ * @return the editor's source viewer configuration which may be
+ * <code>null</code>
+ */
+ public final SourceViewerConfiguration getSourceViewerConfiguration() {
+ return fConfiguration;
+ }
+
+ /**
+ * Returns the editor's source viewer. May return <code>null</code> before
+ * the editor's part has been created and after disposal.
+ *
+ * @return the editor's source viewer which may be <code>null</code>
+ */
+ public final ISourceViewer getSourceViewer() {
+ return fSourceViewer;
+ }
+
+ /**
+ * Sets this editor's source viewer configuration used to configure its
+ * internal source viewer. This method must be called before the editor's
+ * control is created. If not, this editor uses a
+ * <code>SourceViewerConfiguration</code>.
+ *
+ * @param configuration
+ * the source viewer configuration object
+ */
+ protected void setSourceViewerConfiguration(
+ SourceViewerConfiguration configuration) {
+ Assert.isNotNull(configuration);
+ fConfiguration = configuration;
+ }
+
+ /**
+ * Creates the document for the given Detailed Code.
+ * <p>
+ * Subclasses may implement this method.
+ * </p>
+ *
+ * @param detailCode
+ * the {@link DetailCode} object to be represented.
+ * @return the document being created.
+ */
+ protected IDocument createDocument(DetailCode detailCode)
+ throws CoreException {
+ IDocument document = new Document();
+ document.set(SupportUtil.getInstance().getRoomHelpers()
+ .getDetailCode(detailCode));
+ return document;
+ };
+
+ /**
+ * Creates the source viewer to be used by this editor. Subclasses may
+ * re-implement this method.
+ *
+ * @param parent
+ * the parent control
+ * @param ruler
+ * the vertical ruler
+ * @param styles
+ * style bits, <code>SWT.WRAP</code> is currently not supported
+ * @return the source viewer
+ */
+ protected ISourceViewer createSourceViewer(Composite parent,
+ IVerticalRuler ruler, int styles) {
+ return new SourceViewer(parent, ruler, styles);
+ }
+
+ /**
+ * Returns whether the editor is editable or not.
+ *
+ * @return true if editor is editable else false.
+ */
+ public boolean isEditable() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * Sub-classes overriding this should call
+ * {@link #doSetDetailCode(DetailCode)}.
+ * </p>
+ */
+ @Override
+ public void init(DetailCode detailCode) throws CoreException {
+ doSetDetailCode(detailCode);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void createControl(Composite parent) {
+ int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER
+ | SWT.FULL_SELECTION;
+ fSourceViewer = createSourceViewer(parent, null, styles);
+
+ if (fConfiguration == null)
+ fConfiguration = new SourceViewerConfiguration();
+ fSourceViewer.configure(fConfiguration);
+
+ StyledText styledText = fSourceViewer.getTextWidget();
+
+ // Focus listener to activate and deactivate context
+ styledText.addFocusListener(new FocusListener() {
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ // Deactivate context when focus lost
+ deactivateContext();
+ }
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ // Activate context when focus gained
+ activateContext();
+ }
+ });
+
+ // Dispose listener to dispose resources
+ styledText.addDisposeListener(new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ dispose();
+ }
+ });
+
+ // Disable orientation switching
+ styledText.addListener(SWT.OrientationChange, new Listener() {
+ public void handleEvent(Event event) {
+ event.doit = false;
+ }
+ });
+
+ initializeSourceViewer(getDetailCode());
+
+ getControl()
+ .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setDetailCode(DetailCode detailCode) {
+ try {
+ doSetDetailCode(detailCode);
+ } catch (CoreException e) {
+ Activator.getDefault().getLog().log(e.getStatus());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Control getControl() {
+ return fSourceViewer.getTextWidget();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void insertText(String text) {
+ if (fSourceViewer != null && fSourceViewer.getTextWidget() != null) {
+ int braceBegin = text.indexOf('(');
+ int braceEnd = text.indexOf(')');
+
+ int offset = fSourceViewer.getSelectedRange().x;
+ int length = fSourceViewer.getSelectedRange().y;
+
+ try {
+ fDocument.replace(offset, length, text);
+ } catch (BadLocationException e) {
+ }
+ if (braceBegin >= 0 && braceEnd >= 0 && braceEnd > braceBegin + 1)
+ fSourceViewer.setSelectedRange(offset + braceBegin + 1,
+ braceEnd - braceBegin - 1);
+ fSourceViewer.getTextWidget().setFocus();
+ }
+ }
+
+ /**
+ * Method which actually sets the detailed code. This is called by
+ * {@link #init(DetailCode)} as well as by
+ * {@link #setDetailCode(DetailCode)} method.
+ *
+ * @param detailCode
+ * the {code DetailCode} to be set
+ * @throws CoreException
+ * if the {code detailCode} could not be set
+ */
+ protected void doSetDetailCode(DetailCode detailCode) throws CoreException {
+ super.setDetailCode(detailCode);
+ fDocument = createDocument(detailCode);
+ if (fSourceViewer != null) {
+ initializeSourceViewer(detailCode);
+ }
+ }
+
+ /**
+ * Initializes the editor's source viewer based on the given detailed Code.
+ *
+ * @param detailCode
+ * the detailed Code to be used to initialize the source viewer
+ */
+ private void initializeSourceViewer(DetailCode detailCode) {
+
+ if (fDocument != null) {
+ fSourceViewer.setDocument(fDocument, null);
+ fSourceViewer.setEditable(isEditable());
+ fSourceViewer.showAnnotations(false);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void dispose() {
+ deactivateContext();
+
+ fDocument = null;
+ fSourceViewer = null;
+ fConfiguration = null;
+
+ super.dispose();
+ }
+
+ /**
+ * Activates ActionEditor context and attaches handlers with the Editor's
+ * commands.
+ */
+ protected void activateContext() {
+ IContextService contextService = (IContextService) PlatformUI
+ .getWorkbench().getService(IContextService.class);
+ if (contextService != null)
+ fActivation = contextService
+ .activateContext(ACTION_EDITOR_CONTEXT_ID);
+
+ activateHandler(CONTENT_ASSIST_COMMAND_ID,
+ ISourceViewer.CONTENTASSIST_PROPOSALS);
+ activateHandler(UNDO_COMMAND_ID, ITextOperationTarget.UNDO);
+ activateHandler(REDO_COMMAND_ID, ITextOperationTarget.REDO);
+ }
+
+ /**
+ * Deactivate editors context and command handlers.
+ */
+ protected void deactivateContext() {
+ IContextService contextService = (IContextService) PlatformUI
+ .getWorkbench().getService(IContextService.class);
+ if (contextService != null)
+ contextService.deactivateContext(fActivation);
+
+ IHandlerService handlerService = (IHandlerService) PlatformUI
+ .getWorkbench().getService(IHandlerService.class);
+ if (handlerService != null && activatedHandlers != null) {
+ handlerService.deactivateHandlers(activatedHandlers.values());
+ activatedHandlers = null;
+ }
+ }
+
+ /**
+ * Create and activate a new handler for the command with given
+ * {@code commandId} to execute the given {@code operation}.
+ *
+ * @param commandId
+ * the Id of the command
+ * @param operation
+ * the operation code for the required operation to be performed
+ */
+ protected void activateHandler(String commandId, int operation) {
+ IHandlerService handlerService = (IHandlerService) PlatformUI
+ .getWorkbench().getService(IHandlerService.class);
+ if (handlerService != null) {
+ IHandlerActivation contentAssistHandlerActivation = handlerService
+ .activateHandler(commandId,
+ new ActionCodeHandler(operation));
+ if (activatedHandlers == null)
+ activatedHandlers = new HashMap<String, IHandlerActivation>();
+ activatedHandlers.put(commandId, contentAssistHandlerActivation);
+ }
+ }
+
+ /**
+ * Deactivate handler for the given command.
+ *
+ * @param commandId
+ * the Id of the command.
+ */
+ protected void deactivateHandler(String commandId) {
+ IHandlerService handlerService = (IHandlerService) PlatformUI
+ .getWorkbench().getService(IHandlerService.class);
+ if (handlerService != null && activatedHandlers != null) {
+ handlerService.deactivateHandler(activatedHandlers.get(commandId));
+ activatedHandlers.remove(commandId);
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/text/TextActionCodeEditor.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/text/TextActionCodeEditor.java
new file mode 100644
index 000000000..6318d54a1
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/text/TextActionCodeEditor.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.text;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.etrice.ui.behavior.actioneditor.sourceviewer.AbstractActionCodeEditor;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditor;
+import org.eclipse.etrice.ui.behavior.support.SupportUtil;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * An Implementation of the {@link IActionCodeEditor} interface using the SWT
+ * {@link Text} widget.
+ * <p>
+ * Sub-classes may supply a custom {@link SourceViewerConfiguration} using the
+ * {@link #setSourceViewerConfiguration(SourceViewerConfiguration)} method and a
+ * custom {@link Document} creation methodology using the
+ * {@link #createDocument(DetailCode)} method.
+ * </p>
+ *
+ * @author jayant
+ */
+public class TextActionCodeEditor extends AbstractActionCodeEditor {
+
+ /** the internal SWT Text widget instance */
+ private Text text;
+
+ @Override
+ public void init(DetailCode detailCode) throws CoreException {
+ setDetailCode(detailCode);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ int style = SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL;
+ text = new Text(parent, style);
+ if (fDetailCode != null)
+ text.setText(SupportUtil.getInstance().getRoomHelpers()
+ .getDetailCode(fDetailCode));
+ text.setEnabled(true);
+ }
+
+ @Override
+ public Control getControl() {
+ return text;
+ }
+
+ @Override
+ public void insertText(String txt) {
+ int begin = txt.indexOf('(');
+ int end = txt.indexOf(')');
+ int offset = text.getSelection().x;
+ text.insert(txt);
+ if (begin >= 0 && end >= 0 && end > begin + 1)
+ text.setSelection(offset + begin + 1, offset + end);
+ text.setFocus();
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/text/TextActionCodeEditorFactory.java b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/text/TextActionCodeEditorFactory.java
new file mode 100644
index 000000000..c37e40621
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.actioneditor/src/org/eclipse/etrice/ui/behavior/actioneditor/text/TextActionCodeEditorFactory.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.actioneditor.text;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.ui.behavior.actioneditor.Activator;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditor;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditorFactory;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Factory for creation of {@link TextActionCodeEditor}.
+ *
+ * @author jayant
+ */
+public class TextActionCodeEditorFactory implements IActionCodeEditorFactory {
+
+ /** List of constructed editors */
+ ArrayList<TextActionCodeEditor> constructedEditors = new ArrayList<TextActionCodeEditor>();
+
+ @Override
+ public IActionCodeEditor createActionCodeEditor(DetailCode detailCode,
+ Composite parent, ModelComponent mc, boolean useMembers,
+ boolean useMessages, boolean useRecvMessagesOnly) {
+
+ TextActionCodeEditor textActionCodeEditor = null;
+
+ if (mc instanceof ActorClass) {
+ textActionCodeEditor = new TextActionCodeEditor();
+ try {
+ textActionCodeEditor.init(detailCode);
+ } catch (CoreException e) {
+ Activator.getDefault().getLog().log(e.getStatus());
+ System.out.println("Cannot Initialize editor");
+ }
+ textActionCodeEditor.createControl(parent);
+ } else {
+ Activator
+ .getDefault()
+ .getLog()
+ .log(new Status(Status.ERROR, Activator.PLUGIN_ID,
+ "Model Componenent " + mc.getComponentName()
+ + " is not an instance of ActorClass"));
+ }
+
+ return textActionCodeEditor;
+ }
+
+ @Override
+ public void dispose() {
+ for (TextActionCodeEditor constructedEditor : constructedEditors) {
+ constructedEditor.dispose();
+ }
+ constructedEditors.clear();
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF
index d967d4dbc..9beeb4ee9 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Abstract FSM Diagram Editor
-Bundle-SymbolicName: org.eclipse.etrice.ui.behavior.fsm
+Bundle-SymbolicName: org.eclipse.etrice.ui.behavior.fsm;singleton:=true
Bundle-Version: 0.5.0.qualifier
Bundle-Activator: org.eclipse.etrice.ui.behavior.fsm.Activator
Bundle-Vendor: eTrice (Incubation)
@@ -20,7 +20,9 @@ Require-Bundle: org.eclipse.etrice.core.common.ui;bundle-version="0.5.0",
org.eclipse.etrice.abstractexec.behavior;bundle-version="0.5.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
-Export-Package: org.eclipse.etrice.ui.behavior.fsm.commands,
+Export-Package: org.eclipse.etrice.ui.behavior.fsm.actioneditor,
+ org.eclipse.etrice.ui.behavior.fsm.actioneditor.preferences,
+ org.eclipse.etrice.ui.behavior.fsm.commands,
org.eclipse.etrice.ui.behavior.fsm.dialogs,
org.eclipse.etrice.ui.behavior.fsm.editor,
org.eclipse.etrice.ui.behavior.fsm.provider,
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/build.properties b/plugins/org.eclipse.etrice.ui.behavior.fsm/build.properties
index c6baffa00..79785acae 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/build.properties
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/build.properties
@@ -2,4 +2,5 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
- icons/
+ icons/,\
+ plugin.xml
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/plugin.xml b/plugins/org.eclipse.etrice.ui.behavior.fsm/plugin.xml
new file mode 100644
index 000000000..0de00f1df
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/plugin.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="actionCodeEditor" name="Action Code Editor" schema="schema/actionCodeEditor.exsd"/>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.etrice.ui.common.preferences.ETricePreferencePage"
+ class="org.eclipse.etrice.ui.behavior.fsm.actioneditor.preferences.ActionEditorPreferencePage"
+ id="org.eclipse.etrice.ui.behavior.preferences.ActionEditorPreferencePage"
+ name="Action Editor">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.etrice.ui.behavior.fsm.actioneditor.preferences.PreferenceInitializer">
+ </initializer>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/schema/actionCodeEditor.exsd b/plugins/org.eclipse.etrice.ui.behavior.fsm/schema/actionCodeEditor.exsd
new file mode 100644
index 000000000..b28a253bb
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/schema/actionCodeEditor.exsd
@@ -0,0 +1,163 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.etrice.ui.behavior.fsm" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.etrice.ui.behavior.fsm" id="actionCodeEditor" name="Action Code Editor"/>
+ </appinfo>
+ <documentation>
+ This extension point is used to add new Action Code editors to the eTrice Propeties Dialogs. An Action Code editor is a visual editing component within a eTrice property dialog. It is typically used to edit or browse the Detail Code segments embedded within the Behavior of an Actor in eTrice. The editor opens inside the State and Transition property dialogs. When this action is performed the workbench registry and the preference store is consulted to determine an appropriate editor for the target language of the underlying model and then a new instance of the editor type is created using the supplied Factory class.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="editor"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="editor">
+ <complexType>
+ <attribute name="editorName" type="string" use="required">
+ <annotation>
+ <documentation>
+ a translatable name that will be used in the UI for this editor
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="targetLanguage" use="default" value="ALL">
+ <annotation>
+ <documentation>
+ the target language for the editor.
+ </documentation>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="ALL">
+ </enumeration>
+ <enumeration value="C++">
+ </enumeration>
+ <enumeration value="JAVA">
+ </enumeration>
+ <enumeration value="OTHER">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ the name of a class that implements org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditorFactory.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditorFactory"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ a unique name that will be used to identify this editor
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ The following is an example
+of an action code editor extension definition:
+&lt;p&gt;
+&lt;pre&gt;
+ &lt;extension point=&quot;org.eclipse.etrice.ui.behavior.fsm.actionCodeEditor&quot;&gt;
+ &lt;editor
+ class=&quot;com.xyz.FancyActionEditorFactory&quot;
+ editorName=&quot;Fancy Text Editor&quot;
+ id=&quot;com.xyz.FancyActionEditorFactory&quot;
+ targetLanguage=&quot;JAVA&quot;&gt;
+ &lt;/editor&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+&lt;/p&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ The &lt;samp&gt;id&lt;/samp&gt; attribute is a unique name that will be used to identify this editor and must be suuplied.
+
+&lt;p&gt;
+The &lt;samp&gt;name&lt;/samp&gt; attribute is a a translatable human-readable name for the editor. It is used at various places in the UI for this editor (like in Preference Pages to select the editor to use for a particular target language). This attribute must be supplied.
+
+&lt;p&gt;
+The &lt;samp&gt;class&lt;/samp&gt; attribute is a required attribute. The specified class must implement &lt;samp&gt;org.eclipse.etrice.ui.behavior.actioneditor.IActionCodeEditorFactory&lt;/samp&gt;.
+&lt;ul&gt;
+&lt;li&gt; It is common practice to &lt;samp&gt;subclass org.eclipse.etrice.ui.behavior.actioneditor.AbstractActionCodeEditor.java&lt;/samp&gt; when defining a new editor type. &lt;/li&gt;
+&lt;li&gt; A special implementation of the editor based on JFace SourceViewer &lt;samp&gt;subclass org.eclipse.etrice.ui.behavior.actioneditor.SourceViewerActionCodeEditor.java&lt;/samp&gt; is also available and is highly configurable my means of &lt;samp&gt;org.eclipse.jface.text.source.SourceViewerConfiguration.class&lt;samp&gt; and its subclasses &lt;/li&gt;
+&lt;/ul&gt;
+
+&lt;p&gt;
+It is also necessary to define a &lt;samp&gt;targetLanguage&lt;/samp&gt; attribute. The possible values for this attribute are :
+&lt;ul&gt;
+&lt;li&gt; ALL - for all target languages &lt;/li&gt;
+&lt;li&gt; Java - for Java &lt;/li&gt;
+&lt;li&gt; C++ - for C/C++ &lt;/li&gt;
+&lt;li&gt; OTHER - for target languages other than JAVA or C/C++ &lt;/li&gt;
+&lt;/ul&gt;
+ </documentation>
+ </annotation>
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ Copyright (c) 2014 Jayant Gupta.&lt;br&gt;
+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 &lt;a
+href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/Activator.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/Activator.java
index 5caa70211..bf7192baa 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/Activator.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/Activator.java
@@ -1,5 +1,6 @@
package org.eclipse.etrice.ui.behavior.fsm;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.ActionCodeEditorRegistry;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
@@ -36,6 +37,7 @@ public class Activator extends AbstractUIPlugin {
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
+ ActionCodeEditorRegistry.INSTANCE.dispose();
plugin = null;
super.stop(context);
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/ActionCodeEditorRegistry.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/ActionCodeEditorRegistry.java
new file mode 100644
index 000000000..6645d4b50
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/ActionCodeEditorRegistry.java
@@ -0,0 +1,314 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.fsm.actioneditor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.ui.behavior.fsm.Activator;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * A Registry for Action Code Editors. Helps in lazy loading of the extensions
+ * and instantiation of Editors.
+ */
+public class ActionCodeEditorRegistry {
+
+ /**
+ * The Singleton instance of the Action Code Registry.
+ */
+ public static final ActionCodeEditorRegistry INSTANCE = new ActionCodeEditorRegistry();
+
+ /**
+ * Private constructor to prevent instantiation and make Singleton.
+ */
+ private ActionCodeEditorRegistry() {
+ }
+
+ // Constants used when reading "actionCodeEditor" extension point.
+ public static final String TAG_EDITOR = "editor";
+ public static final String ATT_NAME = "editorName";
+ public static final String ATT_CLASS = "class";
+ public static final String ATT_ID = "id";
+ public static final String ATT_TARGET_LANGUAGE = "targetLanguage";
+ public static final String TARGET_LANGUAGE_ALL = "ALL";
+ public static final String TARGET_LANGUAGE_JAVA = "JAVA";
+ public static final String TARGET_LANGUAGE_CPP = "C++";
+ public static final String TARGET_LANGUAGE_OTHER = "OTHER";
+
+ public class ActionCodeEditorRegistryEntry {
+
+ private IConfigurationElement configElem;
+ private final String name;
+ private final String id;
+ private final String targetLanguage;
+ private IActionCodeEditorFactory factory;
+
+ public ActionCodeEditorRegistryEntry(IConfigurationElement configElem) {
+ this.configElem = configElem;
+ name = getAttribute(configElem, ATT_NAME);
+ id = getAttribute(configElem, ATT_ID);
+ targetLanguage = getAttribute(configElem, ATT_TARGET_LANGUAGE);
+
+ // Make sure that class is defined,
+ // but don't load it.
+ getAttribute(configElem, ATT_CLASS);
+ }
+
+ /**
+ * The human readable name for the Action Code Editor
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * The id for the Action Code Editor
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * The Target language for the editor
+ */
+ public String getTargetLanguage() {
+ return targetLanguage;
+ }
+
+ /**
+ * Instantiates a new Action Code Editor which has been registered by
+ * this registry entry.
+ *
+ * @param detailCode
+ * the {@link DetailCode} to be shown
+ * @param parent
+ * the parent {@link Composite} in which the Editor will be
+ * shown
+ *
+ * @return the {@link IActionCodeEditor} instance or <code>null</code>
+ */
+ public IActionCodeEditor newActionCodeEditor(DetailCode detailCode,
+ Composite parent, ModelComponent mc, boolean useMembers,
+ boolean useMessages, boolean useRecvMessagesOnly) {
+ IActionCodeEditorFactory factory = getFactory();
+ if (factory == null)
+ return null;
+ return factory.createActionCodeEditor(detailCode, parent, mc,
+ useMembers, useMessages, useRecvMessagesOnly);
+ }
+
+ /**
+ * Gives the factory for instantiating items of the associated Action
+ * Code Editor
+ *
+ * @return the factory or <code>null</code> if the factory itself could
+ * not be instantiated
+ */
+ private IActionCodeEditorFactory getFactory() {
+ if (factory != null) {
+ return factory;
+ }
+ try {
+ factory = (IActionCodeEditorFactory) configElem
+ .createExecutableExtension(ATT_CLASS);
+ } catch (Exception e) {
+ MultiStatus status = new MultiStatus(Activator.PLUGIN_ID,
+ Status.ERROR, "Failed to instantiate factory: "
+ + configElem.getAttribute(ATT_CLASS)
+ + " in id: "
+ + id
+ + " in plugin: "
+ + configElem.getDeclaringExtension()
+ .getNamespaceIdentifier(), e);
+ Activator.getDefault().getLog().log(status);
+ }
+ return factory;
+ }
+
+ /**
+ * Dispose of any OS resources
+ */
+ public void dispose() {
+ if (factory == null)
+ return;
+ factory.dispose();
+ factory = null;
+ }
+
+ /**
+ * Protected Getter for creation of
+ * {@link ActionCodeEditorRegistry#UNKNOWN} Editor entry
+ */
+ protected ActionCodeEditorRegistryEntry() {
+ this.name = "Unknown";
+ this.id = "Unknown";
+ this.targetLanguage = TARGET_LANGUAGE_OTHER;
+ this.configElem = null;
+ }
+ }
+
+ /**
+ * An cache of {@link ActionCodeEditorRegistryEntry} objects loaded from the
+ * "actionCodeEditor" extension point.
+ */
+ private ActionCodeEditorRegistryEntry[] cachedEditorEntries;
+
+ /**
+ * Gets the {@link ActionCodeEditorRegistryEntry} object with the given id.
+ *
+ * @param id
+ * the id of the editor to be found
+ *
+ * @return a {@code ActionCodeEditorRegistryEntry} object for editor with
+ * given id. Returns {@code null} id no such object is present.
+ */
+ public ActionCodeEditorRegistryEntry getEditorWithId(String id) {
+ ActionCodeEditorRegistryEntry[] entries = getEditors();
+ for (ActionCodeEditorRegistryEntry entry : entries)
+ if (entry.getId().equals(id))
+ return entry;
+ return null;
+ }
+
+ /**
+ * Gives an array of {@link ActionCodeEditorRegistryEntry} loaded from the
+ * "actionCodeEditor" extension point for the given target language.
+ *
+ * @param targetLanguage
+ * the target language for which editor is required.
+ *
+ * @return an array of {@link ActionCodeEditorRegistryEntry} (not
+ * <code>null</code>)
+ */
+ public ActionCodeEditorRegistryEntry[] getEditorsForTargetLanguage(
+ String targetLanguage) {
+ ActionCodeEditorRegistryEntry[] entries = getEditors();
+
+ List<ActionCodeEditorRegistryEntry> found = new ArrayList<ActionCodeEditorRegistryEntry>();
+ for (ActionCodeEditorRegistryEntry entry : entries) {
+ String editorTargetLanguage = entry.getTargetLanguage();
+ if (editorTargetLanguage.equals(targetLanguage)
+ || editorTargetLanguage.equals(TARGET_LANGUAGE_ALL))
+ found.add(entry);
+ }
+
+ return (ActionCodeEditorRegistryEntry[]) found
+ .toArray(new ActionCodeEditorRegistryEntry[found.size()]);
+ }
+
+ /**
+ * Gives an array of {@link ActionCodeEditorRegistryEntry} loaded from the
+ * "actionCodeEditor" extension point as necessary.
+ *
+ * @return an array of {@link ActionCodeEditorRegistryEntry} (not
+ * <code>null</code>)
+ */
+ public ActionCodeEditorRegistryEntry[] getEditors() {
+ if (cachedEditorEntries != null)
+ return cachedEditorEntries;
+
+ IExtension[] extensions = Platform.getExtensionRegistry()
+ .getExtensionPoint(Activator.PLUGIN_ID, "actionCodeEditor")
+ .getExtensions();
+
+ List<ActionCodeEditorRegistryEntry> found = new ArrayList<ActionCodeEditorRegistryEntry>();
+
+ for (IExtension extension : extensions) {
+ IConfigurationElement[] configElements = extension
+ .getConfigurationElements();
+ for (IConfigurationElement configElement : configElements) {
+ ActionCodeEditorRegistryEntry entry = parseEditorEntries(configElement);
+ if (entry != null)
+ found.add(entry);
+ }
+ }
+
+ cachedEditorEntries = (ActionCodeEditorRegistryEntry[]) found
+ .toArray(new ActionCodeEditorRegistryEntry[found.size()]);
+ return cachedEditorEntries;
+ }
+
+ /**
+ * Parse a editor parameters to create {@link ActionCodeEditorRegistryEntry}
+ *
+ * @param configElem
+ * the configuration element containing the editor attributes.
+ *
+ * @return the {@link ActionCodeEditorRegistryEntry} or <code>null</code> if
+ * the parse has failed
+ */
+ private ActionCodeEditorRegistryEntry parseEditorEntries(
+ IConfigurationElement configElement) {
+ if (!configElement.getName().equals(TAG_EDITOR))
+ return null;
+ try {
+ return new ActionCodeEditorRegistryEntry(configElement);
+ } catch (Exception e) {
+ String id = configElement.getAttribute(ATT_ID);
+ if (id == null)
+ id = "[missing id attribute]";
+ String msg = "Failed to load action code editor with id "
+ + id
+ + " in "
+ + configElement.getDeclaringExtension()
+ .getNamespaceIdentifier();
+ Activator
+ .getDefault()
+ .getLog()
+ .log(new MultiStatus(Activator.PLUGIN_ID, Status.ERROR,
+ msg, e));
+ return null;
+ }
+ }
+
+ /**
+ * Dispose of any OS resources. Must be called by the plugin before
+ * shutdown.
+ */
+ public void dispose() {
+ if (cachedEditorEntries == null)
+ return;
+ for (int i = 0; i < cachedEditorEntries.length; i++)
+ cachedEditorEntries[i].dispose();
+ cachedEditorEntries = null;
+ }
+
+ /**
+ * Get the given attribute value from the given
+ * {@link IConfigurationElement} instance. Throws exception if no value
+ * found.
+ *
+ * @param configElem
+ * the configuration element containing the editor attributes.
+ * @param attrName
+ * the attribute required.
+ *
+ * @return the value of the attribute.
+ */
+ private static String getAttribute(IConfigurationElement configElem,
+ String attrName) {
+ String value = configElem.getAttribute(attrName);
+ if (value != null)
+ return value;
+ throw new IllegalArgumentException("Missing " + attrName + " attribute");
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/IActionCodeEditor.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/IActionCodeEditor.java
new file mode 100644
index 000000000..8da8e96d2
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/IActionCodeEditor.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.fsm.actioneditor;
+
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * This interface need to be implemented by all editors which allow editing
+ * Action Code present inside eTrice behavior diagrams.
+ *
+ * @author jayant
+ */
+public interface IActionCodeEditor {
+
+ /**
+ * Getter for the {@link DetailCode} object being represented by the editor.
+ *
+ * @return the DetailCode object associated with the editor instance
+ */
+ DetailCode getDetailCode();
+
+ /**
+ * Getter for the editor {@link Control} representing the Action Code.
+ *
+ * @return the Control within the editor
+ */
+ Control getControl();
+
+ /**
+ * Inserts the given {@code text} String in the editor's control replacing
+ * the selected range.
+ *
+ * @param text
+ * The String to be inserted
+ */
+ void insertText(String text);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/IActionCodeEditorFactory.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/IActionCodeEditorFactory.java
new file mode 100644
index 000000000..f3bd06e7d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/IActionCodeEditorFactory.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Jayant Gupta
+ * 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:
+ * Jayant Gupta (initial contribution)
+ *
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.fsm.actioneditor;
+
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Factory Interface for Action Code Editor Factories.
+ *
+ * @author jayant
+ */
+public interface IActionCodeEditorFactory {
+
+ /**
+ * Create a new instance of an implementation of the
+ * {@link IActionCodeEditor} with given configuration parameters.
+ *
+ * @param detailCode
+ * the {@link DetailCode} object to be represented
+ * @param parent
+ * the {@link Composite} which will hold the editor
+ * @param ac
+ * the {@link ActorClass} class containing the detail Code
+ * @param useMembers
+ * true if the editor is to be member aware
+ * @param useMessages
+ * true if the editor is to be message aware
+ * @param useRecvMessagesOnly
+ * true if the editor is to use only receive only messages
+ * @return the created instance of the action code editor.
+ */
+ IActionCodeEditor createActionCodeEditor(DetailCode detailCode,
+ Composite parent, ModelComponent ac, boolean useMembers,
+ boolean useMessages, boolean useRecvMessagesOnly);
+
+ /**
+ * Disposes all the resources allocate by the factory.
+ */
+ public void dispose();
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/ActionEditorPreferencePage.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/ActionEditorPreferencePage.java
new file mode 100644
index 000000000..8877fe12c
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/ActionEditorPreferencePage.java
@@ -0,0 +1,87 @@
+package org.eclipse.etrice.ui.behavior.fsm.actioneditor.preferences;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.ui.behavior.fsm.Activator;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.ActionCodeEditorRegistry;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.ActionCodeEditorRegistry.ActionCodeEditorRegistryEntry;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * Preference page for the Action Code Editor.
+ *
+ * @author jayant
+ */
+public class ActionEditorPreferencePage extends FieldEditorPreferencePage
+ implements IWorkbenchPreferencePage {
+
+ public static final String CHOOSE_JAVA_EDITOR = "Choose editor for Java :-";
+ public static final String CHOOSE_CPP_EDITOR = "Choose editor for C/C++ :-";
+
+ public ActionEditorPreferencePage() {
+ super(GRID);
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ setDescription("A preference page for choosing action code editors for target languages.");
+ }
+
+ /**
+ * Creates the field editors. Field editors are abstractions of the common
+ * GUI blocks needed to manipulate various types of preferences. Each field
+ * editor knows how to save and restore itself.
+ */
+ public void createFieldEditors() {
+
+ // Choice for Java Editor
+ addField(new RadioGroupFieldEditor(
+ PreferenceConstants.JAVA_EDITOR_PREFERENCE,
+ CHOOSE_JAVA_EDITOR,
+ 1,
+ getChoicesForTargetLanguage(ActionCodeEditorRegistry.TARGET_LANGUAGE_JAVA),
+ getFieldEditorParent()));
+
+ // Choice for C/C++ editor
+ addField(new RadioGroupFieldEditor(
+ PreferenceConstants.CPP_EDITOR_PREFERENCE,
+ CHOOSE_CPP_EDITOR,
+ 1,
+ getChoicesForTargetLanguage(ActionCodeEditorRegistry.TARGET_LANGUAGE_CPP),
+ getFieldEditorParent()));
+ }
+
+ /**
+ * Forms the label and value array for choosing editors for the given target
+ * language.
+ *
+ * @param targetLanguage
+ * the target language for the editor choice
+ * @return label and value array
+ */
+ private String[][] getChoicesForTargetLanguage(String targetLanguage) {
+
+ ActionCodeEditorRegistryEntry[] editors = ActionCodeEditorRegistry.INSTANCE
+ .getEditorsForTargetLanguage(targetLanguage);
+
+ ArrayList<String[]> editorChoices = new ArrayList<String[]>();
+ for (ActionCodeEditorRegistryEntry javaEditor : editors) {
+ String[] choice = new String[] { javaEditor.getName(),
+ javaEditor.getId() };
+ editorChoices.add(choice);
+ }
+
+ return (String[][]) editorChoices.toArray(new String[editorChoices
+ .size()][]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init(IWorkbench workbench) {
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/PreferenceConstants.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/PreferenceConstants.java
new file mode 100644
index 000000000..d4a6e34e3
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/PreferenceConstants.java
@@ -0,0 +1,15 @@
+package org.eclipse.etrice.ui.behavior.fsm.actioneditor.preferences;
+
+/**
+ * Constant definitions for plug-in preferences
+ *
+ * @author jayant
+ */
+public class PreferenceConstants {
+
+ /** Preference name for Java Editor */
+ public static final String JAVA_EDITOR_PREFERENCE = "org.eclipse.etrice.ui.behavior.actioneditor.preferences.javaeditor";
+ /** Preference name for C/C++ Editor */
+ public static final String CPP_EDITOR_PREFERENCE = "org.eclipse.etrice.ui.behavior.actioneditor.preferences.cppeditor";
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/PreferenceInitializer.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/PreferenceInitializer.java
new file mode 100644
index 000000000..7fa791964
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/actioneditor/preferences/PreferenceInitializer.java
@@ -0,0 +1,34 @@
+package org.eclipse.etrice.ui.behavior.fsm.actioneditor.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.etrice.ui.behavior.fsm.Activator;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * Class used to initialize default preference values.
+ *
+ * @author jayant
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /** the Id for ModelAwareActionCodeEditor's contribution. */
+ public static final String MODEL_AWARE_ACTION_CODE_EDITOR_ID = "org.eclipse.etrice.ui.behavior.actioneditor.modelAwareActionCodeEditor";
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
+ * initializeDefaultPreferences()
+ */
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ // Set the default preference value for Java Editor
+ store.setDefault(PreferenceConstants.JAVA_EDITOR_PREFERENCE,
+ MODEL_AWARE_ACTION_CODE_EDITOR_ID);
+
+ // Set the default preference value for C++ Editor
+ store.setDefault(PreferenceConstants.CPP_EDITOR_PREFERENCE,
+ MODEL_AWARE_ACTION_CODE_EDITOR_ID);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/AbstractMemberAwarePropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/AbstractMemberAwarePropertyDialog.java
index 61c27a010..3d45ef94d 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/AbstractMemberAwarePropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/AbstractMemberAwarePropertyDialog.java
@@ -7,15 +7,28 @@
*
* CONTRIBUTORS:
* Henrik Rentz-Reichert (initial contribution)
+ * Jayant Gupta (contributed Action Code Editor)
*
*******************************************************************************/
package org.eclipse.etrice.ui.behavior.fsm.dialogs;
+import java.util.HashMap;
import java.util.HashSet;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.ui.behavior.fsm.Activator;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.ActionCodeEditorRegistry;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditor;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.preferences.PreferenceConstants;
import org.eclipse.etrice.ui.common.base.dialogs.AbstractPropertyDialog;
+import org.eclipse.etrice.ui.common.base.dialogs.MultiValidator2;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
@@ -27,6 +40,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
@@ -38,22 +52,23 @@ import com.google.inject.Inject;
*/
public abstract class AbstractMemberAwarePropertyDialog extends AbstractPropertyDialog implements IMemberAwareConfiguration {
- private class LastTextListener implements FocusListener {
+ private class LastControlListener implements FocusListener {
@Override
public void focusGained(FocusEvent e) {
- if (e.getSource() instanceof Text) {
- boolean enableMemberButton = memberAware.contains(e.getSource());
- boolean enableMessageButton = messageAware.contains(e.getSource());
+ if (e.getSource() instanceof Control) {
+ boolean enableMemberButton = memberAware
+ .contains(e.getSource());
+ boolean enableMessageButton = messageAware.contains(e
+ .getSource());
if (enableMemberButton || enableMessageButton)
- lastTextField = (Text) e.getSource();
+ lastFocusedField = (Control) e.getSource();
else
- lastTextField = null;
+ lastFocusedField = null;
members.setEnabled(enableMemberButton);
messages.setEnabled(enableMessageButton);
- }
- else {
- lastTextField = null;
+ } else {
+ lastFocusedField = null;
members.setEnabled(false);
messages.setEnabled(false);
}
@@ -67,15 +82,21 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty
@Inject
protected IFSMDialogFactory dialogFactory;
- private Text lastTextField = null;
+ private Control lastFocusedField = null;
private Button members;
private Button messages;
private ModelComponent mc;
- private LastTextListener listener = new LastTextListener();
+ private LastControlListener listener = new LastControlListener();
private HashSet<Control> memberAware = new HashSet<Control>();
private HashSet<Control> messageAware = new HashSet<Control>();
private HashSet<Control> recvOnly = new HashSet<Control>();
-
+
+ /**
+ *
+ * @author jayant
+ */
+ private HashMap<Control, IActionCodeEditor> actionEditorControlMap = new HashMap<Control, IActionCodeEditor>();
+
/**
* @param shell
* @param title
@@ -104,7 +125,7 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty
gd.horizontalAlignment = GridData.FILL;
gd.horizontalSpan = 2;
buttonsArea.setLayoutData(gd);
-
+
members = new Button(buttonsArea, SWT.PUSH);
members.setText("Mem&bers");
gd = new GridData();
@@ -113,18 +134,18 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty
members.setLayoutData(gd);
members.setEnabled(false);
members.addSelectionListener(new SelectionListener() {
-
+
@Override
public void widgetSelected(SelectionEvent e) {
handleMembersPressed();
}
-
+
@Override
public void widgetDefaultSelected(SelectionEvent e) {
handleMembersPressed();
}
});
-
+
messages = new Button(buttonsArea, SWT.PUSH);
messages.setText("Me&ssages");
gd = new GridData();
@@ -133,12 +154,12 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty
messages.setLayoutData(gd);
messages.setEnabled(false);
messages.addSelectionListener(new SelectionListener() {
-
+
@Override
public void widgetSelected(SelectionEvent e) {
handleMessagesPressed();
}
-
+
@Override
public void widgetDefaultSelected(SelectionEvent e) {
handleMessagesPressed();
@@ -146,6 +167,103 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty
});
}
+ /**
+ * A delegate to
+ * {@link #createActionCodeEditor(Composite, String, DetailCode, EObject, EStructuralFeature, IValidator, MultiValidator2, IConverter, IConverter, boolean, boolean, boolean)}
+ *
+ * @author jayant
+ */
+ protected IActionCodeEditor createActionCodeEditor(Composite parent,
+ String label, DetailCode detailCode, EObject obj,
+ EStructuralFeature feat, IConverter s2m, IConverter m2s) {
+ return createActionCodeEditor(parent, label, detailCode, obj, feat,
+ null, null, s2m, m2s, true, true, false);
+ }
+
+ /**
+ * Creates Action Code Editor with the given parameters and binds it with the
+ * model.
+ *
+ * @author jayant
+ *
+ * @param parent
+ * the {@link Composite} which will hold the editor
+ * @param label
+ * the label for the editor
+ * @param detailCode
+ * the {@link DetailCode} object to be represented
+ * @param obj
+ * the EMF object containing the detailCode code
+ * @param feat
+ * the {@link EStructuralFeature} associated with the code
+ * @param singleValidator
+ * an {@link IValidator} for the JFace Data binding
+ * @param multiValidator
+ * a {@link MultiValidator2} for the JFace Data binding
+ * @param s2m
+ * a String to Model converter
+ * @param m2s
+ * a Model to string converter
+ * @param useMembers
+ * true if the editor is to be member aware
+ * @param useMessages
+ * true if the editor is to be message aware
+ * @param useRecvMessagesOnly
+ * true if the editor could use receive messages only
+ *
+ * @return the constructed instance of {@link IActionCodeEditor}
+ */
+ protected IActionCodeEditor createActionCodeEditor(Composite parent,
+ String label, DetailCode detailCode, EObject obj,
+ EStructuralFeature feat, IValidator singleValidator,
+ MultiValidator2 multiValidator, IConverter s2m, IConverter m2s,
+ boolean useMembers, boolean useMessages, boolean useRecvMessagesOnly) {
+ Label l = getToolkit().createLabel(parent, label, SWT.NONE);
+ l.setLayoutData(new GridData(SWT.NONE));
+
+ // TODO Auto-detect target language.
+ String targetLanguage = PreferenceConstants.JAVA_EDITOR_PREFERENCE;
+
+ // Get editor id from preferences for the given target language.
+ String id = Activator.getDefault().getPreferenceStore()
+ .getString(targetLanguage);
+
+ // Create new editor instance
+ IActionCodeEditor actionCodeEditor = ActionCodeEditorRegistry.INSTANCE
+ .getEditorWithId(id).newActionCodeEditor(detailCode, parent,
+ mc, useMembers, useMessages, useRecvMessagesOnly);
+ if (actionCodeEditor != null) {
+ configureMemberAwareness(actionCodeEditor, useMembers, useMessages,
+ useRecvMessagesOnly);
+ getToolkit().adapt(actionCodeEditor.getControl(), true, true);
+
+ // JFace Data-binding of editor's control with model.
+ UpdateValueStrategy t2m = null;
+ UpdateValueStrategy m2t = null;
+ if (singleValidator != null || s2m != null || m2s != null) {
+ t2m = new UpdateValueStrategy();
+ if (s2m != null)
+ t2m.setConverter(s2m);
+ if (singleValidator != null) {
+ t2m.setAfterConvertValidator(singleValidator);
+ t2m.setBeforeSetValidator(singleValidator);
+ }
+ m2t = new UpdateValueStrategy();
+ if (m2s != null)
+ m2t.setConverter(m2s);
+ if (singleValidator != null) {
+ m2t.setAfterConvertValidator(singleValidator);
+ m2t.setBeforeSetValidator(singleValidator);
+ }
+ }
+ Object type = (s2m != null) ? s2m.getToType() : String.class;
+ createBinding(actionCodeEditor.getControl(), obj, feat, type, t2m,
+ m2t, multiValidator);
+ }
+
+ return actionCodeEditor;
+ }
+
protected void handleMembersPressed() {
ISelectionDialog dlg = dialogFactory.createMemberSelectionDialog(getShell(), mc);
if (dlg.open()==Window.OK) {
@@ -154,7 +272,7 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty
}
protected void handleMessagesPressed() {
- boolean receiveOnly = recvOnly.contains(lastTextField);
+ boolean receiveOnly = recvOnly.contains(lastFocusedField);
ISelectionDialog dlg = dialogFactory.createMessageSelectionDialog(getShell(), mc, receiveOnly);
if (dlg.open()==Window.OK) {
insertText(dlg.getSelected());
@@ -162,14 +280,20 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty
}
private void insertText(String txt) {
- if (lastTextField!=null) {
- int begin = txt.indexOf('(');
- int end = txt.indexOf(')');
- int offset = lastTextField.getSelection().x;
- lastTextField.insert(txt);
- if (begin>=0 && end>=0 && end>begin+1)
- lastTextField.setSelection(offset+begin+1, offset+end);
- lastTextField.setFocus();
+ if (lastFocusedField != null) {
+ if (actionEditorControlMap.containsKey(lastFocusedField)) {
+ (actionEditorControlMap.get(lastFocusedField)).insertText(txt);
+ } else if (lastFocusedField instanceof Text) {
+ Text lastTextField = (Text) lastFocusedField;
+ int begin = txt.indexOf('(');
+ int end = txt.indexOf(')');
+ int offset = lastTextField.getSelection().x;
+ lastTextField.insert(txt);
+ if (begin >= 0 && end >= 0 && end > begin + 1)
+ lastTextField
+ .setSelection(offset + begin + 1, offset + end);
+ lastTextField.setFocus();
+ }
}
}
@@ -193,4 +317,26 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty
recvOnly.add(ctrl);
ctrl.addFocusListener(listener);
}
+
+ /**
+ * Configure an action code editor to the level of awareness. Helps activate
+ * and deactivate member and message buttons.
+ *
+ * @author jayant
+ *
+ * @param actionCodeEditor
+ * the {@link IActionCodeEditor} instance to configure
+ * @param useMembers
+ * true if the editor is to be member aware
+ * @param useMessages
+ * true if the editor is to be message aware
+ * @param useRecvMessagesOnly
+ * true if the editor could use receive messages only
+ */
+ public void configureMemberAwareness(IActionCodeEditor actionCodeEditor,
+ boolean useMembers, boolean useMessages, boolean useRecvMessagesOnly) {
+ Control ctrl = actionCodeEditor.getControl();
+ actionEditorControlMap.put(ctrl, actionCodeEditor);
+ configureMemberAwareness(ctrl, useMembers, useMessages, useRecvMessagesOnly);
+ }
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/schema/actionCodeEditor.exsd b/plugins/org.eclipse.etrice.ui.behavior/schema/actionCodeEditor.exsd
new file mode 100644
index 000000000..2ab9c31d2
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.behavior/schema/actionCodeEditor.exsd
@@ -0,0 +1,163 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.etrice.ui.behavior" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.etrice.ui.behavior" id="actionCodeEditor" name="Action Code Editor"/>
+ </appinfo>
+ <documentation>
+ This extension point is used to add new Action Code editors to the eTrice Propeties Dialogs. An Action Code editor is a visual editing component within a eTrice property dialog. It is typically used to edit or browse the Detail Code segments embedded within the Behavior of an Actor in eTrice. The editor opens inside the State and Transition property dialogs. When this action is performed the workbench registry and the preference store is consulted to determine an appropriate editor for the target language of the underlying model and then a new instance of the editor type is created using the supplied Factory class.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="editor"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+ a fully qualified identifier of the target extension point
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ an optional identifier of the extension instance
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ an optional name of the extension instance
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="editor">
+ <complexType>
+ <attribute name="editorName" type="string">
+ <annotation>
+ <documentation>
+ a translatable name that will be used in the UI for this editor
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="targetLanguage" use="default" value="ALL">
+ <annotation>
+ <documentation>
+ the target language for the editor.
+ </documentation>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="ALL">
+ </enumeration>
+ <enumeration value="C++">
+ </enumeration>
+ <enumeration value="JAVA">
+ </enumeration>
+ <enumeration value="OTHER">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ the name of a class that implements org.eclipse.etrice.ui.behavior.actioneditor.IActionCodeEditorFactory.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.etrice.ui.behavior.actioneditor.IActionCodeEditorFactory"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ a unique name that will be used to identify this editor
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ The following is an example
+of an action code editor extension definition:
+&lt;p&gt;
+&lt;pre&gt;
+ &lt;extension point=&quot;org.eclipse.etrice.ui.behavior.actionCodeEditor&quot;&gt;
+ &lt;editor
+ class=&quot;com.xyz.FancyActionEditorFactory&quot;
+ editorName=&quot;Fancy Text Editor&quot;
+ id=&quot;com.xyz.FancyActionEditorFactory&quot;
+ targetLanguage=&quot;JAVA&quot;&gt;
+ &lt;/editor&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+&lt;/p&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ The &lt;samp&gt;id&lt;/samp&gt; attribute is a unique name that will be used to identify this editor and must be suuplied.
+
+&lt;p&gt;
+The &lt;samp&gt;name&lt;/samp&gt; attribute is a a translatable human-readable name for the editor. It is used at various places in the UI for this editor (like in Preference Pages to select the editor to use for a particular target language). This attribute must be supplied.
+
+&lt;p&gt;
+The &lt;samp&gt;class&lt;/samp&gt; attribute is a required attribute. The specified class must implement &lt;samp&gt;org.eclipse.etrice.ui.behavior.actioneditor.IActionCodeEditorFactory&lt;/samp&gt;.
+&lt;ul&gt;
+&lt;li&gt; It is common practice to &lt;samp&gt;subclass org.eclipse.etrice.ui.behavior.actioneditor.AbstractActionCodeEditor.java&lt;/samp&gt; when defining a new editor type. &lt;/li&gt;
+&lt;li&gt; A special implementation of the editor based on JFace SourceViewer &lt;samp&gt;subclass org.eclipse.etrice.ui.behavior.actioneditor.SourceViewerActionCodeEditor.java&lt;/samp&gt; is also available and is highly configurable my means of &lt;samp&gt;org.eclipse.jface.text.source.SourceViewerConfiguration.class&lt;samp&gt; and its subclasses &lt;/li&gt;
+&lt;/ul&gt;
+
+&lt;p&gt;
+It is also necessary to define a &lt;samp&gt;targetLanguage&lt;/samp&gt; attribute. The possible values for this attribute are :
+&lt;ul&gt;
+&lt;li&gt; ALL - for all target languages &lt;/li&gt;
+&lt;li&gt; Java - for Java &lt;/li&gt;
+&lt;li&gt; C++ - for C/C++ &lt;/li&gt;
+&lt;li&gt; OTHER - for target languages other than JAVA or C/C++ &lt;/li&gt;
+&lt;/ul&gt;
+ </documentation>
+ </annotation>
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ Copyright (c) 2014 Jayant Gupta.&lt;br&gt;
+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 &lt;a
+href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java
index 27d060006..1cd97f77c 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java
@@ -7,7 +7,9 @@ import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.etrice.core.fsm.fSM.ComponentCommunicationType;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
import org.eclipse.etrice.core.fsm.fSM.FSMPackage;
import org.eclipse.etrice.core.fsm.fSM.RefinedState;
import org.eclipse.etrice.core.fsm.fSM.SimpleState;
@@ -16,6 +18,7 @@ import org.eclipse.etrice.core.fsm.validation.FSMValidationUtilXtend.Result;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.behavior.Activator;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditor;
import org.eclipse.etrice.ui.behavior.fsm.dialogs.AbstractMemberAwarePropertyDialog;
import org.eclipse.etrice.ui.behavior.fsm.dialogs.DetailCodeToString;
import org.eclipse.etrice.ui.behavior.fsm.dialogs.IStatePropertyDialog;
@@ -26,6 +29,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IManagedForm;
@@ -70,6 +74,8 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
public StatePropertyDialog(Shell shell, ActorClass ac, State s, boolean edit) {
super(shell, edit?"Edit State":"View State", ac);
this.state = s;
+
+ Activator.getDefault().getInjector().injectMembers(this);
inherited = SupportUtil.getInstance().getRoomHelpers().getActorClass(s)!=ac;
}
@@ -114,12 +120,6 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 100;
entry.setLayoutData(gd);
-
- if (where.contains(Where.ENTRY)) {
- if (addCode)
- entry.append(codeSelectionString + "();\n");
- setTextSelectionAndFocus(entry, codeSelectionString);
- }
}
else {
if (state instanceof RefinedState)
@@ -136,22 +136,11 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
setTextSelectionAndFocus(entry, codeSelectionString);
}
}
-
- {
- Text entry = createText(body, "&Entry Code:", state, FSMPackage.eINSTANCE.getState_EntryCode(), null, s2m, m2s, true);
- configureMemberAwareness(entry, true, true);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- entry.setLayoutData(gd);
- if (where.contains(Where.ENTRY)) {
- if (addCode)
- entry.append(codeSelectionString + "();\n");
- setTextSelectionAndFocus(entry, codeSelectionString);
- }
- }
+ createActionCodeEditor(body, "&Entry Code:", state.getEntryCode(),
+ FSMPackage.eINSTANCE.getState_EntryCode(), s2m, m2s);
}
-
+
if (inherited) {
String code = roomHelpers.getDetailCode(state.getExitCode());
if (state instanceof RefinedState)
@@ -160,28 +149,11 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 100;
entry.setLayoutData(gd);
-
- if (where.contains(Where.EXIT)) {
- if (addCode)
- entry.append(codeSelectionString + "();\n");
- setTextSelectionAndFocus(entry, codeSelectionString);
- }
}
else {
- {
- Text exit = createText(body, "E&xit Code:", state, FSMPackage.eINSTANCE.getState_ExitCode(), null, s2m, m2s, true);
- configureMemberAwareness(exit, true, true);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- exit.setLayoutData(gd);
+ createActionCodeEditor(body, "E&xit Code:", state.getExitCode(),
+ FSMPackage.eINSTANCE.getState_ExitCode(), s2m, m2s);
- if (where.contains(Where.EXIT)) {
- if (addCode)
- exit.append(codeSelectionString + "();\n");
- setTextSelectionAndFocus(exit, codeSelectionString);
- }
- }
-
if (state instanceof RefinedState)
{
String code = roomHelpers.getBaseExitCode((RefinedState)state);
@@ -189,31 +161,14 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 100;
entry.setLayoutData(gd);
-
- if (where.contains(Where.EXIT)) {
- if (addCode)
- entry.append(codeSelectionString + "();\n");
- setTextSelectionAndFocus(entry, codeSelectionString);
- }
}
}
-
+
ActorClass ac = roomHelpers.getActorClass(state);
if (ac.getCommType()!=ComponentCommunicationType.EVENT_DRIVEN)
- {
- Text dotxt = createText(body, "&Do Code:", state, FSMPackage.eINSTANCE.getState_DoCode(), null, s2m, m2s, true);
- configureMemberAwareness(dotxt, true, true);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- dotxt.setLayoutData(gd);
+ createActionCodeEditor(body, "&Do Code:", state.getDoCode(),
+ FSMPackage.eINSTANCE.getState_DoCode(), s2m, m2s);
- if (where.contains(Where.DO)) {
- if (addCode)
- dotxt.append(codeSelectionString + "();\n");
- setTextSelectionAndFocus(dotxt, codeSelectionString);
- }
- }
-
createMembersAndMessagesButtons(body);
if (!messageToDisplay.isEmpty()) {
@@ -226,6 +181,60 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
}
}
+ /**
+ * Creates Action Code Editor with the given parameters for the
+ * {@link #state} and binds it with the model.
+ *
+ * @author jayant
+ *
+ * @param parent
+ * the {@link Composite} which will hold the editor
+ * @param label
+ * the label for the editor
+ * @param detailCode
+ * the {@link DetailCode} object to be represented
+ * @param feat
+ * the {@link EStructuralFeature} associated with the code
+ * @param s2m
+ * a String to Model converter
+ * @param m2s
+ * a Model to string converter
+ *
+ * @return the constructed instance of {@link IActionCodeEditor}
+ */
+ private void createActionCodeEditor(Composite parent, String label,
+ DetailCode detailCode, EStructuralFeature feat,
+ StringToDetailCode s2m, DetailCodeToString m2s) {
+
+ IActionCodeEditor entry = super.createActionCodeEditor(parent, label,
+ detailCode, state, feat, s2m, m2s);
+
+ Control control;
+ if (entry != null)
+ control = entry.getControl();
+ else {
+ // if action editor cannot be created, create a simple SWT Text
+ // widget.
+ Text textEntry = createText(parent, label, state, feat, null, s2m,
+ m2s, true);
+ configureMemberAwareness(textEntry, true, true);
+ control = textEntry;
+ }
+
+ //set layout for the created control
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 100;
+ control.setLayoutData(gd);
+
+ // TODO Change IActionCodeEditor API to allow append or change
+ // the quick fix method
+ /*if (where.contains(Where.ENTRY)) {
+ if (addCode)
+ entry.append(codeSelectionString + "();\n");
+ setTextSelectionAndFocus(entry, codeSelectionString);
+ }*/
+ }
+
public void setAddCode(boolean add) {
addCode = add;
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java
index 6b3e34702..b1c2ed25d 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java
@@ -4,10 +4,13 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.etrice.core.fsm.fSM.AbstractInterfaceItem;
import org.eclipse.etrice.core.fsm.fSM.CPBranchTransition;
import org.eclipse.etrice.core.fsm.fSM.DetailCode;
@@ -25,6 +28,7 @@ import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.behavior.Activator;
+import org.eclipse.etrice.ui.behavior.fsm.actioneditor.IActionCodeEditor;
import org.eclipse.etrice.ui.behavior.fsm.dialogs.AbstractMemberAwarePropertyDialog;
import org.eclipse.etrice.ui.behavior.fsm.dialogs.DetailCodeToString;
import org.eclipse.etrice.ui.behavior.fsm.dialogs.ITransitionPropertyDialog;
@@ -36,6 +40,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IManagedForm;
@@ -178,14 +183,12 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog
}
else {
GuardValidator gv = new GuardValidator("guard must not be empty");
-
- Text cond = createText(body, "&Guard:", trans, FSMPackage.eINSTANCE.getGuardedTransition_Guard(), gv, s2m_not_null, m2s_null_empty, true);
- configureMemberAwareness(cond, true, true, true);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- cond.setLayoutData(gd);
-
- createDecorator(cond, "empty guard");
+
+ createActionCodeEditor(body, "&Guard:", trans.getAction(),
+ trans,
+ FSMPackage.eINSTANCE.getGuardedTransition_Guard(), gv,
+ s2m_not_null, m2s_null_empty, true, true, true,
+ "empty guard");
}
}
@@ -196,14 +199,15 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog
}
else {
GuardValidator gv = new GuardValidator("condition must not be empty");
-
- Text cond = createText(body, "&Condition:", trans, FSMPackage.eINSTANCE.getCPBranchTransition_Condition(), gv, s2m_not_null, m2s_null_empty, true);
- configureMemberAwareness(cond, true, true, true);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- cond.setLayoutData(gd);
-
- createDecorator(cond, "empty condition");
+
+ createActionCodeEditor(
+ body,
+ "&Condition:",
+ trans.getAction(),
+ trans,
+ FSMPackage.eINSTANCE.getCPBranchTransition_Condition(),
+ gv, s2m_not_null, m2s_null_empty, true, true, true,
+ "empty condition");
}
}
@@ -217,22 +221,17 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog
if (inherited) {
if (refined!=null) {
- Text action = createText(body, "&Action Code:", refined, FSMPackage.eINSTANCE.getRefinedTransition_Action(), null, s2m, m2s, true);
- configureMemberAwareness(action, true, true);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- action.setLayoutData(gd);
- setTextSelectionAndFocus(action, codeSelectionString);
+ createActionCodeEditor(body, "&Action Code:",
+ refined.getAction(), refined,
+ FSMPackage.eINSTANCE.getRefinedTransition_Action(),
+ null, s2m, m2s, true, true, false, null);
}
}
else
{
- Text action = createText(body, "&Action Code:", trans, FSMPackage.eINSTANCE.getTransition_Action(), null, s2m, m2s, true);
- configureMemberAwareness(action, true, true);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- action.setLayoutData(gd);
- setTextSelectionAndFocus(action, codeSelectionString);
+ createActionCodeEditor(body, "&Action Code:", trans.getAction(),
+ trans, FSMPackage.eINSTANCE.getTransition_Action(), null,
+ s2m, m2s, true, true, false, null);
}
createMembersAndMessagesButtons(body);
@@ -279,4 +278,73 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog
messageToDisplay = message;
messageTitle = title;
}
+
+
+ /**
+ * Creates Action Code Editor for the Transition/Guard with the given
+ * parameters and binds it with the model.
+ *
+ * @author jayant
+ *
+ * @param parent
+ * the {@link Composite} which will hold the editor
+ * @param label
+ * the label for the editor
+ * @param detailCode
+ * the {@link DetailCode} object to be represented
+ * @param obj
+ * the EMF object containing the detailCode code
+ * @param feat
+ * the {@link EStructuralFeature} associated with the code
+ * @param singleValidator
+ * an {@link IValidator} for the JFace Data binding
+ * @param s2m
+ * a String to Model converter
+ * @param m2s
+ * a Model to string converter
+ * @param useMembers
+ * true if the editor is to be member aware
+ * @param useMessages
+ * true if the editor is to be message aware
+ * @param useRecvMessagesOnly
+ * true if the editor could use receive messages only
+ * @param decoratorString
+ * the decorator string to attach to the editor's control
+ *
+ * @return the constructed instance of {@link IActionCodeEditor}
+ */
+ private void createActionCodeEditor(Composite parent, String label,
+ DetailCode detailCode, EObject obj, EStructuralFeature feat,
+ IValidator singleValidator, IConverter s2m, IConverter m2s,
+ boolean useMembers, boolean useMessages,
+ boolean useRecvMessagesOnly, String decoratorString) {
+
+ IActionCodeEditor entry = super.createActionCodeEditor(parent, label,
+ detailCode, obj, feat, singleValidator, null, s2m, m2s,
+ useMembers, useMessages, useRecvMessagesOnly);
+
+ Control control;
+ if (entry != null)
+ control = entry.getControl();
+ else {
+ // if action editor cannot be created, create a simple SWT Text
+ // widget.
+ Text textEntry = createText(parent, label, obj, feat, null, s2m,
+ m2s, true);
+ configureMemberAwareness(textEntry, useMembers, useMessages,
+ useRecvMessagesOnly);
+ control = textEntry;
+ }
+
+ // set layout for the created control
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 100;
+ control.setLayoutData(gd);
+ if (decoratorString != null)
+ createDecorator(control, decoratorString);
+
+ // TODO Change IActionCodeEditor API to allow append or change
+ // the quick fix method
+ // setTextSelectionAndFocus(entry, codeSelectionString);
+ }
}
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java
index 0dd964b17..429051358 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/dialogs/AbstractPropertyDialog.java
@@ -48,6 +48,7 @@ import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.graphics.Image;
@@ -529,9 +530,9 @@ public abstract class AbstractPropertyDialog extends FormDialog {
return combo;
}
- private void createBinding(Widget widget, EObject obj, EStructuralFeature feature, Object objType, UpdateValueStrategy t2m, UpdateValueStrategy m2t, MultiValidator2 multiValidator){
+ protected void createBinding(Widget widget, EObject obj, EStructuralFeature feature, Object objType, UpdateValueStrategy t2m, UpdateValueStrategy m2t, MultiValidator2 multiValidator){
IObservableValue observableWidget = null;
- if(widget instanceof Text)
+ if(widget instanceof Text || widget instanceof StyledText)
observableWidget = WidgetProperties.text(SWT.Modify).observe(widget);
else if(widget instanceof Button || widget instanceof Combo)
observableWidget = WidgetProperties.selection().observe(widget);
@@ -638,7 +639,7 @@ public abstract class AbstractPropertyDialog extends FormDialog {
}
/**
- * Selects the string {@code selectSring(...)} inside the Text & shifts the
+ * Selects the string {@code selectSring} inside the Text & shifts the
* keyboard focus to it. If the select string is empty or not present inside
* the text, it does nothing.
*

Back to the top