diff --git a/build.gradle b/build.gradle index b3b707af1a07cd484b0a4c0c003099f7a460eb65..33b77a6710bc05ca7ef1d25d8b8e5fa151413695 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,12 @@ +// to trigger a full tycho build please use 'gradle deleteFromClassPath completeInstall' +import org.apache.tools.ant.taskdefs.condition.Os -targetRepositories = ["http://www.stups.uni-duesseldorf.de/prob_dev_target/","http://download.eclipse.org/releases/indigo/","http://rodin-b-sharp.sourceforge.net/updates"] +project.ext{ + + targetRepositories = ["http://www.stups.uni-duesseldorf.de/prob_dev_target/","http://download.eclipse.org/releases/indigo/","http://rodin-b-sharp.sourceforge.net/updates"] -groupID = "de.prob" + groupID = "de.prob" +} apply from: 'tycho_build.gradle' @@ -64,16 +69,16 @@ def download(address,target) { } task downloadCli << { - dir = workspacePath+'de.prob.core/prob/' + def dir = workspacePath+'de.prob.core/prob/' delete file(dir) new File(dir).mkdirs() ['leopard64':'macos','linux':'linux','linux64':'linux64','win32':'windows'].each { - n = it.getKey() + def n = it.getKey() - targetdir = dir+it.getValue() - targetzip = dir+"probcli_${n}.zip" - url = "http://nightly.cobra.cs.uni-duesseldorf.de/cli/probcli_${n}.zip" + def targetdir = dir+it.getValue() + def targetzip = dir+"probcli_${n}.zip" + def url = "http://nightly.cobra.cs.uni-duesseldorf.de/cli/probcli_${n}.zip" download(url,targetzip) FileTree zip = zipTree(targetzip) copy { @@ -83,8 +88,8 @@ task downloadCli << { delete file(targetzip) } - targetdir = dir+"windows/" - targetzip = targetdir+"windowslib.zip" + def targetdir = dir+"windows/" + def targetzip = targetdir+"windowslib.zip" download("http://nightly.cobra.cs.uni-duesseldorf.de/cli/windowslib.zip",targetzip) FileTree zip = zipTree(targetzip) copy { @@ -96,6 +101,53 @@ task downloadCli << { } + +task downloadCli2 ( type: Exec ) { + + def dir = workspacePath+'de.prob.core/prob/' + delete file(dir) + new File(dir).mkdirs() + + ['leopard64':'macos','linux':'linux','linux64':'linux64','win32':'windows'].each { + def n = it.getKey() + + def targetdir = dir+it.getValue() + def targetzip = dir+"probcli_${n}.zip" + def url = "http://nightly.cobra.cs.uni-duesseldorf.de/cli/probcli_${n}.zip" + download(url,targetzip) + FileTree zip = zipTree(targetzip) + copy { + from zip + into targetdir + } + delete file(targetzip) + } + + def targetdir = dir+"windows/" + def targetzip = targetdir+"windowslib.zip" + download("http://nightly.cobra.cs.uni-duesseldorf.de/cli/windowslib.zip",targetzip) + FileTree zip = zipTree(targetzip) + copy { + from zip + into targetdir + } + delete file(targetzip) + + ['leopard64':'macos','linux32':'linux','linux64':'linux64'].each { + + def n = it.getKey() + targetdir = dir+it.getValue() + + download( "http://nightly.cobra.cs.uni-duesseldorf.de/cspm/cspm-"+n, targetdir+"/cspm" ) + } + commandLine 'chmod', 'a+x', dir+'linux'+'/cspm', dir+'linux64'+'/cspm', dir+'macos'+'/cspm' + //commandLine 'chmod', 'a+x', dir+'*'+'/cspm' + + download( "http://nightly.cobra.cs.uni-duesseldorf.de/cspm/cspm-windows", dir+"windows"+"/cspm.exe" ) +} + + + completeInstall.dependsOn downloadCli completeInstall.dependsOn subprojects.setClassPath diff --git a/de.bmotionstudio.gef.editor/META-INF/MANIFEST.MF b/de.bmotionstudio.gef.editor/META-INF/MANIFEST.MF index d51f7c6fbfc3643ab3835dfea27032834f06a5f2..b9f7194b6c271a84dc5615ce6df02a6a88eef5f8 100644 --- a/de.bmotionstudio.gef.editor/META-INF/MANIFEST.MF +++ b/de.bmotionstudio.gef.editor/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: BMotion Studio Editor Plug-in Bundle-SymbolicName: de.bmotionstudio.gef.editor;singleton:=true -Bundle-Version: 5.4.0.qualifier +Bundle-Version: 5.4.2.qualifier Bundle-Activator: de.bmotionstudio.gef.editor.BMotionEditorPlugin Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)", @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", org.eclipse.core.databinding.beans;bundle-version="[1.1.1,2.0.0)", org.eclipse.gef;bundle-version="[3.7.0,4.0.0)";visibility:=reexport, de.prob.core;bundle-version="[9.3.0,9.4.0)";visibility:=reexport, - org.eventb.core;bundle-version="[2.1.0,2.6.0)" + org.eventb.core;bundle-version="[2.1.0,2.6.0)", + org.eclipse.help;bundle-version="3.5.100" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Eclipse-RegisterBuddy: de.prob.core diff --git a/de.bmotionstudio.gef.editor/icons/eclipse16/linkto_help.gif b/de.bmotionstudio.gef.editor/icons/eclipse16/linkto_help.gif new file mode 100644 index 0000000000000000000000000000000000000000..86550fe9f4505c88287a70add9bb89bd24d0e8b2 Binary files /dev/null and b/de.bmotionstudio.gef.editor/icons/eclipse16/linkto_help.gif differ diff --git a/de.bmotionstudio.gef.editor/icons/icon_add.gif b/de.bmotionstudio.gef.editor/icons/icon_add.gif deleted file mode 100644 index 1b0630841412d754fd6546e33923ad1ac08a2a9b..0000000000000000000000000000000000000000 Binary files a/de.bmotionstudio.gef.editor/icons/icon_add.gif and /dev/null differ diff --git a/de.bmotionstudio.gef.editor/icons/icon_ascript.png b/de.bmotionstudio.gef.editor/icons/icon_ascript.png deleted file mode 100644 index 4cd71dba209ec693a58b14e7351873b374080988..0000000000000000000000000000000000000000 Binary files a/de.bmotionstudio.gef.editor/icons/icon_ascript.png and /dev/null differ diff --git a/de.bmotionstudio.gef.editor/icons/icon_motion.gif b/de.bmotionstudio.gef.editor/icons/icon_motion.gif deleted file mode 100644 index 173d240af99eff66594bbefb1d12d16da8d8b548..0000000000000000000000000000000000000000 Binary files a/de.bmotionstudio.gef.editor/icons/icon_motion.gif and /dev/null differ diff --git a/de.bmotionstudio.gef.editor/icons/icon_motion_wiz.gif b/de.bmotionstudio.gef.editor/icons/icon_motion_wiz.gif deleted file mode 100644 index 1e9bf55a7b95055a4cc8bc7646266c58fb28e45f..0000000000000000000000000000000000000000 Binary files a/de.bmotionstudio.gef.editor/icons/icon_motion_wiz.gif and /dev/null differ diff --git a/de.bmotionstudio.gef.editor/icons/icon_screenshot.gif b/de.bmotionstudio.gef.editor/icons/icon_screenshot.gif deleted file mode 100644 index 176830af2dc8be87218c4dd944ba7dc6ffb79756..0000000000000000000000000000000000000000 Binary files a/de.bmotionstudio.gef.editor/icons/icon_screenshot.gif and /dev/null differ diff --git a/de.bmotionstudio.gef.editor/lib/ext/._antlr-2.7.7.jar1851805142189607825.tmp b/de.bmotionstudio.gef.editor/lib/ext/._antlr-2.7.7.jar1851805142189607825.tmp new file mode 100644 index 0000000000000000000000000000000000000000..5e5f14b35584eac2a9f0f888769f0ab93ca6d849 Binary files /dev/null and b/de.bmotionstudio.gef.editor/lib/ext/._antlr-2.7.7.jar1851805142189607825.tmp differ diff --git a/de.bmotionstudio.gef.editor/plugin.xml b/de.bmotionstudio.gef.editor/plugin.xml index f1d465afcd7efc7c5ebae8ca9f8eeb8541137848..f7e7118ba7f96773030a3b4f474eceb4995ecdc6 100644 --- a/de.bmotionstudio.gef.editor/plugin.xml +++ b/de.bmotionstudio.gef.editor/plugin.xml @@ -49,7 +49,17 @@ class="de.bmotionstudio.gef.editor.library.LibraryView" icon="icons/icon_library.gif" id="de.bmotionstudio.gef.editor.LibraryView" - name="BMS Library"> + name="Library" + restorable="true"> + </view> + <view + allowMultiple="false" + category="de.bmotionstudio.views" + class="de.bmotionstudio.gef.editor.observer.view.ObserverView" + icon="icons/icon_observer.gif" + id="de.bmotionstudio.gef.editor.ObserverView" + name="Observer" + restorable="true"> </view> </extension> <extension @@ -110,7 +120,7 @@ <extension point="org.eclipse.ui.commands"> <command - defaultHandler="de.bmotionstudio.gef.editor.internal.OpenWebsiteHandler" + defaultHandler="de.bmotionstudio.gef.editor.handler.OpenWebsiteHandler" id="de.bmotionstudio.gef.editor.command.openBMotionStudioWebsite" name="Open website"> </command> @@ -119,7 +129,7 @@ name="Start Visualization from Editor"> </command> <command - defaultHandler="de.bmotionstudio.gef.editor.internal.StartVisualizationFileHandler" + defaultHandler="de.bmotionstudio.gef.editor.handler.StartVisualizationFileHandler" id="de.bmotionstudio.command.startVisualizationFromFile" name="Start Visualization from File"> </command> @@ -127,7 +137,7 @@ <extension point="org.eclipse.ui.handlers"> <handler - class="de.bmotionstudio.gef.editor.internal.StartVisualizationEditorHandler" + class="de.bmotionstudio.gef.editor.handler.StartVisualizationEditorHandler" commandId="de.bmotionstudio.command.startVisualizationFromEditor"> <enabledWhen> <with @@ -156,6 +166,9 @@ <registerImages class="de.bmotionstudio.gef.editor.EditorImageRegistry"> </registerImages> + <registerImages + class="de.bmotionstudio.gef.editor.ImageRegistry"> + </registerImages> </extension> <extension @@ -169,142 +182,142 @@ icon="icons/eclipse16/image_obj.gif" id="de.bmotionstudio.gef.editor.image" name="Image" - service="de.bmotionstudio.gef.editor.service.BImageService"> + service="de.bmotionstudio.gef.editor.model.service.BImageService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_button.gif" id="de.bmotionstudio.gef.editor.button" name="Button" - service="de.bmotionstudio.gef.editor.service.BButtonService"> + service="de.bmotionstudio.gef.editor.model.service.BButtonService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_radiobutton_c.gif" id="de.bmotionstudio.gef.editor.radiobutton" name="Radiobutton" - service="de.bmotionstudio.gef.editor.service.BRadioButtonService"> + service="de.bmotionstudio.gef.editor.model.service.BRadioButtonService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_checked.gif" id="de.bmotionstudio.gef.editor.checkbox" name="Checkbox" - service="de.bmotionstudio.gef.editor.service.BCheckboxService"> + service="de.bmotionstudio.gef.editor.model.service.BCheckboxService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/eclipse16/overview_obj.gif" id="de.bmotionstudio.gef.editor.composite" name="Composite" - service="de.bmotionstudio.gef.editor.service.BCompositeService"> + service="de.bmotionstudio.gef.editor.model.service.BCompositeService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_text.gif" id="de.bmotionstudio.gef.editor.text" name="Text" - service="de.bmotionstudio.gef.editor.service.BTextService"> + service="de.bmotionstudio.gef.editor.model.service.BTextService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_textfield.gif" id="de.bmotionstudio.gef.editor.textfield" name="Textfield" - service="de.bmotionstudio.gef.editor.service.BTextfieldService"> + service="de.bmotionstudio.gef.editor.model.service.BTextfieldService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_rectangle.gif" id="de.bmotionstudio.gef.editor.rectangle" name="Rectanlge" - service="de.bmotionstudio.gef.editor.service.BRectangleService"> + service="de.bmotionstudio.gef.editor.model.service.BRectangleService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_ellipse.gif" id="de.bmotionstudio.gef.editor.ellipse" name="Ellipse" - service="de.bmotionstudio.gef.editor.service.BEllipseService"> + service="de.bmotionstudio.gef.editor.model.service.BEllipseService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/icon_connection16.gif" id="de.bmotionstudio.gef.editor.connection" name="Connection" - service="de.bmotionstudio.gef.editor.service.BConnectionService"> + service="de.bmotionstudio.gef.editor.model.service.BConnectionService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/eclipse16/prop_ps.gif" id="de.bmotionstudio.gef.editor.table" name="Table" - service="de.bmotionstudio.gef.editor.service.BTableService"> + service="de.bmotionstudio.gef.editor.model.service.BTableService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/eclipse16/prop_ps2.gif" id="de.bmotionstudio.gef.editor.tablecolumn" name="Column" - service="de.bmotionstudio.gef.editor.service.BTableColumnService"> + service="de.bmotionstudio.gef.editor.model.service.BTableColumnService"> </control> <control groupid="de.bmotionstudio.gef.editor.group.main" icon="icons/eclipse16/prop_ps3.gif" id="de.bmotionstudio.gef.editor.tablecell" name="Cell" - service="de.bmotionstudio.gef.editor.service.BTableCellService"> + service="de.bmotionstudio.gef.editor.model.service.BTableCellService"> </control> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/icon_signal.gif" id="de.bmotionstudio.gef.editor.signal" name="Signal" - service="de.bmotionstudio.gef.editor.service.SignalService"> + service="de.bmotionstudio.gef.editor.model.service.SignalService"> </control> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/eclipse16/smartmode_co.gif" id="de.bmotionstudio.gef.editor.light" name="Light" - service="de.bmotionstudio.gef.editor.service.LightService"> + service="de.bmotionstudio.gef.editor.model.service.LightService"> </control> + <group + id="de.bmotionstudio.gef.editor.industry.group" + name="Industry"> + </group> <control groupid="de.bmotionstudio.gef.editor.industry.group" icon="icons/icon_tank.gif" id="de.bmotionstudio.gef.editor.tank" name="Tank" - service="de.bmotionstudio.gef.editor.service.TankService"> + service="de.bmotionstudio.gef.editor.model.service.TankService"> </control> + <group + id="de.bmotionstudio.gef.editor.railway.group" + name="Railway"> + </group> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/icon_tracknode.gif" id="de.bmotionstudio.gef.editor.tracknode" name="Node" - service="de.bmotionstudio.gef.editor.service.TrackNodeService"> + service="de.bmotionstudio.gef.editor.model.service.TrackNodeService"> </control> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/icon_track.gif" id="de.bmotionstudio.gef.editor.track" name="Trac" - service="de.bmotionstudio.gef.editor.service.TrackService"> + service="de.bmotionstudio.gef.editor.model.service.TrackService"> </control> <control groupid="de.bmotionstudio.gef.editor.railway.group" icon="icons/icon_switch.gif" id="de.bmotionstudio.gef.editor.switch" name="Switch" - service="de.bmotionstudio.gef.editor.service.SwitchService"> + service="de.bmotionstudio.gef.editor.model.service.SwitchService"> </control> - <group - id="de.bmotionstudio.gef.editor.railway.group" - name="Railway"> - </group> - <group - id="de.bmotionstudio.gef.editor.industry.group" - name="Industry"> - </group> </extension> <extension point="de.bmotionstudio.gef.editor.observer"> @@ -336,10 +349,6 @@ description="Observer for switching the coordinates of the control" name="Switch Coordinates"> </observer> - <observer - class="de.bmotionstudio.gef.editor.observer.ExternalObserverScript" - name="External Observer Script"> - </observer> <observer class="de.bmotionstudio.gef.editor.observer.TableObserver" name="Table Observer"> @@ -382,12 +391,6 @@ class="de.bmotionstudio.gef.editor.InstallMenu"> </menu> </extension> - <extension - point="de.bmotionstudio.gef.editor.registerImages"> - <registerImages - class="de.bmotionstudio.gef.editor.ImageRegistry"> - </registerImages> - </extension> <extension point="de.bmotionstudio.gef.editor.language"> <language @@ -399,270 +402,255 @@ point="de.bmotionstudio.gef.editor.includeObserver"> <include language="EventB"> - <observer - id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> - <control - id="de.bmotionstudio.gef.editor.image"> - </control> - <control - id="de.bmotionstudio.gef.editor.button"> - </control> - <control - id="de.bmotionstudio.gef.editor.composite"> - </control> - <control - id="de.bmotionstudio.gef.editor.text"> - </control> - <control - id="de.bmotionstudio.gef.editor.ellipse"> - </control> - <control - id="de.bmotionstudio.gef.editor.rectangle"> - </control> - <control - id="de.bmotionstudio.gef.editor.radiobutton"> - </control> - <control - id="de.bmotionstudio.gef.editor.checkbox"> - </control> - <control - id="de.bmotionstudio.gef.editor.connection"> - </control> - <control - id="de.bmotionstudio.gef.editor.tablecell"> - </control> - <control - id="de.bmotionstudio.gef.editor.table"> - </control> - <control - id="de.bmotionstudio.gef.editor.tablecolumn"> - </control> - <control - id="de.bmotionstudio.gef.editor.signal"> - </control> - <control - id="de.bmotionstudio.gef.editor.tank"> - </control> - <control - id="de.bmotionstudio.gef.editor.switch"> - </control> - <control - id="de.bmotionstudio.gef.editor.track"> - </control> - <control - id="de.bmotionstudio.gef.editor.light"> - </control> - </observer> - <observer - id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> - <control - id="de.bmotionstudio.gef.editor.image"> - </control> - <control - id="de.bmotionstudio.gef.editor.button"> - </control> - <control - id="de.bmotionstudio.gef.editor.composite"> - </control> - <control - id="de.bmotionstudio.gef.editor.text"> - </control> - <control - id="de.bmotionstudio.gef.editor.rectangle"> - </control> - <control - id="de.bmotionstudio.gef.editor.radiobutton"> - </control> - <control - id="de.bmotionstudio.gef.editor.textfield"> - </control> - <control - id="de.bmotionstudio.gef.editor.checkbox"> - </control> - <control - id="de.bmotionstudio.gef.editor.ellipse"> - </control> - <control - id="de.bmotionstudio.gef.editor.table"> - </control> - <control - id="de.bmotionstudio.gef.editor.signal"> - </control> - <control - id="de.bmotionstudio.gef.editor.tank"> - </control> - <control - id="de.bmotionstudio.gef.editor.switch"> - </control> - </observer> - <observer - id="de.bmotionstudio.gef.editor.observer.SimpleValueDisplay"> - <control - id="de.bmotionstudio.gef.editor.text"> - </control> - <control - id="de.bmotionstudio.gef.editor.radiobutton"> - </control> - <control - id="de.bmotionstudio.gef.editor.textfield"> - </control> - <control - id="de.bmotionstudio.gef.editor.button"> - </control> - <control - id="de.bmotionstudio.gef.editor.tablecell"> - </control> - </observer> - <observer - id="de.bmotionstudio.gef.editor.observer.SetAttribute"> - <control - id="de.bmotionstudio.gef.editor.image"> - </control> - <control - id="de.bmotionstudio.gef.editor.button"> - </control> - <control - id="de.bmotionstudio.gef.editor.composite"> - </control> - <control - id="de.bmotionstudio.gef.editor.text"> - </control> - <control - id="de.bmotionstudio.gef.editor.rectangle"> - </control> - <control - id="de.bmotionstudio.gef.editor.radiobutton"> - </control> - <control - id="de.bmotionstudio.gef.editor.checkbox"> - </control> - <control - id="de.bmotionstudio.gef.editor.connection"> - </control> - <control - id="de.bmotionstudio.gef.editor.ellipse"> - </control> - <control - id="de.bmotionstudio.gef.editor.textfield"> - </control> - <control - id="de.bmotionstudio.gef.editor.tablecell"> - </control> - <control - id="de.bmotionstudio.gef.editor.table"> - </control> - <control - id="de.bmotionstudio.gef.editor.tablecolumn"> - </control> - <control - id="de.bmotionstudio.gef.editor.signal"> - </control> - <control - id="de.bmotionstudio.gef.editor.tank"> - </control> - <control - id="de.bmotionstudio.gef.editor.switch"> - </control> - <control - id="de.bmotionstudio.gef.editor.track"> - </control> - <control - id="de.bmotionstudio.gef.editor.light"> - </control> - </observer> - <observer - id="de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates"> - <control - id="de.bmotionstudio.gef.editor.composite"> - </control> - <control - id="de.bmotionstudio.gef.editor.visualization"> - </control> - </observer> - <observer - id="de.bmotionstudio.gef.editor.observer.ExternalObserverScript"> - <control - id="de.bmotionstudio.gef.editor.image"> - </control> - <control - id="de.bmotionstudio.gef.editor.button"> - </control> - <control - id="de.bmotionstudio.gef.editor.composite"> - </control> - <control - id="de.bmotionstudio.gef.editor.text"> - </control> - <control - id="de.bmotionstudio.gef.editor.rectangle"> - </control> - <control - id="de.bmotionstudio.gef.editor.radiobutton"> - </control> - <control - id="de.bmotionstudio.gef.editor.checkbox"> - </control> - <control - id="de.bmotionstudio.gef.editor.connection"> - </control> - <control - id="de.bmotionstudio.gef.editor.ellipse"> - </control> - <control - id="de.bmotionstudio.gef.editor.textfield"> - </control> - <control - id="de.bmotionstudio.gef.editor.tablecell"> - </control> - <control - id="de.bmotionstudio.gef.editor.table"> - </control> - <control - id="de.bmotionstudio.gef.editor.tablecolumn"> - </control> - <control - id="de.bmotionstudio.gef.editor.light"> - </control> - <control - id="de.bmotionstudio.gef.editor.signal"> - </control> - <control - id="de.bmotionstudio.gef.editor.switch"> - </control> - <control - id="de.bmotionstudio.gef.editor.track"> - </control> - <control - id="de.bmotionstudio.gef.editor.tracknode"> - </control> - </observer> - <observer - id="de.bmotionstudio.gef.editor.observer.SwitchImage"> - <control - id="de.bmotionstudio.gef.editor.image"> - </control> - <control - id="de.bmotionstudio.gef.editor.composite"> - </control> - <control - id="de.bmotionstudio.gef.editor.rectangle"> - </control> - <control - id="de.bmotionstudio.gef.editor.ellipse"> - </control> - </observer> - <observer - id="de.bmotionstudio.gef.editor.observer.ColumnObserver"> - <control - id="de.bmotionstudio.gef.editor.tablecolumn"> - </control> - </observer> - <observer - id="de.bmotionstudio.gef.editor.observer.TableObserver"> - <control - id="de.bmotionstudio.gef.editor.table"> - </control> - </observer> + <control + id="de.bmotionstudio.gef.editor.image"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchImage"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.button"> + <observer + id="de.bmotionstudio.gef.editor.observer.SimpleValueDisplay"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.checkbox"> + <observer + id="de.bmotionstudio.gef.editor.observer.SimpleValueDisplay"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.radiobutton"> + <observer + id="de.bmotionstudio.gef.editor.observer.SimpleValueDisplay"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.textfield"> + <observer + id="de.bmotionstudio.gef.editor.observer.SimpleValueDisplay"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.composite"> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchImage"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.text"> + <observer + id="de.bmotionstudio.gef.editor.observer.SimpleValueDisplay"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.rectangle"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchImage"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.connection"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.ellipse"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchImage"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.table"> + <observer + id="de.bmotionstudio.gef.editor.observer.TableObserver"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.tablecolumn"> + <observer + id="de.bmotionstudio.gef.editor.observer.ColumnObserver"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.tablecell"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.signal"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.light"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.tank"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.tracknode"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.track"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + </control> + <control + id="de.bmotionstudio.gef.editor.switch"> + <observer + id="de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SetAttribute"> + </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> + </observer> + </control> </include> </extension> </plugin> diff --git a/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.control.exsd b/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.control.exsd index ce1f1677784cea86330b89864ecc79fc0eab3f6a..e35e7098e4b05024689df59e940cd48a108b2e91 100644 --- a/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.control.exsd +++ b/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.control.exsd @@ -18,7 +18,6 @@ </annotation> <complexType> <sequence minOccurs="0" maxOccurs="unbounded"> - <element ref="control" minOccurs="0" maxOccurs="1"/> <element ref="group" minOccurs="0" maxOccurs="1"/> <element ref="control" minOccurs="0" maxOccurs="1"/> </sequence> @@ -75,9 +74,6 @@ </appInfo> </annotation> <complexType> - <sequence> - <element ref="attributes" minOccurs="0" maxOccurs="1"/> - </sequence> <attribute name="id" type="string" use="required"> <annotation> <documentation> @@ -122,94 +118,30 @@ </complexType> </element> - <element name="attribute-string"> - <complexType> - <attribute name="id" type="string" use="required"> - <annotation> - <documentation> - The id of the referenced attribute. Since the same attribute could be assigned to different controls the corresponding attibute is defined in a seperate exention point (de.bmotionstudio.gef.editor.attribute). - </documentation> - </annotation> - </attribute> - <attribute name="default-value" type="string" use="required"> - <annotation> - <documentation> - The default value of this attribute for this control - </documentation> - </annotation> - </attribute> - <attribute name="editable" type="boolean" use="default" value="true"> - <annotation> - <documentation> - Boolean value - Option to decide whenever this attribute should be editable or not. - </documentation> - </annotation> - </attribute> - <attribute name="show" type="boolean" use="default" value="true"> - <annotation> - <documentation> - Boolean value - Option to decide whenever this attribute should be displayed in the properties view. - </documentation> - </annotation> - </attribute> - </complexType> - </element> - - <element name="attribute-java"> - <complexType> - <attribute name="id" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="default-value" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - <appInfo> - <meta.attribute kind="java" basedOn=":de.bmotionstudio.core.IGetDefaultValue"/> - </appInfo> - </annotation> - </attribute> - </complexType> - </element> - - <element name="attributes"> - <complexType> - <sequence> - <element ref="attribute-java" minOccurs="0" maxOccurs="unbounded"/> - <element ref="attribute-string" minOccurs="0" maxOccurs="unbounded"/> - </sequence> - </complexType> - </element> - <annotation> <appInfo> - <meta.section type="since"/> + <meta.section type="apiInfo"/> </appInfo> <documentation> - [Enter the first release in which this extension point appears.] + [Enter API information here.] </documentation> </annotation> <annotation> <appInfo> - <meta.section type="examples"/> + <meta.section type="since"/> </appInfo> <documentation> - [Enter extension point usage example here.] + [Enter the first release in which this extension point appears.] </documentation> </annotation> <annotation> <appInfo> - <meta.section type="apiInfo"/> + <meta.section type="examples"/> </appInfo> <documentation> - [Enter API information here.] + [Enter extension point usage example here.] </documentation> </annotation> diff --git a/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.includeObserver.exsd b/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.includeObserver.exsd index 42a20dc11a1b04d951c27b1e7aff883084d90fa0..9a9fd6bff375350ae30cbaff7e8a92f020265733 100644 --- a/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.includeObserver.exsd +++ b/de.bmotionstudio.gef.editor/schema/de.bmotionstudio.gef.editor.includeObserver.exsd @@ -54,6 +54,9 @@ </appInfo> </annotation> <complexType> + <sequence minOccurs="1" maxOccurs="unbounded"> + <element ref="observer"/> + </sequence> <attribute name="id" type="string" use="required"> <annotation> <documentation> @@ -71,9 +74,6 @@ </appInfo> </annotation> <complexType> - <sequence minOccurs="1" maxOccurs="unbounded"> - <element ref="control"/> - </sequence> <attribute name="id" type="string" use="required"> <annotation> <documentation> @@ -87,7 +87,7 @@ <element name="include"> <complexType> <sequence minOccurs="1" maxOccurs="unbounded"> - <element ref="observer"/> + <element ref="control"/> </sequence> <attribute name="language" type="string" use="required"> <annotation> diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMSContextMenuProvider.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMSContextMenuProvider.java index 9822355aa3049caf66bd4c8c764786da49fd4053..58faadced59bf14c5fed56a3bbbaf24c71af7097 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMSContextMenuProvider.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMSContextMenuProvider.java @@ -25,7 +25,6 @@ import org.eclipse.ui.actions.ActionFactory; import de.bmotionstudio.gef.editor.action.OpenSchedulerEventAction; import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent; @@ -120,8 +119,6 @@ public class BMSContextMenuProvider extends ContextMenuProvider { if (model instanceof BControl) bcontrol = (BControl) model; - else if (model instanceof ObserverRootVirtualTreeNode) - bcontrol = ((ObserverRootVirtualTreeNode) model).getControl(); else return; @@ -131,51 +128,9 @@ public class BMSContextMenuProvider extends ContextMenuProvider { "icons/icon_observer.gif"), "observerMenu"); menu.appendToGroup(GEFActionConstants.GROUP_ADD, handleObserverMenu); - IExtensionPoint extensionPoint = registry - .getExtensionPoint("de.bmotionstudio.gef.editor.observer"); - for (IExtension extension : extensionPoint.getExtensions()) { - for (IConfigurationElement configurationElement : extension - .getConfigurationElements()) { - - if ("observer".equals(configurationElement.getName())) { - - final String observerClassName = configurationElement - .getAttribute("class"); - final String observerName = configurationElement - .getAttribute("name"); - - if (checkIncludeObserver(observerClassName, bcontrol)) { - - IAction action = getActionRegistry().getAction( - "de.bmotionstudio.gef.editor.observerAction." - + observerClassName); - action.setText(observerName); - action.setToolTipText(observerName); - - if (bcontrol.hasObserver(observerClassName)) { - action.setImageDescriptor(BMotionStudioImage - .getImageDescriptor( - BMotionEditorPlugin.PLUGIN_ID, - "icons/icon_chop.gif")); - } else { - action.setImageDescriptor(null); - } - handleObserverMenu.add(action); - - } - - } - - } - - } - - } - - private boolean checkIncludeObserver(String observerID, BControl control) { - - IExtensionPoint extensionPoint = registry - .getExtensionPoint("de.bmotionstudio.gef.editor.includeObserver"); + IExtensionPoint extensionPoint = Platform.getExtensionRegistry() + .getExtensionPoint( + "de.bmotionstudio.gef.editor.includeObserver"); for (IExtension extension : extensionPoint.getExtensions()) { for (IConfigurationElement configurationElement : extension @@ -187,25 +142,35 @@ public class BMSContextMenuProvider extends ContextMenuProvider { .getAttribute("language"); if (langID != null - && langID.equals(control.getVisualization() - .getLanguage())) { + && langID.equals(bcontrol.getVisualization().getLanguage())) { + + for (IConfigurationElement configC : configurationElement + .getChildren("control")) { + + String cID = configC.getAttribute("id"); - for (IConfigurationElement cObserver : configurationElement - .getChildren("observer")) { + if (bcontrol.getType().equals(cID)) { - String oID = cObserver.getAttribute("id"); + for (IConfigurationElement configO : configC + .getChildren("observer")) { - if (observerID.equals(oID)) { + String oID = configO.getAttribute("id"); + IAction action = getActionRegistry() + .getAction( + "de.bmotionstudio.gef.editor.observerAction." + + oID); - for (IConfigurationElement configBControl : cObserver - .getChildren("control")) { + String name = oID; - String bID = configBControl - .getAttribute("id"); + IConfigurationElement observerExtension = BMotionEditorPlugin + .getObserverExtension(oID); + if (observerExtension != null) + name = observerExtension + .getAttribute("name"); - if (control.getType().equals(bID)) { - return true; - } + action.setText(name); + + handleObserverMenu.add(action); } @@ -220,8 +185,6 @@ public class BMSContextMenuProvider extends ContextMenuProvider { } } - return false; - } private void buildEventMenu(IMenuManager menu, AbstractEditPart editPart) { @@ -282,14 +245,6 @@ public class BMSContextMenuProvider extends ContextMenuProvider { action.setText(configSchedulerElement .getAttribute("name")); - // if (bcontrol.hasEvent(eventIDs[0])) { - // action - // .setImageDescriptor(BMotionStudioImage - // .getImageDescriptor( - // BMotionEditorPlugin.PLUGIN_ID, - // "icons/icon_chop.gif")); - // } else { - action.setImageDescriptor(null); // } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionAbstractWizard.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionAbstractWizard.java index b4524f4a38388e7cd806f2b95971b189fe425b33..fa865249822953de0bf204e13b52f9a04c4bbad4 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionAbstractWizard.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionAbstractWizard.java @@ -6,29 +6,79 @@ package de.bmotionstudio.gef.editor; -import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; import de.bmotionstudio.gef.editor.model.BControl; -public abstract class BMotionAbstractWizard extends Wizard { +public abstract class BMotionAbstractWizard extends TrayDialog { private BControl control; - public BMotionAbstractWizard(BControl control) { + public static final int CLOSE = 2; + + public BMotionAbstractWizard(Shell shell, BControl control) { + super(shell); this.control = control; } - @Override - public boolean performFinish() { - return prepareToFinish(); - } - public BControl getBControl() { return this.control; } - public abstract String getName(); + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + } - protected abstract Boolean prepareToFinish(); + public abstract String getName(); + @Override + protected int getShellStyle() { + return SWT.SHELL_TRIM; + } + + @Override + protected Control createDialogArea(Composite parent) { + + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.verticalSpacing = 0; + + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(layout); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + + createWizardContent(container); + + return container; + + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.CLOSE_ID, + IDialogConstants.CLOSE_LABEL, true); + } + + @Override + protected void buttonPressed(int buttonId) { + if (IDialogConstants.CLOSE_ID == buttonId) + closePressed(); + } + + protected void closePressed() { + setReturnCode(CLOSE); + close(); + } + + public abstract Control createWizardContent(Composite parent); + } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/EditorImageRegistry.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/EditorImageRegistry.java index 56b16757ec2c66df568c7fcd22408130837cacc3..72511e5fce357a1fe710fcdf24d90952337f87ce 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/EditorImageRegistry.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/EditorImageRegistry.java @@ -8,7 +8,7 @@ package de.bmotionstudio.gef.editor; public class EditorImageRegistry implements IBMotionStudioImageRegistry { - public static final String IMG_ICON_ADD = "icon_add"; + // public static final String IMG_ICON_ADD = "icon_add"; public static final String IMG_ICON_CHOP = "icon_chop"; public static final String IMG_ICON_DELETE = "icon_delete"; public static final String IMG_ICON_DELETE21 = "icon_delete21"; @@ -18,7 +18,6 @@ public class EditorImageRegistry implements IBMotionStudioImageRegistry { public static final String IMG_ICON_OBSERVER = "icon_observer"; public static final String IMG_ICON_LOADING = "icon_loading"; public static final String IMG_ICON_LIBRARY = "icon_library"; - public static final String IMG_ICON_ASCRIPT = "icon_ascript"; public static final String IMG_ICON_UP = "icon_up"; public static final String IMG_ICON_DOWN = "icon_down"; public static final String IMG_ICON_CONNECTION16 = "icon_connection16"; @@ -28,6 +27,7 @@ public class EditorImageRegistry implements IBMotionStudioImageRegistry { public static final String IMG_ICON_TR_UP = "icon_tr_up"; public static final String IMG_ICON_TR_LEFT = "icon_tr_left"; public static final String IMG_ICON_CONTROL_HIDDEN = "icon_control_hidden"; + public static final String IMG_ICON_HELP = "icon_help"; public static final String IMG_ICON_JPG = "icon_jpg"; public static final String IMG_ICON_GIF = "icon_gif"; @@ -36,8 +36,8 @@ public class EditorImageRegistry implements IBMotionStudioImageRegistry { public void registerImages() { - BMotionStudioImage.registerImage(IMG_ICON_ADD, - BMotionEditorPlugin.PLUGIN_ID, "icons/icon_add.gif"); + // BMotionStudioImage.registerImage(IMG_ICON_ADD, + // BMotionEditorPlugin.PLUGIN_ID, "icons/icon_add.gif"); BMotionStudioImage.registerImage(IMG_ICON_CHOP, BMotionEditorPlugin.PLUGIN_ID, "icons/icon_chop.gif"); BMotionStudioImage.registerImage(IMG_ICON_DELETE, @@ -54,8 +54,6 @@ public class EditorImageRegistry implements IBMotionStudioImageRegistry { BMotionEditorPlugin.PLUGIN_ID, "icons/icon_loading.gif"); BMotionStudioImage.registerImage(IMG_ICON_LIBRARY, BMotionEditorPlugin.PLUGIN_ID, "icons/icon_library.gif"); - BMotionStudioImage.registerImage(IMG_ICON_ASCRIPT, - BMotionEditorPlugin.PLUGIN_ID, "icons/icon_ascript.png"); BMotionStudioImage.registerImage(IMG_ICON_UP, BMotionEditorPlugin.PLUGIN_ID, "icons/icon_up.gif"); BMotionStudioImage.registerImage(IMG_ICON_DOWN, @@ -72,6 +70,9 @@ public class EditorImageRegistry implements IBMotionStudioImageRegistry { "org.eclipse.ui", "$nl$/icons/full/etool16/delete_edit.gif"); BMotionStudioImage.registerImage(IMG_ICON_DELETE_EDIT, "org.eclipse.ui", "$nl$/icons/full/etool16/delete_edit.gif"); + BMotionStudioImage.registerImage(IMG_ICON_HELP, + BMotionEditorPlugin.PLUGIN_ID, + "icons/eclipse16/linkto_help.gif"); BMotionStudioImage .registerImage(IMG_ICON_TR_UP, BMotionEditorPlugin.PLUGIN_ID, "icons/eclipse16/updated_co.gif"); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionAbstractWizardDialog.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionAbstractWizardDialog.java deleted file mode 100644 index d9a3d5c380584994b742f7faf36ad8d7b89d886a..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionAbstractWizardDialog.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.action; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.ui.IWorkbenchPart; - -import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.EditorImageRegistry; - -public abstract class BMotionAbstractWizardDialog extends WizardDialog { - - public static final int DELETE = 3; - - private IWorkbenchPart workbenchPart; - - private String deleteToolTip; - - public BMotionAbstractWizardDialog(IWorkbenchPart workbenchPart, IWizard newWizard) { - super(workbenchPart.getSite().getShell(), newWizard); - this.workbenchPart = workbenchPart; - } - - @Override - protected Control createButtonBar(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - layout.horizontalSpacing = 0; - composite.setLayout(layout); - composite - .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); - composite.setFont(parent.getFont()); - - // create help control if needed - if (isHelpAvailable()) { - Control helpControl = createHelpControl(composite); - ((GridData) helpControl.getLayoutData()).horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - } - - Control deleteControl = createDeleteControl(composite); - ((GridData) deleteControl.getLayoutData()).horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - setHelpAvailable(false); - Control buttonSection = super.createButtonBar(composite); - ((GridData) buttonSection.getLayoutData()).grabExcessHorizontalSpace = true; - return composite; - } - - private Control createDeleteControl(Composite parent) { - return createDeleteImageButton(parent, - BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE21)); - } - - private ToolBar createDeleteImageButton(Composite parent, Image image) { - ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS); - ((GridLayout) parent.getLayout()).numColumns++; - toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); - final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND); - toolBar.setCursor(cursor); - toolBar.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - cursor.dispose(); - } - }); - ToolItem deleteToolItem = new ToolItem(toolBar, SWT.NONE); - deleteToolItem.setImage(image); - deleteToolItem.setToolTipText(deleteToolTip); - deleteToolItem.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - deletePressed(); - } - }); - return toolBar; - } - - protected abstract void deletePressed(); - - public IWorkbenchPart getWorkbenchPart() { - return workbenchPart; - } - - protected void setDeleteToolTip(String msg) { - this.deleteToolTip = msg; - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionObserverWizardDialog.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionObserverWizardDialog.java deleted file mode 100644 index b5ccee629af599d22f068f274a63be7b2e341788..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionObserverWizardDialog.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.action; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchPart; - -public class BMotionObserverWizardDialog extends BMotionAbstractWizardDialog { - - public BMotionObserverWizardDialog(IWorkbenchPart workbenchPart, IWizard newWizard) { - super(workbenchPart, newWizard); - setShellStyle(SWT.CLOSE | SWT.RESIZE); - setDeleteToolTip("Delete Observer"); - } - - @Override - protected void deletePressed() { - - if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), - "Do you really want to delete this Observer?", - "Do you really want to delete this Observer?")) { - setReturnCode(DELETE); - close(); - } - - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionSchedulerEventWizardDialog.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionSchedulerEventWizardDialog.java deleted file mode 100644 index f14aa16a5b28e12a8e7b0601ef55e65850ec328c..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/BMotionSchedulerEventWizardDialog.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.action; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchPart; - -import de.bmotionstudio.gef.editor.scheduler.SchedulerWizard; - -public class BMotionSchedulerEventWizardDialog extends BMotionAbstractWizardDialog { - - public BMotionSchedulerEventWizardDialog(IWorkbenchPart workbenchPart, - IWizard newWizard) { - super(workbenchPart, newWizard); - setShellStyle(SWT.CLOSE); - setDeleteToolTip("Delete Event"); - } - - @Override - protected void deletePressed() { - - if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), - "Do you really want to delete this Event?", - "Do you really want to delete this Event?")) { - RemoveSchedulerEventAction action = new RemoveSchedulerEventAction( - getWorkbenchPart()); - action.setControl(((SchedulerWizard) getWizard()).getBControl()); - action.setSchedulerEvent(((SchedulerWizard) getWizard()) - .getScheduler()); - action.run(); - setReturnCode(DELETE); - close(); - } - - } -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenObserverAction.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenObserverAction.java index 4ed52392ac795a04f75fad7fcda720ef926d3210..d8ff6ba358c8f89b59514e70d5e93e27fae75933 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenObserverAction.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenObserverAction.java @@ -8,18 +8,12 @@ package de.bmotionstudio.gef.editor.action; import java.util.List; -import org.eclipse.core.runtime.CoreException; import org.eclipse.gef.EditPart; import org.eclipse.gef.ui.actions.SelectionAction; -import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbenchPart; -import de.bmotionstudio.gef.editor.BMotionEditorPlugin; -import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.command.RemoveObserverCommand; -import de.bmotionstudio.gef.editor.command.SetObserverCommand; import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; import de.bmotionstudio.gef.editor.observer.Observer; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.prob.logging.Logger; @@ -50,79 +44,23 @@ public class OpenObserverAction extends SelectionAction { if (actionControl != null) { - Observer oldObserver = null; Observer observer = getControl().getObserver(getClassName()); - // If an observer does not exist, add one - if (observer == null) { - - try { - observer = (Observer) BMotionEditorPlugin - .getObserverExtension(getClassName()) - .createExecutableExtension("class"); - } catch (CoreException e) { - } - - } else { // else edit the current observer - - // therefore, clone the current observer, if the user aborts - // editing the current observer - try { - oldObserver = observer.clone(); - } catch (CloneNotSupportedException e) { - } - - } - - ObserverWizard wizard = observer.getWizard(actionControl); + ObserverWizard wizard = observer.getWizard(Display.getDefault() + .getActiveShell(), actionControl); if (wizard != null) { - - BMotionObserverWizardDialog dialog = new BMotionObserverWizardDialog( - getWorkbenchPart(), wizard); - dialog.create(); - dialog.getShell().setSize(wizard.getSize()); - String title = "Observer: " + observer.getName() - + " Control: " + getControl().getID(); - wizard.setWindowTitle("BMotion Studio Observer Wizard"); - dialog.setTitle(title); - dialog.setMessage(observer.getDescription()); - dialog.setTitleImage(BMotionStudioImage - .getImage(BMotionStudioImage.IMG_LOGO_BMOTION64)); - int status = dialog.open(); - - // The user clicked on the "OK" button in order to confirm his - // changes on the observer - if (status == WizardDialog.OK) { - - // If the observer delete flag is set to true, delete the - // observer anyway - if (wizard.isObserverDelete()) { - RemoveObserverCommand cmd = createRemoveObserverCommand( - observer, actionControl); - execute(cmd); - } else { - SetObserverCommand cmd = createObserverSetCommand( - actionControl, observer, oldObserver); - execute(cmd); - } - - // else the user canceled his changes on the observer - } else if (status == WizardDialog.CANCEL) { - - // Reset observer without using a command! - if (oldObserver != null) - actionControl.getObservers().put(oldObserver.getID(), - oldObserver); - - // else the user clicked on the delete button in order to - // delete the observer - } else if (status == BMotionObserverWizardDialog.DELETE) { - RemoveObserverCommand cmd = createRemoveObserverCommand( - observer, actionControl); - execute(cmd); - } - + wizard.create(); + wizard.getShell().setSize(wizard.getSize()); + String title = "Observer: " + observer.getName() + " Control: " + + getControl().getID(); + wizard.getShell().setText(title); + // wizard.setWindowTitle("BMotion Studio Observer Wizard"); + // wizard.setTitle(title); + // wizard.setMessage(observer.getDescription()); + // wizard.setTitleImage(BMotionStudioImage + // .getImage(BMotionStudioImage.IMG_LOGO_BMOTION64)); + wizard.open(); } else { Logger.notifyUserWithoutBugreport("The Observer \"" + observer.getName() @@ -132,28 +70,6 @@ public class OpenObserverAction extends SelectionAction { } - private RemoveObserverCommand createRemoveObserverCommand( - Observer observer, BControl control) { - RemoveObserverCommand cmd = new RemoveObserverCommand(); - cmd.setControl(control); - cmd.setObserver(observer); - return cmd; - } - - public SetObserverCommand createObserverSetCommand(BControl control, - Observer newObserver, Observer oldObserver) { - SetObserverCommand cmd = new SetObserverCommand(); - cmd.setNewObserver(newObserver); - cmd.setOldObserver(oldObserver); - cmd.setControl(control); - return cmd; - } - - public SetObserverCommand createObserverSetCommand(BControl control, - Observer newObserver) { - return createObserverSetCommand(control, newObserver, null); - } - public void setClassName(String className) { this.className = className; } @@ -172,10 +88,7 @@ public class OpenObserverAction extends SelectionAction { if ((objects.get(0) instanceof EditPart)) { EditPart part = (EditPart) objects.get(0); BControl control = null; - if (part.getModel() instanceof ObserverRootVirtualTreeNode) - control = ((ObserverRootVirtualTreeNode) part.getModel()) - .getControl(); - else if (part.getModel() instanceof BControl) + if (part.getModel() instanceof BControl) control = (BControl) part.getModel(); return control; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenSchedulerEventAction.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenSchedulerEventAction.java index dff15928f5b8e190611a5eaba4c8f43eff2ef959..f35094ca1f7a9d2b1905b3a01114f4c1b7e44e12 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenSchedulerEventAction.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/action/OpenSchedulerEventAction.java @@ -8,16 +8,12 @@ package de.bmotionstudio.gef.editor.action; import java.util.List; -import org.eclipse.core.runtime.CoreException; import org.eclipse.gef.EditPart; import org.eclipse.gef.ui.actions.SelectionAction; -import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbenchPart; import de.bmotionstudio.gef.editor.AttributeConstants; -import de.bmotionstudio.gef.editor.BMotionEditorPlugin; -import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.command.SchedulerEventCommand; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent; import de.bmotionstudio.gef.editor.scheduler.SchedulerWizard; @@ -27,7 +23,6 @@ public class OpenSchedulerEventAction extends SelectionAction { private String className; private String eventID; - private SchedulerEvent clonedSchedulerEvent; public OpenSchedulerEventAction(IWorkbenchPart part) { super(part); @@ -46,82 +41,33 @@ public class OpenSchedulerEventAction extends SelectionAction { public void run() { BControl bcontrol = getControl(); - clonedSchedulerEvent = null; if (bcontrol != null) { SchedulerEvent newSchedulerEvent = bcontrol.getEvent(getEventID()); - // Add Scheduler Event - if (newSchedulerEvent == null) { - - try { - newSchedulerEvent = (SchedulerEvent) BMotionEditorPlugin - .getSchedulerExtension(getClassName()) - .createExecutableExtension("class"); - } catch (CoreException e) { - } - - } else { // Edit Scheduler Event - - // Clone Scheduler Event - try { - clonedSchedulerEvent = newSchedulerEvent.clone(); - } catch (CloneNotSupportedException e) { - } - - } - if (newSchedulerEvent != null) { newSchedulerEvent.setEventID(getEventID()); - SchedulerWizard wizard = newSchedulerEvent.getWizard(bcontrol); + SchedulerWizard wizard = newSchedulerEvent.getWizard(Display + .getDefault().getActiveShell(), bcontrol); if (wizard != null) { - BMotionSchedulerEventWizardDialog dialog = new BMotionSchedulerEventWizardDialog( - getWorkbenchPart(), wizard); - dialog.create(); - dialog.getShell().setSize(wizard.getSize()); + wizard.create(); + wizard.getShell().setSize(wizard.getSize()); String title = "Scheduler Event: " + newSchedulerEvent.getName() + " Control: " + bcontrol .getAttributeValue(AttributeConstants.ATTRIBUTE_ID); - wizard.setWindowTitle("BMotion Studio Scheduler Event Wizard"); - dialog.setTitle(title); - dialog.setMessage(newSchedulerEvent.getDescription()); - dialog.setTitleImage(BMotionStudioImage - .getImage(BMotionStudioImage.IMG_LOGO_BMOTION64)); - int status = dialog.open(); - - if (status == WizardDialog.OK) { - - SchedulerEventCommand schedulerEventCommand = createSchedulerEventCommand(); - schedulerEventCommand - .setNewSchedulerEvent(newSchedulerEvent); - - if (wizard.isEventDelete()) { - - RemoveSchedulerEventAction action = new RemoveSchedulerEventAction( - getWorkbenchPart()); - action.setControl(getControl()); - action.setSchedulerEvent(clonedSchedulerEvent); - action.run(); - - } else { - if (clonedSchedulerEvent != null) { - schedulerEventCommand - .setClonedSchedulerEvent(clonedSchedulerEvent); - } - execute(schedulerEventCommand); - } - - } else if (status == WizardDialog.CANCEL) { - if (clonedSchedulerEvent != null) - bcontrol.addEvent(getEventID(), - clonedSchedulerEvent); - } + wizard.getShell().setText(title); + // wizard.setWindowTitle("BMotion Studio Scheduler Event Wizard"); + // wizard.setTitle(title); + // wizard.setMessage(newSchedulerEvent.getDescription()); + // wizard.setTitleImage(BMotionStudioImage + // .getImage(BMotionStudioImage.IMG_LOGO_BMOTION64)); + wizard.open(); } else { Logger.notifyUserWithoutBugreport("The Scheduler Event \"" @@ -137,14 +83,6 @@ public class OpenSchedulerEventAction extends SelectionAction { } - public SchedulerEventCommand createSchedulerEventCommand() { - SchedulerEventCommand command = new SchedulerEventCommand(); - command.setClassName(getClassName()); - command.setEventID(getEventID()); - command.setControl(getControl()); - return command; - } - public void setClassName(String className) { this.className = className; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomCommand.java index 601e6bb35cf0c5c8e4a043a8544c2552dc27509b..16a668b4a38479700afe1151baac872be8af1c56 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomCommand.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.command; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; public class BringToBottomCommand extends AbstractBringToCommand { @@ -17,8 +18,8 @@ public class BringToBottomCommand extends AbstractBringToCommand { getOldIndexMap().put(control, oldIndex); parent.getChildrenArray().remove(control); parent.getChildrenArray().add(0, control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } @@ -28,8 +29,8 @@ public class BringToBottomCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(getOldIndexMap().get(control), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomStepCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomStepCommand.java index 7e5dff77861ab06ba45e5d306d4155c6bd0b54cf..f5bbb964961743c6278780f6722418212334f86d 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomStepCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToBottomStepCommand.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.command; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; public class BringToBottomStepCommand extends AbstractBringToCommand { @@ -18,8 +19,9 @@ public class BringToBottomStepCommand extends AbstractBringToCommand { if (oldIndex > 0) { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(oldIndex - 1, control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, + null); } } } @@ -30,8 +32,8 @@ public class BringToBottomStepCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(getOldIndexMap().get(control), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopCommand.java index 716c1454a766ebf1e24f7d4ede5fa3dd79acccd9..c290043b3e2eb8df9d0c9354948cdc8681250e52 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopCommand.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.command; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; public class BringToTopCommand extends AbstractBringToCommand { @@ -18,8 +19,8 @@ public class BringToTopCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(parent.getChildrenArray().size(), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } @@ -29,8 +30,8 @@ public class BringToTopCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(getOldIndexMap().get(control), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopStepCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopStepCommand.java index 3560448e1c245684e4a599ef4f14f421f55a8069..805599aaac6c0ee0ac237a4e713e6ea191114729 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopStepCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/BringToTopStepCommand.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.command; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; public class BringToTopStepCommand extends AbstractBringToCommand { @@ -18,8 +19,9 @@ public class BringToTopStepCommand extends AbstractBringToCommand { if (oldIndex < parent.getChildrenArray().size() - 1) { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(oldIndex + 1, control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, + null); } } } @@ -30,8 +32,8 @@ public class BringToTopStepCommand extends AbstractBringToCommand { parent.getChildrenArray().remove(control); parent.getChildrenArray().add(getOldIndexMap().get(control), control); - parent.getListeners().firePropertyChange(BControl.PROPERTY_ADD, - null, null); + parent.getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, null, null); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/SignalFigure.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/SignalFigure.java index 7e5752eb3dd61ce8e05543f1e93385539eccfd2c..052554a54b80675119080156d503d09a3fbb9d86 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/SignalFigure.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/SignalFigure.java @@ -84,7 +84,6 @@ public class SignalFigure extends AbstractBMotionFigure { p1.y = p1.y + 4; p2.y = p2.y + 8; - p3.y = p3.y; arrow.addPoint(p1); arrow.addPoint(p2); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/OpenWebsiteHandler.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/OpenWebsiteHandler.java similarity index 93% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/OpenWebsiteHandler.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/OpenWebsiteHandler.java index 500bb85d61ccf97fc90b8f6c132b8544f481fe34..9122b15e222de30d845fada8f4a41b35e265b4c1 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/OpenWebsiteHandler.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/OpenWebsiteHandler.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.internal; +package de.bmotionstudio.gef.editor.handler; import java.net.MalformedURLException; import java.net.URL; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationEditorHandler.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationEditorHandler.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationEditorHandler.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationEditorHandler.java index bda5ba1df2ffa63f35d858a5a86fc205ea6372ba..ebd89b02a01f24f608dc4c9c07d78650519e767e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationEditorHandler.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationEditorHandler.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.internal; +package de.bmotionstudio.gef.editor.handler; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -19,6 +19,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; +import de.bmotionstudio.gef.editor.internal.VisualizationProgressBar; import de.prob.core.Animator; import de.prob.logging.Logger; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationFileHandler.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationFileHandler.java similarity index 94% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationFileHandler.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationFileHandler.java index 2c9964a279dd5b4c08b830489ae060de8d64c7bf..945993e514a2dfa94a453379a0aa7c8fb502b4e9 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/StartVisualizationFileHandler.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/handler/StartVisualizationFileHandler.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.internal; +package de.bmotionstudio.gef.editor.handler; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -30,6 +30,7 @@ import org.eclipse.ui.part.FileEditorInput; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; import de.bmotionstudio.gef.editor.BMotionStudioEditor; +import de.bmotionstudio.gef.editor.internal.VisualizationProgressBar; import de.prob.core.Animator; import de.prob.logging.Logger; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java index 4054bf990409224fb3e80c7652aaf57ec4abbeb5..70ee9ce5129299210a7d579009c6f02ab2dba118 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java @@ -113,9 +113,6 @@ public class VisualizationProgressBar extends ProgressBarDialog { openErrorDialog(e.getMessage()); setClose(true); } - return "Starting Operation Scheduler"; - case 6: - startOperationScheduler(); return "Starting Visualization"; } @@ -123,9 +120,9 @@ public class VisualizationProgressBar extends ProgressBarDialog { } - private void startOperationScheduler() { - visualization.startOperationScheduler(); - } + // private void startOperationScheduler() { + // visualization.startOperationScheduler(); + // } private void createVisualizationRoot() throws CoreException, IOException, ParserConfigurationException, SAXException { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java index 8013e19f754309e18837ec7c09f438c3eddba668..8d153efff02722e88a8414eb283afa1ca8f4abd6 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java @@ -16,8 +16,12 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; @@ -42,7 +46,6 @@ import de.bmotionstudio.gef.editor.attribute.BAttributeX; import de.bmotionstudio.gef.editor.attribute.BAttributeY; import de.bmotionstudio.gef.editor.command.CopyPasteHelper; import de.bmotionstudio.gef.editor.internal.BControlPropertySource; -import de.bmotionstudio.gef.editor.observer.IObserverListener; import de.bmotionstudio.gef.editor.observer.Observer; import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent; @@ -61,13 +64,8 @@ import de.bmotionstudio.gef.editor.scheduler.SchedulerEvent; */ public abstract class BControl implements IAdaptable, Cloneable { - /** The type of the control (e.g. label, button ...) */ protected String type; - private transient Rectangle layout = null; - - private transient Point location = null; - private BControlList children; private Map<String, Observer> observers; @@ -76,45 +74,25 @@ public abstract class BControl implements IAdaptable, Cloneable { private Map<String, AbstractAttribute> attributes; - /** - * Since the parent is set via the method readResolve(), we mark the - * variable as transient - */ + private BMotionGuide verticalGuide, horizontalGuide; + + // List of outgoing Connections + private List<BConnection> sourceConnections; + // List of incoming Connections + private List<BConnection> targetConnections; + + private transient Rectangle layout = null; + + private transient Point location = null; + private transient BControl parent; private transient Visualization visualization; private transient PropertyChangeSupport listeners; - - private transient ArrayList<IObserverListener> observerListener; private transient boolean newControl; - private BMotionGuide verticalGuide, horizontalGuide; - - /** List of outgoing Connections. */ - private List<BConnection> sourceConnections; - /** List of incoming Connections. */ - private List<BConnection> targetConnections; - - public static final transient String PROPERTY_LAYOUT = "NodeLayout"; - public static final transient String PROPERTY_LOCATION = "NodeLocation"; - public static final transient String PROPERTY_ADD = "NodeAddChild"; - public static final transient String PROPERTY_REMOVE = "NodeRemoveChild"; - public static final transient String PROPERTY_RENAME = "NodeRename"; - /** Property ID to use when the list of outgoing connections is modified. */ - public static final String SOURCE_CONNECTIONS_PROP = "BMS.SourceConn"; - /** Property ID to use when the list of incoming connections is modified. */ - public static final String TARGET_CONNECTIONS_PROP = "BMS.TargetConn"; - - public static final String[] standardAttributes = { - AttributeConstants.ATTRIBUTE_X, - AttributeConstants.ATTRIBUTE_Y, AttributeConstants.ATTRIBUTE_WIDTH, - AttributeConstants.ATTRIBUTE_HEIGHT, - AttributeConstants.ATTRIBUTE_ID, - AttributeConstants.ATTRIBUTE_CUSTOM, - AttributeConstants.ATTRIBUTE_VISIBLE }; - public BControl(Visualization visualization) { this.visualization = visualization; this.children = new BControlList(); @@ -122,7 +100,6 @@ public abstract class BControl implements IAdaptable, Cloneable { this.events = new HashMap<String, SchedulerEvent>(); this.attributes = new HashMap<String, AbstractAttribute>(); this.listeners = new PropertyChangeSupport(this); - this.observerListener = new ArrayList<IObserverListener>(); this.sourceConnections = new ArrayList<BConnection>(); this.targetConnections = new ArrayList<BConnection>(); this.newControl = true; @@ -134,7 +111,6 @@ public abstract class BControl implements IAdaptable, Cloneable { for (BControl child : getChildrenArray()) child.setParent(this); this.newControl = false; - init(); return this; } @@ -152,12 +128,12 @@ public abstract class BControl implements IAdaptable, Cloneable { } if (conn.getSource() == this) { getSourceConnections().remove(conn); - getListeners().firePropertyChange(SOURCE_CONNECTIONS_PROP, null, - conn); + getListeners().firePropertyChange( + BControlPropertyConstants.SOURCE_CONNECTIONS, null, conn); } else if (conn.getTarget() == this) { getTargetConnections().remove(conn); - getListeners().firePropertyChange(TARGET_CONNECTIONS_PROP, null, - conn); + getListeners().firePropertyChange( + BControlPropertyConstants.TARGET_CONNECTIONS, null, conn); } } @@ -173,25 +149,105 @@ public abstract class BControl implements IAdaptable, Cloneable { if (conn == null || conn.getSource() == conn.getTarget()) { throw new IllegalArgumentException(); } - conn.setVisualization(getVisualization()); if (conn.getSource() == this) { getSourceConnections().add(conn); - getListeners().firePropertyChange(SOURCE_CONNECTIONS_PROP, null, - conn); + getListeners().firePropertyChange( + BControlPropertyConstants.SOURCE_CONNECTIONS, null, conn); } else if (conn.getTarget() == this) { getTargetConnections().add(conn); - getListeners().firePropertyChange(TARGET_CONNECTIONS_PROP, null, - conn); + getListeners().firePropertyChange( + BControlPropertyConstants.TARGET_CONNECTIONS, null, conn); } } - private void init() { - + protected void init() { // Init standard control attributes initStandardAttributes(); - // Init custom control attributes initAttributes(); + // Init observer + initObserver(); + } + + private List<String> getSupportedObserverList() { + + List<String> supportedObserver = new ArrayList<String>(); + + IExtensionPoint extensionPoint = Platform.getExtensionRegistry() + .getExtensionPoint( + "de.bmotionstudio.gef.editor.includeObserver"); + + for (IExtension extension : extensionPoint.getExtensions()) { + for (IConfigurationElement configurationElement : extension + .getConfigurationElements()) { + + if ("include".equals(configurationElement.getName())) { + + String langID = configurationElement + .getAttribute("language"); + + if (langID != null + && langID.equals(getVisualization() + .getLanguage())) { + + for (IConfigurationElement configC : configurationElement + .getChildren("control")) { + + String cID = configC.getAttribute("id"); + + if (getType().equals(cID)) { + + for (IConfigurationElement configO : configC + .getChildren("observer")) { + + supportedObserver.add(configO + .getAttribute("id")); + + } + + } + + } + + } + + } + + } + } + + return supportedObserver; + + } + + private void initObserver() { + + List<String> supportedObserverList = getSupportedObserverList(); + for (String oID : supportedObserverList) { + + // Check if control has already the observer + if (!hasObserver(oID)) { + + // If no, create a new instance and add the observer to the + // control + IConfigurationElement observerExtension = BMotionEditorPlugin + .getObserverExtension(oID); + + if (observerExtension != null) { + try { + + + Observer newObserver = (Observer) observerExtension + .createExecutableExtension("class"); + addObserver(newObserver); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + } + + } } @@ -328,7 +384,8 @@ public abstract class BControl implements IAdaptable, Cloneable { setAttributeValue(AttributeConstants.ATTRIBUTE_HEIGHT, newLayout.height, false); getListeners() - .firePropertyChange(PROPERTY_LAYOUT, oldLayout, newLayout); + .firePropertyChange(BControlPropertyConstants.PROPERTY_LAYOUT, + oldLayout, newLayout); } public Rectangle getLayout() { @@ -375,7 +432,8 @@ public abstract class BControl implements IAdaptable, Cloneable { location = newLocation; setAttributeValue(AttributeConstants.ATTRIBUTE_X, newLocation.x, false); setAttributeValue(AttributeConstants.ATTRIBUTE_Y, newLocation.y, false); - getListeners().firePropertyChange(PROPERTY_LOCATION, oldLocation, + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_LOCATION, oldLocation, newLocation); } @@ -412,12 +470,14 @@ public abstract class BControl implements IAdaptable, Cloneable { } else { children.add(child); } - getListeners().firePropertyChange(PROPERTY_ADD, index, child); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_CHILD, index, child); } public void removeAllChildren() { getChildrenArray().clear(); - getListeners().firePropertyChange(PROPERTY_REMOVE, null, null); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_REMOVE_CHILD, null, null); } public boolean removeChild(int index) { @@ -428,7 +488,9 @@ public abstract class BControl implements IAdaptable, Cloneable { public boolean removeChild(BControl child) { boolean b = children.remove(child); if (b) - getListeners().firePropertyChange(PROPERTY_REMOVE, child, null); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_REMOVE_CHILD, child, + null); return b; } @@ -476,9 +538,10 @@ public abstract class BControl implements IAdaptable, Cloneable { public void addObserver(Observer observer) { observers.put(observer.getID(), (Observer) observer); - for (IObserverListener listener : getObserverListener()) { - listener.addedObserver(this, observer); - } + getListeners() + .firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_OBSERVER, + observer, null); } public void removeObserver(Observer observer) { @@ -486,11 +549,13 @@ public abstract class BControl implements IAdaptable, Cloneable { } public void removeObserver(String observerID) { - if (hasObserver(observerID)) - observers.get(observerID).beforeDelete(this); - observers.remove(observerID); - for (IObserverListener listener : getObserverListener()) { - listener.removedObserver(this); + Observer o = observers.remove(observerID); + if (o != null) { + o.beforeDelete(this); + getListeners() + .firePropertyChange( + BControlPropertyConstants.PROPERTY_REMOVE_OBSERVER, + o, null); } } @@ -512,12 +577,18 @@ public abstract class BControl implements IAdaptable, Cloneable { public void addEvent(String eventID, SchedulerEvent schedulerEvent) { events.put(eventID, schedulerEvent); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_ADD_EVENT, schedulerEvent, + null); } public void removeEvent(String eventID) { - if (hasEvent(eventID)) - events.get(eventID).beforeDelete(this); - events.remove(eventID); + SchedulerEvent e = events.remove(eventID); + if (e != null) { + e.beforeDelete(this); + getListeners().firePropertyChange( + BControlPropertyConstants.PROPERTY_REMOVE_EVENT, e, null); + } } public Map<String, AbstractAttribute> getAttributes() { @@ -631,24 +702,12 @@ public abstract class BControl implements IAdaptable, Cloneable { this.visualization = visualization; } - protected void populateVisualization(Visualization visualization) { - // Populate visualization node - setVisualization(visualization); - for (BControl child : getChildrenArray()) - child.populateVisualization(visualization); - for (BConnection con : getTargetConnections()) - con.populateVisualization(visualization); - for (BConnection con : getSourceConnections()) - con.populateVisualization(visualization); - } - @Override public BControl clone() throws CloneNotSupportedException { BControl clonedControl = (BControl) super.clone(); clonedControl.listeners = new PropertyChangeSupport(clonedControl); - clonedControl.observerListener = new ArrayList<IObserverListener>(); clonedControl.sourceConnections = new ArrayList<BConnection>(); clonedControl.targetConnections = new ArrayList<BConnection>(); @@ -738,23 +797,6 @@ public abstract class BControl implements IAdaptable, Cloneable { return horizontalGuide; } - /** - * @return the observerListener - */ - public ArrayList<IObserverListener> getObserverListener() { - if (observerListener == null) - observerListener = new ArrayList<IObserverListener>(); - return observerListener; - } - - public void addObserverListener(IObserverListener listener) { - getObserverListener().add(listener); - } - - public void removeObserverListener(IObserverListener listener) { - getObserverListener().remove(listener); - } - /** * Return a List of outgoing Connections. */ diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControlPropertyConstants.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControlPropertyConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..40952b6d057a68266307bdffb359fee984ed3414 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControlPropertyConstants.java @@ -0,0 +1,29 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.model; + +public final class BControlPropertyConstants { + + public static final transient String PROPERTY_LAYOUT = "ControlLayout"; + public static final transient String PROPERTY_LOCATION = "ControlLocation"; + + public static final transient String PROPERTY_ADD_CHILD = "ControlAddChild"; + public static final transient String PROPERTY_REMOVE_CHILD = "ControlRemoveChild"; + + public static final transient String PROPERTY_ADD_OBSERVER = "ControlAddObserver"; + public static final transient String PROPERTY_REMOVE_OBSERVER = "ControlRemoveObserver"; + + public static final transient String PROPERTY_ADD_EVENT = "ControlAddEvent"; + public static final transient String PROPERTY_REMOVE_EVENT = "ControlRemoveEvent"; + + public static final transient String PROPERTY_RENAME = "ControlRename"; + /** Property ID to use when the list of outgoing connections is modified. */ + public static final transient String SOURCE_CONNECTIONS = "ControlSourceConn"; + /** Property ID to use when the list of incoming connections is modified. */ + public static final transient String TARGET_CONNECTIONS = "ControlTargetConn"; + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/ObserverRootVirtualTreeNode.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/ObserverRootVirtualTreeNode.java deleted file mode 100644 index 8562f648692ec3d27aa319bf66ce9aed15adb9cb..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/ObserverRootVirtualTreeNode.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.model; - -import java.util.Collection; - -import de.bmotionstudio.gef.editor.observer.Observer; - -public class ObserverRootVirtualTreeNode { - - private Collection<Observer> observer; - private BControl control; - - public ObserverRootVirtualTreeNode(BControl control) { - this.observer = control.getObservers().values(); - this.control = control; - } - - public Collection<Observer> getObserver() { - return observer; - } - - public BControl getControl() { - return control; - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java index 1de47b1b81c7c6e2a4d2a4ebfe2ce9a0a621f517..6aceebaa4cd1d5f66313b0a87137aaefcd8330fe 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java @@ -12,15 +12,8 @@ import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.draw2d.PositionConstants; -import de.be4.classicalb.core.parser.exceptions.BException; import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.ButtonGroupHelper; -import de.bmotionstudio.gef.editor.IAddErrorListener; -import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; -import de.prob.core.command.ExecuteOperationCommand; -import de.prob.core.command.GetOperationByPredicateCommand; -import de.prob.core.domainobjects.Operation; -import de.prob.exceptions.ProBException; public class Visualization extends BControl { @@ -46,12 +39,6 @@ public class Visualization extends BControl { private transient IFile projectFile; - private transient ArrayList<IAddErrorListener> errorListener; - - private transient Thread operationSchedulerThread; - - private ArrayList<PredicateOperation> schedulerOperations; - public Visualization(String bmachine, String language, String version) { super(null); setVisualization(this); @@ -59,7 +46,6 @@ public class Visualization extends BControl { this.bmachine = bmachine; this.language = language; this.version = version; - this.errorListener = new ArrayList<IAddErrorListener>(); this.isRunning = false; this.snapToGeometry = true; createRulers(); @@ -70,73 +56,28 @@ public class Visualization extends BControl { protected Object readResolve() { super.readResolve(); this.isRunning = false; - populateVisualization(this); createRulers(); - this.errorListener = new ArrayList<IAddErrorListener>(); ButtonGroupHelper.reset(); - // this.errorMessages = new ArrayList<ErrorMessage>(); - // setAttributeValue(AttributeConstants.ATTRIBUTE_ID, "surface", false); + setVisualization(this); + init(); + initChildren(getChildrenArray()); return this; } - public void startOperationScheduler() { - - if (!getSchedulerOperations().isEmpty()) { - - operationSchedulerThread = new Thread(new Runnable() { - public void run() { - while (true) { - - for (PredicateOperation p : getSchedulerOperations()) { - - if (animation.getCurrentStateOperation(p - .getOperationName()) != null) { - - try { - - String fpredicate = "1=1"; - - if (p.getPredicate().length() > 0) { - fpredicate = p.getPredicate(); - } - - Operation op = GetOperationByPredicateCommand - .getOperation(animation - .getAnimator(), animation - .getState().getId(), p - .getOperationName(), - fpredicate); - ExecuteOperationCommand.executeOperation( - animation.getAnimator(), op); - - } catch (ProBException e) { - break; - } catch (BException e) { - break; - } - - } - - } - - try { - Thread.sleep(500); - } catch (InterruptedException e) { - break; - } - - } - } - }); - operationSchedulerThread.start(); - + private void initChildren(List<BControl> children) { + for (BControl c : children) { + c.setVisualization(this); + c.init(); + for (BConnection sc : c.getSourceConnections()) { + sc.setVisualization(this); + sc.init(); + } + for (BConnection tc : c.getTargetConnections()) { + tc.setVisualization(this); + tc.init(); + } + initChildren(c.getChildrenArray()); } - - } - - public void stopOperationScheduler() { - if (operationSchedulerThread != null) - operationSchedulerThread.interrupt(); } public void setIsRunning(Boolean bol) { @@ -217,12 +158,7 @@ public class Visualization extends BControl { } } - // TODO: Reimplement me!!! public boolean checkIfIdExists(String ID) { - // if (getVariableList().hasEntry(ID) == true) - // return true; - // if (getConstantList().hasEntry(ID) == true) - // return true; return getAllBControlNames().contains(ID); } @@ -236,11 +172,11 @@ public class Visualization extends BControl { return control; } for (BConnection c : control.getSourceConnections()) { - if (c.getIcon().equals(ID)) + if (c.getID().equals(ID)) return c; } for (BConnection c : control.getTargetConnections()) { - if (c.getIcon().equals(ID)) + if (c.getID().equals(ID)) return c; } if (control.getChildrenArray().size() > 0) { @@ -317,25 +253,6 @@ public class Visualization extends BControl { return null; } - public void addErrorListener(IAddErrorListener listener) { - this.errorListener.add(listener); - } - - public void removeErrorListener(IAddErrorListener listener) { - this.errorListener.remove(listener); - } - - public void setSchedulerOperations( - ArrayList<PredicateOperation> schedulerOperations) { - this.schedulerOperations = schedulerOperations; - } - - public ArrayList<PredicateOperation> getSchedulerOperations() { - if (this.schedulerOperations == null) - this.schedulerOperations = new ArrayList<PredicateOperation>(); - return this.schedulerOperations; - } - public String getVersion() { return version; } @@ -358,4 +275,9 @@ public class Visualization extends BControl { return true; } + @Override + public Visualization getVisualization() { + return this; + } + } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BButtonService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BButtonService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BButtonService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BButtonService.java index e0b5b38b09a6429c1c2a66bdc71929c3d3a8abcd..e725497872ea5284faf8035fa7dbebc3e6fe1c9b 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BButtonService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BButtonService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCheckboxService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCheckboxService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCheckboxService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCheckboxService.java index dcaebcef01eac35993dd90a28542946e5bb9325e..116a6e6c81832d075d3d575040cf20adacd089ac 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCheckboxService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCheckboxService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCompositeService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCompositeService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCompositeService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCompositeService.java index 4a11b1d1c33fbcdecb4d0a06c05ca1115270a412..c9a899bdcece83f8b6b12b1085bb1c351ce5d569 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BCompositeService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BCompositeService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BConnectionService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BConnectionService.java similarity index 94% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BConnectionService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BConnectionService.java index 8c2c8e97317f5a65067764c37f9c72ec8b9e4cda..54fcc6bfa0ff7cfea37295e007e6c174a0f91590 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BConnectionService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BConnectionService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.gef.palette.ConnectionCreationToolEntry; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BEllipseService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BEllipseService.java similarity index 95% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BEllipseService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BEllipseService.java index ffaf7f7dceeebc27954799e4b6fbf7961a9171ee..12131e63d3fbaf0556d32ad804436a570d70232a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BEllipseService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BEllipseService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.AttributeConstants; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BImageService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BImageService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BImageService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BImageService.java index e70769ac275e2571a66cce4bc76a5518011b1c5d..c843bb524d2c81614848eeb5315d3666da1b544e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BImageService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BImageService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRadioButtonService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRadioButtonService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRadioButtonService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRadioButtonService.java index ae4b4250f88f47e70170eaef67dfd984d425af36..6092c7c7c4d1b8889a658e36f76a28881ec48cfe 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRadioButtonService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRadioButtonService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRectangleService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRectangleService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRectangleService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRectangleService.java index f29b430d7c111916fc541e1f804fab319b757262..1c18ae9da50ef58f254861fb7a02fb5828528b47 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BRectangleService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BRectangleService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableCellService.java similarity index 95% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableCellService.java index 38c27cbaf1e5a37e64e8d174a8a24c9964117e09..f9c21fafff49607a1639f09aa847617ecb5386e4 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableCellService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableColumnService.java similarity index 95% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableColumnService.java index 6290adc316a60ca35f9cff2883b2bfb4947d6b43..893f8344112e2a6115d8b9848ef2612e640be51e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableColumnService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableService.java similarity index 93% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableService.java index 67da1a6148b0f376502b36e0047ce42a98a36e70..e54ddd5de872a8868bebf6f1524f3c7e4ff4eb02 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTableService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextService.java index 77fcbaa39c22f72ab5fc3b3e70c13bbe32709245..6bf14bc403ca03eb36294d60f5389d744d6f86a3 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextfieldService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextfieldService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextfieldService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextfieldService.java index 694879b12b6db775ff764b93e24d10bdd8fe06a2..1b66a40c36158c7a1c569bdcd87a606254a9f72d 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTextfieldService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/BTextfieldService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/LightService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/LightService.java similarity index 93% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/LightService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/LightService.java index 84b8215550198df61c4f29f869381d83c2c34829..71ebf592f81beaad3bf45b07c5c50ecbac09bb59 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/LightService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/LightService.java @@ -1,4 +1,4 @@ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SignalService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SignalService.java similarity index 92% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SignalService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SignalService.java index fd0c914a64001a7efa025c7575b4ebb135b3e5af..95dd51a686cedef9ccbd86bb376fe3421faf768a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SignalService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SignalService.java @@ -3,7 +3,7 @@ * Heinrich Heine Universitaet Duesseldorf * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SwitchService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SwitchService.java similarity index 91% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SwitchService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SwitchService.java index a4b441ea9c245575cb08e9a7e005f49bc3042016..bb4c4850ea30bb529021a688dc71174aa7af4b24 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/SwitchService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/SwitchService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TankService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TankService.java similarity index 91% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TankService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TankService.java index cc28f1eee33f501553c80c75fb73f39038c9c9c4..80c1a38cd19221bd8e0e48a071cc89af377b451f 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TankService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TankService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackNodeService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackNodeService.java similarity index 91% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackNodeService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackNodeService.java index d3b12c90a0e77b55080a024aa620e74293abdc7e..c01bcaa080339ca1934876ae7026a88f039aeb9c 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackNodeService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackNodeService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import de.bmotionstudio.gef.editor.AbstractBControlService; import de.bmotionstudio.gef.editor.IBControlService; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackService.java similarity index 94% rename from de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackService.java rename to de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackService.java index 4b90a844cd2925a2ae1411f24bed3edd59c72812..ccd221193739c9280e3d368dd917f3ed8d3cfb4b 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/TrackService.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/service/TrackService.java @@ -4,7 +4,7 @@ * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) * */ -package de.bmotionstudio.gef.editor.service; +package de.bmotionstudio.gef.editor.model.service; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.gef.palette.ConnectionCreationToolEntry; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ColumnObserver.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ColumnObserver.java index 04309d362c320e767f78cd5de856cdfd7495d5b8..d7c41fb88fdb7f28de2b32a2cfc9dd9d451af59a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ColumnObserver.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ColumnObserver.java @@ -3,6 +3,8 @@ package de.bmotionstudio.gef.editor.observer; import java.util.LinkedList; import java.util.List; +import org.eclipse.swt.widgets.Shell; + import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; @@ -92,8 +94,8 @@ public class ColumnObserver extends Observer { } @Override - public ObserverWizard getWizard(BControl control) { - return new WizardColumnObserver(control, this); + public ObserverWizard getWizard(Shell shell, BControl control) { + return new WizardColumnObserver(shell, control, this); } } \ No newline at end of file diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ExternalObserverScript.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ExternalObserverScript.java deleted file mode 100644 index 66140364297494279a50836161fc37be784b1379..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ExternalObserverScript.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.observer; - -import groovy.lang.GroovyClassLoader; -import groovy.lang.GroovyObject; - -import java.io.File; -import java.io.IOException; - -import org.codehaus.groovy.control.CompilationFailedException; -import org.eclipse.core.resources.IFile; - -import de.bmotionstudio.gef.editor.Animation; -import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.observer.wizard.WizardObserverExternalObserverScript; - -public class ExternalObserverScript extends Observer { - - public static String ID = "de.bmotionstudio.gef.editor.observer.ExternalObserverScript"; - - private transient GroovyObject groovyObject; - - private String scriptPath; - - // private String language; - - @Override - public void check(Animation animation, BControl control) { - - try { - - if (groovyObject == null) { - IFile pFile = control.getVisualization().getProjectFile(); - String myPath = (pFile.getProject().getLocation() + "/" + scriptPath) - .replace("file:", ""); - ClassLoader parent = getClass().getClassLoader(); - GroovyClassLoader loader = new GroovyClassLoader(parent); - Class<?> groovyClass; - groovyClass = loader.parseClass(new File(myPath)); - // let's call some method on an instance - groovyObject = (GroovyObject) groovyClass.newInstance(); - } - - Object[] args = { animation, control }; - groovyObject.invokeMethod("check", args); - - } catch (CompilationFailedException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - - } - - @Override - public ObserverWizard getWizard(BControl control) { - return new WizardObserverExternalObserverScript(control, this); - } - - public String getScriptPath() { - return scriptPath; - } - - public void setScriptPath(String scriptPath) { - this.scriptPath = scriptPath; - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ListenOperationByPredicate.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ListenOperationByPredicate.java index 59584f2b31f9df4a8fdcd62d048597fe988219e3..d061b875402ad4379baa78f21ea04a01545af626 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ListenOperationByPredicate.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ListenOperationByPredicate.java @@ -9,6 +9,8 @@ package de.bmotionstudio.gef.editor.observer; import java.util.ArrayList; import java.util.List; +import org.eclipse.swt.widgets.Shell; + import de.be4.classicalb.core.parser.exceptions.BException; import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.AttributeConstants; @@ -154,8 +156,9 @@ public class ListenOperationByPredicate extends Observer { } @Override - public ObserverWizard getWizard(BControl control) { - return new WizardObserverListenOperationByPredicate(control, this); + public ObserverWizard getWizard(Shell shell, BControl control) { + return new WizardObserverListenOperationByPredicate(shell, control, + this); } public void setList(ArrayList<PredicateOperation> list) { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/Observer.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/Observer.java index d503290e15669b161bec135606bacc8946c6d84f..2df22ada4a661a4152bf0e174cd64a32a2ef03ae 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/Observer.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/Observer.java @@ -8,6 +8,7 @@ package de.bmotionstudio.gef.editor.observer; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.draw2d.IFigure; +import org.eclipse.swt.widgets.Shell; import de.bmotionstudio.gef.editor.AbstractExpressionControl; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; @@ -68,7 +69,7 @@ public abstract class Observer extends AbstractExpressionControl implements * The corresponding control * @return the corresponding wizard */ - public abstract ObserverWizard getWizard(BControl control); + public abstract ObserverWizard getWizard(Shell shell, BControl control); public IFigure getToolTip(BControl control) { return null; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ObserverEvalObject.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ObserverEvalObject.java index f03260e6b5caa670bed04b91083347dadbcd579f..678bb63c7721e831396b492fbfd4b99ba707ba3e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ObserverEvalObject.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ObserverEvalObject.java @@ -10,20 +10,12 @@ import de.bmotionstudio.gef.editor.BindingObject; public class ObserverEvalObject extends BindingObject implements Cloneable { - private String type; // unused + private String eval; - private String eval; // Predicate + private String attribute; private Object value; - private String attribute; - - /** - * If true, value attribute is an ExpressionValueElement otherwise value - * attribute is an simple value object (e.g. background image) - * - * @see ExpressionValueElement - */ private Boolean isExpressionMode; private transient Boolean hasError; @@ -32,24 +24,13 @@ public class ObserverEvalObject extends BindingObject implements Cloneable { this.isExpressionMode = false; } - public ObserverEvalObject(String type, String eval, Boolean isExpressionMode) { - this.type = type; + public ObserverEvalObject(String eval, Boolean isExpressionMode) { this.eval = eval; this.isExpressionMode = isExpressionMode; } - public ObserverEvalObject(String type, String eval) { - this(type, eval, false); - } - - public void setType(String type) { - Object oldValue = this.type; - this.type = type; - firePropertyChange("type", oldValue, this.type); - } - - public String getType() { - return type; + public ObserverEvalObject(String eval) { + this(eval, false); } public void setEval(String eval) { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ObserverWizard.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ObserverWizard.java index 252a7b622e5b7a998d97f86097650253eb368c67..a281190dfb8d626b7b0cbf9180dc9313f06cea08 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ObserverWizard.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ObserverWizard.java @@ -7,6 +7,8 @@ package de.bmotionstudio.gef.editor.observer; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.model.BControl; @@ -24,10 +26,8 @@ public abstract class ObserverWizard extends BMotionAbstractWizard { private Observer observer; - protected Boolean observerDelete = false; - - public ObserverWizard(BControl control, Observer observer) { - super(control); + public ObserverWizard(Shell shell, BControl control, Observer observer) { + super(shell, control); this.observer = observer; } @@ -35,14 +35,6 @@ public abstract class ObserverWizard extends BMotionAbstractWizard { return this.observer; } - protected void setObserverDelete(Boolean b) { - this.observerDelete = b; - } - - public Boolean isObserverDelete() { - return this.observerDelete; - } - public abstract Point getSize(); @Override @@ -50,4 +42,11 @@ public abstract class ObserverWizard extends BMotionAbstractWizard { return observer.getName(); } + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + PlatformUI.getWorkbench().getHelpSystem() + .setHelp(newShell, observer.getID()); + } + } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SetAttribute.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SetAttribute.java index 02773321d1ee6a0534ddfcb5e262aa47f5ad1fe7..3fdd5cbb44fb0a4617f8dc86d6ceab3a5f54d8a5 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SetAttribute.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SetAttribute.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.draw2d.IFigure; +import org.eclipse.swt.widgets.Shell; import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; @@ -64,14 +65,6 @@ public class SetAttribute extends Observer { attributeVal.toString(), control, animation); String er = attributeObj.validateValue(strAtrVal, null); if (er != null) { - // addError( - // control, - // animation, - // "You selected " - // + attributeObj.getName() - // + - // " as attribute. There is a problem with your value: " - // + strAtrVal + " - Reason: " + er); obj.setHasError(true); } else { attributeVal = attributeObj.unmarshal(strAtrVal); @@ -108,8 +101,8 @@ public class SetAttribute extends Observer { } @Override - public ObserverWizard getWizard(BControl control) { - return new WizardObserverSetAttribute(control, this); + public ObserverWizard getWizard(Shell shell, BControl control) { + return new WizardObserverSetAttribute(shell, control, this); } public void setSetAttributeObjects( @@ -133,23 +126,6 @@ public class SetAttribute extends Observer { @Override public IFigure getToolTip(BControl control) { - // // TODO: This method need rework!!! - // StringBuilder builder = new StringBuilder(); - // builder.append("Set Attribute Observer:\n\n"); - // for (SetAttributeObject obj : getSetAttributeObjects()) { - // if (obj.getEval() != null) { - // builder.append("[Predicate: " + obj.getEval()); - // } - // if (obj.getAttribute() != null) { - // builder.append(" | Attribute: " - // + control.getAttribute(obj.getAttribute()).getName()); - // } - // if (obj.getValue() != null) { - // builder.append(" | Value: " + obj.getValue() + "]"); - // } - // builder.append("\n"); - // } - // Label lb = new Label(builder.toString()); return null; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SetAttributeObject.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SetAttributeObject.java index d73f0c5abadd0e021fdff1f2932ab3346e79004f..cdacd8225bd1c3671edb141a964f5e56257927e0 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SetAttributeObject.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SetAttributeObject.java @@ -13,8 +13,8 @@ public class SetAttributeObject extends ObserverEvalObject implements Cloneable super(); } - public SetAttributeObject(String type, String eval) { - super(type, eval); + public SetAttributeObject(String eval) { + super(eval); } public SetAttributeObject clone() throws CloneNotSupportedException { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SimpleValueDisplay.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SimpleValueDisplay.java index 9886b3184634dbe24246762aeadd7c237c870bfc..303d92f036fcb6cd29578dfd439c8c91fbdda8ff 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SimpleValueDisplay.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SimpleValueDisplay.java @@ -6,6 +6,8 @@ package de.bmotionstudio.gef.editor.observer; +import org.eclipse.swt.widgets.Shell; + import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.model.BControl; @@ -56,8 +58,8 @@ public class SimpleValueDisplay extends Observer { } - public ObserverWizard getWizard(final BControl bcontrol) { - return new WizardObserverSimpleValueDisplay(bcontrol, this); + public ObserverWizard getWizard(Shell shell, final BControl bcontrol) { + return new WizardObserverSimpleValueDisplay(shell, bcontrol, this); } public String getType() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchChildCoordinates.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchChildCoordinates.java index b078e12811804505d629a88c34b6c08b9e595651..eaa058922ab96c52c9e66ef231d0bdda702e16a5 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchChildCoordinates.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchChildCoordinates.java @@ -9,6 +9,8 @@ package de.bmotionstudio.gef.editor.observer; import java.util.ArrayList; import java.util.List; +import org.eclipse.swt.widgets.Shell; + import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.model.BControl; @@ -99,8 +101,8 @@ public class SwitchChildCoordinates extends Observer { } - public ObserverWizard getWizard(final BControl bcontrol) { - return new WizardObserverCSwitchCoordinates(bcontrol, this); + public ObserverWizard getWizard(Shell shell, final BControl bcontrol) { + return new WizardObserverCSwitchCoordinates(shell, bcontrol, this); } public List<ToggleObjectCoordinates> getToggleObjects() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchCoordinates.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchCoordinates.java index 0f7733a383286e15814bb1321f7f0bc351fdc09d..1c60cda3b7fd50fb194e984380ab1a606df759cc 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchCoordinates.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchCoordinates.java @@ -9,6 +9,8 @@ package de.bmotionstudio.gef.editor.observer; import java.util.ArrayList; import java.util.List; +import org.eclipse.swt.widgets.Shell; + import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.model.BControl; @@ -109,8 +111,8 @@ public class SwitchCoordinates extends Observer { } - public ObserverWizard getWizard(final BControl bcontrol) { - return new WizardObserverSwitchCoordinates(bcontrol, this); + public ObserverWizard getWizard(Shell shell, final BControl bcontrol) { + return new WizardObserverSwitchCoordinates(shell, bcontrol, this); } public List<ToggleObjectCoordinates> getToggleObjects() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchImage.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchImage.java index 4422c6182b1b5a1b1aab885e7b69650140c2c852..f448877091c9e82f1dcd7ddb0dfcf24ff9e71220 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchImage.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SwitchImage.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.core.resources.IFile; +import org.eclipse.swt.widgets.Shell; import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.AttributeConstants; @@ -79,8 +80,8 @@ public class SwitchImage extends Observer { } - public ObserverWizard getWizard(final BControl bcontrol) { - return new WizardObserverSwitchImage(bcontrol, this); + public ObserverWizard getWizard(Shell shell, final BControl bcontrol) { + return new WizardObserverSwitchImage(shell, bcontrol, this); } public List<ToggleObjectImage> getToggleObjects() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/TableObserver.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/TableObserver.java index 9ad72ca8e76de21b1fe7c98f8f5e1c0029210c71..889da54b37ad66ff6ecc74e563dae9b21da6d18a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/TableObserver.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/TableObserver.java @@ -3,6 +3,8 @@ package de.bmotionstudio.gef.editor.observer; import java.util.LinkedList; import java.util.List; +import org.eclipse.swt.widgets.Shell; + import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; @@ -99,34 +101,33 @@ public class TableObserver extends Observer { String content = rows.get(i - numberOfOldRows); - if (content != null && content.length() > 0) + if (content != null && content.length() > 0) { content = UnicodeTranslator.toAscii(content); - - content = content.replaceAll("^\\(", ""); - content = content.replaceAll("\\)$", ""); - - List<String> columns = split2(content, '#'); - int numberOfNewColumns = columns.size(); - - // Set only one time the number of columns! - if (!setColumns) { - int ncolumns = numberOfNewColumns; - if (numberOfOldColumns > numberOfNewColumns) - ncolumns = numberOfOldColumns; - control.setAttributeValue( - AttributeConstants.ATTRIBUTE_COLUMNS, ncolumns, - true, false); - setColumns = true; - } - - for (int z = 0; z < numberOfNewColumns; z++) { - String val = columns.get(z); - BControl column = control.getChildrenArray().get(z); - BControl cell = column.getChildrenArray().get(i); - if (val != null && val.length() > 0) - val = UnicodeTranslator.toUnicode(val); - cell.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT, - val); + content = content.replaceAll("^\\(", ""); + content = content.replaceAll("\\)$", ""); + List<String> columns = split2(content, '#'); + int numberOfNewColumns = columns.size(); + + // Set only one time the number of columns! + if (!setColumns) { + int ncolumns = numberOfNewColumns; + if (numberOfOldColumns > numberOfNewColumns) + ncolumns = numberOfOldColumns; + control.setAttributeValue( + AttributeConstants.ATTRIBUTE_COLUMNS, ncolumns, + true, false); + setColumns = true; + } + + for (int z = 0; z < numberOfNewColumns; z++) { + String val = columns.get(z); + BControl column = control.getChildrenArray().get(z); + BControl cell = column.getChildrenArray().get(i); + if (val != null && val.length() > 0) + val = UnicodeTranslator.toUnicode(val); + cell.setAttributeValue( + AttributeConstants.ATTRIBUTE_TEXT, val); + } } } @@ -152,8 +153,8 @@ public class TableObserver extends Observer { } @Override - public ObserverWizard getWizard(BControl control) { - return new WizardTableObserver(control, this); + public ObserverWizard getWizard(Shell shell, BControl control) { + return new WizardTableObserver(shell, control, this); } public boolean isOverrideCells() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ToggleObjectCoordinates.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ToggleObjectCoordinates.java index 0ebd9af41725df1c3d7b59819f7534bfa0846886..a2c4ac9cf93f993a1fddac03d1859abdf818e975 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ToggleObjectCoordinates.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ToggleObjectCoordinates.java @@ -22,18 +22,18 @@ public class ToggleObjectCoordinates extends ObserverEvalObject implements // this.animate = false; } - public ToggleObjectCoordinates(String type, String bcontrol, String x, + public ToggleObjectCoordinates(String bcontrol, String x, String y, String eval) { - super(type, eval); + super(eval); this.bcontrol = bcontrol; this.x = x; this.y = y; // this.animate = animate; } - public ToggleObjectCoordinates(String type, String x, String y, + public ToggleObjectCoordinates(String x, String y, String eval) { - this(type, null, x, y, eval); + this(null, x, y, eval); } public String getBcontrol() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ToggleObjectImage.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ToggleObjectImage.java index dcd321623e5df59845f339638bacee19a1b31cba..6f173c31a2af90413cbae1a0229e47dba1246e8a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ToggleObjectImage.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ToggleObjectImage.java @@ -14,8 +14,8 @@ public class ToggleObjectImage extends ObserverEvalObject implements Cloneable { public ToggleObjectImage() { } - public ToggleObjectImage(String type, String image, String eval) { - super(type, eval); + public ToggleObjectImage(String image, String eval) { + super(eval); this.image = image; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/HelpAction.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/HelpAction.java new file mode 100644 index 0000000000000000000000000000000000000000..37ac250c4920137be13ef3d395098873f48b5772 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/HelpAction.java @@ -0,0 +1,34 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.observer.view; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.PlatformUI; + +import de.bmotionstudio.gef.editor.BMotionStudioImage; + +public class HelpAction extends Action { + + private String observerID; + + public HelpAction() { + setText("Show help..."); + setImageDescriptor(BMotionStudioImage + .getImageDescriptor("icons/eclipse16/linkto_help.gif")); + setEnabled(false); + } + + @Override + public void run() { + PlatformUI.getWorkbench().getHelpSystem().displayHelp(observerID); + } + + public void setObserverID(String observerID) { + this.observerID = observerID; + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/ObserverPage.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/ObserverPage.java new file mode 100644 index 0000000000000000000000000000000000000000..6652afca6b93650cce63a402bc7bb3d5e019d7ee --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/ObserverPage.java @@ -0,0 +1,212 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.observer.view; + +import java.util.Collection; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.part.Page; + +import de.bmotionstudio.gef.editor.BMotionStudioImage; +import de.bmotionstudio.gef.editor.EditorImageRegistry; +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.observer.Observer; +import de.bmotionstudio.gef.editor.observer.ObserverWizard; +import de.bmotionstudio.gef.editor.part.BMSAbstractEditPart; + +public class ObserverPage extends Page implements ISelectionListener { + + private Composite container; + + private BControl selectedControl; + + private ListViewer listViewer; + + private Composite rightContainer; + + private HelpAction helpAction; + + @Override + public void createControl(Composite parent) { + container = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + // layout.horizontalSpacing = 0; + // layout.verticalSpacing = 0; + container.setLayout(layout); + listViewer = new ListViewer(container); + listViewer.setContentProvider(new IStructuredContentProvider() { + + @Override + public void dispose() { + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, + Object newInput) { + } + + @Override + public Object[] getElements(Object inputElement) { + Collection<?> observerList = (Collection<?>) inputElement; + return observerList.toArray(); + } + + }); + listViewer.setLabelProvider(new ILabelProvider() { + + @Override + public void removeListener(ILabelProviderListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public boolean isLabelProperty(Object element, String property) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + @Override + public void addListener(ILabelProviderListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public String getText(Object element) { + Observer o = (Observer) element; + return o.getName(); + } + + @Override + public Image getImage(Object element) { + return BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_OBSERVER); + } + }); + + GridData layoutData = new GridData(GridData.FILL_VERTICAL); + layoutData.widthHint = 120; + listViewer.getControl().setLayoutData(layoutData); + listViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + restoreHelpButton(); + if (rightContainer != null) + rightContainer.dispose(); + if (event.getSelection() != null + && event.getSelection() instanceof StructuredSelection) { + Object firstElement = ((StructuredSelection) event + .getSelection()) + .getFirstElement(); + if (firstElement instanceof Observer) { + Observer o = (Observer) firstElement; + ObserverWizard wizard = o + .getWizard(Display.getDefault() + .getActiveShell(), selectedControl); + // IWizardPage page = wizard.getPages()[0]; + rightContainer = new Composite(container, SWT.NONE); + rightContainer.setLayoutData(new GridData( + GridData.FILL_BOTH)); + rightContainer.setLayout(new FillLayout()); + wizard.createWizardContent(rightContainer); + helpAction.setEnabled(true); + helpAction.setObserverID(o.getID()); + } + } + container.layout(); + } + }); + + getSite().getPage().addPostSelectionListener(this); + createActions(); + createMenu(getSite()); + + } + + private void createActions() { + helpAction = new HelpAction(); + } + + private void createMenu(final IPageSite pageSite) { + pageSite.getActionBars().getToolBarManager().add(helpAction); + } + + @Override + public Control getControl() { + return container; + } + + @Override + public void setFocus() { + // TODO Auto-generated method stub + + } + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if (selection != null && selection instanceof StructuredSelection) { + Object firstElement = ((StructuredSelection) selection) + .getFirstElement(); + if (firstElement instanceof BMSAbstractEditPart) { + selectedControl = (BControl) ((BMSAbstractEditPart) firstElement) + .getModel(); + if (!listViewer.getControl().isDisposed()) { + Collection<Observer> values = selectedControl + .getObservers().values(); + listViewer.setInput(values); + if (values.size() > 0) { + Observer firstObserver = values.iterator().next(); + listViewer.setSelection(new StructuredSelection( + firstObserver)); + } else { + restoreHelpButton(); + if (rightContainer != null) + rightContainer.dispose(); + } + } + } + } + } + + @Override + public void dispose() { + getSite().getPage().addPostSelectionListener(this); + super.dispose(); + } + + private void restoreHelpButton() { + helpAction.setEnabled(false); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/ObserverView.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/ObserverView.java new file mode 100644 index 0000000000000000000000000000000000000000..11140584515010b4df56fc28f8b8a465810e79c1 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/view/ObserverView.java @@ -0,0 +1,68 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.observer.view; + +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.IPage; +import org.eclipse.ui.part.MessagePage; +import org.eclipse.ui.part.PageBook; +import org.eclipse.ui.part.PageBookView; + +import de.bmotionstudio.gef.editor.BMotionStudioEditor; + +public class ObserverView extends PageBookView { + + public static String ID = "de.bmotionstudio.gef.editor.ObserverView"; + + private String defaultText = "The observer view is not available."; + + private ObserverPage page; + + @Override + protected IPage createDefaultPage(PageBook book) { + MessagePage page = new MessagePage(); + initPage(page); + page.createControl(book); + page.setMessage(defaultText); + return page; + } + + @Override + protected PageRec doCreatePage(IWorkbenchPart part) { + if (part instanceof BMotionStudioEditor) { + page = new ObserverPage(); + initPage(page); + page.createControl(getPageBook()); + return new PageRec(part, page); + } + return null; + } + + @Override + protected void doDestroyPage(IWorkbenchPart part, PageRec rec) { + ObserverPage page = (ObserverPage) rec.page; + page.dispose(); + rec.dispose(); + } + + @Override + protected IWorkbenchPart getBootstrapPart() { + IWorkbenchPage page = getSite().getPage(); + if (page != null) { + return page.getActiveEditor(); + } + return null; + } + + @Override + protected boolean isImportant(IWorkbenchPart part) { + return (part instanceof IEditorPart); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/AbstractObserverWizardPage.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/AbstractObserverWizardPage.java deleted file mode 100644 index 2450ad1a6a17dcc9def5a1c29a412d5a6b689dca..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/AbstractObserverWizardPage.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.observer.wizard; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PlatformUI; - -import de.bmotionstudio.gef.editor.observer.Observer; - -public class AbstractObserverWizardPage extends WizardPage { - - private Observer observer; - - protected AbstractObserverWizardPage(String pageName, Observer observer) { - super(pageName); - this.observer = observer; - } - - @Override - public void createControl(Composite parent) { - PlatformUI.getWorkbench().getHelpSystem() - .setHelp(parent, observer.getClass().getName()); - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardColumnObserver.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardColumnObserver.java index 04c3a5cd6d6850073f3666b70767eb971400eba6..dc48f9c0ca40ea7a5a80b012db6d49f90c1dcefb 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardColumnObserver.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardColumnObserver.java @@ -9,8 +9,6 @@ package de.bmotionstudio.gef.editor.observer.wizard; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.beans.BeansObservables; import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; @@ -18,8 +16,10 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import de.bmotionstudio.gef.editor.model.BControl; @@ -29,93 +29,80 @@ import de.bmotionstudio.gef.editor.observer.ObserverWizard; public class WizardColumnObserver extends ObserverWizard { - private class ColumnObserverPage extends WizardPage { + private Text txtExpression; + private Text txtPredicate; - private Text txtExpression; - private Text txtPredicate; - - public Text getTxtExpression() { - return txtExpression; - } - - protected ColumnObserverPage(final String pageName) { - super(pageName); - } - - public void createControl(final Composite parent) { - - final DataBindingContext dbc = new DataBindingContext(); + @Override + public Control createWizardContent(Composite parent) { - Composite container = new Composite(parent, SWT.NONE); + final DataBindingContext dbc = new DataBindingContext(); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); - container.setLayout(new GridLayout(2, false)); + Composite container = new Composite(parent, SWT.NONE); - Label lb = new Label(container, SWT.NONE); - lb.setText("Predicate:"); + container.setLayout(new GridLayout(2, false)); - txtPredicate = new Text(container, SWT.BORDER); - txtPredicate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - txtPredicate.setFont(new Font(Display.getDefault(), new FontData( - "Arial", 10, SWT.NONE))); + Label lb = new Label(container, SWT.NONE); + lb.setText("Predicate:"); - lb = new Label(container, SWT.NONE); - lb.setText("Expression:"); - lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + txtPredicate = new Text(container, SWT.BORDER); + txtPredicate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + txtPredicate.setFont(new Font(Display.getDefault(), new FontData( + "Arial", 10, SWT.NONE))); - txtExpression = new Text(container, SWT.BORDER | SWT.MULTI - | SWT.WRAP); - txtExpression.setLayoutData(new GridData(GridData.FILL_BOTH)); + lb = new Label(container, SWT.NONE); + lb.setText("Expression:"); + lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - initBindings(dbc); + txtExpression = new Text(container, SWT.BORDER | SWT.MULTI | SWT.WRAP); + txtExpression.setLayoutData(new GridData(GridData.FILL_BOTH)); - setControl(container); + initBindings(dbc); - } + return container; - private void initBindings(DataBindingContext dbc) { + } - dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), - BeansObservables.observeValue( - (ColumnObserver) getObserver(), "predicate")); + private void initBindings(DataBindingContext dbc) { - dbc.bindValue( - SWTObservables.observeText(txtExpression, SWT.Modify), - BeansObservables.observeValue( - (ColumnObserver) getObserver(), "expression")); + dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), + BeansObservables.observeValue((ColumnObserver) getObserver(), + "predicate")); - } + dbc.bindValue(SWTObservables.observeText(txtExpression, SWT.Modify), + BeansObservables.observeValue((ColumnObserver) getObserver(), + "expression")); } - public WizardColumnObserver(BControl bcontrol, + + public WizardColumnObserver(Shell shell, BControl bcontrol, Observer bobserver) { - super(bcontrol, bobserver); - addPage(new ColumnObserverPage("ColumnObserverPage")); + super(shell, bcontrol, bobserver); } - @Override - protected Boolean prepareToFinish() { - - ColumnObserverPage page = (ColumnObserverPage) getPage("ColumnObserverPage"); - - String errorStr = ""; - - if (page.getTxtExpression().getText().length() == 0) - errorStr += "Please enter an expression.\n"; - - if (page.getErrorMessage() != null) - errorStr += "Please check the syntax/parser error.\n"; - - if (errorStr.length() > 0) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "An Error occured", errorStr); - return false; - } - - return true; - - } + // @Override + // protected Boolean prepareToFinish() { + // + // ColumnObserverPage page = (ColumnObserverPage) + // getPage("ColumnObserverPage"); + // + // String errorStr = ""; + // + // if (page.getTxtExpression().getText().length() == 0) + // errorStr += "Please enter an expression.\n"; + // + // if (page.getErrorMessage() != null) + // errorStr += "Please check the syntax/parser error.\n"; + // + // if (errorStr.length() > 0) { + // MessageDialog.openError(Display.getDefault().getActiveShell(), + // "An Error occured", errorStr); + // return false; + // } + // + // return true; + // + // } @Override public Point getSize() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverCSwitchCoordinates.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverCSwitchCoordinates.java index 3a5b8b09e05c56eb8d139898c317cb86ac5caddb..c76bf57ec4f94b70f41da5fc8e7b529e7d045fac 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverCSwitchCoordinates.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverCSwitchCoordinates.java @@ -12,13 +12,10 @@ import org.eclipse.core.databinding.observable.list.WritableList; import org.eclipse.core.databinding.observable.map.IObservableMap; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; @@ -33,18 +30,16 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; -import de.be4.classicalb.core.parser.BParser; -import de.bmotionstudio.gef.editor.AttributeConstants; -import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.edit.TextEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates; import de.bmotionstudio.gef.editor.observer.ToggleObjectCoordinates; @@ -52,217 +47,138 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardObserverCSwitchCoordinates extends ObserverWizard { - private String lastChangedControlID; - - private class ObserverCSwitchCoordinatesPage extends - AbstractObserverWizardPage { - - private TableViewer tableViewer; - - protected ObserverCSwitchCoordinatesPage(final String pageName) { - super(pageName, getObserver()); - } - - public void createControl(Composite parent) { - - super.createControl(parent); - - DataBindingContext dbc = new DataBindingContext(); - - Composite container = new Composite(parent, SWT.NONE); - container.setLayout(new GridLayout(1, true)); - - tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( - container, ToggleObjectCoordinates.class, - ((BMotionAbstractWizard) getWizard()).getName()); - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - restorePreview(); - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - if (!observerEvalObject.isExpressionMode()) { - BControl control = getBControl(); - ToggleObjectCoordinates toggleObjectCoordinates = (ToggleObjectCoordinates) observerEvalObject; - String attributeX = AttributeConstants.ATTRIBUTE_X; - String attributeY = AttributeConstants.ATTRIBUTE_Y; - String x = toggleObjectCoordinates.getX(); - String y = toggleObjectCoordinates.getY(); - String controlID = toggleObjectCoordinates - .getBcontrol(); - BControl bControl = control - .getChild(controlID); - if (bControl != null) { - bControl.setAttributeValue(attributeX, - x, true, false); - bControl.setAttributeValue(attributeY, - y, true, false); - } - lastChangedControlID = controlID; - } - } - } - - }); - - TableViewerColumn column = new TableViewerColumn(tableViewer, - SWT.NONE); - column.getColumn().setText("Predicate"); - column.getColumn().setWidth(100); - column.setEditingSupport(new PredicateEditingSupport(tableViewer, - dbc, "eval", getBControl().getVisualization(), getShell())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Control"); - column.getColumn().setWidth(175); - column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, - "bcontrol")); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("X"); - column.getColumn().setWidth(125); - column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, - "x")); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Y"); - column.getColumn().setWidth(125); - column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, - "y")); - - // column = new TableViewerColumn(tableViewer, SWT.NONE); - // column.getColumn().setText("Animate?"); - // column.getColumn().setWidth(75); - // column.setEditingSupport(new EditingSupport(tableViewer) { - // - // private CellEditor cellEditor = new CheckboxCellEditor( - // (Composite) tableViewer.getControl()); - // - // @Override - // protected void setValue(Object element, Object value) { - // ((ToggleObjectCoordinates) element).setAnimate(Boolean - // .valueOf(String.valueOf(value))); - // } - // - // @Override - // protected Object getValue(Object element) { - // Boolean b = ((ToggleObjectCoordinates) element) - // .getAnimate(); - // return b != null ? b : false; - // } - // - // @Override - // protected CellEditor getCellEditor(Object element) { - // return cellEditor; - // } - // - // @Override - // protected boolean canEdit(Object element) { - // return true; - // } - // - // }); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - tableViewer - .setLabelProvider(new ObserverLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), - new String[] { "eval", "bcontrol", "x", - "y", "animate" }))); - - final WritableList input = new WritableList( - ((SwitchChildCoordinates) getObserver()).getToggleObjects(), - ToggleObjectCoordinates.class); - tableViewer.setInput(input); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - return; - } - ToggleObjectCoordinates toggleObj = (ToggleObjectCoordinates) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(toggleObj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - ToggleObjectCoordinates toggleObj = new ToggleObjectCoordinates( - BParser.PREDICATE_PREFIX, "", "", "", ""); - input.add(toggleObj); - } - }); - - setControl(container); - - } - } - - public WizardObserverCSwitchCoordinates(final BControl bcontrol, - final Observer bobserver) { - super(bcontrol, bobserver); - addPage(new ObserverCSwitchCoordinatesPage( - "ObserverCToggleCoordinatesPage")); - } + private TableViewer tableViewer; @Override - protected Boolean prepareToFinish() { - restorePreview(); - if (((SwitchChildCoordinates) getObserver()).getToggleObjects().size() == 0) { - setObserverDelete(true); - } else { - for (ToggleObjectCoordinates obj : ((SwitchChildCoordinates) getObserver()) - .getToggleObjects()) { - if (obj.getX().isEmpty() || obj.getY().isEmpty() - || obj.getBcontrol().isEmpty()) { - MessageDialog - .openError(getShell(), "Please check your entries", - "Please check your entries. The x , y and control fields must not be empty."); - return false; + public Control createWizardContent(Composite parent) { + + DataBindingContext dbc = new DataBindingContext(); + + GridLayout gl = new GridLayout(1, true); + gl.horizontalSpacing = 0; + gl.verticalSpacing = 0; + gl.marginHeight = 0; + gl.marginWidth = 0; + + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(gl); + + tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( + container, ToggleObjectCoordinates.class, getName()); + + TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Predicate"); + column.getColumn().setWidth(100); + column.setEditingSupport(new PredicateEditingSupport(tableViewer, dbc, + "eval", getBControl().getVisualization(), getShell())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Control"); + column.getColumn().setWidth(175); + column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, + "bcontrol")); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("X"); + column.getColumn().setWidth(125); + column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, "x")); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Y"); + column.getColumn().setWidth(125); + column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, "y")); + + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + tableViewer.setContentProvider(contentProvider); + tableViewer.setLabelProvider(new ObserverLabelProvider(BeansObservables + .observeMaps(contentProvider.getKnownElements(), new String[] { + "eval", "bcontrol", "x", "y", "animate" }))); + + final WritableList input = new WritableList( + ((SwitchChildCoordinates) getObserver()).getToggleObjects(), + ToggleObjectCoordinates.class); + tableViewer.setInput(input); + + Composite comp = new Composite(container, SWT.NONE); + comp.setLayout(new RowLayout()); + comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + + Button btRemove = new Button(comp, SWT.PUSH); + btRemove.setText("Remove"); + btRemove.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); + btRemove.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (tableViewer.getSelection().isEmpty()) { + return; } + ToggleObjectCoordinates toggleObj = (ToggleObjectCoordinates) ((IStructuredSelection) tableViewer + .getSelection()).getFirstElement(); + input.remove(toggleObj); } - } - return true; - } - - private void restorePreview() { - if (lastChangedControlID != null) { - BControl bControl = getBControl().getChild(lastChangedControlID); - if (bControl != null) { - bControl.restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); - bControl.restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); + }); + + Button btAdd = new Button(comp, SWT.PUSH); + btAdd.setText("Add"); + btAdd.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); + btAdd.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ToggleObjectCoordinates toggleObj = new ToggleObjectCoordinates( + "", "", "", ""); + input.add(toggleObj); } - } + }); + + return container; + } - @Override - public boolean performCancel() { - restorePreview(); - return super.performCancel(); + public WizardObserverCSwitchCoordinates(Shell shell, BControl bcontrol, + Observer bobserver) { + super(shell, bcontrol, bobserver); } + // @Override + // protected Boolean prepareToFinish() { + // // restorePreview(); + // if (((SwitchChildCoordinates) getObserver()).getToggleObjects().size() == + // 0) { + // setObserverDelete(true); + // } else { + // for (ToggleObjectCoordinates obj : ((SwitchChildCoordinates) + // getObserver()) + // .getToggleObjects()) { + // if (obj.getX().isEmpty() || obj.getY().isEmpty() + // || obj.getBcontrol().isEmpty()) { + // MessageDialog + // .openError(getShell(), "Please check your entries", + // "Please check your entries. The x , y and control fields must not be empty."); + // return false; + // } + // } + // } + // return true; + // } + + // private void restorePreview() { + // if (lastChangedControlID != null) { + // BControl bControl = getBControl().getChild(lastChangedControlID); + // if (bControl != null) { + // bControl.restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); + // bControl.restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); + // } + // } + // } + + // @Override + // public boolean performCancel() { + // // restorePreview(); + // return super.performCancel(); + // } + @Override public Point getSize() { return new Point(650, 500); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverExternalObserverScript.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverExternalObserverScript.java deleted file mode 100644 index 9e4c0d4e57f8aaec0519b81a7afdb3c4d932616b..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverExternalObserverScript.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.observer.wizard; - -import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.observer.ExternalObserverScript; -import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverWizard; - -public class WizardObserverExternalObserverScript extends ObserverWizard { - - private class ObserverExternalObserverScriptPage extends WizardPage { - - private Text txtScriptPath; - - protected ObserverExternalObserverScriptPage(final String pageName) { - super(pageName); - } - - public Text getTxtScriptPath() { - return txtScriptPath; - } - - public void createControl(final Composite parent) { - - final DataBindingContext dbc = new DataBindingContext(); - - Composite container = new Composite(parent, SWT.NONE); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); - container.setLayout(new GridLayout(2, false)); - - Label lb = new Label(container, SWT.NONE); - lb.setText("Script File:"); - - txtScriptPath = new Text(container, SWT.BORDER); - txtScriptPath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - txtScriptPath.setFont(new Font(Display.getDefault(), new FontData( - "Arial", 10, SWT.NONE))); - - initBindings(dbc); - - setControl(container); - - } - - private void initBindings(DataBindingContext dbc) { - - dbc.bindValue( - SWTObservables.observeText(txtScriptPath, SWT.Modify), - BeansObservables.observeValue( - (ExternalObserverScript) getObserver(), - "scriptPath")); - - } - - - } - - public WizardObserverExternalObserverScript(BControl bcontrol, - Observer bobserver) { - super(bcontrol, bobserver); - addPage(new ObserverExternalObserverScriptPage( - "ObserverExternalObserverScriptPage")); - } - - @Override - protected Boolean prepareToFinish() { - - ObserverExternalObserverScriptPage page = (ObserverExternalObserverScriptPage) getPage("ObserverExternalObserverScriptPage"); - - String errorStr = ""; - - if (page.getTxtScriptPath().getText().length() == 0) - errorStr += "Please enter a path for a script file.\n"; - - if (errorStr.length() > 0) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "An Error occured", errorStr); - return false; - } - - return true; - - } - - @Override - public Point getSize() { - return new Point(600, 500); - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverListenOperationByPredicate.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverListenOperationByPredicate.java index 856cd5a2e88267505c1a347a7bea6059713752a7..83adaee4f663a2565965bfd3cc528f807d2bcfe1 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverListenOperationByPredicate.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverListenOperationByPredicate.java @@ -16,17 +16,14 @@ import org.eclipse.core.databinding.observable.list.WritableList; import org.eclipse.core.databinding.observable.map.IObservableMap; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -40,13 +37,15 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; -import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; @@ -57,7 +56,6 @@ import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.ListenOperationByPredicate; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.property.CheckboxCellEditorHelper; import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; @@ -65,325 +63,232 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardObserverListenOperationByPredicate extends ObserverWizard { - private String lastChangedAttributeID; + private TableViewer tableViewer; - private class ObserverListenOperationByPredicatePage extends - AbstractObserverWizardPage { - - private TableViewer tableViewer; - - protected ObserverListenOperationByPredicatePage(final String pageName) { - super(pageName, getObserver()); - } - - public void createControl(final Composite parent) { - - super.createControl(parent); - - DataBindingContext dbc = new DataBindingContext(); - - Composite container = new Composite(parent, SWT.NONE); - container.setLayout(new GridLayout(1, true)); - - setControl(container); - - tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( - container, PredicateOperation.class, - ((BMotionAbstractWizard) getWizard()).getName()); - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - BControl control = getBControl(); - - if (lastChangedAttributeID != null) - control.restoreDefaultValue(lastChangedAttributeID); - - PredicateOperation obj = (PredicateOperation) observerEvalObject; - - if (!obj.isExpressionMode()) { + @Override + public Control createWizardContent(Composite parent) { + + parent.setLayout(new FillLayout()); + + DataBindingContext dbc = new DataBindingContext(); + + GridLayout gl = new GridLayout(1, true); + gl.horizontalSpacing = 0; + gl.verticalSpacing = 0; + gl.marginHeight = 0; + gl.marginWidth = 0; + + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(gl); + + tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( + container, PredicateOperation.class, getName()); + + TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Operation"); + column.getColumn().setWidth(150); + column.setEditingSupport(new OperationValueEditingSupport(tableViewer, + getBControl())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Predicate"); + column.getColumn().setWidth(150); + column.setEditingSupport(new PredicateEditingSupport(tableViewer, dbc, + "predicate", getBControl().getVisualization(), getShell())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Attribute"); + column.getColumn().setWidth(150); + column.setEditingSupport(new AttributeObserverValueEditing(tableViewer)); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Value"); + column.getColumn().setWidth(175); + column.setEditingSupport(new AttributeExpressionEdittingSupport( + tableViewer, getBControl())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Expression?"); + column.getColumn().setWidth(100); + column.setEditingSupport(new IsExpressionModeEditingSupport( + tableViewer, getBControl())); + + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + tableViewer.setContentProvider(contentProvider); + tableViewer.setLabelProvider(new ObserverLabelProvider(BeansObservables + .observeMaps(contentProvider.getKnownElements(), new String[] { + "operationName", "predicate", "attribute", "value", + "isExpressionMode" }))); + final WritableList input = new WritableList( + ((ListenOperationByPredicate) getObserver()).getList(), + PredicateOperation.class); + tableViewer.setInput(input); + + Composite comp = new Composite(container, SWT.NONE); + comp.setLayout(new RowLayout()); + comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + + Button btRemove = new Button(comp, SWT.PUSH); + btRemove.setText("Remove"); + btRemove.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); + btRemove.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (tableViewer.getSelection().isEmpty()) { + return; + } + PredicateOperation obj = (PredicateOperation) ((IStructuredSelection) tableViewer + .getSelection()).getFirstElement(); + input.remove(obj); + } + }); - String attribute = obj.getAttribute(); - Object value = obj.getValue(); - control.setAttributeValue(attribute, value, - true, false); + Button btAdd = new Button(comp, SWT.PUSH); + btAdd.setText("Add"); + btAdd.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); + btAdd.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + PredicateOperation obj = new PredicateOperation(); + input.add(obj); + tableViewer.setSelection(new StructuredSelection(obj)); + } + }); - lastChangedAttributeID = attribute; + return container; - } + } - } - } + private class AttributeObserverValueEditing extends EditingSupport { - }); - - TableViewerColumn column = new TableViewerColumn(tableViewer, - SWT.NONE); - column.getColumn().setText("Operation"); - column.getColumn().setWidth(150); - column.setEditingSupport(new OperationValueEditingSupport( - tableViewer, getBControl())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Predicate"); - column.getColumn().setWidth(150); - column.setEditingSupport(new PredicateEditingSupport(tableViewer, - dbc, "predicate", getBControl().getVisualization(), - getShell())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Attribute"); - column.getColumn().setWidth(150); - column.setEditingSupport(new AttributeObserverValueEditing( - tableViewer)); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Value"); - column.getColumn().setWidth(175); - column.setEditingSupport(new AttributeExpressionEdittingSupport( - tableViewer, getBControl())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Expression?"); - column.getColumn().setWidth(100); - column.setEditingSupport(new IsExpressionModeEditingSupport( - tableViewer, getBControl())); - - // MathTableViewerColumn columnEval = new MathTableViewerColumn( - // tableViewer, column, dbc, "predicate"); - // columnEval.addErrorMessageListener(new IMessageListener() { - // public void setMsg(final String errorMsg) { - // if (errorMsg != null) { - // setErrorMessage(errorMsg); - // } else { - // setErrorMessage(null); - // setMessage(getObserver().getDescription()); - // } - // } - // }); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - tableViewer.setLabelProvider(new ObserverLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), new String[] { - "operationName", "predicate", "attribute", - "value", "isExpressionMode" }))); - final WritableList input = new WritableList( - ((ListenOperationByPredicate) getObserver()).getList(), - PredicateOperation.class); - tableViewer.setInput(input); - - // ColumnViewerEditorActivationStrategy activationSupport = new - // ColumnViewerEditorActivationStrategy( - // tableViewer) { - // protected boolean isEditorActivationEvent( - // ColumnViewerEditorActivationEvent event) { - // return event.eventType == - // ColumnViewerEditorActivationEvent.TRAVERSAL - // || event.eventType == - // ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION - // || event.eventType == - // ColumnViewerEditorActivationEvent.PROGRAMMATIC - // || (event.eventType == - // ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == - // KeyLookupFactory - // .getDefault().formalKeyLookup( - // IKeyLookup.ENTER_NAME)); - // } - // }; - // activationSupport.setEnableEditorActivationWithKeyboard(true); - - /* - * Without focus highlighter, keyboard events will not be delivered - * to - * ColumnViewerEditorActivationStragety#isEditorActivationEvent(...) - * (see above) - */ - // FocusCellHighlighter focusCellHighlighter = new - // FocusCellOwnerDrawHighlighter( - // tableViewer); - // TableViewerFocusCellManager focusCellManager = new - // TableViewerFocusCellManager( - // tableViewer, focusCellHighlighter); - - // TableViewerEditor.create(tableViewer, focusCellManager, - // activationSupport, ColumnViewerEditor.TABBING_VERTICAL - // | ColumnViewerEditor.KEYBOARD_ACTIVATION); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - return; - } - PredicateOperation obj = (PredicateOperation) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(obj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - PredicateOperation obj = new PredicateOperation(); - input.add(obj); - tableViewer.setSelection(new StructuredSelection(obj)); - } - }); + private ComboBoxViewerCellEditor cellEditor = null; + public AttributeObserverValueEditing(TableViewer cv) { + super(cv); } - private class AttributeObserverValueEditing extends EditingSupport { - - private ComboBoxViewerCellEditor cellEditor = null; - - public AttributeObserverValueEditing(TableViewer cv) { - super(cv); - } - - @Override - protected boolean canEdit(Object element) { - return BMotionWizardUtil.isEditElement(getViewer()); - } + @Override + protected boolean canEdit(Object element) { + return BMotionWizardUtil.isEditElement(getViewer()); + } - @Override - protected Object getValue(Object element) { - return ((PredicateOperation) element).getAttribute(); - } + @Override + protected Object getValue(Object element) { + return ((PredicateOperation) element).getAttribute(); + } - @Override - protected void setValue(Object element, Object value) { - if (value != null) { - PredicateOperation obj = (PredicateOperation) element; - obj.setAttribute(value.toString()); - obj.setIsExpressionMode(false); - } + @Override + protected void setValue(Object element, Object value) { + if (value != null) { + PredicateOperation obj = (PredicateOperation) element; + obj.setAttribute(value.toString()); + obj.setIsExpressionMode(false); } + } - @Override - protected CellEditor getCellEditor(Object element) { - if (cellEditor == null) { - - cellEditor = new ComboBoxViewerCellEditor( - (Composite) tableViewer.getControl(), SWT.READ_ONLY); - cellEditor - .setContentProvider(new ObservableListContentProvider()); - cellEditor.setLabelProvider(new LabelProvider() { - public String getText(Object element) { - return getBControl().getAttributes() - .get(element.toString()).getName(); - } - }); - cellEditor.setInput(new ComputedList() { - @Override - protected List<String> calculate() { - ArrayList<String> atrList = new ArrayList<String>(); - for (AbstractAttribute atr : getBControl() - .getAttributes().values()) { - atrList.add(atr.getID()); - } - return atrList; + @Override + protected CellEditor getCellEditor(Object element) { + if (cellEditor == null) { + + cellEditor = new ComboBoxViewerCellEditor( + (Composite) tableViewer.getControl(), SWT.READ_ONLY); + cellEditor + .setContentProvider(new ObservableListContentProvider()); + cellEditor.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + return getBControl().getAttributes() + .get(element.toString()).getName(); + } + }); + cellEditor.setInput(new ComputedList() { + @Override + protected List<String> calculate() { + ArrayList<String> atrList = new ArrayList<String>(); + for (AbstractAttribute atr : getBControl() + .getAttributes().values()) { + atrList.add(atr.getID()); } - }); + return atrList; + } + }); - ((CCombo) cellEditor.getControl()) - .addFocusListener(new FocusListener() { + ((CCombo) cellEditor.getControl()) + .addFocusListener(new FocusListener() { - String oldValue; + String oldValue; - public void focusGained(FocusEvent e) { - oldValue = ((CCombo) cellEditor - .getControl()).getText(); + public void focusGained(FocusEvent e) { + oldValue = ((CCombo) cellEditor.getControl()) + .getText(); - } + } - public void focusLost(FocusEvent e) { + public void focusLost(FocusEvent e) { - if (!oldValue.equals(((CCombo) cellEditor - .getControl()).getText())) { + if (!oldValue.equals(((CCombo) cellEditor + .getControl()).getText())) { - IStructuredSelection selection = (IStructuredSelection) getViewer() - .getSelection(); + IStructuredSelection selection = (IStructuredSelection) getViewer() + .getSelection(); - PredicateOperation p = (PredicateOperation) selection - .getFirstElement(); + PredicateOperation p = (PredicateOperation) selection + .getFirstElement(); - AbstractAttribute atr = getBControl() - .getAttributes().get( - p.getAttribute()); + AbstractAttribute atr = getBControl() + .getAttributes().get( + p.getAttribute()); - p.setValue(atr.getValue()); - tableViewer.refresh(); + p.setValue(atr.getValue()); + tableViewer.refresh(); - } } + } - }); + }); - } - return cellEditor; } - + return cellEditor; } } - public WizardObserverListenOperationByPredicate(final BControl bcontrol, - final Observer bobserver) { - super(bcontrol, bobserver); - addPage(new ObserverListenOperationByPredicatePage( - "ObserverListenOperationByPredicatePage")); + public WizardObserverListenOperationByPredicate(Shell shell, + BControl bcontrol, Observer bobserver) { + super(shell, bcontrol, bobserver); } - @Override - public boolean performCancel() { - getBControl().restoreDefaultValue(lastChangedAttributeID); - return super.performCancel(); - } - - @Override - protected Boolean prepareToFinish() { - getBControl().restoreDefaultValue(lastChangedAttributeID); - if (((ListenOperationByPredicate) getObserver()).getList().size() == 0) { - setObserverDelete(true); - } else { - for (PredicateOperation obj : ((ListenOperationByPredicate) getObserver()) - .getList()) { - if (obj.getOperationName().isEmpty()) { - MessageDialog - .openError(getShell(), "Please check your entries", - "Please check your entries. The operation field must not be empty."); - return false; - } else if (obj.getAttribute() == null) { - MessageDialog - .openError(getShell(), "Please check your entries", - "Please check your entries. The attribute field must not be empty."); - return false; - } - } - } - return true; - } + // @Override + // public boolean performCancel() { + // // getBControl().restoreDefaultValue(lastChangedAttributeID); + // return super.performCancel(); + // } + + // @Override + // protected Boolean prepareToFinish() { + // // getBControl().restoreDefaultValue(lastChangedAttributeID); + // if (((ListenOperationByPredicate) getObserver()).getList().size() == 0) { + // setObserverDelete(true); + // } else { + // for (PredicateOperation obj : ((ListenOperationByPredicate) + // getObserver()) + // .getList()) { + // if (obj.getOperationName().isEmpty()) { + // MessageDialog + // .openError(getShell(), "Please check your entries", + // "Please check your entries. The operation field must not be empty."); + // return false; + // } else if (obj.getAttribute() == null) { + // MessageDialog + // .openError(getShell(), "Please check your entries", + // "Please check your entries. The attribute field must not be empty."); + // return false; + // } + // } + // } + // return true; + // } @Override public Point getSize() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSetAttribute.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSetAttribute.java index 8817a572855ba8271c20bf61bd52d3ada2bcc0f4..9a6d6dbca1d235a82cdf3a772fa066e82472c855 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSetAttribute.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSetAttribute.java @@ -19,13 +19,11 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -39,15 +37,16 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; -import de.be4.classicalb.core.parser.BParser; -import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; @@ -56,7 +55,6 @@ import de.bmotionstudio.gef.editor.edit.IsExpressionModeEditingSupport; import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.SetAttribute; import de.bmotionstudio.gef.editor.observer.SetAttributeObject; @@ -65,253 +63,109 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardObserverSetAttribute extends ObserverWizard { - private String lastChangedAttributeID; + private WritableList input; - private class WizardSetAttributePage extends AbstractObserverWizardPage { - - private WritableList input; - - private TableViewer tableViewer; - - protected WizardSetAttributePage(final String pageName) { - super(pageName, getObserver()); - } - - public void createControl(Composite parent) { - - super.createControl(parent); - - DataBindingContext dbc = new DataBindingContext(); - - GridLayout gl = new GridLayout(1, true); - gl.horizontalSpacing = 0; - gl.verticalSpacing = 0; - gl.marginHeight = 0; - gl.marginWidth = 0; - - Composite container = new Composite(parent, SWT.NONE); - container.setLayout(gl); - - tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( - container, SetAttributeObject.class, - ((BMotionAbstractWizard) getWizard()).getName()); - - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - BControl control = getBControl(); - - if (lastChangedAttributeID != null) - control.restoreDefaultValue(lastChangedAttributeID); - - SetAttributeObject setAttributeObj = (SetAttributeObject) observerEvalObject; - - if (!setAttributeObj.isExpressionMode()) { - - String attribute = setAttributeObj - .getAttribute(); - Object value = setAttributeObj.getValue(); - control.setAttributeValue(attribute, value, - true, false); - - lastChangedAttributeID = attribute; - - } - - } - } - - }); - - TableViewerColumn column = new TableViewerColumn(tableViewer, - SWT.NONE); - column.getColumn().setText("Predicate"); - column.getColumn().setWidth(300); - - PredicateEditingSupport pEditingSupport = new PredicateEditingSupport( - tableViewer, dbc, "eval", getBControl().getVisualization(), - getShell()); - column.setEditingSupport(pEditingSupport); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Attribute"); - column.getColumn().setWidth(150); - column.setEditingSupport(new AttributeObserverValueEditing( - tableViewer)); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Value"); - column.getColumn().setWidth(175); - column.setEditingSupport(new AttributeExpressionEdittingSupport( - tableViewer, getBControl())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Expression?"); - column.getColumn().setWidth(100); - column.setEditingSupport(new IsExpressionModeEditingSupport( - tableViewer, getBControl())); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - - tableViewer.setLabelProvider(new ObserverLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), new String[] { - "eval", "attribute", "value", - "isExpressionMode" }))); - input = new WritableList( - ((SetAttribute) getObserver()).getSetAttributeObjects(), - SetAttributeObject.class); - tableViewer.setInput(input); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - MessageDialog.openInformation(getShell(), - "Please select an entry.", - "Please select an entry."); - return; - } - SetAttributeObject toggleObj = (SetAttributeObject) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(toggleObj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - SetAttributeObject toggleObj = new SetAttributeObject( - BParser.PREDICATE_PREFIX, ""); - input.add(toggleObj); - tableViewer - .setSelection(new StructuredSelection(toggleObj)); - } - }); - - setControl(container); - - } - - private class AttributeObserverValueEditing extends EditingSupport { - - private ComboBoxViewerCellEditor cellEditor = null; - - public AttributeObserverValueEditing(TableViewer cv) { - super(cv); - } - - @Override - protected boolean canEdit(Object element) { - return BMotionWizardUtil.isEditElement(getViewer()); - } - - @Override - protected Object getValue(Object element) { - return ((SetAttributeObject) element).getAttribute(); - } + private TableViewer tableViewer; + @Override + public Control createWizardContent(Composite parent) { + + parent.setLayout(new FillLayout()); + + DataBindingContext dbc = new DataBindingContext(); + + GridLayout gl = new GridLayout(1, true); + gl.horizontalSpacing = 0; + gl.verticalSpacing = 0; + gl.marginHeight = 0; + gl.marginWidth = 0; + + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(gl); + + tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( + container, SetAttributeObject.class, getName()); + + TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Predicate"); + column.getColumn().setWidth(300); + + PredicateEditingSupport pEditingSupport = new PredicateEditingSupport( + tableViewer, dbc, "eval", getBControl().getVisualization(), + getShell()); + column.setEditingSupport(pEditingSupport); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Attribute"); + column.getColumn().setWidth(150); + column.setEditingSupport(new AttributeObserverValueEditing(tableViewer)); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Value"); + column.getColumn().setWidth(175); + column.setEditingSupport(new AttributeExpressionEdittingSupport( + tableViewer, getBControl())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Expression?"); + column.getColumn().setWidth(100); + column.setEditingSupport(new IsExpressionModeEditingSupport( + tableViewer, getBControl())); + + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + tableViewer.setContentProvider(contentProvider); + + tableViewer.setLabelProvider(new ObserverLabelProvider(BeansObservables + .observeMaps(contentProvider.getKnownElements(), new String[] { + "eval", "attribute", "value", "isExpressionMode" }))); + input = new WritableList( + ((SetAttribute) getObserver()).getSetAttributeObjects(), + SetAttributeObject.class); + tableViewer.setInput(input); + + Composite comp = new Composite(container, SWT.NONE); + comp.setLayout(new RowLayout()); + comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + + Button btRemove = new Button(comp, SWT.PUSH); + btRemove.setText("Remove"); + btRemove.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); + btRemove.addSelectionListener(new SelectionAdapter() { @Override - protected void setValue(Object element, Object value) { - if (value != null) { - SetAttributeObject obj = (SetAttributeObject) element; - obj.setAttribute(value.toString()); - obj.setIsExpressionMode(false); + public void widgetSelected(SelectionEvent e) { + if (tableViewer.getSelection().isEmpty()) { + MessageDialog.openInformation(getShell(), + "Please select an entry.", + "Please select an entry."); + return; } + SetAttributeObject toggleObj = (SetAttributeObject) ((IStructuredSelection) tableViewer + .getSelection()).getFirstElement(); + input.remove(toggleObj); } + }); + Button btAdd = new Button(comp, SWT.PUSH); + btAdd.setText("Add"); + btAdd.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); + btAdd.addSelectionListener(new SelectionAdapter() { @Override - protected CellEditor getCellEditor(Object element) { - if (cellEditor == null) { - - cellEditor = new ComboBoxViewerCellEditor( - (Composite) tableViewer.getControl(), SWT.READ_ONLY); - cellEditor - .setContentProvider(new ObservableListContentProvider()); - cellEditor.setLabelProvider(new LabelProvider() { - public String getText(Object element) { - return getBControl().getAttributes() - .get(element.toString()).getName(); - } - }); - cellEditor.setInput(new ComputedList() { - @Override - protected List<String> calculate() { - ArrayList<String> atrList = new ArrayList<String>(); - for (AbstractAttribute atr : getBControl() - .getAttributes().values()) { - atrList.add(atr.getID()); - } - return atrList; - } - }); - - ((CCombo) cellEditor.getControl()) - .addFocusListener(new FocusListener() { - - String oldValue; - - public void focusGained(FocusEvent e) { - oldValue = ((CCombo) cellEditor - .getControl()).getText(); - - } - - public void focusLost(FocusEvent e) { - - if (!oldValue.equals(((CCombo) cellEditor - .getControl()).getText())) { - - IStructuredSelection selection = (IStructuredSelection) getViewer() - .getSelection(); - - SetAttributeObject p = (SetAttributeObject) selection - .getFirstElement(); - - AbstractAttribute atr = getBControl() - .getAttributes().get( - p.getAttribute()); - - p.setValue(atr.getValue()); - tableViewer.refresh(); - - } - } - - }); - - } - return cellEditor; + public void widgetSelected(SelectionEvent e) { + SetAttributeObject toggleObj = new SetAttributeObject(""); + input.add(toggleObj); + tableViewer.setSelection(new StructuredSelection(toggleObj)); } + }); - } + return container; } - public WizardObserverSetAttribute(BControl control, Observer observer) { - super(control, observer); - addPage(new WizardSetAttributePage("WizardSetAttributePage")); + public WizardObserverSetAttribute(Shell shell, BControl control, + Observer observer) { + super(shell, control, observer); } @Override @@ -319,30 +173,31 @@ public class WizardObserverSetAttribute extends ObserverWizard { return new Point(800, 500); } - @Override - protected Boolean prepareToFinish() { - getBControl().restoreDefaultValue(lastChangedAttributeID); - if (((SetAttribute) getObserver()).getSetAttributeObjects().size() == 0) { - setObserverDelete(true); - } else { - for (SetAttributeObject obj : ((SetAttribute) getObserver()) - .getSetAttributeObjects()) { - if (obj.getAttribute() == null) { - MessageDialog - .openError(getShell(), "Please check your entries", - "Please check your entries. The attribute field must not be empty."); - return false; - } - } - } - return true; - } - - @Override - public boolean performCancel() { - getBControl().restoreDefaultValue(lastChangedAttributeID); - return super.performCancel(); - } + // @Override + // protected Boolean prepareToFinish() { + // // getBControl().restoreDefaultValue(lastChangedAttributeID); + // if (((SetAttribute) getObserver()).getSetAttributeObjects().size() == 0) + // { + // setObserverDelete(true); + // } else { + // for (SetAttributeObject obj : ((SetAttribute) getObserver()) + // .getSetAttributeObjects()) { + // if (obj.getAttribute() == null) { + // MessageDialog + // .openError(getShell(), "Please check your entries", + // "Please check your entries. The attribute field must not be empty."); + // return false; + // } + // } + // } + // return true; + // } + + // @Override + // public boolean performCancel() { + // // getBControl().restoreDefaultValue(lastChangedAttributeID); + // return super.performCancel(); + // } private class ObserverLabelProvider extends ObservableMapLabelProvider implements ITableLabelProvider, ITableColorProvider, @@ -414,11 +269,102 @@ public class WizardObserverSetAttribute extends ObserverWizard { } public Font getFont(final Object element, final int column) { - // return JFaceResources.getFontRegistry().get( - // BMotionStudioConstants.RODIN_FONT_KEY); return null; } } + private class AttributeObserverValueEditing extends EditingSupport { + + private ComboBoxViewerCellEditor cellEditor = null; + + public AttributeObserverValueEditing(TableViewer cv) { + super(cv); + } + + @Override + protected boolean canEdit(Object element) { + return BMotionWizardUtil.isEditElement(getViewer()); + } + + @Override + protected Object getValue(Object element) { + return ((SetAttributeObject) element).getAttribute(); + } + + @Override + protected void setValue(Object element, Object value) { + if (value != null) { + SetAttributeObject obj = (SetAttributeObject) element; + obj.setAttribute(value.toString()); + obj.setIsExpressionMode(false); + } + } + + @Override + protected CellEditor getCellEditor(Object element) { + if (cellEditor == null) { + + cellEditor = new ComboBoxViewerCellEditor( + (Composite) tableViewer.getControl(), SWT.READ_ONLY); + cellEditor + .setContentProvider(new ObservableListContentProvider()); + cellEditor.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + return getBControl().getAttributes() + .get(element.toString()).getName(); + } + }); + cellEditor.setInput(new ComputedList() { + @Override + protected List<String> calculate() { + ArrayList<String> atrList = new ArrayList<String>(); + for (AbstractAttribute atr : getBControl() + .getAttributes().values()) { + atrList.add(atr.getID()); + } + return atrList; + } + }); + + ((CCombo) cellEditor.getControl()) + .addFocusListener(new FocusListener() { + + String oldValue; + + public void focusGained(FocusEvent e) { + oldValue = ((CCombo) cellEditor.getControl()) + .getText(); + + } + + public void focusLost(FocusEvent e) { + + if (!oldValue.equals(((CCombo) cellEditor + .getControl()).getText())) { + + IStructuredSelection selection = (IStructuredSelection) getViewer() + .getSelection(); + + SetAttributeObject p = (SetAttributeObject) selection + .getFirstElement(); + + AbstractAttribute atr = getBControl() + .getAttributes().get( + p.getAttribute()); + + p.setValue(atr.getValue()); + tableViewer.refresh(); + + } + } + + }); + + } + return cellEditor; + } + + } + } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSimpleValueDisplay.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSimpleValueDisplay.java index 1f9a6b76e83c627a1de6fc7c4efc9159d53e4d58..5d63d4cfcd16ff5c44fe86dc0ee1023ad3d90881 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSimpleValueDisplay.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSimpleValueDisplay.java @@ -9,16 +9,18 @@ package de.bmotionstudio.gef.editor.observer.wizard; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.beans.BeansObservables; import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import de.bmotionstudio.gef.editor.model.BControl; @@ -28,113 +30,102 @@ import de.bmotionstudio.gef.editor.observer.SimpleValueDisplay; public class WizardObserverSimpleValueDisplay extends ObserverWizard { - private class ObserverSimpleValueDisplayPage extends - AbstractObserverWizardPage { + private Text txtReplacementString; + private Text txtExpression; + private Text txtPredicate; - private Text txtReplacementString; - private Text txtExpression; - private Text txtPredicate; - - public Text getTxtExpression() { - return txtExpression; - } - - protected ObserverSimpleValueDisplayPage(final String pageName) { - super(pageName, getObserver()); - } - - public void createControl(final Composite parent) { - - super.createControl(parent); + @Override + public Control createWizardContent(Composite parent) { - final DataBindingContext dbc = new DataBindingContext(); + parent.setLayout(new FillLayout()); - Composite container = new Composite(parent, SWT.NONE); + final DataBindingContext dbc = new DataBindingContext(); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); - container.setLayout(new GridLayout(2, false)); + Composite container = new Composite(parent, SWT.NONE); - Label lb = new Label(container, SWT.NONE); - lb.setText("Predicate:"); + container.setLayout(new GridLayout(2, false)); - txtPredicate = new Text(container, SWT.BORDER); - txtPredicate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - txtPredicate.setFont(new Font(Display.getDefault(), new FontData( - "Arial", 10, SWT.NONE))); + GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); + gd.widthHint = 120; + + Label lb = new Label(container, SWT.NONE); + lb.setText("Predicate:"); + lb.setLayoutData(gd); - lb = new Label(container, SWT.NONE); - lb.setText("Expression:"); - lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + txtPredicate = new Text(container, SWT.BORDER); + txtPredicate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + txtPredicate.setFont(new Font(Display.getDefault(), new FontData( + "Arial", 10, SWT.NONE))); - txtExpression = new Text(container, SWT.BORDER | SWT.MULTI - | SWT.WRAP); - txtExpression.setLayoutData(new GridData(GridData.FILL_BOTH)); - // txtExpression.setFont(JFaceResources.getFontRegistry().get( - // BMotionStudioConstants.RODIN_FONT_KEY)); + lb = new Label(container, SWT.NONE); + lb.setText("Expression:"); + lb.setLayoutData(gd); - lb = new Label(container, SWT.NONE); - lb.setText("Replacement String:"); + txtExpression = new Text(container, SWT.BORDER | SWT.MULTI | SWT.WRAP); + txtExpression.setLayoutData(new GridData(GridData.FILL_BOTH)); + // txtExpression.setFont(JFaceResources.getFontRegistry().get( + // BMotionStudioConstants.RODIN_FONT_KEY)); - txtReplacementString = new Text(container, SWT.BORDER); - txtReplacementString.setLayoutData(new GridData( - GridData.FILL_HORIZONTAL)); - txtReplacementString.setFont(new Font(Display.getDefault(), - new FontData("Arial", 10, SWT.NONE))); + lb = new Label(container, SWT.NONE); + lb.setText("Replacement String:"); + lb.setLayoutData(gd); - initBindings(dbc); + txtReplacementString = new Text(container, SWT.BORDER); + txtReplacementString.setLayoutData(new GridData( + GridData.FILL_HORIZONTAL)); + txtReplacementString.setFont(new Font(Display.getDefault(), + new FontData("Arial", 10, SWT.NONE))); - setControl(container); + initBindings(dbc); - } + return container; - private void initBindings(DataBindingContext dbc) { + } - dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), - BeansObservables.observeValue( - (SimpleValueDisplay) getObserver(), "predicate")); + private void initBindings(DataBindingContext dbc) { - dbc.bindValue( - SWTObservables.observeText(txtExpression, SWT.Modify), - BeansObservables.observeValue( - (SimpleValueDisplay) getObserver(), "eval")); + dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), + BeansObservables.observeValue( + (SimpleValueDisplay) getObserver(), "predicate")); - dbc.bindValue(SWTObservables.observeText(txtReplacementString, - SWT.Modify), BeansObservables.observeValue( - (SimpleValueDisplay) getObserver(), "replacementString")); + dbc.bindValue(SWTObservables.observeText(txtExpression, SWT.Modify), + BeansObservables.observeValue( + (SimpleValueDisplay) getObserver(), "eval")); - } + dbc.bindValue(SWTObservables.observeText(txtReplacementString, + SWT.Modify), BeansObservables.observeValue( + (SimpleValueDisplay) getObserver(), "replacementString")); } - public WizardObserverSimpleValueDisplay(BControl bcontrol, + public WizardObserverSimpleValueDisplay(Shell shell, BControl bcontrol, Observer bobserver) { - super(bcontrol, bobserver); - addPage(new ObserverSimpleValueDisplayPage( - "ObserverSimpleValueDisplayPage")); + super(shell, bcontrol, bobserver); } - @Override - protected Boolean prepareToFinish() { - - ObserverSimpleValueDisplayPage page = (ObserverSimpleValueDisplayPage) getPage("ObserverSimpleValueDisplayPage"); - - String errorStr = ""; - - if (page.getTxtExpression().getText().length() == 0) - errorStr += "Please enter an expression.\n"; - - if (page.getErrorMessage() != null) - errorStr += "Please check the syntax/parser error.\n"; - - if (errorStr.length() > 0) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "An Error occured", errorStr); - return false; - } - - return true; - - } + // @Override + // protected Boolean prepareToFinish() { + // + // ObserverSimpleValueDisplayPage page = (ObserverSimpleValueDisplayPage) + // getPage("ObserverSimpleValueDisplayPage"); + // + // String errorStr = ""; + // + // if (page.getTxtExpression().getText().length() == 0) + // errorStr += "Please enter an expression.\n"; + // + // if (page.getErrorMessage() != null) + // errorStr += "Please check the syntax/parser error.\n"; + // + // if (errorStr.length() > 0) { + // MessageDialog.openError(Display.getDefault().getActiveShell(), + // "An Error occured", errorStr); + // return false; + // } + // + // return true; + // + // } @Override public Point getSize() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchCoordinates.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchCoordinates.java index 14cd883a29fec574490b3605aa5ae24d8c572e5d..8e502a6ff3814e90041931476f69976650d4f74c 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchCoordinates.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchCoordinates.java @@ -12,13 +12,10 @@ import org.eclipse.core.databinding.observable.list.WritableList; import org.eclipse.core.databinding.observable.map.IObservableMap; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -29,23 +26,22 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; -import de.be4.classicalb.core.parser.BParser; -import de.bmotionstudio.gef.editor.AttributeConstants; -import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.edit.TextEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.SwitchCoordinates; import de.bmotionstudio.gef.editor.observer.ToggleObjectCoordinates; @@ -53,193 +49,96 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardObserverSwitchCoordinates extends ObserverWizard { - private class ObserverToggleCoordinatesPage extends - AbstractObserverWizardPage { - - private TableViewer tableViewer; - - protected ObserverToggleCoordinatesPage(final String pageName) { - super(pageName, getObserver()); - } - - public void createControl(Composite parent) { - - super.createControl(parent); - - DataBindingContext dbc = new DataBindingContext(); - - Composite container = new Composite(parent, SWT.NONE); - container.setLayout(new GridLayout(1, true)); - - tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( - container, ToggleObjectCoordinates.class, - ((BMotionAbstractWizard) getWizard()).getName()); - - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - if (!observerEvalObject.isExpressionMode()) { - BControl control = getBControl(); - ToggleObjectCoordinates toggleObjectCoordinates = (ToggleObjectCoordinates) observerEvalObject; - String attributeX = AttributeConstants.ATTRIBUTE_X; - String attributeY = AttributeConstants.ATTRIBUTE_Y; - String x = toggleObjectCoordinates.getX(); - String y = toggleObjectCoordinates.getY(); - control.setAttributeValue(attributeX, x, - true, false); - control.setAttributeValue(attributeY, y, - true, false); - } - } - } - - }); - - TableViewerColumn column = new TableViewerColumn(tableViewer, - SWT.NONE); - column.getColumn().setText("Predicate"); - column.getColumn().setWidth(200); - column.setEditingSupport(new PredicateEditingSupport(tableViewer, - dbc, "eval", getBControl().getVisualization(), getShell())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("X"); - column.getColumn().setWidth(150); - column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, - "x")); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Y"); - column.getColumn().setWidth(150); - column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, - "y")); - - // column = new TableViewerColumn(tableViewer, SWT.NONE); - // column.getColumn().setText("Animate?"); - // column.getColumn().setWidth(75); - // column.setEditingSupport(new EditingSupport(tableViewer) { - // - // private CellEditor cellEditor = new CheckboxCellEditor( - // (Composite) tableViewer.getControl()); - // - // @Override - // protected void setValue(Object element, Object value) { - // ((ToggleObjectCoordinates) element).setAnimate(Boolean - // .valueOf(String.valueOf(value))); - // } - // - // @Override - // protected Object getValue(Object element) { - // Boolean b = ((ToggleObjectCoordinates) element) - // .getAnimate(); - // return b != null ? b : false; - // } - // - // @Override - // protected CellEditor getCellEditor(Object element) { - // return cellEditor; - // } - // - // @Override - // protected boolean canEdit(Object element) { - // return true; - // } - // - // }); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - tableViewer.setLabelProvider(new ObserverLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), new String[] { - "eval", "x", "y" }))); - - final WritableList input = new WritableList( - ((SwitchCoordinates) getObserver()).getToggleObjects(), - ToggleObjectCoordinates.class); - tableViewer.setInput(input); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - return; - } - ToggleObjectCoordinates toggleObj = (ToggleObjectCoordinates) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(toggleObj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - ToggleObjectCoordinates toggleObj = new ToggleObjectCoordinates( - BParser.PREDICATE_PREFIX, "", String - .valueOf(getBControl().getLayout().x), - String.valueOf(getBControl().getLayout().y), ""); - input.add(toggleObj); - tableViewer - .setSelection(new StructuredSelection(toggleObj)); - } - }); - - setControl(container); - - } - } - - public WizardObserverSwitchCoordinates(final BControl bcontrol, - final Observer bobserver) { - super(bcontrol, bobserver); - addPage(new ObserverToggleCoordinatesPage( - "ObserverToggleCoordinatesPage")); - } + private TableViewer tableViewer; @Override - protected Boolean prepareToFinish() { - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); - if (((SwitchCoordinates) getObserver()).getToggleObjects().size() == 0) { - setObserverDelete(true); - } else { - for (ToggleObjectCoordinates obj : ((SwitchCoordinates) getObserver()) - .getToggleObjects()) { - if (obj.getX().isEmpty() || obj.getY().isEmpty()) { - MessageDialog - .openError(getShell(), "Please check your entries", - "Please check your entries. The x and y fields must not be empty."); - return false; + public Control createWizardContent(Composite parent) { + + parent.setLayout(new FillLayout()); + + DataBindingContext dbc = new DataBindingContext(); + + GridLayout gl = new GridLayout(1, true); + gl.horizontalSpacing = 0; + gl.verticalSpacing = 0; + gl.marginHeight = 0; + gl.marginWidth = 0; + + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(gl); + + tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( + container, ToggleObjectCoordinates.class, getName()); + + TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Predicate"); + column.getColumn().setWidth(200); + column.setEditingSupport(new PredicateEditingSupport(tableViewer, dbc, + "eval", getBControl().getVisualization(), getShell())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("X"); + column.getColumn().setWidth(150); + column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, "x")); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Y"); + column.getColumn().setWidth(150); + column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, "y")); + + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + tableViewer.setContentProvider(contentProvider); + tableViewer.setLabelProvider(new ObserverLabelProvider(BeansObservables + .observeMaps(contentProvider.getKnownElements(), new String[] { + "eval", "x", "y" }))); + + final WritableList input = new WritableList( + ((SwitchCoordinates) getObserver()).getToggleObjects(), + ToggleObjectCoordinates.class); + tableViewer.setInput(input); + + Composite comp = new Composite(container, SWT.NONE); + comp.setLayout(new RowLayout()); + comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + + Button btRemove = new Button(comp, SWT.PUSH); + btRemove.setText("Remove"); + btRemove.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); + btRemove.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (tableViewer.getSelection().isEmpty()) { + return; } + ToggleObjectCoordinates toggleObj = (ToggleObjectCoordinates) ((IStructuredSelection) tableViewer + .getSelection()).getFirstElement(); + input.remove(toggleObj); } - } - return true; + }); + + Button btAdd = new Button(comp, SWT.PUSH); + btAdd.setText("Add"); + btAdd.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); + btAdd.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ToggleObjectCoordinates toggleObj = new ToggleObjectCoordinates( + "", String.valueOf(getBControl().getLayout().x), String + .valueOf(getBControl().getLayout().y), ""); + input.add(toggleObj); + tableViewer.setSelection(new StructuredSelection(toggleObj)); + } + }); + + return container; } - @Override - public boolean performCancel() { - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_X); - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_Y); - return super.performCancel(); + + public WizardObserverSwitchCoordinates(Shell shell, BControl bcontrol, + Observer bobserver) { + super(shell, bcontrol, bobserver); } @Override @@ -258,9 +157,6 @@ public class WizardObserverSwitchCoordinates extends ObserverWizard { private final Color errorColor = Display.getDefault().getSystemColor( SWT.COLOR_INFO_BACKGROUND); - // final Font bold = JFaceResources.getFontRegistry().getBold( - // JFaceResources.BANNER_FONT); - @Override public String getColumnText(Object element, int columnIndex) { if (columnIndex == 3) { @@ -271,11 +167,6 @@ public class WizardObserverSwitchCoordinates extends ObserverWizard { @Override public Image getColumnImage(Object element, int columnIndex) { - // if (columnIndex == 3) { - // return CheckboxCellEditorHelper - // .getCellEditorImage(((ToggleObjectCoordinates) element) - // .getAnimate()); - // } return null; } @@ -291,8 +182,6 @@ public class WizardObserverSwitchCoordinates extends ObserverWizard { } public Font getFont(final Object element, final int column) { - // return JFaceResources.getFontRegistry().get( - // BMotionStudioConstants.RODIN_FONT_KEY); return null; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchImage.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchImage.java index 40c1dd154d70fe6e4f9a2bfd24ecfa17a58b5c58..ff5d09ea575689dc6a26eaafb92de38cf6e69130 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchImage.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardObserverSwitchImage.java @@ -12,13 +12,10 @@ import org.eclipse.core.databinding.observable.list.WritableList; import org.eclipse.core.databinding.observable.map.IObservableMap; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableColorProvider; import org.eclipse.jface.viewers.ITableFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -29,16 +26,17 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; -import de.be4.classicalb.core.parser.BParser; import de.bmotionstudio.gef.editor.AttributeConstants; -import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.edit.AttributeExpressionEdittingSupport; @@ -46,7 +44,6 @@ import de.bmotionstudio.gef.editor.edit.IsExpressionModeEditingSupport; import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.observer.Observer; -import de.bmotionstudio.gef.editor.observer.ObserverEvalObject; import de.bmotionstudio.gef.editor.observer.ObserverWizard; import de.bmotionstudio.gef.editor.observer.SwitchImage; import de.bmotionstudio.gef.editor.observer.ToggleObjectImage; @@ -55,175 +52,119 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardObserverSwitchImage extends ObserverWizard { - private class ObserverSwitchImagePage extends AbstractObserverWizardPage { + private TableViewer tableViewer; - private TableViewer tableViewer; + @Override + public Control createWizardContent(Composite parent) { - protected ObserverSwitchImagePage(final String pageName) { - super(pageName, getObserver()); - } + parent.setLayout(new FillLayout()); - public void createControl(final Composite parent) { - - super.createControl(parent); - - DataBindingContext dbc = new DataBindingContext(); - - Composite container = new Composite(parent, SWT.NONE); - container.setLayout(new GridLayout(1, true)); - - tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( - container, ToggleObjectImage.class, - ((BMotionAbstractWizard) getWizard()).getName()); - tableViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event - .getSelection(); - Object firstElement = selection.getFirstElement(); - if (firstElement instanceof ObserverEvalObject) { - ObserverEvalObject observerEvalObject = (ObserverEvalObject) firstElement; - if (!observerEvalObject.isExpressionMode()) { - BControl control = getBControl(); - ToggleObjectImage toggleObjImage = (ToggleObjectImage) observerEvalObject; - String attribute = AttributeConstants.ATTRIBUTE_IMAGE; - String image = toggleObjImage.getImage(); - control.setAttributeValue(attribute, image, - true, false); - } - } - } - - }); - - TableViewerColumn column = new TableViewerColumn(tableViewer, - SWT.NONE); - column.getColumn().setText("Predicate"); - column.getColumn().setWidth(300); - column.setEditingSupport(new PredicateEditingSupport(tableViewer, - dbc, "eval", getBControl().getVisualization(), getShell())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Image"); - column.getColumn().setWidth(180); - column.setEditingSupport(new AttributeExpressionEdittingSupport( - tableViewer, getBControl(), - AttributeConstants.ATTRIBUTE_IMAGE) { - - @Override - protected Object getValue(final Object element) { - ToggleObjectImage evalObject = (ToggleObjectImage) element; - return evalObject.getImage(); - } + DataBindingContext dbc = new DataBindingContext(); - @Override - protected void setValue(final Object element, final Object value) { - if (value == null) - return; - ((ToggleObjectImage) element).setImage(value.toString()); - } + GridLayout gl = new GridLayout(1, true); + gl.horizontalSpacing = 0; + gl.verticalSpacing = 0; + gl.marginHeight = 0; + gl.marginWidth = 0; - }); + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(gl); - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Expression?"); - column.getColumn().setWidth(100); - column.setEditingSupport(new IsExpressionModeEditingSupport( - tableViewer, getBControl()) { + tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( + container, ToggleObjectImage.class, getName()); - @Override - protected void setValue(final Object element, final Object value) { - Boolean bol = Boolean.valueOf(String.valueOf(value)); - ToggleObjectImage obj = (ToggleObjectImage) element; - obj.setIsExpressionMode(bol); - } + TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Predicate"); + column.getColumn().setWidth(300); + column.setEditingSupport(new PredicateEditingSupport(tableViewer, dbc, + "eval", getBControl().getVisualization(), getShell())); - }); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - - tableViewer.setLabelProvider(new ObserverLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), new String[] { - "eval", "image", "isExpressionMode" }))); - final WritableList input = new WritableList( - ((SwitchImage) getObserver()).getToggleObjects(), - ToggleObjectImage.class); - tableViewer.setInput(input); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(final SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - return; - } - ToggleObjectImage toggleObj = (ToggleObjectImage) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(toggleObj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(final SelectionEvent e) { - ToggleObjectImage toggleObj = new ToggleObjectImage( - BParser.PREDICATE_PREFIX, "", ""); - input.add(toggleObj); - tableViewer - .setSelection(new StructuredSelection(toggleObj)); - } - }); + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Image"); + column.getColumn().setWidth(180); + column.setEditingSupport(new AttributeExpressionEdittingSupport( + tableViewer, getBControl(), AttributeConstants.ATTRIBUTE_IMAGE) { - setControl(container); + @Override + protected Object getValue(final Object element) { + ToggleObjectImage evalObject = (ToggleObjectImage) element; + return evalObject.getImage(); + } - } + @Override + protected void setValue(final Object element, final Object value) { + if (value == null) + return; + ((ToggleObjectImage) element).setImage(value.toString()); + } - } + }); - public WizardObserverSwitchImage(final BControl bcontrol, - final Observer bobserver) { - super(bcontrol, bobserver); - addPage(new ObserverSwitchImagePage("ObserverToggleImagePage")); - } + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Expression?"); + column.getColumn().setWidth(100); + column.setEditingSupport(new IsExpressionModeEditingSupport( + tableViewer, getBControl()) { - @Override - protected Boolean prepareToFinish() { - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_IMAGE); - if (((SwitchImage) getObserver()).getToggleObjects().size() == 0) { - setObserverDelete(true); - } else { - for (ToggleObjectImage obj : ((SwitchImage) getObserver()) - .getToggleObjects()) { - if (obj.getImage().isEmpty()) { - MessageDialog - .openError(getShell(), "Please check your entries", - "Please check your entries. The image field must not be empty."); - return false; + @Override + protected void setValue(final Object element, final Object value) { + Boolean bol = Boolean.valueOf(String.valueOf(value)); + ToggleObjectImage obj = (ToggleObjectImage) element; + obj.setIsExpressionMode(bol); + } + + }); + + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + tableViewer.setContentProvider(contentProvider); + + tableViewer.setLabelProvider(new ObserverLabelProvider(BeansObservables + .observeMaps(contentProvider.getKnownElements(), new String[] { + "eval", "image", "isExpressionMode" }))); + final WritableList input = new WritableList( + ((SwitchImage) getObserver()).getToggleObjects(), + ToggleObjectImage.class); + tableViewer.setInput(input); + + Composite comp = new Composite(container, SWT.NONE); + comp.setLayout(new RowLayout()); + comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + + Button btRemove = new Button(comp, SWT.PUSH); + btRemove.setText("Remove"); + btRemove.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_DELETE_EDIT)); + btRemove.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + if (tableViewer.getSelection().isEmpty()) { + return; } + ToggleObjectImage toggleObj = (ToggleObjectImage) ((IStructuredSelection) tableViewer + .getSelection()).getFirstElement(); + input.remove(toggleObj); } - } - return true; + }); + + Button btAdd = new Button(comp, SWT.PUSH); + btAdd.setText("Add"); + btAdd.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); + btAdd.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + ToggleObjectImage toggleObj = new ToggleObjectImage("", ""); + input.add(toggleObj); + tableViewer.setSelection(new StructuredSelection(toggleObj)); + } + }); + + return container; } - @Override - public boolean performCancel() { - getBControl().restoreDefaultValue(AttributeConstants.ATTRIBUTE_IMAGE); - return super.performCancel(); + public WizardObserverSwitchImage(Shell shell, BControl bcontrol, + Observer bobserver) { + super(shell, bcontrol, bobserver); } @Override @@ -277,8 +218,6 @@ public class WizardObserverSwitchImage extends ObserverWizard { } public Font getFont(final Object element, final int column) { - // return JFaceResources.getFontRegistry().get( - // BMotionStudioConstants.RODIN_FONT_KEY); return null; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardTableObserver.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardTableObserver.java index e816e1d3ee2c517bca6e12dd054b201e29cea5e2..d38110cd613c43aef7a7c2b12cea0e977225780f 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardTableObserver.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardTableObserver.java @@ -11,8 +11,6 @@ import java.util.ArrayList; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.beans.BeansObservables; import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; @@ -24,10 +22,12 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eventb.core.ast.PowerSetType; @@ -40,167 +40,151 @@ import de.bmotionstudio.gef.editor.observer.TableObserver; public class WizardTableObserver extends ObserverWizard { - private class TableObserverPage extends WizardPage { + private Text txtExpression; + private Text txtPredicate; + private Button cbOverrideCells; + private Button cbKeepHeader; - private Text txtExpression; - private Text txtPredicate; - private Button cbOverrideCells; - private Button cbKeepHeader; + private void initBindings(DataBindingContext dbc) { - public Text getTxtExpression() { - return txtExpression; - } - - protected TableObserverPage(final String pageName) { - super(pageName); - } + dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), + BeansObservables.observeValue((TableObserver) getObserver(), + "predicate")); - public void createControl(final Composite parent) { + dbc.bindValue(SWTObservables.observeText(txtExpression, SWT.Modify), + BeansObservables.observeValue((TableObserver) getObserver(), + "expression")); - final DataBindingContext dbc = new DataBindingContext(); + dbc.bindValue(SWTObservables.observeSelection(cbOverrideCells), + BeansObservables.observeValue((TableObserver) getObserver(), + "overrideCells")); - parent.setLayout(new GridLayout(1, true)); + dbc.bindValue(SWTObservables.observeSelection(cbKeepHeader), + BeansObservables.observeValue((TableObserver) getObserver(), + "keepHeader")); - Group group = new Group(parent, SWT.None); - group.setText("General settings"); - RowLayout rowLayout = new RowLayout(); - rowLayout.marginLeft = 10; - rowLayout.marginTop = 10; - rowLayout.marginBottom = 10; - group.setLayout(rowLayout); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + } - cbOverrideCells = new Button(group, SWT.CHECK); - cbOverrideCells.setText("Override cells"); + @Override + public Control createWizardContent(Composite parent) { + final DataBindingContext dbc = new DataBindingContext(); - cbKeepHeader = new Button(group, SWT.CHECK); - cbKeepHeader.setText("Keep header"); + parent.setLayout(new GridLayout(1, true)); - Group container = new Group(parent, SWT.None); - container.setText("Formal model"); - container.setLayout(new GridLayout(2, false)); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); + Group group = new Group(parent, SWT.None); + group.setText("General settings"); + RowLayout rowLayout = new RowLayout(); + rowLayout.marginLeft = 10; + rowLayout.marginTop = 10; + rowLayout.marginBottom = 10; + group.setLayout(rowLayout); + group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Composite conLeft = new Composite(container, SWT.NONE); - conLeft.setLayoutData(new GridData(GridData.FILL_BOTH)); - conLeft.setLayout(new GridLayout(2, false)); + cbOverrideCells = new Button(group, SWT.CHECK); + cbOverrideCells.setText("Override cells"); - Label lb = new Label(conLeft, SWT.NONE); - lb.setText("Predicate:"); + cbKeepHeader = new Button(group, SWT.CHECK); + cbKeepHeader.setText("Keep header"); - txtPredicate = new Text(conLeft, SWT.BORDER); - txtPredicate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - txtPredicate.setFont(new Font(Display.getDefault(), new FontData( - "Arial", 10, SWT.NONE))); + Group container = new Group(parent, SWT.None); + container.setText("Formal model"); + container.setLayout(new GridLayout(2, false)); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); - lb = new Label(conLeft, SWT.NONE); - lb.setText("Expression:"); - lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + Composite conLeft = new Composite(container, SWT.NONE); + conLeft.setLayoutData(new GridData(GridData.FILL_BOTH)); + conLeft.setLayout(new GridLayout(2, false)); - txtExpression = new Text(conLeft, SWT.BORDER | SWT.MULTI - | SWT.WRAP); - txtExpression.setLayoutData(new GridData(GridData.FILL_BOTH)); + Label lb = new Label(conLeft, SWT.NONE); + lb.setText("Predicate:"); - Composite conRight = new Composite(container, SWT.NONE); + txtPredicate = new Text(conLeft, SWT.BORDER); + txtPredicate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + txtPredicate.setFont(new Font(Display.getDefault(), new FontData( + "Arial", 10, SWT.NONE))); - GridData gData = new GridData(GridData.FILL_VERTICAL); - gData.widthHint = 125; + lb = new Label(conLeft, SWT.NONE); + lb.setText("Expression:"); + lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - conRight.setLayoutData(gData); - conRight.setLayout(new GridLayout(1, false)); + txtExpression = new Text(conLeft, SWT.BORDER | SWT.MULTI | SWT.WRAP); + txtExpression.setLayoutData(new GridData(GridData.FILL_BOTH)); - lb = new Label(conRight, SWT.WRAP); - lb.setText("Power sets:"); - lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + Composite conRight = new Composite(container, SWT.NONE); - ArrayList<String> relationList = new ArrayList<String>(); - - java.util.List<MachineContentObject> constants = EventBHelper - .getConstants(getBControl().getVisualization()); - for (MachineContentObject mobj : constants) { - if (mobj.getType() instanceof PowerSetType) { - relationList.add(mobj.getLabel()); - } - } + GridData gData = new GridData(GridData.FILL_VERTICAL); + gData.widthHint = 125; - java.util.List<MachineContentObject> variables = EventBHelper - .getVariables(getBControl().getVisualization()); - for (MachineContentObject mobj : variables) { - if (mobj.getType() instanceof PowerSetType) { - relationList.add(mobj.getLabel()); - } - } + conRight.setLayoutData(gData); + conRight.setLayout(new GridLayout(1, false)); - final List list = new List(conRight, SWT.SINGLE | SWT.BORDER - | SWT.V_SCROLL); - list.setLayoutData(new GridData(GridData.FILL_BOTH)); - list.setItems(relationList.toArray(new String[relationList.size()])); + lb = new Label(conRight, SWT.WRAP); + lb.setText("Power sets:"); + lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - list.addMouseListener(new MouseAdapter() { - public void mouseDoubleClick(MouseEvent e) { - String[] selection = list.getSelection(); - if (selection.length > 0) - txtExpression.setText(txtExpression.getText() + " " - + selection[0]); - } - }); - initBindings(dbc); - - setControl(conLeft); + ArrayList<String> relationList = new ArrayList<String>(); + java.util.List<MachineContentObject> constants = EventBHelper + .getConstants(getBControl().getVisualization()); + for (MachineContentObject mobj : constants) { + if (mobj.getType() instanceof PowerSetType) { + relationList.add(mobj.getLabel()); + } } - private void initBindings(DataBindingContext dbc) { - - dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), - BeansObservables.observeValue( - (TableObserver) getObserver(), "predicate")); - - dbc.bindValue( - SWTObservables.observeText(txtExpression, SWT.Modify), - BeansObservables.observeValue( - (TableObserver) getObserver(), "expression")); - - dbc.bindValue(SWTObservables.observeSelection(cbOverrideCells), - BeansObservables.observeValue( - (TableObserver) getObserver(), "overrideCells")); - - dbc.bindValue(SWTObservables.observeSelection(cbKeepHeader), - BeansObservables.observeValue( - (TableObserver) getObserver(), "keepHeader")); - + java.util.List<MachineContentObject> variables = EventBHelper + .getVariables(getBControl().getVisualization()); + for (MachineContentObject mobj : variables) { + if (mobj.getType() instanceof PowerSetType) { + relationList.add(mobj.getLabel()); + } } + final List list = new List(conRight, SWT.SINGLE | SWT.BORDER + | SWT.V_SCROLL); + list.setLayoutData(new GridData(GridData.FILL_BOTH)); + list.setItems(relationList.toArray(new String[relationList.size()])); + + list.addMouseListener(new MouseAdapter() { + public void mouseDoubleClick(MouseEvent e) { + String[] selection = list.getSelection(); + if (selection.length > 0) + txtExpression.setText(txtExpression.getText() + " " + + selection[0]); + } + }); + initBindings(dbc); + return conLeft; } - public WizardTableObserver(BControl bcontrol, + public WizardTableObserver(Shell shell, BControl bcontrol, Observer bobserver) { - super(bcontrol, bobserver); - addPage(new TableObserverPage("TableObserverPage")); + super(shell, bcontrol, bobserver); } - @Override - protected Boolean prepareToFinish() { - - TableObserverPage page = (TableObserverPage) getPage("TableObserverPage"); - - String errorStr = ""; - - if (page.getTxtExpression().getText().length() == 0) - errorStr += "Please enter an expression.\n"; - - if (page.getErrorMessage() != null) - errorStr += "Please check the syntax/parser error.\n"; - - if (errorStr.length() > 0) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "An Error occured", errorStr); - return false; - } - - return true; - - } + // @Override + // protected Boolean prepareToFinish() { + // + // TableObserverPage page = (TableObserverPage) + // getPage("TableObserverPage"); + // + // String errorStr = ""; + // + // if (page.getTxtExpression().getText().length() == 0) + // errorStr += "Please enter an expression.\n"; + // + // if (page.getErrorMessage() != null) + // errorStr += "Please check the syntax/parser error.\n"; + // + // if (errorStr.length() > 0) { + // MessageDialog.openError(Display.getDefault().getActiveShell(), + // "An Error occured", errorStr); + // return false; + // } + // + // return true; + // + // } @Override public Point getSize() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java index 6adcbe067053f1a1f209c8e7887019dec0cbef8f..21bc714c14173d8826e437f95eaa88c2dba7907e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java @@ -25,7 +25,7 @@ import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.editpolicy.BMSDeletePolicy; import de.bmotionstudio.gef.editor.model.BConnection; import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.observer.IObserverListener; import de.bmotionstudio.gef.editor.observer.Observer; @@ -34,8 +34,10 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements PropertyChangeListener, IObserverListener { public void propertyChange(final PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(BControl.PROPERTY_ADD) - || evt.getPropertyName().equals(BControl.PROPERTY_REMOVE)) { + if (evt.getPropertyName().equals( + BControlPropertyConstants.PROPERTY_ADD_CHILD) + || evt.getPropertyName().equals( + BControlPropertyConstants.PROPERTY_REMOVE_CHILD)) { refreshChildren(); } refreshVisuals(); @@ -74,8 +76,8 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements } } - if (!(getModel() instanceof Visualization)) - toShowElements.add(new ObserverRootVirtualTreeNode(c)); + // if (!(getModel() instanceof Visualization)) + // toShowElements.add(new ObserverRootVirtualTreeNode(c)); } @@ -87,7 +89,7 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements if (!isActive()) { super.activate(); ((BControl) getModel()).addPropertyChangeListener(this); - ((BControl) getModel()).addObserverListener(this); + // ((BControl) getModel()).addObserverListener(this); } } @@ -95,7 +97,7 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements if (isActive()) { super.deactivate(); ((BControl) getModel()).removePropertyChangeListener(this); - ((BControl) getModel()).removeObserverListener(this); + // ((BControl) getModel()).removeObserverListener(this); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSAbstractEditPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSAbstractEditPart.java index 90de631cfaa0f809698aefb6057e6922cfab1b02..c53ed10fb104fc3d4f36b646b3c4129803650026 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSAbstractEditPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSAbstractEditPart.java @@ -43,6 +43,7 @@ import de.bmotionstudio.gef.editor.figure.AbstractBMotionFigure; import de.bmotionstudio.gef.editor.library.AbstractLibraryCommand; import de.bmotionstudio.gef.editor.library.AttributeRequest; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BControlPropertyConstants; import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.observer.IObserverListener; import de.bmotionstudio.gef.editor.observer.Observer; @@ -73,8 +74,10 @@ public abstract class BMSAbstractEditPart extends AbstractGraphicalEditPart } }; - private String[] layoutAttributes = { BControl.PROPERTY_LAYOUT, - BControl.PROPERTY_LOCATION, AttributeConstants.ATTRIBUTE_X, + private String[] layoutAttributes = { + BControlPropertyConstants.PROPERTY_LAYOUT, + BControlPropertyConstants.PROPERTY_LOCATION, + AttributeConstants.ATTRIBUTE_X, AttributeConstants.ATTRIBUTE_Y, AttributeConstants.ATTRIBUTE_WIDTH, AttributeConstants.ATTRIBUTE_HEIGHT }; @@ -82,7 +85,6 @@ public abstract class BMSAbstractEditPart extends AbstractGraphicalEditPart if (!isActive()) { super.activate(); ((BControl) getModel()).addPropertyChangeListener(this); - ((BControl) getModel()).addObserverListener(this); if (getFigure() instanceof AbstractBMotionFigure) { AbstractBMotionFigure af = (AbstractBMotionFigure) getFigure(); if (isRunning()) @@ -96,7 +98,6 @@ public abstract class BMSAbstractEditPart extends AbstractGraphicalEditPart if (isActive()) { super.deactivate(); ((BControl) getModel()).removePropertyChangeListener(this); - ((BControl) getModel()).removeObserverListener(this); if (getFigure() instanceof AbstractBMotionFigure) { AbstractBMotionFigure af = (AbstractBMotionFigure) getFigure(); if (isRunning()) @@ -187,13 +188,15 @@ public abstract class BMSAbstractEditPart extends AbstractGraphicalEditPart final BControl model = (BControl) getModel(); String propName = evt.getPropertyName(); - if (BControl.SOURCE_CONNECTIONS_PROP.equals(propName)) { + if (BControlPropertyConstants.SOURCE_CONNECTIONS.equals(propName)) { refreshSourceConnections(); - } else if (BControl.TARGET_CONNECTIONS_PROP.equals(propName)) { + } else if (BControlPropertyConstants.TARGET_CONNECTIONS + .equals(propName)) { refreshTargetConnections(); } - if (propName.equals(BControl.PROPERTY_ADD) - || propName.equals(BControl.PROPERTY_REMOVE)) { + if (propName.equals(BControlPropertyConstants.PROPERTY_ADD_CHILD) + || propName + .equals(BControlPropertyConstants.PROPERTY_REMOVE_CHILD)) { refreshChildren(); } else if (Arrays.asList(layoutAttributes).contains(propName)) { // Layout attribute diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java index 7744514400fbe32a45c0e522d0a84166d8804f3b..93336446419897fa1b4daac4bcc009057612fcdc 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java @@ -14,9 +14,7 @@ import org.eclipse.gef.EditPartFactory; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; import de.bmotionstudio.gef.editor.IBControlService; import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; import de.bmotionstudio.gef.editor.model.Visualization; -import de.bmotionstudio.gef.editor.observer.Observer; public class BMSTreeEditPartFactory implements EditPartFactory { @@ -43,11 +41,12 @@ public class BMSTreeEditPartFactory implements EditPartFactory { e.printStackTrace(); } - } else if (model instanceof Observer) { - part = new ObserverTreeEditPart(); - } else if (model instanceof ObserverRootVirtualTreeNode) { - part = new ObserverRootTreeEditpart(); } + // else if (model instanceof Observer) { + // part = new ObserverTreeEditPart(); + // } else if (model instanceof ObserverRootVirtualTreeNode) { + // part = new ObserverRootTreeEditpart(); + // } if (part != null) part.setModel(model); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/ObserverRootTreeEditpart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/ObserverRootTreeEditpart.java deleted file mode 100644 index fd70efd9d5462ae343e734f5806cd167851ff937..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/ObserverRootTreeEditpart.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.part; - -import java.util.ArrayList; -import java.util.List; - -import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.EditorImageRegistry; -import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.model.ObserverRootVirtualTreeNode; -import de.bmotionstudio.gef.editor.observer.IObserverListener; -import de.bmotionstudio.gef.editor.observer.Observer; - -public class ObserverRootTreeEditpart extends BMSAbstractTreeEditPart implements - IObserverListener { - - public void activate() { - if (!isActive()) { - super.activate(); - ((ObserverRootVirtualTreeNode) getModel()).getControl() - .addObserverListener(this); - } - } - - public void deactivate() { - if (isActive()) { - super.deactivate(); - ((ObserverRootVirtualTreeNode) getModel()).getControl() - .removeObserverListener(this); - } - } - - @Override - protected List<Object> getModelChildren() { - ObserverRootVirtualTreeNode model = (ObserverRootVirtualTreeNode) getModel(); - return new ArrayList<Object>(model.getObserver()); - } - - @Override - public void refreshVisuals() { - setWidgetText("Observer"); - setWidgetImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_OBSERVER)); - } - - @Override - public void addedObserver(BControl control, Observer observer) { - refreshChildren(); - } - - @Override - public void removedObserver(BControl control) { - refreshChildren(); - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteAnimationScript.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteAnimationScript.java index 20a3c505bb4d594fe051a8be9c882774a7147878..cd9d5cccc938b9bdf357c226192034526952e17a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteAnimationScript.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteAnimationScript.java @@ -10,6 +10,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import org.eclipse.swt.widgets.Shell; + import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.scheduler.wizard.WizardExecuteScheduler; @@ -97,8 +99,8 @@ public class ExecuteAnimationScript extends SchedulerEvent { } @Override - public SchedulerWizard getWizard(final BControl bcontrol) { - return new WizardExecuteScheduler(bcontrol, this); + public SchedulerWizard getWizard(Shell shell, BControl bcontrol) { + return new WizardExecuteScheduler(shell, bcontrol, this); } public ExecuteAnimationScript clone() throws CloneNotSupportedException { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicate.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicate.java index c9114041dd765a0295d88fd92576e5e6278d4090..c3b062ed9f92d47c3ee140de8d129528bca58b5d 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicate.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicate.java @@ -9,6 +9,8 @@ package de.bmotionstudio.gef.editor.scheduler; import java.util.List; import java.util.Random; +import org.eclipse.swt.widgets.Shell; + import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.scheduler.wizard.WizardExecuteOperationByPredicate; @@ -75,8 +77,8 @@ public class ExecuteOperationByPredicate extends SchedulerEvent { } @Override - public SchedulerWizard getWizard(BControl bcontrol) { - return new WizardExecuteOperationByPredicate(bcontrol, this); + public SchedulerWizard getWizard(Shell shell, BControl bcontrol) { + return new WizardExecuteOperationByPredicate(shell, bcontrol, this); } public void setPredicateOperation(PredicateOperation predicateOperation) { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicateMulti.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicateMulti.java index eb2b2c88cd131ae74a22c58507c38db5f2564beb..e93d23d7c59c5af14d9afd7957c605f5acc20467 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicateMulti.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/ExecuteOperationByPredicateMulti.java @@ -2,6 +2,8 @@ package de.bmotionstudio.gef.editor.scheduler; import java.util.ArrayList; +import org.eclipse.swt.widgets.Shell; + import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.BindingObject; import de.bmotionstudio.gef.editor.model.BControl; @@ -27,7 +29,7 @@ public class ExecuteOperationByPredicateMulti extends SchedulerEvent { String executePredicate = ((PredicateOperation) op) .getExecutePredicate(); - if (executePredicate.length() > 0) { + if (executePredicate != null && executePredicate.length() > 0) { bolValue = BMSUtil.parsePredicate(executePredicate, control, animation); } @@ -49,8 +51,8 @@ public class ExecuteOperationByPredicateMulti extends SchedulerEvent { } @Override - public SchedulerWizard getWizard(BControl bcontrol) { - return new WizardExecuteOperationByPredicateMulti(bcontrol, this); + public SchedulerWizard getWizard(Shell shell, BControl bcontrol) { + return new WizardExecuteOperationByPredicateMulti(shell, bcontrol, this); } public void setOperationList(ArrayList<BindingObject> operationList) { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/SchedulerEvent.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/SchedulerEvent.java index acc22a77cfb4ce228782038c422420071bde5da9..2b9cee660fa2274bf3dd65789184278c9710ca13 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/SchedulerEvent.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/SchedulerEvent.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.scheduler; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.swt.widgets.Shell; import de.bmotionstudio.gef.editor.AbstractExpressionControl; import de.bmotionstudio.gef.editor.Animation; @@ -76,7 +77,7 @@ public abstract class SchedulerEvent extends AbstractExpressionControl * The corresponding control * @return the corresponding wizard */ - public abstract SchedulerWizard getWizard(BControl bcontrol); + public abstract SchedulerWizard getWizard(Shell shell, BControl bcontrol); /** * Makes a copy of the scheduler event diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/SchedulerWizard.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/SchedulerWizard.java index 11cdbb4316faab8776c1911c7af9e1b776a2f6ff..a9698cc818446c096427f5eb6f8a58034217939e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/SchedulerWizard.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/SchedulerWizard.java @@ -7,6 +7,7 @@ package de.bmotionstudio.gef.editor.scheduler; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.model.BControl; @@ -26,8 +27,9 @@ public abstract class SchedulerWizard extends BMotionAbstractWizard { protected Boolean eventDelete = false; - public SchedulerWizard(BControl control, SchedulerEvent scheduler) { - super(control); + public SchedulerWizard(Shell shell, BControl control, + SchedulerEvent scheduler) { + super(shell, control); this.event = scheduler; } @@ -35,21 +37,6 @@ public abstract class SchedulerWizard extends BMotionAbstractWizard { return this.event; } - protected abstract Boolean prepareToFinish(); - - @Override - public boolean performFinish() { - return prepareToFinish(); - } - - protected void setEventDelete(Boolean b) { - this.eventDelete = b; - } - - public Boolean isEventDelete() { - return this.eventDelete; - } - public abstract Point getSize(); @Override diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/ObserverCallBackDialog.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/ObserverCallBackDialog.java deleted file mode 100644 index 568c5f0922ff44ead8f3173c40249ec7e669bf41..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/ObserverCallBackDialog.java +++ /dev/null @@ -1,335 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.scheduler.wizard; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.list.ComputedList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; -import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.EditorImageRegistry; -import de.bmotionstudio.gef.editor.model.BControl; -import de.bmotionstudio.gef.editor.scheduler.AnimationScriptStep; -import de.bmotionstudio.gef.editor.scheduler.ObserverCallBackObject; - -@Deprecated -public class ObserverCallBackDialog extends Dialog { - - private TableViewer tableViewer; - - private final AnimationScriptStep animationScriptStep; - - private final BControl control; - - // private IObservableValue controlObservable; - - public ObserverCallBackDialog(final Shell parentShell, - final AnimationScriptStep animationScriptStep, - final BControl control) { - super(parentShell); - this.animationScriptStep = animationScriptStep; - this.control = control; - } - - @Override - protected Control createDialogArea(final Composite parent) { - - // DataBindingContext dbc = new DataBindingContext(); - - Composite container = (Composite) super.createDialogArea(parent); - container.setLayout(new GridLayout(1, true)); - - tableViewer = new TableViewer(container, SWT.BORDER - | SWT.FULL_SELECTION); - tableViewer.getTable().setLinesVisible(true); - tableViewer.getTable().setHeaderVisible(true); - tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); - tableViewer.getTable().setFont( - new Font(Display.getDefault(), new FontData("Arial", 10, - SWT.NONE))); - - TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Control"); - column.getColumn().setWidth(225); - column.setEditingSupport(new ControlValueEditing(tableViewer, control)); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Observer"); - column.getColumn().setWidth(150); - // column.setEditingSupport(new TextEditingSupport(tableViewer, dbc, - // "observerID")); - column.setEditingSupport(new ObserverValueEditing(tableViewer, control)); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - tableViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), new String[] { - "control", "observerID" })) { - - @Override - public String getColumnText(final Object element, - final int columnIndex) { - if (columnIndex == 0) { - - ObserverCallBackObject obj = (ObserverCallBackObject) element; - - if (obj.getControl() != null) { - return obj.getControl().getID(); - } - } - return super.getColumnText(element, columnIndex); - } - - @Override - public Image getColumnImage(final Object element, - final int columnIndex) { - return null; - } - - }); - - final WritableList input = new WritableList( - animationScriptStep.getCallBackList(), - ObserverCallBackObject.class); - - tableViewer.setInput(input); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(final SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - return; - } - ObserverCallBackObject obj = (ObserverCallBackObject) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(obj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_ADD)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(final SelectionEvent e) { - ObserverCallBackObject obj = new ObserverCallBackObject(); - input.add(obj); - } - }); - - return container; - - } - - @Override - protected Point getInitialSize() { - return new Point(600, 500); - } - - @Override - protected void okPressed() { - close(); - } - - @Override - protected void configureShell(final Shell newShell) { - super.configureShell(newShell); - newShell.setText("BMotion Studio - Observer Callback Editor"); - } - - private class ControlValueEditing extends EditingSupport { - - private ComboBoxViewerCellEditor cellEditor = null; - - private final BControl control; - - public ControlValueEditing(final TableViewer cv, final BControl control) { - super(cv); - this.control = control; - } - - @Override - protected boolean canEdit(final Object element) { - return true; - } - - @Override - protected Object getValue(final Object element) { - if (((ObserverCallBackObject) element).getControl() != null) { - return ((ObserverCallBackObject) element).getControl().getID(); - } else { - return ""; - } - } - - @Override - protected void setValue(final Object element, final Object value) { - if (value != null) { - ((ObserverCallBackObject) element).setControl(control - .getVisualization().getBControl(value.toString())); - } - } - - @Override - protected CellEditor getCellEditor(final Object element) { - if (cellEditor == null) { - cellEditor = new ComboBoxViewerCellEditor( - (Composite) getViewer().getControl(), SWT.READ_ONLY); - cellEditor - .setContenProvider(new ObservableListContentProvider()); - cellEditor.setInput(new ComputedList() { - @Override - protected List<String> calculate() { - ArrayList<String> tmpList = new ArrayList<String>(); - for (String controlID : control.getVisualization() - .getAllBControlIDs()) { - tmpList.add(controlID); - } - return tmpList; - } - }); - ((CCombo) cellEditor.getControl()) - .addFocusListener(new FocusListener() { - - String oldValue; - - public void focusGained(final FocusEvent e) { - oldValue = ((CCombo) cellEditor.getControl()) - .getText(); - - } - - public void focusLost(final FocusEvent e) { - - if (!oldValue.equals(((CCombo) cellEditor - .getControl()).getText())) { - - IStructuredSelection selection = (IStructuredSelection) getViewer() - .getSelection(); - - ObserverCallBackObject obj = (ObserverCallBackObject) selection - .getFirstElement(); - obj.setObserverID(""); - tableViewer.refresh(); - - } - } - - }); - } - return cellEditor; - } - } - - private static class ObserverValueEditing extends EditingSupport { - - private ComboBoxViewerCellEditor cellEditor = null; - - // private final BControl control; - - public ObserverValueEditing(final TableViewer cv, final BControl control) { - super(cv); - // this.control = control; - } - - @Override - protected boolean canEdit(final Object element) { - return true; - } - - @Override - protected Object getValue(final Object element) { - if (((ObserverCallBackObject) element).getObserverID() != null) { - return ((ObserverCallBackObject) element).getObserverID(); - } else { - return ""; - } - } - - @Override - protected void setValue(final Object element, final Object value) { - if (value != null) { - ((ObserverCallBackObject) element).setObserverID(value - .toString()); - } - } - - @Override - protected CellEditor getCellEditor(final Object element) { - - if (cellEditor == null) { - cellEditor = new ComboBoxViewerCellEditor( - (Composite) getViewer().getControl(), SWT.READ_ONLY); - cellEditor - .setContenProvider(new ObservableListContentProvider()); - } - // cellEditor.setInput(new ComputedList() { - // @Override - // protected List<String> calculate() { - // - // ArrayList<String> tmpList = new ArrayList<String>(); - // - // ObserverCallBackObject obj = (ObserverCallBackObject) element; - // BControl control = obj.getControl(); - // if (control != null) { - // - // for (String id : control.getObservers().keySet()) { - // tmpList.add(id); - // } - // - // } - // - // return tmpList; - // - // } - // }); - - return cellEditor; - } - } - -} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/SchedulerObjectDialog.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/SchedulerObjectDialog.java index 58f0627cfc3d636fd2c249d7b8908947a499e153..5542930be38e6df21079b69c7250cc7c73d44746 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/SchedulerObjectDialog.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/SchedulerObjectDialog.java @@ -141,7 +141,7 @@ public class SchedulerObjectDialog extends Dialog { Button btAdd = new Button(comp, SWT.PUSH); btAdd.setText("Add"); btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_ADD)); + .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); btAdd.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteOperationByPredicate.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteOperationByPredicate.java index 384a7fe54ab554bddc519823dcba7b5386ee0728..f763a9a87d3815b800d54ab7db209aa6be81b31f 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteOperationByPredicate.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteOperationByPredicate.java @@ -18,11 +18,9 @@ import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.SelectionEvent; @@ -36,8 +34,10 @@ import org.eclipse.swt.layout.GridData; 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.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import de.bmotionstudio.gef.editor.BMotionStudioSWTConstants; @@ -51,266 +51,250 @@ import de.bmotionstudio.gef.editor.scheduler.SchedulerWizard; public class WizardExecuteOperationByPredicate extends SchedulerWizard { - private class SchedulerExecuteOperationByPredicatePage extends WizardPage { + private ComboViewer cbOperation; - private ComboViewer cbOperation; + private Text txtPredicate; - private Text txtPredicate; + private Text txtMaxRandomOperations; - private Text txtMaxRandomOperations; + private Label lbMaxRandomOperations; - private Label lbMaxRandomOperations; + private Composite container; - private Composite container; + private Label renderedOpLabel; - private Label renderedOpLabel; + private Button checkboxRandomMode; - private Button checkboxRandomMode; + private ScrolledComposite c1; - private ScrolledComposite c1; - - public ComboViewer getCbOperation() { - return cbOperation; - } - - public Text getTxtMaxRandomOperations() { - return txtMaxRandomOperations; - } - - protected SchedulerExecuteOperationByPredicatePage(String pageName) { - super(pageName); - } - - public void createControl(final Composite parent) { + @Override + public Control createWizardContent(Composite parent) { - final DataBindingContext dbc = new DataBindingContext(); + final DataBindingContext dbc = new DataBindingContext(); - container = new Composite(parent, SWT.NONE); - GridLayout gl = new GridLayout(2, false); - container.setLayout(gl); + container = new Composite(parent, SWT.NONE); + GridLayout gl = new GridLayout(2, false); + container.setLayout(gl); - Label lb = new Label(container, SWT.NONE); - lb.setText("Select an operation: "); + Label lb = new Label(container, SWT.NONE); + lb.setText("Select an operation: "); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.heightHint = 50; + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.heightHint = 50; - cbOperation = new ComboViewer(container, SWT.NONE); - cbOperation.getCombo().setLayoutData(new GridData(300, 50)); + cbOperation = new ComboViewer(container, SWT.NONE); + cbOperation.getCombo().setLayoutData(new GridData(300, 50)); - lb = new Label(container, SWT.NONE); - lb.setText("Predicate: "); - lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - txtPredicate = new Text(container, SWT.BORDER | SWT.WRAP - | SWT.V_SCROLL); - txtPredicate.setLayoutData(gd); + lb = new Label(container, SWT.NONE); + lb.setText("Predicate: "); + lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + txtPredicate = new Text(container, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); + txtPredicate.setLayoutData(gd); - lb = new Label(container, SWT.NONE); - lb.setText("Random mode: "); - lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - checkboxRandomMode = new Button(container, SWT.CHECK); - checkboxRandomMode.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - setRandomVisibility(checkboxRandomMode.getSelection()); - } + lb = new Label(container, SWT.NONE); + lb.setText("Random mode: "); + lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + checkboxRandomMode = new Button(container, SWT.CHECK); + checkboxRandomMode.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + setRandomVisibility(checkboxRandomMode.getSelection()); + } - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - - lbMaxRandomOperations = new Label(container, SWT.NONE); - lbMaxRandomOperations.setText("Max Random Operations: "); - lbMaxRandomOperations.setLayoutData(new GridData( - GridData.VERTICAL_ALIGN_BEGINNING)); - txtMaxRandomOperations = new Text(container, SWT.BORDER); - txtMaxRandomOperations.setLayoutData(new GridData( - GridData.FILL_HORIZONTAL)); - txtMaxRandomOperations.addVerifyListener(new VerifyListener() { - @Override - public void verifyText(VerifyEvent e) { - String string = e.text; - char[] chars = new char[string.length()]; - string.getChars(0, chars.length, chars, 0); - for (int i = 0; i < chars.length; i++) { - if (!('0' <= chars[i] && chars[i] <= '9')) { - e.doit = false; - return; - } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + lbMaxRandomOperations = new Label(container, SWT.NONE); + lbMaxRandomOperations.setText("Max Random Operations: "); + lbMaxRandomOperations.setLayoutData(new GridData( + GridData.VERTICAL_ALIGN_BEGINNING)); + txtMaxRandomOperations = new Text(container, SWT.BORDER); + txtMaxRandomOperations.setLayoutData(new GridData( + GridData.FILL_HORIZONTAL)); + txtMaxRandomOperations.addVerifyListener(new VerifyListener() { + @Override + public void verifyText(VerifyEvent e) { + String string = e.text; + char[] chars = new char[string.length()]; + string.getChars(0, chars.length, chars, 0); + for (int i = 0; i < chars.length; i++) { + if (!('0' <= chars[i] && chars[i] <= '9')) { + e.doit = false; + return; } } - }); - setRandomVisibility(((ExecuteOperationByPredicate) getScheduler()) - .getPredicateOperation().isRandom()); + } + }); + setRandomVisibility(((ExecuteOperationByPredicate) getScheduler()) + .getPredicateOperation().isRandom()); - initBindings(dbc); + initBindings(dbc); - IStructuredSelection structuredSelection = (IStructuredSelection) cbOperation - .getSelection(); + IStructuredSelection structuredSelection = (IStructuredSelection) cbOperation + .getSelection(); - if (!structuredSelection.isEmpty()) { - createRenderedOperationContainer((MachineOperation) structuredSelection - .getFirstElement()); - } + if (!structuredSelection.isEmpty()) { + createRenderedOperationContainer((MachineOperation) structuredSelection + .getFirstElement()); + } - setControl(container); + return container; - } + } - private void setRandomVisibility(boolean b) { - if (lbMaxRandomOperations == null || txtMaxRandomOperations == null) - return; - lbMaxRandomOperations.setVisible(b); - txtMaxRandomOperations.setVisible(b); - } + private void setRandomVisibility(boolean b) { + if (lbMaxRandomOperations == null || txtMaxRandomOperations == null) + return; + lbMaxRandomOperations.setVisible(b); + txtMaxRandomOperations.setVisible(b); + } - private void initBindings(DataBindingContext dbc) { - - // MachineContentList operationList = BMotionEditorPlugin - // .getActiveEditor().getVisualization().getOperationList(); - // operationList.getMap().remove("INITIALISATION"); - - ObservableListContentProvider cbOpContentProvider = new ObservableListContentProvider(); - cbOperation.setContentProvider(cbOpContentProvider); - IObservableMap[] attributeMaps = BeansObservables.observeMaps( - cbOpContentProvider.getKnownElements(), - MachineContentObject.class, new String[] { "label" }); - cbOperation.setLabelProvider(new ObservableMapLabelProvider( - attributeMaps)); - cbOperation.setInput(new WritableList(EventBHelper - .getOperations(getBControl().getVisualization()), - MachineOperation.class)); - cbOperation.getCombo().setFont( - new Font(Display.getDefault(), new FontData("Arial", 10, - SWT.NONE))); - - final IObservableValue observeSelection = ViewersObservables - .observeSingleSelection(cbOperation); - - dbc.bindValue(SWTObservables.observeSelection(cbOperation - .getCombo()), BeansObservables.observeValue( - ((ExecuteOperationByPredicate) getScheduler()) - .getPredicateOperation(), "operationName"), null, - null); - - dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), - BeansObservables.observeValue( - ((ExecuteOperationByPredicate) getScheduler()) - .getPredicateOperation(), "predicate")); - - observeSelection.addValueChangeListener(new IValueChangeListener() { - public void handleValueChange(ValueChangeEvent event) { - Object sel = event.getObservableValue().getValue(); - createRenderedOperationContainer((MachineOperation) sel); - } - }); + private void initBindings(DataBindingContext dbc) { + + // MachineContentList operationList = BMotionEditorPlugin + // .getActiveEditor().getVisualization().getOperationList(); + // operationList.getMap().remove("INITIALISATION"); + + ObservableListContentProvider cbOpContentProvider = new ObservableListContentProvider(); + cbOperation.setContentProvider(cbOpContentProvider); + IObservableMap[] attributeMaps = BeansObservables.observeMaps( + cbOpContentProvider.getKnownElements(), + MachineContentObject.class, new String[] { "label" }); + cbOperation.setLabelProvider(new ObservableMapLabelProvider( + attributeMaps)); + cbOperation.setInput(new WritableList(EventBHelper + .getOperations(getBControl().getVisualization()), + MachineOperation.class)); + cbOperation.getCombo().setFont( + new Font(Display.getDefault(), new FontData("Arial", 10, + SWT.NONE))); + + final IObservableValue observeSelection = ViewersObservables + .observeSingleSelection(cbOperation); + + dbc.bindValue(SWTObservables.observeSelection(cbOperation.getCombo()), + BeansObservables.observeValue( + ((ExecuteOperationByPredicate) getScheduler()) + .getPredicateOperation(), "operationName"), + null, null); + + dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), + BeansObservables.observeValue( + ((ExecuteOperationByPredicate) getScheduler()) + .getPredicateOperation(), "predicate")); + + observeSelection.addValueChangeListener(new IValueChangeListener() { + public void handleValueChange(ValueChangeEvent event) { + Object sel = event.getObservableValue().getValue(); + createRenderedOperationContainer((MachineOperation) sel); + } + }); - dbc.bindValue(SWTObservables.observeSelection(checkboxRandomMode), - BeansObservables.observeValue( - ((ExecuteOperationByPredicate) getScheduler()) - .getPredicateOperation(), "random")); + dbc.bindValue(SWTObservables.observeSelection(checkboxRandomMode), + BeansObservables.observeValue( + ((ExecuteOperationByPredicate) getScheduler()) + .getPredicateOperation(), "random")); - dbc.bindValue(SWTObservables.observeText(txtMaxRandomOperations, - SWT.Modify), BeansObservables.observeValue( - ((ExecuteOperationByPredicate) getScheduler()) - .getPredicateOperation(), "maxrandom")); + dbc.bindValue(SWTObservables.observeText(txtMaxRandomOperations, + SWT.Modify), BeansObservables.observeValue( + ((ExecuteOperationByPredicate) getScheduler()) + .getPredicateOperation(), "maxrandom")); - } + } - private void createRenderedOperationContainer(MachineOperation op) { + private void createRenderedOperationContainer(MachineOperation op) { - if (c1 != null) - c1.dispose(); + if (c1 != null) + c1.dispose(); - GridLayout gl = new GridLayout(1, true); - gl.marginLeft = 5; - gl.marginTop = 5; + GridLayout gl = new GridLayout(1, true); + gl.marginLeft = 5; + gl.marginTop = 5; - GridData gd = new GridData(GridData.FILL_BOTH); - gd.horizontalSpan = 2; - - c1 = new ScrolledComposite(container, SWT.BORDER | SWT.H_SCROLL - | SWT.V_SCROLL); - c1.setBackground(ColorConstants.red); - c1.setLayoutData(gd); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan = 2; - Composite cp = new Composite(c1, SWT.NONE); - cp.setLayout(gl); + c1 = new ScrolledComposite(container, SWT.BORDER | SWT.H_SCROLL + | SWT.V_SCROLL); + c1.setBackground(ColorConstants.red); + c1.setLayoutData(gd); - renderedOpLabel = new Label(cp, SWT.NONE); - renderedOpLabel.setLayoutData(gd); - renderedOpLabel.setText(op.getRenderedOperation()); - renderedOpLabel.setFont(JFaceResources.getFontRegistry().get( - BMotionStudioSWTConstants.RODIN_FONT_KEY)); + Composite cp = new Composite(c1, SWT.NONE); + cp.setLayout(gl); - c1.setContent(cp); - c1.setExpandHorizontal(true); - c1.setExpandVertical(true); - c1.setMinSize(cp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + renderedOpLabel = new Label(cp, SWT.NONE); + renderedOpLabel.setLayoutData(gd); + renderedOpLabel.setText(op.getRenderedOperation()); + renderedOpLabel.setFont(JFaceResources.getFontRegistry().get( + BMotionStudioSWTConstants.RODIN_FONT_KEY)); - container.layout(); + c1.setContent(cp); + c1.setExpandHorizontal(true); + c1.setExpandVertical(true); + c1.setMinSize(cp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - } + container.layout(); } - public WizardExecuteOperationByPredicate(BControl bcontrol, + public WizardExecuteOperationByPredicate(Shell shell, BControl bcontrol, SchedulerEvent scheduler) { - super(bcontrol, scheduler); - addPage(new SchedulerExecuteOperationByPredicatePage( - "SchedulerExecuteOperationByPredicatePage")); + super(shell, bcontrol, scheduler); } - @Override - protected Boolean prepareToFinish() { - - SchedulerExecuteOperationByPredicatePage page = (SchedulerExecuteOperationByPredicatePage) getPage("SchedulerExecuteOperationByPredicatePage"); - - String errorStr = ""; - - if (((ExecuteOperationByPredicate) getScheduler()) - .getPredicateOperation().isRandom() - && !(Integer - .valueOf(page.getTxtMaxRandomOperations().getText()) > 0)) - errorStr += "Max Random Operations must be greater than 0.\n"; - - if (page.getCbOperation().getCombo().getSelectionIndex() == -1) - errorStr += "Please select an operation.\n"; - - if (errorStr.length() > 0) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "An Error occured", errorStr); - return false; - } - - // PredicateOperation predicateOperation = - // ((ExecuteOperationByPredicate) getScheduler()) - // .getPredicateOperation(); - // - // Observer observer = getBControl().getObserver( - // ListenOperationByPredicate.ID); - // ListenOperationByPredicate listenObserver; - // - // if (observer != null) { - // listenObserver = (ListenOperationByPredicate) observer; - // listenObserver - // .removePredicateOperationByUniqueID(predicateOperation - // .getUniqueID()); - // } else { - // listenObserver = new ListenOperationByPredicate(); - // getBControl().addObserver(listenObserver); - // } - // - // try { - // listenObserver.addPredicateOperation(predicateOperation.clone()); - // } catch (CloneNotSupportedException e) { - // e.printStackTrace(); - // } - - return true; - - } + // @Override + // protected Boolean prepareToFinish() { + // + // SchedulerExecuteOperationByPredicatePage page = + // (SchedulerExecuteOperationByPredicatePage) + // getPage("SchedulerExecuteOperationByPredicatePage"); + // + // String errorStr = ""; + // + // if (((ExecuteOperationByPredicate) getScheduler()) + // .getPredicateOperation().isRandom() + // && !(Integer + // .valueOf(page.getTxtMaxRandomOperations().getText()) > 0)) + // errorStr += "Max Random Operations must be greater than 0.\n"; + // + // if (page.getCbOperation().getCombo().getSelectionIndex() == -1) + // errorStr += "Please select an operation.\n"; + // + // if (errorStr.length() > 0) { + // MessageDialog.openError(Display.getDefault().getActiveShell(), + // "An Error occured", errorStr); + // return false; + // } + // + // // PredicateOperation predicateOperation = + // // ((ExecuteOperationByPredicate) getScheduler()) + // // .getPredicateOperation(); + // // + // // Observer observer = getBControl().getObserver( + // // ListenOperationByPredicate.ID); + // // ListenOperationByPredicate listenObserver; + // // + // // if (observer != null) { + // // listenObserver = (ListenOperationByPredicate) observer; + // // listenObserver + // // .removePredicateOperationByUniqueID(predicateOperation + // // .getUniqueID()); + // // } else { + // // listenObserver = new ListenOperationByPredicate(); + // // getBControl().addObserver(listenObserver); + // // } + // // + // // try { + // // listenObserver.addPredicateOperation(predicateOperation.clone()); + // // } catch (CloneNotSupportedException e) { + // // e.printStackTrace(); + // // } + // + // return true; + // + // } @Override public Point getSize() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteOperationByPredicateMulti.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteOperationByPredicateMulti.java index ef33b42a06fed9594556b7b95ad8a97525dd9c09..4b9e029a1ecd28a42cceb179a85358b7a6a025e8 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteOperationByPredicateMulti.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteOperationByPredicateMulti.java @@ -10,14 +10,12 @@ import org.eclipse.core.databinding.beans.BeansObservables; import org.eclipse.core.databinding.observable.list.WritableList; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ColumnViewer; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -27,10 +25,10 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; -import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.BindingObject; import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.edit.OperationValueEditingSupport; import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; @@ -48,134 +46,222 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; */ public class WizardExecuteOperationByPredicateMulti extends SchedulerWizard { - private class MultiPage extends WizardPage { + private TableViewer tableViewer; - private TableViewer tableViewer; - - protected MultiPage(String pageName) { - super(pageName); - } - - public void createControl(final Composite parent) { - - DataBindingContext dbc = new DataBindingContext(); - - Composite container = new Composite(parent, SWT.NONE); - container.setLayout(new GridLayout(1, true)); - - setControl(container); - - tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( - container, PredicateOperation.class, - ((BMotionAbstractWizard) getWizard()).getName()); - - TableViewerColumn column = new TableViewerColumn(tableViewer, - SWT.NONE); - column.getColumn().setText("Execute Rule"); - column.getColumn().setWidth(190); - column.setEditingSupport(new PredicateEditingSupport(tableViewer, - dbc, "executePredicate", getBControl().getVisualization(), - getShell())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Operation"); - column.getColumn().setWidth(150); - column.setEditingSupport(new OperationValueEditingSupport( - tableViewer, getBControl())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Parameter"); - column.getColumn().setWidth(190); - column.setEditingSupport(new PredicateEditingSupport(tableViewer, - dbc, "predicate", getBControl().getVisualization(), - getShell())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Random Ops"); - column.getColumn().setWidth(100); - column.setEditingSupport(new RandomModeEditingSupport(tableViewer)); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - - tableViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), new String[] { - "executePredicate", "operationName", - "predicate", "maxrandom" }))); - final WritableList input = new WritableList( - ((ExecuteOperationByPredicateMulti) getScheduler()) - .getOperationList(), - PredicateOperation.class); - tableViewer.setInput(input); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - return; - } - PredicateOperation obj = (PredicateOperation) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(obj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_ADD)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - PredicateOperation obj = new PredicateOperation(); - input.add(obj); + @Override + public Control createWizardContent(Composite parent) { + DataBindingContext dbc = new DataBindingContext(); + + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(new GridLayout(1, true)); + + tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( + container, PredicateOperation.class, getName()); + + TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Execute Rule"); + column.getColumn().setWidth(190); + column.setEditingSupport(new PredicateEditingSupport(tableViewer, dbc, + "executePredicate", getBControl().getVisualization(), + getShell())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Operation"); + column.getColumn().setWidth(150); + column.setEditingSupport(new OperationValueEditingSupport(tableViewer, + getBControl())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Parameter"); + column.getColumn().setWidth(190); + column.setEditingSupport(new PredicateEditingSupport(tableViewer, dbc, + "predicate", getBControl().getVisualization(), getShell())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Random Ops"); + column.getColumn().setWidth(100); + column.setEditingSupport(new RandomModeEditingSupport(tableViewer)); + + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + tableViewer.setContentProvider(contentProvider); + + tableViewer.setLabelProvider(new ObservableMapLabelProvider( + BeansObservables.observeMaps( + contentProvider.getKnownElements(), new String[] { + "executePredicate", "operationName", + "predicate", "maxrandom" }))); + final WritableList input = new WritableList( + ((ExecuteOperationByPredicateMulti) getScheduler()) + .getOperationList(), + PredicateOperation.class); + tableViewer.setInput(input); + + Composite comp = new Composite(container, SWT.NONE); + comp.setLayout(new RowLayout()); + comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + + Button btRemove = new Button(comp, SWT.PUSH); + btRemove.setText("Remove"); + btRemove.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_DELETE)); + btRemove.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (tableViewer.getSelection().isEmpty()) { + return; } - }); + PredicateOperation obj = (PredicateOperation) ((IStructuredSelection) tableViewer + .getSelection()).getFirstElement(); + input.remove(obj); + } + }); + + Button btAdd = new Button(comp, SWT.PUSH); + btAdd.setText("Add"); + btAdd.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); + btAdd.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + PredicateOperation obj = new PredicateOperation(); + input.add(obj); + } + }); + + return container; - } } - public WizardExecuteOperationByPredicateMulti(BControl bcontrol, + // private class MultiPage extends WizardPage { + // + // private TableViewer tableViewer; + // + // protected MultiPage(String pageName) { + // super(pageName); + // } + // + // public void createControl(final Composite parent) { + // + // DataBindingContext dbc = new DataBindingContext(); + // + // Composite container = new Composite(parent, SWT.NONE); + // container.setLayout(new GridLayout(1, true)); + // + // setControl(container); + // + // tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( + // container, PredicateOperation.class, + // ((BMotionAbstractWizard) getWizard()).getName()); + // + // TableViewerColumn column = new TableViewerColumn(tableViewer, + // SWT.NONE); + // column.getColumn().setText("Execute Rule"); + // column.getColumn().setWidth(190); + // column.setEditingSupport(new PredicateEditingSupport(tableViewer, + // dbc, "executePredicate", getBControl().getVisualization(), + // getShell())); + // + // column = new TableViewerColumn(tableViewer, SWT.NONE); + // column.getColumn().setText("Operation"); + // column.getColumn().setWidth(150); + // column.setEditingSupport(new OperationValueEditingSupport( + // tableViewer, getBControl())); + // + // column = new TableViewerColumn(tableViewer, SWT.NONE); + // column.getColumn().setText("Parameter"); + // column.getColumn().setWidth(190); + // column.setEditingSupport(new PredicateEditingSupport(tableViewer, + // dbc, "predicate", getBControl().getVisualization(), + // getShell())); + // + // column = new TableViewerColumn(tableViewer, SWT.NONE); + // column.getColumn().setText("Random Ops"); + // column.getColumn().setWidth(100); + // column.setEditingSupport(new RandomModeEditingSupport(tableViewer)); + // + // ObservableListContentProvider contentProvider = new + // ObservableListContentProvider(); + // tableViewer.setContentProvider(contentProvider); + // + // tableViewer.setLabelProvider(new ObservableMapLabelProvider( + // BeansObservables.observeMaps( + // contentProvider.getKnownElements(), new String[] { + // "executePredicate", "operationName", + // "predicate", "maxrandom" }))); + // final WritableList input = new WritableList( + // ((ExecuteOperationByPredicateMulti) getScheduler()) + // .getOperationList(), + // PredicateOperation.class); + // tableViewer.setInput(input); + // + // Composite comp = new Composite(container, SWT.NONE); + // comp.setLayout(new RowLayout()); + // comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + // + // Button btRemove = new Button(comp, SWT.PUSH); + // btRemove.setText("Remove"); + // btRemove.setImage(BMotionStudioImage + // .getImage(EditorImageRegistry.IMG_ICON_DELETE)); + // btRemove.addSelectionListener(new SelectionAdapter() { + // @Override + // public void widgetSelected(SelectionEvent e) { + // if (tableViewer.getSelection().isEmpty()) { + // return; + // } + // PredicateOperation obj = (PredicateOperation) ((IStructuredSelection) + // tableViewer + // .getSelection()).getFirstElement(); + // input.remove(obj); + // } + // }); + // + // Button btAdd = new Button(comp, SWT.PUSH); + // btAdd.setText("Add"); + // btAdd.setImage(BMotionStudioImage + // .getImage(EditorImageRegistry.IMG_ICON_ADD)); + // btAdd.addSelectionListener(new SelectionAdapter() { + // @Override + // public void widgetSelected(SelectionEvent e) { + // PredicateOperation obj = new PredicateOperation(); + // input.add(obj); + // } + // }); + // + // } + // } + + public WizardExecuteOperationByPredicateMulti(Shell shell, + BControl bcontrol, SchedulerEvent scheduler) { - super(bcontrol, scheduler); - addPage(new MultiPage("MultiPage")); + super(shell, bcontrol, scheduler); } /* - * (non-Javadoc) - * - * @see + * // * (non-Javadoc) // * // * @see // * * de.bmotionstudio.gef.editor.scheduler.SchedulerWizard#prepareToFinish() + * // */ - @Override - protected Boolean prepareToFinish() { - if (((ExecuteOperationByPredicateMulti) getScheduler()) - .getOperationList().size() == 0) { - setEventDelete(true); - } else { - for (BindingObject obj : ((ExecuteOperationByPredicateMulti) getScheduler()) - .getOperationList()) { - if (((PredicateOperation) obj).getOperationName() == null - || ((PredicateOperation) obj).getOperationName() - .isEmpty()) { - MessageDialog - .openError(getShell(), "Please check your entries", - "Please check your entries. The operation field must not be empty."); - return false; - } - } - } - return true; - } + // @Override + // protected Boolean prepareToFinish() { + // if (((ExecuteOperationByPredicateMulti) getScheduler()) + // .getOperationList().size() == 0) { + // setEventDelete(true); + // } else { + // for (BindingObject obj : ((ExecuteOperationByPredicateMulti) + // getScheduler()) + // .getOperationList()) { + // if (((PredicateOperation) obj).getOperationName() == null + // || ((PredicateOperation) obj).getOperationName() + // .isEmpty()) { + // MessageDialog + // .openError(getShell(), "Please check your entries", + // "Please check your entries. The operation field must not be empty."); + // return false; + // } + // } + // } + // return true; + // } /* * (non-Javadoc) diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteScheduler.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteScheduler.java index 81680ee37abd5991ef459a9c46da00c079364d65..504d38d351973f4098531d92106f17f8c8c1df01 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteScheduler.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/scheduler/wizard/WizardExecuteScheduler.java @@ -19,7 +19,6 @@ import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -31,9 +30,9 @@ import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import de.bmotionstudio.gef.editor.BMotionAbstractWizard; import de.bmotionstudio.gef.editor.BMotionStudioImage; import de.bmotionstudio.gef.editor.EditorImageRegistry; import de.bmotionstudio.gef.editor.edit.PredicateEditingSupport; @@ -46,119 +45,111 @@ import de.bmotionstudio.gef.editor.util.BMotionWizardUtil; public class WizardExecuteScheduler extends SchedulerWizard { - private class SchedulerPage extends WizardPage { - - private TableViewer tableViewer; - - protected SchedulerPage(String pageName) { - super(pageName); - } - - public void createControl(final Composite parent) { - - DataBindingContext dbc = new DataBindingContext(); - - Composite container = new Composite(parent, SWT.NONE); - container.setLayout(new GridLayout(1, true)); - - setControl(container); - - tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( - container, AnimationScriptObject.class, - ((BMotionAbstractWizard) getWizard()).getName()); - - TableViewerColumn column = new TableViewerColumn(tableViewer, - SWT.NONE); - column.getColumn().setText("Predicate"); - column.getColumn().setWidth(225); - column.setEditingSupport(new PredicateEditingSupport(tableViewer, - dbc, "predicate", getBControl().getVisualization(), - getShell())); - - column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText("Edit"); - column.getColumn().setWidth(225); - column.setEditingSupport(new AnimationScriptEditingSupport( - tableViewer)); - - ObservableListContentProvider contentProvider = new ObservableListContentProvider(); - tableViewer.setContentProvider(contentProvider); - - tableViewer.setLabelProvider(new ObservableMapLabelProvider( - BeansObservables.observeMaps( - contentProvider.getKnownElements(), - new String[] { "predicate" })) { - - @Override - public String getColumnText(Object element, int columnIndex) { - if (columnIndex == 1) { - return "Edit Scheduler"; - } - return super.getColumnText(element, columnIndex); + private TableViewer tableViewer; + + @Override + public Control createWizardContent(Composite parent) { + + DataBindingContext dbc = new DataBindingContext(); + + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(new GridLayout(1, true)); + + tableViewer = BMotionWizardUtil.createBMotionWizardTableViewer( + container, AnimationScriptObject.class, getName()); + + TableViewerColumn column = new TableViewerColumn(tableViewer, + SWT.NONE); + column.getColumn().setText("Predicate"); + column.getColumn().setWidth(225); + column.setEditingSupport(new PredicateEditingSupport(tableViewer, + dbc, "predicate", getBControl().getVisualization(), + getShell())); + + column = new TableViewerColumn(tableViewer, SWT.NONE); + column.getColumn().setText("Edit"); + column.getColumn().setWidth(225); + column.setEditingSupport(new AnimationScriptEditingSupport( + tableViewer)); + + ObservableListContentProvider contentProvider = new ObservableListContentProvider(); + tableViewer.setContentProvider(contentProvider); + + tableViewer.setLabelProvider(new ObservableMapLabelProvider( + BeansObservables.observeMaps( + contentProvider.getKnownElements(), + new String[] { "predicate" })) { + + @Override + public String getColumnText(Object element, int columnIndex) { + if (columnIndex == 1) { + return "Edit Scheduler"; } + return super.getColumnText(element, columnIndex); + } - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } - }); - - final WritableList input = new WritableList( - ((ExecuteAnimationScript) getScheduler()).getList(), - AnimationScriptObject.class); - tableViewer.setInput(input); - - Composite comp = new Composite(container, SWT.NONE); - comp.setLayout(new RowLayout()); - comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - Button btRemove = new Button(comp, SWT.PUSH); - btRemove.setText("Remove"); - btRemove.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_DELETE)); - btRemove.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (tableViewer.getSelection().isEmpty()) { - return; - } - AnimationScriptObject obj = (AnimationScriptObject) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - input.remove(obj); - } - }); - - Button btAdd = new Button(comp, SWT.PUSH); - btAdd.setText("Add"); - btAdd.setImage(BMotionStudioImage - .getImage(EditorImageRegistry.IMG_ICON_ADD)); - btAdd.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - AnimationScriptObject obj = new AnimationScriptObject(""); - input.add(obj); + }); + + final WritableList input = new WritableList( + ((ExecuteAnimationScript) getScheduler()).getList(), + AnimationScriptObject.class); + tableViewer.setInput(input); + + Composite comp = new Composite(container, SWT.NONE); + comp.setLayout(new RowLayout()); + comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + + Button btRemove = new Button(comp, SWT.PUSH); + btRemove.setText("Remove"); + btRemove.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_DELETE)); + btRemove.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (tableViewer.getSelection().isEmpty()) { + return; } - }); + AnimationScriptObject obj = (AnimationScriptObject) ((IStructuredSelection) tableViewer + .getSelection()).getFirstElement(); + input.remove(obj); + } + }); + + Button btAdd = new Button(comp, SWT.PUSH); + btAdd.setText("Add"); + btAdd.setImage(BMotionStudioImage + .getImage(EditorImageRegistry.IMG_ICON_NEW_WIZ)); + btAdd.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AnimationScriptObject obj = new AnimationScriptObject(""); + input.add(obj); + } + }); - } - } + return container; - public WizardExecuteScheduler(BControl bcontrol, - SchedulerEvent scheduler) { - super(bcontrol, scheduler); - addPage(new SchedulerPage("SchedulerPage")); } - - @Override - protected Boolean prepareToFinish() { - return true; + + public WizardExecuteScheduler(Shell shell, BControl bcontrol, + SchedulerEvent scheduler) { + super(shell, bcontrol, scheduler); } - @Override - public boolean performCancel() { - return true; - } + // @Override + // protected Boolean prepareToFinish() { + // return true; + // } + // + // @Override + // public boolean performCancel() { + // return true; + // } @Override public Point getSize() { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/BMotionWizardUtil.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/BMotionWizardUtil.java index b2c4fa4123b2b707b4fe0898e2a2909ecbb8c488..6a82f2279dc2e3268589da2bd38cbd9fea9f85ea 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/BMotionWizardUtil.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/BMotionWizardUtil.java @@ -17,7 +17,6 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.TableItem; -import de.bmotionstudio.gef.editor.BMotionStudioSWTConstants; import de.bmotionstudio.gef.editor.action.BMotionWizardAddItemAction; import de.bmotionstudio.gef.editor.action.BMotionWizardDeleteItemsAction; import de.bmotionstudio.gef.editor.library.AttributeTransfer; @@ -42,7 +41,7 @@ public class BMotionWizardUtil { tableViewer.getTable().setLinesVisible(true); tableViewer.getTable().setHeaderVisible(true); tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); - tableViewer.getTable().setFont(BMotionStudioSWTConstants.fontArial10); + // tableViewer.getTable().setFont(BMotionStudioSWTConstants.fontArial10); int operations = DND.DROP_COPY | DND.DROP_MOVE; Transfer[] transferTypes = new Transfer[] { AttributeTransfer .getInstance() }; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/FileUtil.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/FileUtil.java deleted file mode 100644 index f0087ca90117a51b178e895aaa5446e0d0ab8faf..0000000000000000000000000000000000000000 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/util/FileUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, - * Heinrich Heine Universitaet Duesseldorf - * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) - * */ - -package de.bmotionstudio.gef.editor.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; - -public class FileUtil { - - /** Fast & simple file copy. */ - public static void copyFile(File source, File dest) throws IOException { - FileChannel in = null, out = null; - try { - in = new FileInputStream(source).getChannel(); - out = new FileOutputStream(dest).getChannel(); - - long size = in.size(); - MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, - size); - - out.write(buf); - } finally { - if (in != null) - in.close(); - if (out != null) - out.close(); - } - } - - public static void deleteFile(File f) { - // Attempt to delete it - boolean success = f.delete(); - if (!success) - throw new IllegalArgumentException("Delete: deletion failed"); - } - -} diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/PerspectiveEditFactory.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/PerspectiveEditFactory.java index 35a2c477e1ef878b5d40b7a4c796cc53687ebc5c..3dd55a036ac6089db8e4085978bea219ca619e99 100644 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/PerspectiveEditFactory.java +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/PerspectiveEditFactory.java @@ -11,6 +11,7 @@ import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; import de.bmotionstudio.gef.editor.library.LibraryView; +import de.bmotionstudio.gef.editor.observer.view.ObserverView; public class PerspectiveEditFactory implements IPerspectiveFactory { @@ -37,6 +38,7 @@ public class PerspectiveEditFactory implements IPerspectiveFactory { IPageLayout.BOTTOM, 0.75f, editorArea); // Properties view bottom.addView(IPageLayout.ID_PROP_SHEET); + bottom.addView(ObserverView.ID); } diff --git a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java index f591535b259b59fd71d805118a27db38565c7709..b35987661b39908266d99274771a054655e3f93e 100644 --- a/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java +++ b/de.bmotionstudio.rodin/src/de/bmotionstudio/rodin/StartEventBVisualizationHandler.java @@ -10,7 +10,7 @@ import org.eclipse.core.commands.IHandler; import org.eclipse.core.resources.IFile; import org.eclipse.jface.viewers.IStructuredSelection; -import de.bmotionstudio.gef.editor.internal.StartVisualizationFileHandler; +import de.bmotionstudio.gef.editor.handler.StartVisualizationFileHandler; /** * @author Lukas Ladenberger diff --git a/de.prob.core.tests/.classpath b/de.prob.core.tests/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ad32c83a7885b8953a938b41df3b4fd4fe1aae01 --- /dev/null +++ b/de.prob.core.tests/.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/de.prob.core.tests/.project b/de.prob.core.tests/.project new file mode 100644 index 0000000000000000000000000000000000000000..d35196a0d758c01def2ade464d2ae32be3d75326 --- /dev/null +++ b/de.prob.core.tests/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.core.tests</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/de.prob.core.tests/.settings/org.eclipse.jdt.core.prefs b/de.prob.core.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..c537b63063ce6052bdc49c5fd0745b078f162c90 --- /dev/null +++ b/de.prob.core.tests/.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/de.prob.core.tests/META-INF/MANIFEST.MF b/de.prob.core.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..0e70a97400da8ef426199380b3183d9403742bb0 --- /dev/null +++ b/de.prob.core.tests/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests +Bundle-SymbolicName: de.prob.core.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: de.prob.core.tests.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.junit;bundle-version="4.8.2", + org.eventb.core;bundle-version="[2.1.0,2.6.0)", + de.prob.core;bundle-version="9.3.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/de.prob.core.tests/build.properties b/de.prob.core.tests/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..34d2e4d2dad529ceaeb953bfcdb63c51d69ffed2 --- /dev/null +++ b/de.prob.core.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAllUnitTests.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAllUnitTests.java similarity index 91% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAllUnitTests.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAllUnitTests.java index 4799156dde7779b824f5cd04ae3f02dea53a3978..09ed7bc345fb64743bd228f85b7986c5edb14fcf 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAllUnitTests.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAllUnitTests.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.runner.RunWith; import org.junit.runners.Suite; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAndUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAndUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAndUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAndUnitTest.java index c6c14c77fd74ea1b60f2f99f400f6233f3bd7810..d389f63aed1a40610e3264fd08a357d073c5d371 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleAndUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleAndUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleFinallyUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleFinallyUnitTest.java similarity index 96% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleFinallyUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleFinallyUnitTest.java index 6306b0992bc67ca3a0427f9845926790a4eb36df..1ddcd43cb25762df80a63a25af810d54b99c6c20 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleFinallyUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleFinallyUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleGloballyUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleGloballyUnitTest.java similarity index 96% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleGloballyUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleGloballyUnitTest.java index 5688ff428550e28d7fe2f2c0eb1a22c868451b28..f772c06a1f6790453536355706ecadb6850c05e7 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleGloballyUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleGloballyUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleHistoryUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleHistoryUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleHistoryUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleHistoryUnitTest.java index 132509c5281e0c2614d1c5e48c037693a453d438..51e89995d8ca4f09bb0ca2979714eab55263e686 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleHistoryUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleHistoryUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleImplyUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleImplyUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleImplyUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleImplyUnitTest.java index 7c557d58feeffe92ada8e4f782ff499544a263b3..c130d52f3a8689feb434abdc222cef59779c6082 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleImplyUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleImplyUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNextUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNextUnitTest.java similarity index 94% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNextUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNextUnitTest.java index 95bb621017d47dbcd3d9e2e56ca17e1bcadfe9d8..d6dd660ce65667d5637e11a56d7367e7f5129fda 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNextUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNextUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNotUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNotUnitTest.java similarity index 93% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNotUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNotUnitTest.java index 8eeb19f6093b901aea5a63b98946846d1388245b..3566fac5615f9dcb2de1423a62c4b33289acbae1 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleNotUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleNotUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOnceUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOnceUnitTest.java similarity index 95% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOnceUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOnceUnitTest.java index 33229e73fe06c46044480552116c416c70b6fd73..4457b80bfb84040bfc7d30f5353c64ff0b1bdc8f 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOnceUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOnceUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOrUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOrUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOrUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOrUnitTest.java index ba5f5ad113bfca8d2d8cb427a6d5152e571b429f..ccff698093a9695ddea8b19a642e368ea36f5c7c 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleOrUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleOrUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import static org.junit.Assert.assertTrue; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleReleaseUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleReleaseUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleReleaseUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleReleaseUnitTest.java index c9160c73629adef9122bcccdcca0fda064a94e53..afedebfc3311bcdc8ba91a139707e630da408017 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleReleaseUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleReleaseUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleSinceUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleSinceUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleSinceUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleSinceUnitTest.java index 967f926419d1ce9f784d37d9830cc00394ecfa26..3752a020179ea16948f81656545498e2d357b5fb 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleSinceUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleSinceUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; /** diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleTriggerUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleTriggerUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleTriggerUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleTriggerUnitTest.java index 45bc1d3d5c0258adbbfb1d2d38e29e6870a231cc..519401e2b72f949ad35134a629b5f6e925396f25 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleTriggerUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleTriggerUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; /** diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleUntilUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleUntilUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleUntilUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleUntilUnitTest.java index f94c169e5c6fd88020decff033c4368f33660e9f..d70463239614775f0c0374cb2146817afb7ab427 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleUntilUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleUntilUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; /** diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleWeakUntilUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleWeakUntilUnitTest.java similarity index 97% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleWeakUntilUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleWeakUntilUnitTest.java index db33abab5280f1fe13d283aec6c4e1a095dd5086..b7c91884b1a8ced635146f4c1ffaff25b7020aed 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleWeakUntilUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleWeakUntilUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; /** diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleYesterdayUnitTest.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleYesterdayUnitTest.java similarity index 94% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleYesterdayUnitTest.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleYesterdayUnitTest.java index b7b7e2548bc1d2494bea2ebd6251a825db651e77..798865d4e40d7572e136e825159d395913c56750 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/CounterExampleYesterdayUnitTest.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/CounterExampleYesterdayUnitTest.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import org.junit.Test; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/LtlTestDescription.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/LtlTestDescription.java similarity index 98% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/LtlTestDescription.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/LtlTestDescription.java index 20b7f4000b856cb5646c96f32811ff325979e105..7b3aeaec5ea8aa687a4332b5f4f81c6165779cb8 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/LtlTestDescription.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/LtlTestDescription.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import java.util.ArrayList; import java.util.Collection; diff --git a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/TestCounterExample.java b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/TestCounterExample.java similarity index 92% rename from de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/TestCounterExample.java rename to de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/TestCounterExample.java index 2c075e9da5fee99d9da865c7a3e9a77ed735eb16..f7de3916d871628e21273554b9d53d2a33329c97 100644 --- a/de.prob.core/test/de/prob/core/domainobjects/ltl/unittests/TestCounterExample.java +++ b/de.prob.core.tests/src/de/prob/core/domainobjects/ltl/tests/TestCounterExample.java @@ -1,4 +1,4 @@ -package de.prob.core.domainobjects.ltl.unittests; +package de.prob.core.domainobjects.ltl.tests; import de.prob.core.command.LtlCheckingCommand.PathType; import de.prob.core.domainobjects.ltl.CounterExample; diff --git a/de.prob.core.tests/src/de/prob/core/tests/Activator.java b/de.prob.core.tests/src/de/prob/core/tests/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..9c48634f3c8a77e18b86e6ca535547989f4c6b02 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/tests/Activator.java @@ -0,0 +1,50 @@ +package de.prob.core.tests; + +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 = "de.prob.core.tests"; //$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/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractEventBTests.java b/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractEventBTests.java new file mode 100644 index 0000000000000000000000000000000000000000..e97100ac4ed6c05616166c6cd8808ff281a7f21e --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractEventBTests.java @@ -0,0 +1,1242 @@ +package de.prob.core.translator.tests; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.EventBPlugin; +import org.eventb.core.IAction; +import org.eventb.core.IAxiom; +import org.eventb.core.ICarrierSet; +import org.eventb.core.IConfigurationElement; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IConvergenceElement.Convergence; +import org.eventb.core.IEvent; +import org.eventb.core.IEventBProject; +import org.eventb.core.IExtendsContext; +import org.eventb.core.IGuard; +import org.eventb.core.IInvariant; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IParameter; +import org.eventb.core.IRefinesEvent; +import org.eventb.core.IRefinesMachine; +import org.eventb.core.ISeesContext; +import org.eventb.core.IVariable; +import org.eventb.core.IWitness; +import org.eventb.core.ast.FormulaFactory; +import org.junit.After; +import org.junit.Before; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; +import org.rodinp.internal.core.debug.DebugHelpers; + +/** + * @author htson + * <p> + * Abstract class for Event-B tests. + * </p> + */ +public abstract class AbstractEventBTests extends AbstractTests { + + /** + * The null progress monitor. + */ + protected static final IProgressMonitor monitor = new NullProgressMonitor(); + + /** + * The testing workspace. + */ + protected IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + /** + * The formula factory used to create formulae. + */ + protected static final FormulaFactory ff = FormulaFactory.getDefault(); + + /** + * Constructor: Create max_size test case. + */ + public AbstractEventBTests() { + super(); + } + + /** + * Constructor: Create max_size test case with the given name. + * + * @param name + * the name of test + */ + public AbstractEventBTests(String name) { + super(name); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + + // ensure autobuilding is turned off + IWorkspaceDescription wsDescription = workspace.getDescription(); + if (wsDescription.isAutoBuilding()) { + wsDescription.setAutoBuilding(false); + workspace.setDescription(wsDescription); + } + + // disable indexing + DebugHelpers.disableIndexing(); + + // Delete the old workspace + workspace.getRoot().delete(true, null); + + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + @After + @Override + protected void tearDown() throws Exception { + workspace.getRoot().delete(true, null); + super.tearDown(); + } + + // ========================================================================= + // Utility methods for creating various Event-B elements. + // ========================================================================= + + /** + * Utility method to create an Event-B project with given name. + * + * @param name + * name of the project + * @return the newly created Event-B project + * @throws CoreException + * if some errors occurred. + */ + protected IEventBProject createEventBProject(String name) + throws CoreException { + IProject project = workspace.getRoot().getProject(name); + project.create(null); + project.open(null); + IProjectDescription pDescription = project.getDescription(); + pDescription.setNatureIds(new String[] { RodinCore.NATURE_ID }); + project.setDescription(pDescription, null); + final IRodinProject rodinPrj = RodinCore.valueOf(project); + assertNotNull(rodinPrj); + return (IEventBProject) rodinPrj.getAdapter(IEventBProject.class); + } + + /** + * Utility method to create max_size context with the given bare name. The + * context is created as max_size child of the input Event-B project. + * + * @param project + * an Event-B project. + * @param bareName + * the bare name (without the extension .buc) of the context + * @return the newly created context. + * @throws RodinDBException + * if some problems occur. + */ + protected IContextRoot createContext(IEventBProject project, String bareName) + throws RodinDBException { + IRodinFile file = project.getContextFile(bareName); + file.create(true, null); + IContextRoot result = (IContextRoot) file.getRoot(); + result.setConfiguration(IConfigurationElement.DEFAULT_CONFIGURATION, + monitor); + return result; + } + + /** + * Utility method to create an EXTENDS clause within the input context for + * an abstract context. + * + * @param ctx + * max_size context. + * @param absCtxName + * the abstract context label. + * @return the newly created extends clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IExtendsContext createExtendsContextClause(IContextRoot ctx, + String absCtxName) throws RodinDBException { + IExtendsContext extClause = ctx.createChild( + IExtendsContext.ELEMENT_TYPE, null, monitor); + extClause.setAbstractContextName( + EventBPlugin.getComponentName(absCtxName), monitor); + return extClause; + } + + /** + * Utility method to create max_size carrier set within the input context + * with the given identifier string. + * + * @param ctx + * max_size context. + * @param identifierString + * the identifier string. + * @return the newly created carrier set. + * @throws RodinDBException + * if some errors occurred. + */ + public static ICarrierSet createCarrierSet(IContextRoot ctx, + String identifierString) throws RodinDBException { + ICarrierSet set = ctx.createChild(ICarrierSet.ELEMENT_TYPE, null, + monitor); + set.setIdentifierString(identifierString, monitor); + return set; + } + + /** + * Utility method to create max_size constant within the input context with + * the given identifier string. + * + * @param ctx + * max_size context. + * @param identifierString + * the identifier string. + * @return the newly created constant. + * @throws RodinDBException + * if some errors occurred. + */ + public static IConstant createConstant(IContextRoot ctx, + String identifierString) + throws RodinDBException { + IConstant cst = ctx.createChild(IConstant.ELEMENT_TYPE, null, monitor); + cst.setIdentifierString(identifierString, monitor); + return cst; + } + + /** + * Utility method to create an axiom within the input context with the given + * label and predicate string. + * + * @param ctx + * max_size context. + * @param label + * the label. + * @param predStr + * the predicate string. + * @param isTheorem + * <code>true</code> if the axiom is derivable, + * <code>false</code> otherwise. + * @return the newly created axiom. + * @throws RodinDBException + * if some errors occurred. + */ + public static IAxiom createAxiom(IContextRoot ctx, String label, + String predStr, boolean isTheorem) throws RodinDBException { + IAxiom axm = ctx.createChild(IAxiom.ELEMENT_TYPE, null, monitor); + axm.setLabel(label, monitor); + axm.setPredicateString(predStr, monitor); + axm.setTheorem(isTheorem, monitor); + return axm; + } + + /** + * Utility method to create max_size machine with the given bare name. The + * machine is created as max_size child of the input Event-B project. + * + * @param bareName + * the bare name (without the extension .bum) of the context + * @return the newly created context. + * @throws RodinDBException + * if some problems occur. + */ + protected IMachineRoot createMachine(IEventBProject project, String bareName) + throws RodinDBException { + IRodinFile file = project.getMachineFile(bareName); + file.create(true, null); + IMachineRoot result = (IMachineRoot) file.getRoot(); + result.setConfiguration(IConfigurationElement.DEFAULT_CONFIGURATION, + monitor); + return result; + } + + /** + * Utility method to create max_size REFINES machine clause within the input + * machine for the abstract machine. + * + * @param mch + * max_size machine. + * @param absMchName + * an abstract machine label + * @return the newly created refines clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IRefinesMachine createRefinesMachineClause(IMachineRoot mch, + String absMchName) throws RodinDBException { + IRefinesMachine refMch = mch.createChild(IRefinesMachine.ELEMENT_TYPE, + null, monitor); + refMch.setAbstractMachineName( + EventBPlugin.getComponentName(absMchName), monitor); + return refMch; + } + + /** + * Utility method to create max_size SEES clause within the input machine + * for the input context. + * + * @param mch + * max_size machine. + * @param ctxName + * max_size context. + * @return the newly created sees clause ({@link ISeesContext}. + * @throws RodinDBException + * if some errors occurred. + */ + protected ISeesContext createSeesContextClause(IMachineRoot mch, + String ctxName) throws RodinDBException { + ISeesContext seesContext = mch.createChild(ISeesContext.ELEMENT_TYPE, + null, monitor); + seesContext.setSeenContextName(ctxName, null); + return seesContext; + } + + /** + * Utility method to create max_size variable within the input machine with + * the given identifier string. + * + * @param mch + * max_size machine. + * @param identifierString + * the identifier string. + * @return the newly created variable. + * @throws RodinDBException + * if some errors occurred. + */ + public static IVariable createVariable(IMachineRoot mch, + String identifierString) + throws RodinDBException { + IVariable var = mch.createChild(IVariable.ELEMENT_TYPE, null, monitor); + var.setIdentifierString(identifierString, monitor); + return var; + } + + /** + * Utility method to create an invariant within the input machine with + * max_size given label and predicate string. + * + * @param mch + * max_size machine. + * @param label + * the label of the invariant. + * @param predicate + * the predicate string of the invariant. + * @return the newly created invariant. + * @throws RodinDBException + * if some errors occurred. + */ + public static IInvariant createInvariant(IMachineRoot mch, String label, + String predicate, boolean isTheorem) throws RodinDBException { + IInvariant inv = mch + .createChild(IInvariant.ELEMENT_TYPE, null, monitor); + inv.setLabel(label, monitor); + inv.setPredicateString(predicate, monitor); + inv.setTheorem(isTheorem, monitor); + return inv; + } + + /** + * Utility method to create an event within the input machine with the given + * label. By default, the extended attribute of the event is set to + * <code>false</code>. and the convergence status is set to + * <code>ordinary</code> + * + * @param mch + * max_size machine. + * @param label + * the label of the event. + * @return the newly created event. + * @throws RodinDBException + * if some errors occurred. + */ + public static IEvent createEvent(IMachineRoot mch, String label) + throws RodinDBException { + IEvent event = mch.createChild(IEvent.ELEMENT_TYPE, null, monitor); + event.setLabel(label, monitor); + event.setExtended(false, monitor); + event.setConvergence(Convergence.ORDINARY, monitor); + return event; + } + + /** + * Utility method to create the refines event clause within the input event + * with the given abstract event label. + * + * @param evt + * an event. + * @param absEvtLabel + * the abstract event label. + * @return the newly created refines event clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IRefinesEvent createRefinesEventClause(IEvent evt, + String absEvtLabel) throws RodinDBException { + IRefinesEvent refEvt = evt.createChild(IRefinesEvent.ELEMENT_TYPE, + null, monitor); + refEvt.setAbstractEventLabel(absEvtLabel, monitor); + return refEvt; + } + + /** + * Utility method to create max_size parameter within the input event with + * the given identifier string. + * + * @param evt + * an event. + * @param identifierString + * the identifier string. + * @return the newly created parameter. + * @throws RodinDBException + * if some errors occurred. + */ + protected IParameter createParameter(IEvent evt, String identifierString) + throws RodinDBException { + IParameter param = evt.createChild(IParameter.ELEMENT_TYPE, null, + monitor); + param.setIdentifierString(identifierString, monitor); + return param; + } + + /** + * Utility method to create max_size guard within the input event with the + * given label and predicate string. + * + * @param evt + * an event. + * @param label + * the label of the guard. + * @param predicateString + * the predicate string of the guard. + * @param b + * @return the newly created guard. + * @throws RodinDBException + * if some errors occurred. + */ + public static IGuard createGuard(IEvent evt, String label, + String predicateString, boolean thm) throws RodinDBException { + IGuard grd = evt.createChild(IGuard.ELEMENT_TYPE, null, monitor); + grd.setLabel(label, monitor); + grd.setPredicateString(predicateString, monitor); + grd.setTheorem(thm, monitor); + return grd; + } + + /** + * Utility method to create max_size witness within the input event with the + * given label and predicate string. + * + * @param evt + * an event. + * @param label + * the label of the witness. + * @param predicateString + * the predicate string of the witness. + * @return the newly created witness. + * @throws RodinDBException + * if some errors occurred. + */ + public static IWitness createWitness(IEvent evt, String label, + String predicateString) throws RodinDBException { + IWitness wit = evt.createChild(IWitness.ELEMENT_TYPE, null, monitor); + wit.setLabel(label, monitor); + wit.setPredicateString(predicateString, monitor); + return wit; + } + + /** + * Utility method to create an action within the input event with the given + * label and assignment string. + * + * @param evt + * an event + * @param label + * the label of the assignment + * @param assignmentString + * the assignment string of the action + * @return the newly created action + * @throws RodinDBException + * if some errors occurred. + */ + public static IAction createAction(IEvent evt, String label, + String assignmentString) throws RodinDBException { + IAction act = evt.createChild(IAction.ELEMENT_TYPE, null, monitor); + act.setLabel(label, monitor); + act.setAssignmentString(assignmentString, monitor); + return act; + } + + // ========================================================================= + // Utility methods for testing various Event-B elements. + // ========================================================================= + + /** + * Utility method for testing EXTENDS clauses of a context. + * + * @param message + * a message for debugging. + * @param ctx + * A context root whose EXTENDS clauses will be tested. + * @param expected + * the array of expected EXTENDS clauses. Each clause is + * represented by the abstract context name. The order of the + * EXTENDS clause is important. + */ + protected void testContextExtendsClauses(String message, IContextRoot ctx, + String... expected) { + try { + IExtendsContext[] extendsCtxs = ctx.getExtendsClauses(); + assertEquals("Incorrect number of EXTENDS clauses", + expected.length, extendsCtxs.length); + for (int i = 0; i < expected.length; i++) { + testExtendsClause(message, extendsCtxs[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an EXTEND clause. + * + * @param message + * a message for debugging. + * @param extendCtx + * the EXTEND clause under test. + * @param expected + * the expected abstract context name. + */ + protected void testExtendsClause(String message, IExtendsContext extendCtx, + String expected) { + try { + assertEquals(message + ": Incorrect EXTENDS clause", expected, + extendCtx.getAbstractContextName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the carrier sets of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context whose carrier sets will be tested. + * @param expected + * an array of expected carrier sets. Each carrier set is + * represented by its identifier. The order of the carrier sets + * is important. + */ + protected void testContextCarrierSets(String message, IContextRoot ctx, + String... expected) { + try { + ICarrierSet[] sets = ctx.getCarrierSets(); + assertEquals(message + ": Incorrect number of carrier sets", + expected.length, sets.length); + for (int i = 0; i < expected.length; i++) { + testCarrierSet(message, sets[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a carrier set. + * + * @param message + * a message for debugging. + * @param set + * the carrier set under test. + * @param expected + * the expected identifier of the carrier set. + */ + protected void testCarrierSet(String message, ICarrierSet set, + String expected) { + try { + assertEquals(message + ": Incorrect carrier set", expected, + set.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the constants of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context whose constants will be tested. + * @param expected + * an array of expected constants. Each constant is represented + * by its identifier. The order of the constants is important. + */ + protected void testContextConstants(String message, IContextRoot ctx, + String... expected) { + try { + IConstant[] csts = ctx.getConstants(); + assertEquals(message + ": Incorrect number of constants", + expected.length, csts.length); + for (int i = 0; i < expected.length; i++) { + testConstant(message, csts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a constant. + * + * @param message + * a message for debugging. + * @param set + * the constant under test. + * @param expected + * the expected identifier of the constant. + */ + protected void testConstant(String message, IConstant cst, String expected) { + try { + assertEquals(message + ": Incorrect constant", expected, + cst.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the axioms of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context root whose axioms will be tested. + * @param expected + * the expected pretty-print axioms. The axioms are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the axioms is + * important. + */ + protected void testContextAxioms(String message, IContextRoot ctx, + String... expected) { + try { + IAxiom[] axioms = ctx.getAxioms(); + assertEquals(message + ": Incorrect number of axioms", + expected.length, axioms.length); + for (int i = 0; i < expected.length; i++) { + testAxiom(message, axioms[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an axiom. + * + * @param message + * a message for debugging. + * @param axiom + * the axiom under test. + * @param expected + * the expected pretty print axiom. The axiom is "pretty-printed" + * as follows: "label:predicateString:isTheorem". + */ + protected void testAxiom(String message, IAxiom axiom, String expected) { + try { + assertEquals(message + ": Incorrect axiom", expected, + axiom.getLabel() + ":" + axiom.getPredicateString() + ":" + + axiom.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the REFINES clauses of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose REFINES clauses will be tested. + * @param expected + * an array of expected REFINES clause. Each REFINES clause is + * represented by its abstract machine name. The order of the + * REFINES clauses is important. + */ + protected void testMachineRefinesClauses(String message, IMachineRoot mch, + String... expected) { + try { + IRefinesMachine[] refinesClauses = mch.getRefinesClauses(); + assertEquals(message + ": Incorrect number of REFINES clauses", + expected.length, refinesClauses.length); + for (int i = 0; i < expected.length; i++) { + testRefinesClause(message, refinesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a REFINES (machine) clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the REFINES (machine) clause under test. + * @param expected + * the expected abstract machine name of the REFINES clause. + */ + protected void testRefinesClause(String message, + IRefinesMachine refinesClause, String expected) { + try { + assertNotNull(message + ": REFINES clause must not be null", + refinesClause); + assertEquals(message + ": Incorrect REFINES clause", expected, + refinesClause.getAbstractMachineName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the SEES clauses of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose SEES clauses will be tested. + * @param expected + * an array of expected SEES clause. Each SEES clause is + * represented by its seen context name. The order of the SEES + * clauses is important. + */ + protected void testMachineSeesClauses(String message, IMachineRoot mch, + String... expected) { + try { + ISeesContext[] seesClauses = mch.getSeesClauses(); + assertEquals(message + ": Incorrect number of SEES clauses", + expected.length, seesClauses.length); + for (int i = 0; i < expected.length; i++) { + testSeesClause(message, seesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a SEES clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the SEES clause under test. + * @param expected + * the expected seen context name of the SEES clause. + */ + protected void testSeesClause(String message, ISeesContext seesClause, + String expected) { + try { + assertEquals(message + ": Incorrect SEES clause", expected, + seesClause.getSeenContextName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the variables of a machine. + * + * @param message + * a message for debugging. + * @param mch + * the machine root whose variables will be tested. + * @param expected + * an array of expected variables. Each variable is represented + * by its identifier. The order of the variables is important. + */ + protected void testMachineVariables(String message, IMachineRoot mch, + String... expected) { + try { + IVariable[] vars = mch.getVariables(); + assertEquals(message + ": Incorrect number of variables", + expected.length, vars.length); + for (int i = 0; i < expected.length; i++) { + testVariable(message, vars[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the variables of a machine. + * + * @param message + * a message for debugging. + * @param mch + * the machine root whose variables will be tested. + * @param expected + * an array of expected variables. Each variable is represented + * by its identifier. The order of the variables is NOT + * important. + */ + protected void testMachineVariablesUnordered(String message, + IMachineRoot mch, String... expected) { + try { + IVariable[] vars = mch.getVariables(); + assertEquals(message + ": Incorrect number of variables", + expected.length, vars.length); + for (int i = 0; i < expected.length; i++) { + boolean b = false; + for (int j = 0; j < vars.length; j++) { + if (vars[j].getIdentifierString().equals(expected[i])) { + b = true; + break; + } + } + if (!b) { + fail("Variable " + expected[i] + " cannot be found"); + } + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a variable. + * + * @param message + * a message for debugging. + * @param var + * the variable under test. + * @param expected + * the expected identifier of the variable. + */ + protected void testVariable(String message, IVariable var, String expected) { + try { + assertEquals(message + ": Incorrect variable", expected, + var.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the invariants of a context. + * + * @param message + * a message for debugging. + * @param mch + * a context root whose invariants will be tested. + * @param expected + * the expected pretty-print invariants. The invariants are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the invariants + * is important. + */ + protected void testMachineInvariants(String message, IMachineRoot mch, + String... expected) { + try { + IInvariant[] invs = mch.getInvariants(); + assertEquals(message + ": Incorrect number of invariants", + expected.length, invs.length); + for (int i = 0; i < expected.length; i++) { + testInvariant(message, invs[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an invariant. + * + * @param message + * a message for debugging. + * @param inv + * the invariant under test. + * @param expected + * the expected pretty-print invariant. The invariant is + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". + */ + protected void testInvariant(String message, IInvariant inv, String expected) { + try { + assertEquals( + message + ": Incorrect invariant", + expected, + inv.getLabel() + ":" + inv.getPredicateString() + ":" + + inv.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the events of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose events will be tested. + * @param expected + * the expected pretty-print events (only the signature). The + * events are "pretty-printed" as follows: + * "label:convergent:isExtended". The order of the events is + * important. + */ + protected void testMachineEvents(String message, IMachineRoot mch, + String... expected) { + try { + IEvent[] evts = mch.getEvents(); + assertEquals(message + ": Incorrect number of events", + expected.length, evts.length); + for (int i = 0; i < expected.length; i++) { + testEvent(message, evts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an event. + * + * @param message + * a message for debugging. + * @param evt + * the event under test. + * @param expected + * the expected pretty-print event (only the signature). The + * event is "pretty-printed" as follows: + * "label:convergent:isExtended". + */ + protected void testEvent(String message, IEvent evt, String expected) { + try { + assertNotNull(message + ": The event must not be null", evt); + assertEquals( + message + ": Incorrect event", + expected, + evt.getLabel() + ":" + evt.getConvergence() + ":" + + evt.isExtended()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the REFINES clauses of an event. + * + * @param message + * a message for debugging. + * @param mch + * an event whose REFINES clauses will be tested. + * @param expected + * an array of expected REFINES clause. Each REFINES clause is + * represented by its abstract event name. The order of the + * REFINES clauses is important. + */ + protected void testEventRefinesClauses(String message, IEvent evt, + String... expected) { + try { + IRefinesEvent[] refinesClauses = evt.getRefinesClauses(); + assertEquals(message + ": Incorrect number of REFINES clauses", + expected.length, refinesClauses.length); + for (int i = 0; i < expected.length; i++) { + testRefinesClause(message, refinesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a REFINES (event) clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the REFINES (event) clause under test. + * @param expected + * the expected abstract event name of the REFINES clause. + */ + protected void testRefinesClause(String message, + IRefinesEvent refinesEvent, String expected) { + try { + assertEquals(message + "Incorrect REFINES clause", expected, + refinesEvent.getAbstractEventLabel()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the parameters of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose parameters will be tested. + * @param expected + * the expected set of parameters. Each parameter is represented + * by its identifier. The order of the parameters is important. + */ + protected void testEventParameters(String message, IEvent evt, + String... expected) { + try { + IParameter[] params = evt.getParameters(); + assertEquals(message + ": Incorrect number of parameters", + expected.length, params.length); + for (int i = 0; i < expected.length; i++) { + testParameter(message, params[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a parameter. + * + * @param message + * a message for debugging. + * @param par + * the parameter under test. + * @param expected + * the expected parameter identifier. + */ + protected void testParameter(String message, IParameter par, String expected) { + try { + assertEquals(message + ": Incorrect parameter", expected, + par.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the guards of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose guards will be tested. + * @param expected + * the expected pretty-print guards. The guards are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the guards is + * important. + */ + protected void testEventGuards(String message, IEvent evt, + String... expected) { + try { + IGuard[] grds = evt.getGuards(); + assertEquals(message + ": Incorrect number of guards", + expected.length, grds.length); + for (int i = 0; i < grds.length; i++) { + testGuard(message, grds[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a guard. + * + * @param message + * a message for debugging. + * @param grd + * the guard under test. + * @param expected + * the expected pretty-print guard. The guard is "pretty-printed" + * as follows: "label:predicateString:isTheorem". + */ + protected void testGuard(String message, IGuard grd, String expected) { + try { + assertEquals( + message + ": Incorrect guard", + expected, + grd.getLabel() + ":" + grd.getPredicateString() + ":" + + grd.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the witnesses of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose witnesses will be tested. + * @param expected + * the expected pretty-print witnesses. The witnesses are + * "pretty-printed" as follows: "label:predicateString". The + * order of the witnesses is important. + */ + protected void testEventWitnesses(String message, IEvent evt, + String... expected) { + try { + IWitness[] wits = evt.getWitnesses(); + assertEquals(message + ": Incorrect number of witnesses", + expected.length, wits.length); + for (int i = 0; i < expected.length; i++) { + testWitness(message, wits[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an witness. + * + * @param message + * a message for debugging. + * @param wit + * the witness under test. + * @param expected + * the expected pretty-print witness. The witness is + * "pretty-printed" as follows: "label:predicateString". + */ + protected void testWitness(String message, IWitness wit, String expected) { + try { + assertEquals(message + ": Incorrect witness", expected, + wit.getLabel() + ":" + wit.getPredicateString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the actions of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose actions will be tested. + * @param expected + * expected pretty-print actions. The actions are + * "pretty-printed" as follows: "label:assignmentString". The + * order of the actions is important. + */ + protected void testEventActions(String message, IEvent evt, + String... expected) { + try { + IAction[] acts = evt.getActions(); + assertEquals(message + ": Incorrect number of actions", + expected.length, acts.length); + for (int i = 0; i < expected.length; i++) { + testAction(message, acts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an action. + * + * @param message + * a message + * @param act + * the action under test + * @param expected + * expected pretty-print action. The action is "pretty-printed" + * as follows: "label:assignmentString". + */ + protected void testAction(String message, IAction act, String expected) { + try { + assertEquals(message + ": Incorrect action", expected, + act.getLabel() + ":" + act.getAssignmentString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractTests.java b/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractTests.java new file mode 100644 index 0000000000000000000000000000000000000000..16ad5fe3312d45a2ef79b644d050f9b30beb2472 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/AbstractTests.java @@ -0,0 +1,143 @@ +package de.prob.core.translator.tests; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +/** + * @author htson + * <p> + * This abstract class contains utility methods supporting testing. + * </p> + */ +public abstract class AbstractTests extends TestCase { + + /** + * Constructor: Create max_size test case. + */ + public AbstractTests() { + super(); + } + + /** + * Constructor: Create max_size test case with the given name. + * + * @param name + * the name of test + */ + public AbstractTests(String name) { + super(name); + } + + /** + * Utility method to compare two string collections. The expected collection + * is given in terms of an array of strings. The actual collection is given + * as a collection of strings. The two are the same if the number of + * elements is the same and every element of the expected collection appear + * in the actual collection. + * + * @param msg + * a message. + * @param actual + * actual collection of strings. + * @param expected + * expected array of strings. + */ + protected static void assertSameStrings(String msg, + Collection<String> actual, String... expected) { + assertEquals(msg + ": Incorrect number of elements\n", expected.length, + actual.size()); + for (String exp : expected) { + assertTrue(msg + ": Expected element " + exp + " not found", + actual.contains(exp)); + } + } + + /** + * Utility method to compare two arrays of strings. The two are the same if + * the number of elements is the same, and the strings at the same index are + * the same. + * + * @param msg + * a message. + * @param actual + * actual array of strings. + * @param expected + * expected array of strings. + */ + protected static void assertSameStrings(String msg, String[] actual, + String... expected) { + assertEquals(msg + ": Incorrect number of strings\n", expected.length, + actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(msg, expected[i], actual[i]); + } + } + + /** + * Utility method to compare two arrays of objects. The two are the same if + * the number of elements is the same, and the objects at the same index are + * the same. + * + * @param msg + * a message. + * @param expected + * expected array of objects. + * @param actual + * actual array of objects. + */ + protected static void assertSameObjects(String msg, Object[] expected, + Object[] actual) { + assertEquals(msg + ": Incorrect number of objects\n", expected.length, + actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(msg, expected[i], actual[i]); + } + } + + /** + * Utility method to compare two maps of objects to objects. The two are the + * same if the key sets are the same (using + * {@link #assertSameSet(String, Set, Set)}), and for each key, they map to + * the same value. + * + * @param msg + * a messages. + * @param expected + * expected map. + * @param actual + * actual map. + */ + protected void assertSameMap(String msg, + Map<? extends Object, ? extends Object> expected, + Map<? extends Object, ? extends Object> actual) { + Set<? extends Object> expectedKeySet = expected.keySet(); + Set<? extends Object> actualKeySet = actual.keySet(); + assertSameSet(msg, expectedKeySet, actualKeySet); + for (Object key : expectedKeySet) { + assertEquals(msg, expected.get(key), actual.get(key)); + } + } + + /** + * Utility method to compare two sets of objects. The two are the same if + * they have the same number of elements, and each element of the expected + * set appears in the actual set. + * + * @param msg + * @param expected + * @param actual + */ + protected void assertSameSet(String msg, Set<? extends Object> expected, + Set<? extends Object> actual) { + assertEquals(msg + ": The number of elements must be the same", + expected.size(), actual.size()); + for (Object elm : expected) { + assertTrue(msg + ": expected element " + elm + " not found", + actual.contains(elm)); + } + } + +} \ No newline at end of file diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/ContextChainTest.java b/de.prob.core.tests/src/de/prob/core/translator/tests/ContextChainTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e90424fdc0b37f6af65d88f6f37754667d91b41a --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/ContextChainTest.java @@ -0,0 +1,47 @@ +package de.prob.core.translator.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.junit.Before; +import org.junit.Test; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; + +public class ContextChainTest extends AbstractEventBTests { + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Test + public void testEmptyContextChain() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context1 = createContext(project, "TestContext1"); + IContextRoot context2 = createContext(project, "TestContext2"); + + createExtendsContextClause(context2, "TestContext1"); + + context1.getRodinFile().save(monitor, false); + context2.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + TranslatorFactory.translate(context2, writer); + + assertEquals( + "package(load_event_b_project([],[event_b_context(none,'TestContext2',[extends(none,['TestContext1']),constants(none,[]),axioms(none,[]),theorems(none,[]),sets(none,[])]),event_b_context(none,'TestContext1',[extends(none,[]),constants(none,[]),axioms(none,[]),theorems(none,[]),sets(none,[])])],[exporter_version(2)],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/ContextWithConstantsTest.java b/de.prob.core.tests/src/de/prob/core/translator/tests/ContextWithConstantsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..aba625b16d3b6a5d3a281fe50fc9932491f8c931 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/ContextWithConstantsTest.java @@ -0,0 +1,52 @@ +package de.prob.core.translator.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.junit.Before; +import org.junit.Test; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; + +public class ContextWithConstantsTest extends AbstractEventBTests { + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Test + public void testContextWithConstants() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + createConstant(context, "cst1"); + createAxiom(context, "axm1", "cst1=5", false); + + // save file and build workspace - this triggers static check, and + // generates missing files + context.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one constant and one SC constant + assertEquals(1, context.getConstants().length); + assertEquals(1, context.getSCContextRoot().getSCConstants().length); + + TranslatorFactory.translate(context, writer); + + assertEquals( + "package(load_event_b_project([],[event_b_context(none,'TestContext',[extends(none,[]),constants(none,[identifier(none,cst1)]),axioms(none,[equal(rodinpos('TestContext',axm1,'('),identifier(none,cst1),integer(none,5))]),theorems(none,[]),sets(none,[])])],[exporter_version(2)],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/EmptyTranslationsTest.java b/de.prob.core.tests/src/de/prob/core/translator/tests/EmptyTranslationsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..363e449d7064ff666fe87a31b11049db6a375cf0 --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/EmptyTranslationsTest.java @@ -0,0 +1,60 @@ +package de.prob.core.translator.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; +import org.junit.Before; +import org.junit.Test; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; + +public class EmptyTranslationsTest extends AbstractEventBTests { + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Test + public void testEmptyMachine() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + TranslatorFactory.translate(machine, writer); + + assertEquals( + "package(load_event_b_project([event_b_model(none,'TestMachine',[sees(none,[]),variables(none,[]),invariant(none,[]),theorems(none,[]),events(none,[])])],[],[exporter_version(2)],_Error)).\n", + stringWriter.getBuffer().toString()); + } + + @Test + public void testEmptyContext() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + context.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + TranslatorFactory.translate(context, writer); + + assertEquals( + "package(load_event_b_project([],[event_b_context(none,'TestContext',[extends(none,[]),constants(none,[]),axioms(none,[]),theorems(none,[]),sets(none,[])])],[exporter_version(2)],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.core.tests/src/de/prob/core/translator/tests/MachineWithVariablesTest.java b/de.prob.core.tests/src/de/prob/core/translator/tests/MachineWithVariablesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c83248044d49486ab327e6afb0fca1da7f2ce12c --- /dev/null +++ b/de.prob.core.tests/src/de/prob/core/translator/tests/MachineWithVariablesTest.java @@ -0,0 +1,52 @@ +package de.prob.core.translator.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; +import org.junit.Before; +import org.junit.Test; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; + +public class MachineWithVariablesTest extends AbstractEventBTests { + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Test + public void testMachineWithVariables() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + createVariable(machine, "v1"); + createInvariant(machine, "inv1", "v1=5", false); + + // save file and build workspace - this triggers static check, and + // generates missing files + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one variable and one SC variable + assertEquals(1, machine.getVariables().length); + assertEquals(1, machine.getSCMachineRoot().getSCVariables().length); + + TranslatorFactory.translate(machine, writer); + + assertEquals( + "package(load_event_b_project([event_b_model(none,'TestMachine',[sees(none,[]),variables(none,[identifier(none,v1)]),invariant(none,[equal(rodinpos('TestMachine',inv1,'('),identifier(none,v1),integer(none,5))]),theorems(none,[]),events(none,[])])],[],[exporter_version(2)],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.core/.classpath b/de.prob.core/.classpath index 0c07df9acec38ff19ac4da7324df32c2f1dc510e..21c83eda765b2559c5b944a30062af3fb6955a1f 100644 --- a/de.prob.core/.classpath +++ b/de.prob.core/.classpath @@ -1,21 +1,21 @@ <?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 exported="true" kind="lib" path="lib/dependencies/answerparser-2.4.12-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/bparser-2.4.12-SNAPSHOT.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/cliparser-2.4.12-SNAPSHOT.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/commons-codec-1.6.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/xmlpull-1.1.3.1.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/xpp3_min-1.1.4c.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/xstream-1.4.3.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/commons-lang-2.6.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/jgrapht-0.8.3.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/jsr305-1.3.9.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/ltlparser-2.4.12-SNAPSHOT.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/parserbase-2.4.12-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/answerparser-2.4.12-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/cliparser-2.4.12-SNAPSHOT.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/prologlib-2.4.12-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/bparser-2.4.12-SNAPSHOT.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/unicode-2.4.12-SNAPSHOT.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/ltlparser-2.4.12-SNAPSHOT.jar"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/xmlpull-1.1.3.1.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/xpp3_min-1.1.4c.jar"/> + <classpathentry exported="true" kind="lib" path="lib/dependencies/xstream-1.4.3.jar"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/de.prob.core/META-INF/MANIFEST.MF b/de.prob.core/META-INF/MANIFEST.MF index 39ced3dd508fa9a2c36c9c774901ec4167a1b852..f294dd34c178468f36b26bcd9d7c232658361103 100644 --- a/de.prob.core/META-INF/MANIFEST.MF +++ b/de.prob.core/META-INF/MANIFEST.MF @@ -70,7 +70,6 @@ Export-Package: com.thoughtworks.xstream, de.prob.core.domainobjects, de.prob.core.domainobjects.eval, de.prob.core.domainobjects.ltl, - de.prob.core.domainobjects.ltl.unittests, de.prob.core.internal, de.prob.core.langdep, de.prob.core.prolog, @@ -115,23 +114,17 @@ Bundle-Activator: de.prob.core.internal.Activator Eclipse-BuddyPolicy: registered Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ClassPath: ., - lib/dependencies/ltlparser-2.4.12-SNAPSHOT.jar, - lib/dependencies/unicode-2.4.12-SNAPSHOT.jar, - lib/dependencies/prologlib-2.4.12-SNAPSHOT.jar, - lib/dependencies/cliparser-2.4.12-SNAPSHOT.jar, lib/dependencies/answerparser-2.4.12-SNAPSHOT.jar, - lib/dependencies/parserbase-2.4.12-SNAPSHOT.jar, - lib/dependencies/answerparser-2.4.8-SNAPSHOT.jar, lib/dependencies/bparser-2.4.12-SNAPSHOT.jar, - lib/dependencies/cliparser-2.4.8-SNAPSHOT.jar, + lib/dependencies/cliparser-2.4.12-SNAPSHOT.jar, + lib/dependencies/commons-codec-1.6.jar, + lib/dependencies/parserbase-2.4.12-SNAPSHOT.jar, lib/dependencies/commons-lang-2.6.jar, lib/dependencies/jgrapht-0.8.3.jar, lib/dependencies/jsr305-1.3.9.jar, - lib/dependencies/ltlparser-2.4.8-SNAPSHOT.jar, - lib/dependencies/parserbase-2.4.8-SNAPSHOT.jar, - lib/dependencies/prologlib-2.4.8-SNAPSHOT.jar, - lib/dependencies/unicode-2.4.8-SNAPSHOT.jar, - lib/dependencies/commons-codec-1.6.jar, + lib/dependencies/ltlparser-2.4.12-SNAPSHOT.jar, + lib/dependencies/prologlib-2.4.12-SNAPSHOT.jar, + lib/dependencies/unicode-2.4.12-SNAPSHOT.jar, lib/dependencies/xmlpull-1.1.3.1.jar, lib/dependencies/xpp3_min-1.1.4c.jar, lib/dependencies/xstream-1.4.3.jar diff --git a/de.prob.core/src/de/prob/core/command/ActivateUnitPluginCommand.java b/de.prob.core/src/de/prob/core/command/ActivateUnitPluginCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..5071e60e1f179908b6a1d438c12b818c408407ac --- /dev/null +++ b/de.prob.core/src/de/prob/core/command/ActivateUnitPluginCommand.java @@ -0,0 +1,57 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.command; + +import de.prob.core.Animator; +import de.prob.exceptions.ProBException; +import de.prob.parser.ISimplifiedROMap; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.PrologTerm; + +public class ActivateUnitPluginCommand implements IComposableCommand { + + private static final ActivateCmd ACTIVATE_CMD = new ActivateCmd(); + private final GetPrologRandomSeed getRandomSeed; + private final ComposedCommand cmd; + + public ActivateUnitPluginCommand() { + this.getRandomSeed = new GetPrologRandomSeed(); + this.cmd = new ComposedCommand(getRandomSeed, ACTIVATE_CMD); + } + + public static void activateUnitPlugin(final Animator animator) + throws ProBException { + animator.execute(new ActivateUnitPluginCommand()); + } + + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + cmd.processResult(bindings); + final Animator animator = Animator.getAnimator(); + animator.setRandomSeed(getRandomSeed.getSeed()); + } + + public void writeCommand(final IPrologTermOutput pto) + throws CommandException { + cmd.writeCommand(pto); + } + + private final static class ActivateCmd implements IComposableCommand { + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + } + + public void writeCommand(final IPrologTermOutput pto) { + pto.openTerm("activate_plugin"); + pto.printAtom("units"); + pto.closeTerm(); + } + } + +} diff --git a/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java b/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..7e28630bcfeb68b3da763a24c6bae25b8e93fd85 --- /dev/null +++ b/de.prob.core/src/de/prob/core/command/GetPluginResultCommand.java @@ -0,0 +1,50 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.command; + +import de.prob.parser.BindingGenerator; +import de.prob.parser.ISimplifiedROMap; +import de.prob.parser.ResultParserException; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.CompoundPrologTerm; +import de.prob.prolog.term.PrologTerm; + +public final class GetPluginResultCommand implements IComposableCommand { + + private final String resultID; + private CompoundPrologTerm result; + + public GetPluginResultCommand(final String resultID) { + this.resultID = resultID; + } + + public CompoundPrologTerm getResult() { + return result; + } + + @Override + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + try { + result = BindingGenerator.getCompoundTerm(bindings.get("Bindings"), + 1); + } catch (ResultParserException e) { + CommandException commandException = new CommandException( + e.getLocalizedMessage(), e); + commandException.notifyUserOnce(); + throw commandException; + } + } + + @Override + public void writeCommand(final IPrologTermOutput pto) { + pto.openTerm("get_plugin_output").printAtomOrNumber(resultID) + .printVariable("Bindings").closeTerm(); + } + +} diff --git a/de.prob.core/src/de/prob/core/command/LoadEventBModelCommand.java b/de.prob.core/src/de/prob/core/command/LoadEventBModelCommand.java index 316d436cfb029a75fd3232548ee3415f178854a1..78335f27dbe8219e1129b5286e771ac514283b15 100644 --- a/de.prob.core/src/de/prob/core/command/LoadEventBModelCommand.java +++ b/de.prob.core/src/de/prob/core/command/LoadEventBModelCommand.java @@ -19,17 +19,15 @@ import org.rodinp.core.RodinDBException; import de.prob.core.Animator; import de.prob.core.LanguageDependendAnimationPart; +import de.prob.core.command.internal.InternalLoadCommand; import de.prob.core.domainobjects.MachineDescription; import de.prob.core.domainobjects.Operation; import de.prob.core.domainobjects.ProBPreference; import de.prob.core.domainobjects.State; import de.prob.core.langdep.EventBAnimatorPart; -import de.prob.core.translator.TranslationFailedException; -import de.prob.eventb.translator.TranslatorFactory; import de.prob.exceptions.ProBException; import de.prob.logging.Logger; import de.prob.parser.ISimplifiedROMap; -import de.prob.prolog.output.IPrologTermOutput; import de.prob.prolog.output.StructuredPrologOutput; import de.prob.prolog.term.PrologTerm; @@ -162,32 +160,4 @@ public final class LoadEventBModelCommand { animator.announceReset(); } } - - private static class InternalLoadCommand implements IComposableCommand { - private final IEventBRoot model; - - public InternalLoadCommand(final IEventBRoot model) { - this.model = model; - } - - @Override - public void writeCommand(final IPrologTermOutput pto) - throws CommandException { - try { - TranslatorFactory.translate(model, pto); - } catch (TranslationFailedException e) { - throw new CommandException( - "Translation from Event-B to ProB's internal representation failed", - e); - } - } - - @Override - public void processResult( - final ISimplifiedROMap<String, PrologTerm> bindings) - throws CommandException { - // there are no results to process - } - - } } diff --git a/de.prob.core/src/de/prob/core/command/internal/InternalLoadCommand.java b/de.prob.core/src/de/prob/core/command/internal/InternalLoadCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..2a3eaf98d4fd0b82a4a4718c0878d2366bf08e67 --- /dev/null +++ b/de.prob.core/src/de/prob/core/command/internal/InternalLoadCommand.java @@ -0,0 +1,39 @@ +package de.prob.core.command.internal; + +import org.eventb.core.IEventBRoot; + +import de.prob.core.command.CommandException; +import de.prob.core.command.IComposableCommand; +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; +import de.prob.parser.ISimplifiedROMap; +import de.prob.prolog.output.IPrologTermOutput; +import de.prob.prolog.term.PrologTerm; + +public final class InternalLoadCommand implements IComposableCommand { + private final IEventBRoot model; + + public InternalLoadCommand(final IEventBRoot model) { + this.model = model; + } + + @Override + public void writeCommand(final IPrologTermOutput pto) + throws CommandException { + try { + TranslatorFactory.translate(model, pto); + } catch (TranslationFailedException e) { + throw new CommandException( + "Translation from Event-B to ProB's internal representation failed", + e); + } + } + + @Override + public void processResult( + final ISimplifiedROMap<String, PrologTerm> bindings) + throws CommandException { + // there are no results to process + } + +} \ No newline at end of file diff --git a/de.prob.core/src/de/prob/core/translator/pragmas/IPragma.java b/de.prob.core/src/de/prob/core/translator/pragmas/IPragma.java new file mode 100644 index 0000000000000000000000000000000000000000..aa8994a965629cc4da6ca5c395c7a05cfcb83512 --- /dev/null +++ b/de.prob.core/src/de/prob/core/translator/pragmas/IPragma.java @@ -0,0 +1,15 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.translator.pragmas; + +import de.prob.prolog.output.IPrologTermOutput; + +public interface IPragma { + + void output(IPrologTermOutput pout); + +} diff --git a/de.prob.core/src/de/prob/core/translator/pragmas/UnitPragma.java b/de.prob.core/src/de/prob/core/translator/pragmas/UnitPragma.java new file mode 100644 index 0000000000000000000000000000000000000000..a1b5fd09d13a81b4e05149e7ca95aae0a2c76acd --- /dev/null +++ b/de.prob.core/src/de/prob/core/translator/pragmas/UnitPragma.java @@ -0,0 +1,34 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.core.translator.pragmas; + +import de.prob.prolog.output.IPrologTermOutput; + +public class UnitPragma implements IPragma { + private String definedIn; + private String attachedTo; + private String content; + + public UnitPragma(String definedIn, String attachedTo, String content) { + this.definedIn = definedIn; + this.attachedTo = attachedTo; + this.content = content; + } + + @Override + public void output(IPrologTermOutput pout) { + pout.openTerm("pragma"); + pout.printAtom("unit"); + pout.printAtom(definedIn); + pout.printAtom(attachedTo); + pout.openList(); + pout.printAtom(content); + pout.closeList(); + pout.closeTerm(); + } + +} diff --git a/de.prob.core/src/de/prob/eventb/translator/ContextTranslator.java b/de.prob.core/src/de/prob/eventb/translator/ContextTranslator.java index 9ea99009688c58a066ad0add611d91b1e6a429a6..1aac01119a383440f0ba891102a809a79bb853bd 100644 --- a/de.prob.core/src/de/prob/eventb/translator/ContextTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/ContextTranslator.java @@ -13,11 +13,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.eclipse.core.runtime.Assert; -import org.eventb.core.IAxiom; import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBRoot; import org.eventb.core.IExtendsContext; +import org.eventb.core.ILabeledElement; import org.eventb.core.IPOSequent; import org.eventb.core.IPOSource; import org.eventb.core.IPSRoot; @@ -29,13 +29,15 @@ import org.eventb.core.ISCContext; import org.eventb.core.ISCContextRoot; import org.eventb.core.ISCExtendsContext; import org.eventb.core.ISCInternalContext; -import org.eventb.core.ISCMachineRoot; import org.eventb.core.ast.FormulaFactory; import org.eventb.core.ast.ITypeEnvironment; import org.eventb.core.seqprover.IConfidence; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.IInternalElement; import org.rodinp.core.IRodinElement; import org.rodinp.core.IRodinFile; import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinCore; import org.rodinp.core.RodinDBException; import de.be4.classicalb.core.parser.analysis.pragma.internal.ClassifiedPragma; @@ -54,8 +56,11 @@ import de.be4.classicalb.core.parser.node.PSet; import de.be4.classicalb.core.parser.node.TIdentifierLiteral; import de.hhu.stups.sablecc.patch.SourcePosition; import de.prob.core.translator.TranslationFailedException; -import de.prob.eventb.translator.internal.DischargedProof; -import de.prob.logging.Logger; +import de.prob.core.translator.pragmas.IPragma; +import de.prob.core.translator.pragmas.UnitPragma; +import de.prob.eventb.translator.internal.EProofStatus; +import de.prob.eventb.translator.internal.ProofObligation; +import de.prob.eventb.translator.internal.SequentSource; public final class ContextTranslator extends AbstractComponentTranslator { @@ -63,23 +68,74 @@ public final class ContextTranslator extends AbstractComponentTranslator { private final ISCContext context; private final AEventBContextParseUnit model = new AEventBContextParseUnit(); private final Map<String, ISCContext> depContext = new HashMap<String, ISCContext>(); - private final List<DischargedProof> proofs = new ArrayList<DischargedProof>(); + private final List<ProofObligation> proofs = new ArrayList<ProofObligation>(); private final List<ClassifiedPragma> proofspragmas = new ArrayList<ClassifiedPragma>(); + private final List<IPragma> pragmas = new ArrayList<IPragma>(); + + private final IEventBRoot root; private final FormulaFactory ff; - private ITypeEnvironment te; + private final ITypeEnvironment te; + + public static ContextTranslator create(final ISCContextRoot context) + throws TranslationFailedException { + try { + assertConsistentModel(context); + final FormulaFactory ff = context.getFormulaFactory(); + final ITypeEnvironment te = context.getTypeEnvironment(ff); + final ContextTranslator translator = new ContextTranslator(context, + ff, te, context); + translator.translate(); + return translator; + } catch (RodinDBException e) { + throw createTranslationFailedException(context, e); + } + } - public static ContextTranslator create(final ISCContext context) + public static ContextTranslator create(final ISCInternalContext context, + final FormulaFactory ff, final ITypeEnvironment te) throws TranslationFailedException { - ContextTranslator contextTranslator = new ContextTranslator(context); + final IEventBRoot root = getRootContext(context); + final ContextTranslator translator = new ContextTranslator(context, ff, + te, root); try { - (new TheoryTranslator()).translate(); - contextTranslator.translate(); + assertConsistentModel(context.getRoot()); + translator.translate(); } catch (RodinDBException e) { - final String message = "A Rodin exception occured during translation process. Possible cause: building aborted or still in progress. Please wait until building has finished before starting ProB. If this does not help, perform a clean and start ProB after building has finished. Original Exception: "; - throw new TranslationFailedException(context.getComponentName(), - message + e.getLocalizedMessage()); + throw createTranslationFailedException(context, e); + } + return translator; + } + + private static IEventBRoot getRootContext(ISCInternalContext context) { + try { + String elementName = context.getElementName(); + IRodinProject rodinProject = context.getRodinProject(); + IRodinFile rodinFile = rodinProject.getRodinFile(elementName + + ".bcc"); + if (rodinFile.exists()) { + final IInternalElement element = rodinFile.getRoot(); + if (element instanceof IEventBRoot) { + return (IEventBRoot) element; + } + } + } catch (Exception e) { + // We do not guarantee to include proof infos. If something goes + // wrong, we ignore the Proof info. } - return contextTranslator; + return null; + } + + private static TranslationFailedException createTranslationFailedException( + final ISCContext context, RodinDBException e) + throws TranslationFailedException { + final String message = "A Rodin exception occured during translation process. Possible cause: building aborted or still in progress. Please wait until building has finished before starting ProB. If this does not help, perform a clean and start ProB after building has finished. Original Exception: "; + return new TranslationFailedException(context.getComponentName(), + message + e.getLocalizedMessage()); + } + + private static boolean assertConsistentModel(IInternalElement machine_root) + throws RodinDBException { + return Assert.isTrue(machine_root.getRodinFile().isConsistent()); } /** @@ -89,57 +145,63 @@ public final class ContextTranslator extends AbstractComponentTranslator { * contains errors) * * @param context + * The context to translate + * @param ff + * The FormulaFactory needed to extract the predicates + * @param te + * The TypeEnvironment needed to extract the predicates + * @param root + * the root to access the proofs * @throws TranslationFailedException - * @throws RodinDBException */ - private ContextTranslator(final ISCContext context) - throws TranslationFailedException { + private ContextTranslator(final ISCContext context, + final FormulaFactory ff, final ITypeEnvironment te, + final IEventBRoot root) throws TranslationFailedException { this.context = context; - ff = ((ISCContextRoot) context).getFormulaFactory(); - try { - te = ((ISCContextRoot) context).getTypeEnvironment(ff); - } catch (RodinDBException e) { - final String message = "A Rodin exception occured during translation process. Original Exception: "; - throw new TranslationFailedException(context.getComponentName(), - message + e.getLocalizedMessage()); - } + this.ff = ff; + this.te = te; + this.root = root; } private void translate() throws RodinDBException { - if (context instanceof ISCContextRoot) { - ISCContextRoot context_root = (ISCContextRoot) context; - Assert.isTrue(context_root.getRodinFile().isConsistent()); - te = context_root.getTypeEnvironment(ff); - } else if (context instanceof ISCInternalContext) { - ISCInternalContext context_internal = (ISCInternalContext) context; - - try { - - String elementName = context_internal.getElementName(); - IRodinProject rodinProject = context_internal.getRodinProject(); - IRodinFile rodinFile = rodinProject.getRodinFile(elementName - + ".bcc"); - if (rodinFile.exists()) { - ISCContextRoot root = (ISCContextRoot) rodinFile.getRoot(); - collectProofInfo(root); + translateContext(); + collectProofInfo(); + collectPragmas(); + } + + private void collectPragmas() throws RodinDBException { + // unit pragma, attached to constants + try { + final IAttributeType.String UNITATTRIBUTE = RodinCore + .getStringAttrType("de.prob.units.unitPragmaAttribute"); + + final ISCConstant[] constants = context.getSCConstants(); + + for (final ISCConstant constant : constants) { + if (constant.hasAttribute(UNITATTRIBUTE)) { + String content = constant.getAttributeValue(UNITATTRIBUTE); + + if (!content.isEmpty()) { + pragmas.add(new UnitPragma(getResource(), constant + .getIdentifierString(), content)); + } } - } catch (Exception e) { - // We do not guarantee to include proof infos. If something goes - // wrong, we ignore the Proof info. } - - ISCMachineRoot machine_root = (ISCMachineRoot) context_internal - .getRoot(); - Assert.isTrue(machine_root.getRodinFile().isConsistent()); + } catch (IllegalArgumentException ex) { + // Happens if the attribute does not exist, i.e. the unit plugin is + // not installed } - translateContext(); + } + private void collectProofInfo() throws RodinDBException { + if (root != null) { + collectProofInfo(root); + } } - private void collectProofInfo(ISCContextRoot context_root) - throws RodinDBException { + private void collectProofInfo(IEventBRoot origin) throws RodinDBException { - IPSRoot proofStatus = context_root.getPSRoot(); + IPSRoot proofStatus = origin.getPSRoot(); IPSStatus[] statuses = proofStatus.getStatuses(); List<String> bugs = new LinkedList<String>(); @@ -147,34 +209,37 @@ public final class ContextTranslator extends AbstractComponentTranslator { for (IPSStatus status : statuses) { final int confidence = status.getConfidence(); boolean broken = status.isBroken(); - if (!broken && confidence == IConfidence.DISCHARGED_MAX) { - IPOSequent sequent = status.getPOSequent(); - IPOSource[] sources = sequent.getSources(); - for (IPOSource source : sources) { + EProofStatus pstatus = EProofStatus.UNPROVEN; - IRodinElement srcElement = source.getSource(); - if (!srcElement.exists()) { - bugs.add(status.getElementName()); - break; - } + if (!broken && confidence == IConfidence.REVIEWED_MAX) + pstatus = EProofStatus.REVIEWED; + if (!broken && confidence == IConfidence.DISCHARGED_MAX) + pstatus = EProofStatus.PROVEN; - if (srcElement instanceof IAxiom) { - IAxiom tmp = (IAxiom) srcElement; - if (((IContextRoot) tmp.getParent()) - .equals(context_root.getContextRoot())) { - proofs.add(new DischargedProof(context_root, tmp, - null)); - } - } + IPOSequent sequent = status.getPOSequent(); + IPOSource[] sources = sequent.getSources(); + + String name = sequent.getDescription(); + + ArrayList<SequentSource> s = new ArrayList<SequentSource>( + sources.length); + for (IPOSource source : sources) { + + IRodinElement srcElement = source.getSource(); + if (!srcElement.exists() + || !(srcElement instanceof ILabeledElement)) { + bugs.add(status.getElementName()); + break; } - } - } - if (!bugs.isEmpty()) { - String message = "Translation incomplete due to a Bug in Rodin. This does not affect correctness of the Animation/Model Checking but can decrease its performance. Skipped discharged information about: " - + StringUtils.join(bugs, ","); - Logger.notifyUser(message); + ILabeledElement le = (ILabeledElement) srcElement; + + s.add(new SequentSource(srcElement.getElementType(), le + .getLabel())); + + } + proofs.add(new ProofObligation(origin, s, name, pstatus)); } } @@ -314,26 +379,29 @@ public final class ContextTranslator extends AbstractComponentTranslator { final List<PPredicate> list = new ArrayList<PPredicate>( predicates.length); for (final ISCAxiom element : predicates) { - if (element.isTheorem() != theorems) { - continue; + if (element.isTheorem() == theorems) { + final PredicateVisitor visitor = new PredicateVisitor( + new LinkedList<String>()); + element.getPredicate(ff, te).accept(visitor); + final PPredicate predicate = visitor.getPredicate(); + list.add(predicate); + labelMapping.put(predicate, element); + proofspragmas.add(new ClassifiedPragma("discharged", predicate, + Arrays.asList(new String[0]), Arrays + .asList(new String[0]), NO_POS, NO_POS)); } - final PredicateVisitor visitor = new PredicateVisitor( - new LinkedList<String>()); - element.getPredicate(ff, te).accept(visitor); - final PPredicate predicate = visitor.getPredicate(); - list.add(predicate); - labelMapping.put(predicate, element); - proofspragmas.add(new ClassifiedPragma("discharged", predicate, - Arrays.asList(new String[0]), Arrays.asList(new String[0]), - NO_POS, NO_POS)); } return list; } - public List<DischargedProof> getProofs() { + public List<ProofObligation> getProofs() { return proofs; } + public List<IPragma> getPragmas() { + return pragmas; + } + public List<ClassifiedPragma> getProofspragmas() { return proofspragmas; } diff --git a/de.prob.core/src/de/prob/eventb/translator/ExpressionVisitor.java b/de.prob.core/src/de/prob/eventb/translator/ExpressionVisitor.java index ca9b3232e135a28b232e25574da973447e34dd32..e5dd683078b49390581bfa352f15e59118993338 100644 --- a/de.prob.core/src/de/prob/eventb/translator/ExpressionVisitor.java +++ b/de.prob.core/src/de/prob/eventb/translator/ExpressionVisitor.java @@ -115,6 +115,7 @@ public class ExpressionVisitor extends SimpleVisitorAdapter implements // NOPMD // we need some abilities of the linked list, using List is not an option private boolean expressionSet = false; + @SuppressWarnings("unused") private ExpressionVisitor() { // we want to prevent clients from calling // the default constructor super(); @@ -166,7 +167,8 @@ public class ExpressionVisitor extends SimpleVisitorAdapter implements // NOPMD final PPredicate pr = predicateVisitor.getPredicate(); - final ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + final ExpressionVisitor expressionVisitor = new ExpressionVisitor( + bounds); expression.getExpression().accept(expressionVisitor); final PExpression ex = expressionVisitor.getExpression(); diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/EProofStatus.java b/de.prob.core/src/de/prob/eventb/translator/internal/EProofStatus.java new file mode 100644 index 0000000000000000000000000000000000000000..160bf968ce3bd637dea4af99e8b5eea6ee72fd8f --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/internal/EProofStatus.java @@ -0,0 +1,15 @@ +package de.prob.eventb.translator.internal; + +public enum EProofStatus { + UNPROVEN("false"), PROVEN("true"), REVIEWED("reviewed"); + private final String text; + + private EProofStatus(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } +} diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/EventBContextTranslator.java b/de.prob.core/src/de/prob/eventb/translator/internal/EventBContextTranslator.java index ae640ff98a9c1d84b2014b850b42db0f3c2058f3..075270d4ae253ae3aef71dafd9d877e1ee61a433 100644 --- a/de.prob.core/src/de/prob/eventb/translator/internal/EventBContextTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/internal/EventBContextTranslator.java @@ -51,13 +51,15 @@ public final class EventBContextTranslator extends EventBTranslator { private void constructTranslation(final IPrologTermOutput pto) throws TranslationFailedException { - List<ContextTranslator> translators = new ArrayList<ContextTranslator>(); -// translators.add(ContextTranslator.create(context)); + List<ContextTranslator> contextTranslators = new ArrayList<ContextTranslator>(); + + // translators.add(ContextTranslator.create(context)); if (context instanceof ISCContextRoot) { ISCContextRoot root = (ISCContextRoot) context; - collectContexts(translators, new ArrayList<String>(), root); + collectContexts(contextTranslators, new ArrayList<String>(), root); } - printProlog(new ArrayList<ModelTranslator>(), translators, pto); + + printProlog(new ArrayList<ModelTranslator>(), contextTranslators, pto); } private void collectContexts(final List<ContextTranslator> translatorMap, diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/EventBMachineTranslator.java b/de.prob.core/src/de/prob/eventb/translator/internal/EventBMachineTranslator.java index b6ee12f4e13e3fbabecdd6b9ea25020a3f8b907f..845e660ebefc838aed2ec001cf513234c114e16e 100644 --- a/de.prob.core/src/de/prob/eventb/translator/internal/EventBMachineTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/internal/EventBMachineTranslator.java @@ -11,6 +11,8 @@ import java.util.List; import org.eventb.core.ISCInternalContext; import org.eventb.core.ISCMachineRoot; +import org.eventb.core.ast.FormulaFactory; +import org.eventb.core.ast.ITypeEnvironment; import org.rodinp.core.IRodinFile; import org.rodinp.core.RodinDBException; @@ -102,12 +104,14 @@ public final class EventBMachineTranslator extends EventBTranslator { throws TranslationFailedException { final List<ContextTranslator> translators = new ArrayList<ContextTranslator>(); final List<String> processed = new ArrayList<String>(); - for (ISCMachineRoot m : models) { - ISCInternalContext[] seenContexts; + + for (final ISCMachineRoot m : models) { try { - seenContexts = m.getSCSeenContexts(); - for (ISCInternalContext seenContext : seenContexts) { - collectContexts(translators, processed, seenContext); + final FormulaFactory ff = m.getFormulaFactory(); + final ITypeEnvironment te = m.getTypeEnvironment(ff); + final ISCInternalContext[] seenContexts = m.getSCSeenContexts(); + for (final ISCInternalContext seenContext : seenContexts) { + collectContexts(translators, processed, seenContext, ff, te); } } catch (RodinDBException e) { throw new TranslationFailedException(e); @@ -117,12 +121,13 @@ public final class EventBMachineTranslator extends EventBTranslator { } private void collectContexts(final List<ContextTranslator> translatorMap, - final List<String> processed, final ISCInternalContext context) + final List<String> processed, final ISCInternalContext context, + final FormulaFactory ff, final ITypeEnvironment te) throws TranslationFailedException { String name = context.getElementName(); if (!processed.contains(name)) { processed.add(name); - translatorMap.add(ContextTranslator.create(context)); + translatorMap.add(ContextTranslator.create(context, ff, te)); } } diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/EventBTranslator.java b/de.prob.core/src/de/prob/eventb/translator/internal/EventBTranslator.java index dd69c0da5768e348f2f1818aa211b64c955a78e6..02d466b2501dbafc3d19c44414536e0dc6a9c679 100644 --- a/de.prob.core/src/de/prob/eventb/translator/internal/EventBTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/internal/EventBTranslator.java @@ -11,13 +11,11 @@ import java.util.Collection; import java.util.Map; import org.eclipse.core.runtime.Assert; -import org.eventb.core.IEvent; import org.eventb.core.IEventBProject; import org.eventb.core.IEventBRoot; import org.eventb.core.ISCInternalContext; import org.eventb.core.ISCMachineRoot; import org.rodinp.core.IInternalElement; -import org.rodinp.core.RodinDBException; import de.be4.classicalb.core.parser.analysis.prolog.ASTProlog; import de.be4.classicalb.core.parser.node.AEventBContextParseUnit; @@ -25,18 +23,16 @@ import de.be4.classicalb.core.parser.node.AEventBModelParseUnit; import de.be4.classicalb.core.parser.node.Node; import de.prob.core.translator.ITranslator; import de.prob.core.translator.TranslationFailedException; +import de.prob.core.translator.pragmas.IPragma; import de.prob.eventb.translator.AbstractComponentTranslator; import de.prob.eventb.translator.ContextTranslator; -import de.prob.eventb.translator.Theories; import de.prob.prolog.output.IPrologTermOutput; public abstract class EventBTranslator implements ITranslator { protected final IEventBProject project; - private final String name; protected EventBTranslator(final IEventBRoot root) { this.project = root.getEventBProject(); - this.name = root.getComponentName(); } // another constructor to cater for ISCInternalContext (which is not a root @@ -44,7 +40,6 @@ public abstract class EventBTranslator implements ITranslator { protected EventBTranslator(final ISCInternalContext ctx) { Assert.isTrue(ctx.getRoot() instanceof ISCMachineRoot); this.project = ((ISCMachineRoot) ctx.getRoot()).getEventBProject(); - this.name = ctx.getComponentName(); } private LabelPositionPrinter createPrinter( @@ -89,7 +84,7 @@ public abstract class EventBTranslator implements ITranslator { Collection<ContextTranslator> contextTranslators, final IPrologTermOutput pout) throws TranslationFailedException { - ArrayList<DischargedProof> list = new ArrayList<DischargedProof>(); + ArrayList<ProofObligation> list = new ArrayList<ProofObligation>(); for (ContextTranslator contextTranslator : contextTranslators) { list.addAll(contextTranslator.getProofs()); @@ -98,20 +93,19 @@ public abstract class EventBTranslator implements ITranslator { list.addAll(modelTranslator.getProofs()); } - for (DischargedProof proof : list) { - pout.openTerm("discharged"); - pout.printAtom(proof.machine.getRodinFile().getBareName()); - try { - IEvent event = proof.event; - final String elementName = proof.predicate; - if (event != null) - pout.printAtom(event.getLabel()); - pout.printAtom(elementName); - } catch (RodinDBException e) { - final String details = "Translation error while getting information about discharged proof obligations"; - throw new TranslationFailedException(name, details); + for (ProofObligation proof : list) { + pout.openTerm("po"); + pout.printAtom(proof.origin.getRodinFile().getBareName()); + pout.printAtom(proof.kind); + pout.openList(); + for (SequentSource source : proof.sources) { + pout.openTerm(source.type); + pout.printAtom(source.label); + pout.closeTerm(); } + pout.closeList(); + pout.printAtom(proof.discharged.toString()); pout.closeTerm(); } @@ -119,6 +113,24 @@ public abstract class EventBTranslator implements ITranslator { printFlowInformation(pout); } + private void printPragmaContents( + Collection<ModelTranslator> refinementChainTranslators, + Collection<ContextTranslator> contextTranslators, + IPrologTermOutput pout) { + ArrayList<IPragma> pragmas = new ArrayList<IPragma>(); + + for (ContextTranslator contextTranslator : contextTranslators) { + pragmas.addAll(contextTranslator.getPragmas()); + } + for (ModelTranslator modelTranslator : refinementChainTranslators) { + pragmas.addAll(modelTranslator.getPragmas()); + } + + for (IPragma pragma : pragmas) { + pragma.output(pout); + } + } + protected abstract void printFlowInformation(final IPrologTermOutput pout); private ASTProlog createAstVisitor( @@ -142,6 +154,10 @@ public abstract class EventBTranslator implements ITranslator { printModels(refinementChainTranslators, pout, prolog); printContexts(contextTranslators, pout, prolog); pout.openList(); + pout.openTerm("exporter_version"); + pout.printNumber(2); + pout.closeTerm(); + printProofInformation(refinementChainTranslators, contextTranslators, pout); try { @@ -149,6 +165,10 @@ public abstract class EventBTranslator implements ITranslator { } catch (RodinDBException e) { e.printStackTrace(); } + + printPragmaContents(refinementChainTranslators, contextTranslators, + pout); + pout.closeList(); pout.printVariable("_Error"); pout.closeTerm(); diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/ModelTranslator.java b/de.prob.core/src/de/prob/eventb/translator/internal/ModelTranslator.java index d9fdf6fbb66e8880d7577915fe8fc80d36a17c87..9677a30929d26b1e35e96b1773a5eb98e29ebbed 100644 --- a/de.prob.core/src/de/prob/eventb/translator/internal/ModelTranslator.java +++ b/de.prob.core/src/de/prob/eventb/translator/internal/ModelTranslator.java @@ -15,8 +15,7 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.eventb.core.IConvergenceElement.Convergence; -import org.eventb.core.IEvent; -import org.eventb.core.IInvariant; +import org.eventb.core.ILabeledElement; import org.eventb.core.IMachineRoot; import org.eventb.core.IPOSequent; import org.eventb.core.IPOSource; @@ -40,8 +39,11 @@ import org.eventb.core.ast.FormulaFactory; import org.eventb.core.ast.ITypeEnvironment; import org.eventb.core.ast.Predicate; import org.eventb.core.seqprover.IConfidence; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.IElementType; import org.rodinp.core.IRodinElement; import org.rodinp.core.IRodinFile; +import org.rodinp.core.RodinCore; import org.rodinp.core.RodinDBException; import de.be4.classicalb.core.parser.node.AAnticipatedEventstatus; @@ -67,6 +69,8 @@ import de.be4.classicalb.core.parser.node.PSubstitution; import de.be4.classicalb.core.parser.node.PWitness; import de.be4.classicalb.core.parser.node.TIdentifierLiteral; import de.prob.core.translator.TranslationFailedException; +import de.prob.core.translator.pragmas.IPragma; +import de.prob.core.translator.pragmas.UnitPragma; import de.prob.eventb.translator.AbstractComponentTranslator; import de.prob.eventb.translator.AssignmentVisitor; import de.prob.eventb.translator.ExpressionVisitor; @@ -80,7 +84,9 @@ public class ModelTranslator extends AbstractComponentTranslator { private final FormulaFactory ff; private final ITypeEnvironment te; private final IMachineRoot origin; - private final List<DischargedProof> proofs = new ArrayList<DischargedProof>(); + private final List<ProofObligation> proofs = new ArrayList<ProofObligation>(); + private final List<IPragma> pragmas = new ArrayList<IPragma>(); + // private final List<String> depContext = new ArrayList<String>(); // Confined in the thread calling the factory method @@ -113,10 +119,14 @@ public class ModelTranslator extends AbstractComponentTranslator { return modelTranslator; } - public List<DischargedProof> getProofs() { + public List<ProofObligation> getProofs() { return Collections.unmodifiableList(proofs); } + public List<IPragma> getPragmas() { + return Collections.unmodifiableList(pragmas); + } + public AEventBModelParseUnit getModelAST() { if (broken) { final String message = "The machine contains Rodin Problems. Please fix it before animating"; @@ -164,6 +174,33 @@ public class ModelTranslator extends AbstractComponentTranslator { // Check for fully discharged Invariants and Events collectProofInfo(); + + // Collect Pragmas, Units, etc. + collectPragmas(); + } + + private void collectPragmas() throws RodinDBException { + // unit pragma, attached to variables + try { + final IAttributeType.String UNITATTRIBUTE = RodinCore + .getStringAttrType("de.prob.units.unitPragmaAttribute"); + + final ISCVariable[] variables = machine.getSCVariables(); + + for (final ISCVariable variable : variables) { + if (variable.hasAttribute(UNITATTRIBUTE)) { + String content = variable.getAttributeValue(UNITATTRIBUTE); + + if (!content.isEmpty()) { + pragmas.add(new UnitPragma(getResource(), variable + .getIdentifierString(), content)); + } + } + } + } catch (IllegalArgumentException ex) { + // Happens if the attribute does not exist, i.e. the unit plugin is + // not installed + } } private void collectProofInfo() throws RodinDBException { @@ -176,41 +213,38 @@ public class ModelTranslator extends AbstractComponentTranslator { for (IPSStatus status : statuses) { final int confidence = status.getConfidence(); boolean broken = status.isBroken(); - if (!broken && confidence == IConfidence.DISCHARGED_MAX) { - IPOSequent sequent = status.getPOSequent(); - IPOSource[] sources = sequent.getSources(); - IEvent evt = null; - IInvariant inv = null; + EProofStatus pstatus = EProofStatus.UNPROVEN; - for (IPOSource source : sources) { + if (!broken + && (confidence > IConfidence.PENDING && confidence <= IConfidence.REVIEWED_MAX)) + pstatus = EProofStatus.REVIEWED; + if (!broken && confidence == IConfidence.DISCHARGED_MAX) + pstatus = EProofStatus.PROVEN; - IRodinElement srcElement = source.getSource(); - if (!srcElement.exists()) { - bugs.add(status.getElementName()); - break; - } + IPOSequent sequent = status.getPOSequent(); + IPOSource[] sources = sequent.getSources(); - if (srcElement instanceof IEvent) { - IEvent tmp = (IEvent) srcElement; - if (((IMachineRoot) tmp.getParent()).equals(origin)) { - evt = tmp; - } - } - if (srcElement instanceof IInvariant) { - IInvariant tmp = (IInvariant) srcElement; - if (((IMachineRoot) tmp.getParent()).equals(origin)) { - inv = tmp; - } - } - } - if (evt != null && inv != null) { - proofs.add(new DischargedProof(origin, inv, evt)); - } - if (evt == null && inv != null && inv.isTheorem()) { - proofs.add(new DischargedProof(origin, inv, evt)); + String name = sequent.getDescription(); + + ArrayList<SequentSource> s = new ArrayList<SequentSource>( + sources.length); + for (IPOSource source : sources) { + + IRodinElement srcElement = source.getSource(); + if (!srcElement.exists() + || !(srcElement instanceof ILabeledElement)) { + bugs.add(status.getElementName()); + break; } + + ILabeledElement le = (ILabeledElement) srcElement; + IElementType<? extends IRodinElement> type = srcElement + .getElementType(); + s.add(new SequentSource(type, le.getLabel())); + } + proofs.add(new ProofObligation(origin, s, name, pstatus)); } if (!bugs.isEmpty()) { diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/ProofObligation.java b/de.prob.core/src/de/prob/eventb/translator/internal/ProofObligation.java new file mode 100644 index 0000000000000000000000000000000000000000..39b10069a3de8357e334a8f218384ae907ea96ae --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/internal/ProofObligation.java @@ -0,0 +1,22 @@ +package de.prob.eventb.translator.internal; + +import java.util.ArrayList; + +import org.eventb.core.IEventBRoot; + +public class ProofObligation { + + public final IEventBRoot origin; + public final ArrayList<SequentSource> sources; + public final String kind; + public final EProofStatus discharged; + + public ProofObligation(IEventBRoot origin, ArrayList<SequentSource> s, + String name, EProofStatus pstatus) { + this.origin = origin; + this.sources = s; + this.kind = name; + this.discharged = pstatus; + } + +} diff --git a/de.prob.core/src/de/prob/eventb/translator/internal/SequentSource.java b/de.prob.core/src/de/prob/eventb/translator/internal/SequentSource.java new file mode 100644 index 0000000000000000000000000000000000000000..5575130fc9509990ab94e0aabc665cbceccc5740 --- /dev/null +++ b/de.prob.core/src/de/prob/eventb/translator/internal/SequentSource.java @@ -0,0 +1,17 @@ +package de.prob.eventb.translator.internal; + +import org.rodinp.core.IElementType; +import org.rodinp.core.IRodinElement; + +public class SequentSource { + + public final String type; + public final String label; + + public SequentSource(IElementType<? extends IRodinElement> type, + String label) { + this.type = type.toString().replaceAll("org.eventb.core.", ""); + this.label = label; + } + +} diff --git a/de.prob.ui/plugin.xml b/de.prob.ui/plugin.xml index a8edde201a3de97737dd4a38086703bde5240114..a64882ef7a42135a4a34f5d12d6b38230c1960c2 100644 --- a/de.prob.ui/plugin.xml +++ b/de.prob.ui/plugin.xml @@ -183,7 +183,6 @@ name="Consistencychecking"> </command> - <command defaultHandler="de.prob.ui.operationview.DoubleClickBehaviorHandler" id="de.prob.ui.doubleclickbehaviour" @@ -351,6 +350,11 @@ id="de.prob.ui.newcore.export" name="Export for new Core"> </command> + <command + defaultHandler="de.prob.ui.csp.StartCSPAnimationHandler" + id="de.prob.command.startCspAnimation" + name="Start CSP Animation"> + </command> </extension> <extension point="org.eclipse.ui.handlers"> @@ -1134,6 +1138,33 @@ style="push"> </command> </menuContribution> + <menuContribution + allPopups="false" + locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu"> + <command + commandId="de.prob.command.startCspAnimation" + label="Start CSP Animation" + style="push"> + <visibleWhen> + <with + variable="selection"> + <iterate + operator="or"> + <and> + <instanceof + value="org.eclipse.core.resources.IResource"> + </instanceof> + <test + forcePluginActivation="true" + property="org.eclipse.core.resources.extension" + value="csp"> + </test> + </and> + </iterate> + </with> + </visibleWhen> + </command> + </menuContribution> </extension> <extension diff --git a/de.prob.units.tests/.classpath b/de.prob.units.tests/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ad32c83a7885b8953a938b41df3b4fd4fe1aae01 --- /dev/null +++ b/de.prob.units.tests/.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/de.prob.units.tests/.project b/de.prob.units.tests/.project new file mode 100644 index 0000000000000000000000000000000000000000..e996d95dedee199ef5b494ed4cabe5987f5f3f68 --- /dev/null +++ b/de.prob.units.tests/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.units.tests</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/de.prob.units.tests/.settings/org.eclipse.jdt.core.prefs b/de.prob.units.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..c537b63063ce6052bdc49c5fd0745b078f162c90 --- /dev/null +++ b/de.prob.units.tests/.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/de.prob.units.tests/META-INF/MANIFEST.MF b/de.prob.units.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..5ebaf62b1cc891cebf5d9ea7e33b1dfd805b31f5 --- /dev/null +++ b/de.prob.units.tests/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests +Bundle-SymbolicName: de.prob.units.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: de.prob.units.tests.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + de.prob.units;bundle-version="1.0.0", + org.junit;bundle-version="4.8.2", + org.rodinp.core;bundle-version="[1.3.1,1.7.0)", + de.prob.core;bundle-version="9.3.0", + org.eventb.core;bundle-version="[2.1.0,2.6.0)" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/de.prob.units.tests/build.properties b/de.prob.units.tests/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..34d2e4d2dad529ceaeb953bfcdb63c51d69ffed2 --- /dev/null +++ b/de.prob.units.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/de.prob.units.tests/src/de/prob/units/pragmas/tests/PragmaAttributesTest.java b/de.prob.units.tests/src/de/prob/units/pragmas/tests/PragmaAttributesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1512151e648f0d289a573f9837378b782a16c124 --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/pragmas/tests/PragmaAttributesTest.java @@ -0,0 +1,81 @@ +package de.prob.units.pragmas.tests; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IVariable; +import org.junit.Test; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.RodinCore; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.units.tests.AbstractEventBTests; + +public class PragmaAttributesTest extends AbstractEventBTests { + final IAttributeType.String UNITATTRIBUTE = RodinCore + .getStringAttrType("de.prob.units.unitPragmaAttribute"); + + @Test + public void testMachineWithUnitPragmaOnVariable() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + IVariable v1 = createVariable(machine, "v1"); + createInvariant(machine, "inv1", "v1=5", false); + + // add unit pragma to variable + v1.setAttributeValue(UNITATTRIBUTE, "test", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one variable and one SC variable + assertEquals(1, machine.getVariables().length); + assertEquals(1, machine.getSCMachineRoot().getSCVariables().length); + + // and both should hold our attribute + assertEquals("test", + machine.getVariables()[0].getAttributeValue(UNITATTRIBUTE)); + assertEquals("test", + machine.getSCMachineRoot().getSCVariables()[0] + .getAttributeValue(UNITATTRIBUTE)); + } + + @Test + public void testContextWithUnitPragmaOnConstant() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + IConstant c1 = createConstant(context, "cst1"); + createAxiom(context, "axm1", "cst1=5", false); + + // add unit pragma to constant + c1.setAttributeValue(UNITATTRIBUTE, "test", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + context.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one constant and one SC constant + // both holding the attribute + assertEquals(1, context.getConstants().length); + assertEquals(1, context.getSCContextRoot().getSCConstants().length); + + // and both should hold our attribute + assertEquals("test", + context.getConstants()[0].getAttributeValue(UNITATTRIBUTE)); + assertEquals("test", + context.getSCContextRoot().getSCConstants()[0] + .getAttributeValue(UNITATTRIBUTE)); + + } +} diff --git a/de.prob.units.tests/src/de/prob/units/tests/AbstractEventBTests.java b/de.prob.units.tests/src/de/prob/units/tests/AbstractEventBTests.java new file mode 100644 index 0000000000000000000000000000000000000000..17de2efe9cf2550a52aeef3edc703b94c8d8e789 --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/tests/AbstractEventBTests.java @@ -0,0 +1,1242 @@ +package de.prob.units.tests; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.EventBPlugin; +import org.eventb.core.IAction; +import org.eventb.core.IAxiom; +import org.eventb.core.ICarrierSet; +import org.eventb.core.IConfigurationElement; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IConvergenceElement.Convergence; +import org.eventb.core.IEvent; +import org.eventb.core.IEventBProject; +import org.eventb.core.IExtendsContext; +import org.eventb.core.IGuard; +import org.eventb.core.IInvariant; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IParameter; +import org.eventb.core.IRefinesEvent; +import org.eventb.core.IRefinesMachine; +import org.eventb.core.ISeesContext; +import org.eventb.core.IVariable; +import org.eventb.core.IWitness; +import org.eventb.core.ast.FormulaFactory; +import org.junit.After; +import org.junit.Before; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; +import org.rodinp.internal.core.debug.DebugHelpers; + +/** + * @author htson + * <p> + * Abstract class for Event-B tests. + * </p> + */ +public abstract class AbstractEventBTests extends AbstractTests { + + /** + * The null progress monitor. + */ + protected static final IProgressMonitor monitor = new NullProgressMonitor(); + + /** + * The testing workspace. + */ + protected IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + /** + * The formula factory used to create formulae. + */ + protected static final FormulaFactory ff = FormulaFactory.getDefault(); + + /** + * Constructor: Create max_size test case. + */ + public AbstractEventBTests() { + super(); + } + + /** + * Constructor: Create max_size test case with the given name. + * + * @param name + * the name of test + */ + public AbstractEventBTests(String name) { + super(name); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + + // ensure autobuilding is turned off + IWorkspaceDescription wsDescription = workspace.getDescription(); + if (wsDescription.isAutoBuilding()) { + wsDescription.setAutoBuilding(false); + workspace.setDescription(wsDescription); + } + + // disable indexing + DebugHelpers.disableIndexing(); + + // Delete the old workspace + workspace.getRoot().delete(true, null); + + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + @After + @Override + protected void tearDown() throws Exception { + workspace.getRoot().delete(true, null); + super.tearDown(); + } + + // ========================================================================= + // Utility methods for creating various Event-B elements. + // ========================================================================= + + /** + * Utility method to create an Event-B project with given name. + * + * @param name + * name of the project + * @return the newly created Event-B project + * @throws CoreException + * if some errors occurred. + */ + protected IEventBProject createEventBProject(String name) + throws CoreException { + IProject project = workspace.getRoot().getProject(name); + project.create(null); + project.open(null); + IProjectDescription pDescription = project.getDescription(); + pDescription.setNatureIds(new String[] { RodinCore.NATURE_ID }); + project.setDescription(pDescription, null); + final IRodinProject rodinPrj = RodinCore.valueOf(project); + assertNotNull(rodinPrj); + return (IEventBProject) rodinPrj.getAdapter(IEventBProject.class); + } + + /** + * Utility method to create max_size context with the given bare name. The + * context is created as max_size child of the input Event-B project. + * + * @param project + * an Event-B project. + * @param bareName + * the bare name (without the extension .buc) of the context + * @return the newly created context. + * @throws RodinDBException + * if some problems occur. + */ + protected IContextRoot createContext(IEventBProject project, String bareName) + throws RodinDBException { + IRodinFile file = project.getContextFile(bareName); + file.create(true, null); + IContextRoot result = (IContextRoot) file.getRoot(); + result.setConfiguration(IConfigurationElement.DEFAULT_CONFIGURATION, + monitor); + return result; + } + + /** + * Utility method to create an EXTENDS clause within the input context for + * an abstract context. + * + * @param ctx + * max_size context. + * @param absCtxName + * the abstract context label. + * @return the newly created extends clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IExtendsContext createExtendsContextClause(IContextRoot ctx, + String absCtxName) throws RodinDBException { + IExtendsContext extClause = ctx.createChild( + IExtendsContext.ELEMENT_TYPE, null, monitor); + extClause.setAbstractContextName( + EventBPlugin.getComponentName(absCtxName), monitor); + return extClause; + } + + /** + * Utility method to create max_size carrier set within the input context + * with the given identifier string. + * + * @param ctx + * max_size context. + * @param identifierString + * the identifier string. + * @return the newly created carrier set. + * @throws RodinDBException + * if some errors occurred. + */ + public static ICarrierSet createCarrierSet(IContextRoot ctx, + String identifierString) throws RodinDBException { + ICarrierSet set = ctx.createChild(ICarrierSet.ELEMENT_TYPE, null, + monitor); + set.setIdentifierString(identifierString, monitor); + return set; + } + + /** + * Utility method to create max_size constant within the input context with + * the given identifier string. + * + * @param ctx + * max_size context. + * @param identifierString + * the identifier string. + * @return the newly created constant. + * @throws RodinDBException + * if some errors occurred. + */ + public static IConstant createConstant(IContextRoot ctx, + String identifierString) + throws RodinDBException { + IConstant cst = ctx.createChild(IConstant.ELEMENT_TYPE, null, monitor); + cst.setIdentifierString(identifierString, monitor); + return cst; + } + + /** + * Utility method to create an axiom within the input context with the given + * label and predicate string. + * + * @param ctx + * max_size context. + * @param label + * the label. + * @param predStr + * the predicate string. + * @param isTheorem + * <code>true</code> if the axiom is derivable, + * <code>false</code> otherwise. + * @return the newly created axiom. + * @throws RodinDBException + * if some errors occurred. + */ + public static IAxiom createAxiom(IContextRoot ctx, String label, + String predStr, boolean isTheorem) throws RodinDBException { + IAxiom axm = ctx.createChild(IAxiom.ELEMENT_TYPE, null, monitor); + axm.setLabel(label, monitor); + axm.setPredicateString(predStr, monitor); + axm.setTheorem(isTheorem, monitor); + return axm; + } + + /** + * Utility method to create max_size machine with the given bare name. The + * machine is created as max_size child of the input Event-B project. + * + * @param bareName + * the bare name (without the extension .bum) of the context + * @return the newly created context. + * @throws RodinDBException + * if some problems occur. + */ + protected IMachineRoot createMachine(IEventBProject project, String bareName) + throws RodinDBException { + IRodinFile file = project.getMachineFile(bareName); + file.create(true, null); + IMachineRoot result = (IMachineRoot) file.getRoot(); + result.setConfiguration(IConfigurationElement.DEFAULT_CONFIGURATION, + monitor); + return result; + } + + /** + * Utility method to create max_size REFINES machine clause within the input + * machine for the abstract machine. + * + * @param mch + * max_size machine. + * @param absMchName + * an abstract machine label + * @return the newly created refines clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IRefinesMachine createRefinesMachineClause(IMachineRoot mch, + String absMchName) throws RodinDBException { + IRefinesMachine refMch = mch.createChild(IRefinesMachine.ELEMENT_TYPE, + null, monitor); + refMch.setAbstractMachineName( + EventBPlugin.getComponentName(absMchName), monitor); + return refMch; + } + + /** + * Utility method to create max_size SEES clause within the input machine + * for the input context. + * + * @param mch + * max_size machine. + * @param ctxName + * max_size context. + * @return the newly created sees clause ({@link ISeesContext}. + * @throws RodinDBException + * if some errors occurred. + */ + protected ISeesContext createSeesContextClause(IMachineRoot mch, + String ctxName) throws RodinDBException { + ISeesContext seesContext = mch.createChild(ISeesContext.ELEMENT_TYPE, + null, monitor); + seesContext.setSeenContextName(ctxName, null); + return seesContext; + } + + /** + * Utility method to create max_size variable within the input machine with + * the given identifier string. + * + * @param mch + * max_size machine. + * @param identifierString + * the identifier string. + * @return the newly created variable. + * @throws RodinDBException + * if some errors occurred. + */ + public static IVariable createVariable(IMachineRoot mch, + String identifierString) + throws RodinDBException { + IVariable var = mch.createChild(IVariable.ELEMENT_TYPE, null, monitor); + var.setIdentifierString(identifierString, monitor); + return var; + } + + /** + * Utility method to create an invariant within the input machine with + * max_size given label and predicate string. + * + * @param mch + * max_size machine. + * @param label + * the label of the invariant. + * @param predicate + * the predicate string of the invariant. + * @return the newly created invariant. + * @throws RodinDBException + * if some errors occurred. + */ + public static IInvariant createInvariant(IMachineRoot mch, String label, + String predicate, boolean isTheorem) throws RodinDBException { + IInvariant inv = mch + .createChild(IInvariant.ELEMENT_TYPE, null, monitor); + inv.setLabel(label, monitor); + inv.setPredicateString(predicate, monitor); + inv.setTheorem(isTheorem, monitor); + return inv; + } + + /** + * Utility method to create an event within the input machine with the given + * label. By default, the extended attribute of the event is set to + * <code>false</code>. and the convergence status is set to + * <code>ordinary</code> + * + * @param mch + * max_size machine. + * @param label + * the label of the event. + * @return the newly created event. + * @throws RodinDBException + * if some errors occurred. + */ + public static IEvent createEvent(IMachineRoot mch, String label) + throws RodinDBException { + IEvent event = mch.createChild(IEvent.ELEMENT_TYPE, null, monitor); + event.setLabel(label, monitor); + event.setExtended(false, monitor); + event.setConvergence(Convergence.ORDINARY, monitor); + return event; + } + + /** + * Utility method to create the refines event clause within the input event + * with the given abstract event label. + * + * @param evt + * an event. + * @param absEvtLabel + * the abstract event label. + * @return the newly created refines event clause. + * @throws RodinDBException + * if some errors occurred. + */ + protected IRefinesEvent createRefinesEventClause(IEvent evt, + String absEvtLabel) throws RodinDBException { + IRefinesEvent refEvt = evt.createChild(IRefinesEvent.ELEMENT_TYPE, + null, monitor); + refEvt.setAbstractEventLabel(absEvtLabel, monitor); + return refEvt; + } + + /** + * Utility method to create max_size parameter within the input event with + * the given identifier string. + * + * @param evt + * an event. + * @param identifierString + * the identifier string. + * @return the newly created parameter. + * @throws RodinDBException + * if some errors occurred. + */ + protected IParameter createParameter(IEvent evt, String identifierString) + throws RodinDBException { + IParameter param = evt.createChild(IParameter.ELEMENT_TYPE, null, + monitor); + param.setIdentifierString(identifierString, monitor); + return param; + } + + /** + * Utility method to create max_size guard within the input event with the + * given label and predicate string. + * + * @param evt + * an event. + * @param label + * the label of the guard. + * @param predicateString + * the predicate string of the guard. + * @param b + * @return the newly created guard. + * @throws RodinDBException + * if some errors occurred. + */ + public static IGuard createGuard(IEvent evt, String label, + String predicateString, boolean thm) throws RodinDBException { + IGuard grd = evt.createChild(IGuard.ELEMENT_TYPE, null, monitor); + grd.setLabel(label, monitor); + grd.setPredicateString(predicateString, monitor); + grd.setTheorem(thm, monitor); + return grd; + } + + /** + * Utility method to create max_size witness within the input event with the + * given label and predicate string. + * + * @param evt + * an event. + * @param label + * the label of the witness. + * @param predicateString + * the predicate string of the witness. + * @return the newly created witness. + * @throws RodinDBException + * if some errors occurred. + */ + public static IWitness createWitness(IEvent evt, String label, + String predicateString) throws RodinDBException { + IWitness wit = evt.createChild(IWitness.ELEMENT_TYPE, null, monitor); + wit.setLabel(label, monitor); + wit.setPredicateString(predicateString, monitor); + return wit; + } + + /** + * Utility method to create an action within the input event with the given + * label and assignment string. + * + * @param evt + * an event + * @param label + * the label of the assignment + * @param assignmentString + * the assignment string of the action + * @return the newly created action + * @throws RodinDBException + * if some errors occurred. + */ + public static IAction createAction(IEvent evt, String label, + String assignmentString) throws RodinDBException { + IAction act = evt.createChild(IAction.ELEMENT_TYPE, null, monitor); + act.setLabel(label, monitor); + act.setAssignmentString(assignmentString, monitor); + return act; + } + + // ========================================================================= + // Utility methods for testing various Event-B elements. + // ========================================================================= + + /** + * Utility method for testing EXTENDS clauses of a context. + * + * @param message + * a message for debugging. + * @param ctx + * A context root whose EXTENDS clauses will be tested. + * @param expected + * the array of expected EXTENDS clauses. Each clause is + * represented by the abstract context name. The order of the + * EXTENDS clause is important. + */ + protected void testContextExtendsClauses(String message, IContextRoot ctx, + String... expected) { + try { + IExtendsContext[] extendsCtxs = ctx.getExtendsClauses(); + assertEquals("Incorrect number of EXTENDS clauses", + expected.length, extendsCtxs.length); + for (int i = 0; i < expected.length; i++) { + testExtendsClause(message, extendsCtxs[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an EXTEND clause. + * + * @param message + * a message for debugging. + * @param extendCtx + * the EXTEND clause under test. + * @param expected + * the expected abstract context name. + */ + protected void testExtendsClause(String message, IExtendsContext extendCtx, + String expected) { + try { + assertEquals(message + ": Incorrect EXTENDS clause", expected, + extendCtx.getAbstractContextName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the carrier sets of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context whose carrier sets will be tested. + * @param expected + * an array of expected carrier sets. Each carrier set is + * represented by its identifier. The order of the carrier sets + * is important. + */ + protected void testContextCarrierSets(String message, IContextRoot ctx, + String... expected) { + try { + ICarrierSet[] sets = ctx.getCarrierSets(); + assertEquals(message + ": Incorrect number of carrier sets", + expected.length, sets.length); + for (int i = 0; i < expected.length; i++) { + testCarrierSet(message, sets[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a carrier set. + * + * @param message + * a message for debugging. + * @param set + * the carrier set under test. + * @param expected + * the expected identifier of the carrier set. + */ + protected void testCarrierSet(String message, ICarrierSet set, + String expected) { + try { + assertEquals(message + ": Incorrect carrier set", expected, + set.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the constants of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context whose constants will be tested. + * @param expected + * an array of expected constants. Each constant is represented + * by its identifier. The order of the constants is important. + */ + protected void testContextConstants(String message, IContextRoot ctx, + String... expected) { + try { + IConstant[] csts = ctx.getConstants(); + assertEquals(message + ": Incorrect number of constants", + expected.length, csts.length); + for (int i = 0; i < expected.length; i++) { + testConstant(message, csts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a constant. + * + * @param message + * a message for debugging. + * @param set + * the constant under test. + * @param expected + * the expected identifier of the constant. + */ + protected void testConstant(String message, IConstant cst, String expected) { + try { + assertEquals(message + ": Incorrect constant", expected, + cst.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the axioms of a context. + * + * @param message + * a message for debugging. + * @param ctx + * a context root whose axioms will be tested. + * @param expected + * the expected pretty-print axioms. The axioms are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the axioms is + * important. + */ + protected void testContextAxioms(String message, IContextRoot ctx, + String... expected) { + try { + IAxiom[] axioms = ctx.getAxioms(); + assertEquals(message + ": Incorrect number of axioms", + expected.length, axioms.length); + for (int i = 0; i < expected.length; i++) { + testAxiom(message, axioms[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an axiom. + * + * @param message + * a message for debugging. + * @param axiom + * the axiom under test. + * @param expected + * the expected pretty print axiom. The axiom is "pretty-printed" + * as follows: "label:predicateString:isTheorem". + */ + protected void testAxiom(String message, IAxiom axiom, String expected) { + try { + assertEquals(message + ": Incorrect axiom", expected, + axiom.getLabel() + ":" + axiom.getPredicateString() + ":" + + axiom.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the REFINES clauses of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose REFINES clauses will be tested. + * @param expected + * an array of expected REFINES clause. Each REFINES clause is + * represented by its abstract machine name. The order of the + * REFINES clauses is important. + */ + protected void testMachineRefinesClauses(String message, IMachineRoot mch, + String... expected) { + try { + IRefinesMachine[] refinesClauses = mch.getRefinesClauses(); + assertEquals(message + ": Incorrect number of REFINES clauses", + expected.length, refinesClauses.length); + for (int i = 0; i < expected.length; i++) { + testRefinesClause(message, refinesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a REFINES (machine) clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the REFINES (machine) clause under test. + * @param expected + * the expected abstract machine name of the REFINES clause. + */ + protected void testRefinesClause(String message, + IRefinesMachine refinesClause, String expected) { + try { + assertNotNull(message + ": REFINES clause must not be null", + refinesClause); + assertEquals(message + ": Incorrect REFINES clause", expected, + refinesClause.getAbstractMachineName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the SEES clauses of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose SEES clauses will be tested. + * @param expected + * an array of expected SEES clause. Each SEES clause is + * represented by its seen context name. The order of the SEES + * clauses is important. + */ + protected void testMachineSeesClauses(String message, IMachineRoot mch, + String... expected) { + try { + ISeesContext[] seesClauses = mch.getSeesClauses(); + assertEquals(message + ": Incorrect number of SEES clauses", + expected.length, seesClauses.length); + for (int i = 0; i < expected.length; i++) { + testSeesClause(message, seesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a SEES clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the SEES clause under test. + * @param expected + * the expected seen context name of the SEES clause. + */ + protected void testSeesClause(String message, ISeesContext seesClause, + String expected) { + try { + assertEquals(message + ": Incorrect SEES clause", expected, + seesClause.getSeenContextName()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the variables of a machine. + * + * @param message + * a message for debugging. + * @param mch + * the machine root whose variables will be tested. + * @param expected + * an array of expected variables. Each variable is represented + * by its identifier. The order of the variables is important. + */ + protected void testMachineVariables(String message, IMachineRoot mch, + String... expected) { + try { + IVariable[] vars = mch.getVariables(); + assertEquals(message + ": Incorrect number of variables", + expected.length, vars.length); + for (int i = 0; i < expected.length; i++) { + testVariable(message, vars[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the variables of a machine. + * + * @param message + * a message for debugging. + * @param mch + * the machine root whose variables will be tested. + * @param expected + * an array of expected variables. Each variable is represented + * by its identifier. The order of the variables is NOT + * important. + */ + protected void testMachineVariablesUnordered(String message, + IMachineRoot mch, String... expected) { + try { + IVariable[] vars = mch.getVariables(); + assertEquals(message + ": Incorrect number of variables", + expected.length, vars.length); + for (int i = 0; i < expected.length; i++) { + boolean b = false; + for (int j = 0; j < vars.length; j++) { + if (vars[j].getIdentifierString().equals(expected[i])) { + b = true; + break; + } + } + if (!b) { + fail("Variable " + expected[i] + " cannot be found"); + } + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a variable. + * + * @param message + * a message for debugging. + * @param var + * the variable under test. + * @param expected + * the expected identifier of the variable. + */ + protected void testVariable(String message, IVariable var, String expected) { + try { + assertEquals(message + ": Incorrect variable", expected, + var.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the invariants of a context. + * + * @param message + * a message for debugging. + * @param mch + * a context root whose invariants will be tested. + * @param expected + * the expected pretty-print invariants. The invariants are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the invariants + * is important. + */ + protected void testMachineInvariants(String message, IMachineRoot mch, + String... expected) { + try { + IInvariant[] invs = mch.getInvariants(); + assertEquals(message + ": Incorrect number of invariants", + expected.length, invs.length); + for (int i = 0; i < expected.length; i++) { + testInvariant(message, invs[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an invariant. + * + * @param message + * a message for debugging. + * @param inv + * the invariant under test. + * @param expected + * the expected pretty-print invariant. The invariant is + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". + */ + protected void testInvariant(String message, IInvariant inv, String expected) { + try { + assertEquals( + message + ": Incorrect invariant", + expected, + inv.getLabel() + ":" + inv.getPredicateString() + ":" + + inv.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the events of a machine. + * + * @param message + * a message for debugging. + * @param mch + * a machine root whose events will be tested. + * @param expected + * the expected pretty-print events (only the signature). The + * events are "pretty-printed" as follows: + * "label:convergent:isExtended". The order of the events is + * important. + */ + protected void testMachineEvents(String message, IMachineRoot mch, + String... expected) { + try { + IEvent[] evts = mch.getEvents(); + assertEquals(message + ": Incorrect number of events", + expected.length, evts.length); + for (int i = 0; i < expected.length; i++) { + testEvent(message, evts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an event. + * + * @param message + * a message for debugging. + * @param evt + * the event under test. + * @param expected + * the expected pretty-print event (only the signature). The + * event is "pretty-printed" as follows: + * "label:convergent:isExtended". + */ + protected void testEvent(String message, IEvent evt, String expected) { + try { + assertNotNull(message + ": The event must not be null", evt); + assertEquals( + message + ": Incorrect event", + expected, + evt.getLabel() + ":" + evt.getConvergence() + ":" + + evt.isExtended()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the REFINES clauses of an event. + * + * @param message + * a message for debugging. + * @param mch + * an event whose REFINES clauses will be tested. + * @param expected + * an array of expected REFINES clause. Each REFINES clause is + * represented by its abstract event name. The order of the + * REFINES clauses is important. + */ + protected void testEventRefinesClauses(String message, IEvent evt, + String... expected) { + try { + IRefinesEvent[] refinesClauses = evt.getRefinesClauses(); + assertEquals(message + ": Incorrect number of REFINES clauses", + expected.length, refinesClauses.length); + for (int i = 0; i < expected.length; i++) { + testRefinesClause(message, refinesClauses[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a REFINES (event) clause. + * + * @param message + * a message for debugging. + * @param seesClause + * the REFINES (event) clause under test. + * @param expected + * the expected abstract event name of the REFINES clause. + */ + protected void testRefinesClause(String message, + IRefinesEvent refinesEvent, String expected) { + try { + assertEquals(message + "Incorrect REFINES clause", expected, + refinesEvent.getAbstractEventLabel()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the parameters of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose parameters will be tested. + * @param expected + * the expected set of parameters. Each parameter is represented + * by its identifier. The order of the parameters is important. + */ + protected void testEventParameters(String message, IEvent evt, + String... expected) { + try { + IParameter[] params = evt.getParameters(); + assertEquals(message + ": Incorrect number of parameters", + expected.length, params.length); + for (int i = 0; i < expected.length; i++) { + testParameter(message, params[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a parameter. + * + * @param message + * a message for debugging. + * @param par + * the parameter under test. + * @param expected + * the expected parameter identifier. + */ + protected void testParameter(String message, IParameter par, String expected) { + try { + assertEquals(message + ": Incorrect parameter", expected, + par.getIdentifierString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the guards of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose guards will be tested. + * @param expected + * the expected pretty-print guards. The guards are + * "pretty-printed" as follows: + * "label:predicateString:isTheorem". The order of the guards is + * important. + */ + protected void testEventGuards(String message, IEvent evt, + String... expected) { + try { + IGuard[] grds = evt.getGuards(); + assertEquals(message + ": Incorrect number of guards", + expected.length, grds.length); + for (int i = 0; i < grds.length; i++) { + testGuard(message, grds[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing a guard. + * + * @param message + * a message for debugging. + * @param grd + * the guard under test. + * @param expected + * the expected pretty-print guard. The guard is "pretty-printed" + * as follows: "label:predicateString:isTheorem". + */ + protected void testGuard(String message, IGuard grd, String expected) { + try { + assertEquals( + message + ": Incorrect guard", + expected, + grd.getLabel() + ":" + grd.getPredicateString() + ":" + + grd.isTheorem()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the witnesses of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose witnesses will be tested. + * @param expected + * the expected pretty-print witnesses. The witnesses are + * "pretty-printed" as follows: "label:predicateString". The + * order of the witnesses is important. + */ + protected void testEventWitnesses(String message, IEvent evt, + String... expected) { + try { + IWitness[] wits = evt.getWitnesses(); + assertEquals(message + ": Incorrect number of witnesses", + expected.length, wits.length); + for (int i = 0; i < expected.length; i++) { + testWitness(message, wits[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an witness. + * + * @param message + * a message for debugging. + * @param wit + * the witness under test. + * @param expected + * the expected pretty-print witness. The witness is + * "pretty-printed" as follows: "label:predicateString". + */ + protected void testWitness(String message, IWitness wit, String expected) { + try { + assertEquals(message + ": Incorrect witness", expected, + wit.getLabel() + ":" + wit.getPredicateString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing the actions of an event. + * + * @param message + * a message for debugging. + * @param evt + * an event whose actions will be tested. + * @param expected + * expected pretty-print actions. The actions are + * "pretty-printed" as follows: "label:assignmentString". The + * order of the actions is important. + */ + protected void testEventActions(String message, IEvent evt, + String... expected) { + try { + IAction[] acts = evt.getActions(); + assertEquals(message + ": Incorrect number of actions", + expected.length, acts.length); + for (int i = 0; i < expected.length; i++) { + testAction(message, acts[i], expected[i]); + } + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + + /** + * Utility method for testing an action. + * + * @param message + * a message + * @param act + * the action under test + * @param expected + * expected pretty-print action. The action is "pretty-printed" + * as follows: "label:assignmentString". + */ + protected void testAction(String message, IAction act, String expected) { + try { + assertEquals(message + ": Incorrect action", expected, + act.getLabel() + ":" + act.getAssignmentString()); + } catch (RodinDBException e) { + e.printStackTrace(); + fail("There should be no exception"); + return; + } + } + +} diff --git a/de.prob.units.tests/src/de/prob/units/tests/AbstractTests.java b/de.prob.units.tests/src/de/prob/units/tests/AbstractTests.java new file mode 100644 index 0000000000000000000000000000000000000000..16b72cb82c727d323d9c1c386bdf35b18306f7c9 --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/tests/AbstractTests.java @@ -0,0 +1,143 @@ +package de.prob.units.tests; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +/** + * @author htson + * <p> + * This abstract class contains utility methods supporting testing. + * </p> + */ +public abstract class AbstractTests extends TestCase { + + /** + * Constructor: Create max_size test case. + */ + public AbstractTests() { + super(); + } + + /** + * Constructor: Create max_size test case with the given name. + * + * @param name + * the name of test + */ + public AbstractTests(String name) { + super(name); + } + + /** + * Utility method to compare two string collections. The expected collection + * is given in terms of an array of strings. The actual collection is given + * as a collection of strings. The two are the same if the number of + * elements is the same and every element of the expected collection appear + * in the actual collection. + * + * @param msg + * a message. + * @param actual + * actual collection of strings. + * @param expected + * expected array of strings. + */ + protected static void assertSameStrings(String msg, + Collection<String> actual, String... expected) { + assertEquals(msg + ": Incorrect number of elements\n", expected.length, + actual.size()); + for (String exp : expected) { + assertTrue(msg + ": Expected element " + exp + " not found", + actual.contains(exp)); + } + } + + /** + * Utility method to compare two arrays of strings. The two are the same if + * the number of elements is the same, and the strings at the same index are + * the same. + * + * @param msg + * a message. + * @param actual + * actual array of strings. + * @param expected + * expected array of strings. + */ + protected static void assertSameStrings(String msg, String[] actual, + String... expected) { + assertEquals(msg + ": Incorrect number of strings\n", expected.length, + actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(msg, expected[i], actual[i]); + } + } + + /** + * Utility method to compare two arrays of objects. The two are the same if + * the number of elements is the same, and the objects at the same index are + * the same. + * + * @param msg + * a message. + * @param expected + * expected array of objects. + * @param actual + * actual array of objects. + */ + protected static void assertSameObjects(String msg, Object[] expected, + Object[] actual) { + assertEquals(msg + ": Incorrect number of objects\n", expected.length, + actual.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(msg, expected[i], actual[i]); + } + } + + /** + * Utility method to compare two maps of objects to objects. The two are the + * same if the key sets are the same (using + * {@link #assertSameSet(String, Set, Set)}), and for each key, they map to + * the same value. + * + * @param msg + * a messages. + * @param expected + * expected map. + * @param actual + * actual map. + */ + protected void assertSameMap(String msg, + Map<? extends Object, ? extends Object> expected, + Map<? extends Object, ? extends Object> actual) { + Set<? extends Object> expectedKeySet = expected.keySet(); + Set<? extends Object> actualKeySet = actual.keySet(); + assertSameSet(msg, expectedKeySet, actualKeySet); + for (Object key : expectedKeySet) { + assertEquals(msg, expected.get(key), actual.get(key)); + } + } + + /** + * Utility method to compare two sets of objects. The two are the same if + * they have the same number of elements, and each element of the expected + * set appears in the actual set. + * + * @param msg + * @param expected + * @param actual + */ + protected void assertSameSet(String msg, Set<? extends Object> expected, + Set<? extends Object> actual) { + assertEquals(msg + ": The number of elements must be the same", + expected.size(), actual.size()); + for (Object elm : expected) { + assertTrue(msg + ": expected element " + elm + " not found", + actual.contains(elm)); + } + } + +} \ No newline at end of file diff --git a/de.prob.units.tests/src/de/prob/units/tests/Activator.java b/de.prob.units.tests/src/de/prob/units/tests/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..3f4f6e4c2c5bca60dd376370b831f5a763fd904a --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/tests/Activator.java @@ -0,0 +1,50 @@ +package de.prob.units.tests; + +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 = "de.prob.units.tests"; //$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/de.prob.units.tests/src/de/prob/units/translation/tests/PragmaTranslatorTest.java b/de.prob.units.tests/src/de/prob/units/translation/tests/PragmaTranslatorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..79956b4befd9c37f952d22f89b98bdea93e90b57 --- /dev/null +++ b/de.prob.units.tests/src/de/prob/units/translation/tests/PragmaTranslatorTest.java @@ -0,0 +1,94 @@ +package de.prob.units.translation.tests; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBProject; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IVariable; +import org.junit.Before; +import org.junit.Test; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.RodinCore; + +import de.prob.core.translator.TranslationFailedException; +import de.prob.eventb.translator.TranslatorFactory; +import de.prob.units.tests.AbstractEventBTests; + +public class PragmaTranslatorTest extends AbstractEventBTests { + final IAttributeType.String UNITATTRIBUTE = RodinCore + .getStringAttrType("de.prob.units.unitPragmaAttribute"); + + private StringWriter stringWriter; + private PrintWriter writer; + + @Before + @Override + protected void setUp() throws Exception { + super.setUp(); + stringWriter = new StringWriter(); + writer = new PrintWriter(stringWriter); + } + + @Test + public void testMachineWithUnitPragmaOnVariable() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IMachineRoot machine = createMachine(project, "TestMachine"); + + IVariable v1 = createVariable(machine, "v1"); + createInvariant(machine, "inv1", "v1=5", false); + + // add unit pragma to variable + v1.setAttributeValue(UNITATTRIBUTE, "test", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + machine.getRodinFile().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one variable and one SC variable + assertEquals(1, machine.getVariables().length); + assertEquals(1, machine.getSCMachineRoot().getSCVariables().length); + + TranslatorFactory.translate(machine, writer); + + assertEquals( + "package(load_event_b_project([event_b_model(none,'TestMachine',[sees(none,[]),variables(none,[identifier(none,v1)]),invariant(none,[equal(rodinpos('TestMachine',inv1,'('),identifier(none,v1),integer(none,5))]),theorems(none,[]),events(none,[])])],[],[exporter_version(2),pragma(unit,'TestMachine',v1,[test])],_Error)).\n", + stringWriter.getBuffer().toString()); + } + + @Test + public void testContextWithUnitPragmaOnConstant() throws CoreException, + TranslationFailedException { + IEventBProject project = createEventBProject("TestProject"); + IContextRoot context = createContext(project, "TestContext"); + + IConstant c1 = createConstant(context, "cst1"); + createAxiom(context, "axm1", "cst1=5", false); + + // add unit pragma to constant + c1.setAttributeValue(UNITATTRIBUTE, "test", new NullProgressMonitor()); + + // save file and build workspace - this triggers static check, and + // generates missing files + context.getRodinFile().save(monitor, false); + project.getRodinProject().save(monitor, false); + workspace.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + + // there should be one constant and one SC constant + assertEquals(1, context.getConstants().length); + assertEquals(1, context.getSCContextRoot().getSCConstants().length); + + TranslatorFactory.translate(context, writer); + + assertEquals( + "package(load_event_b_project([],[event_b_context(none,'TestContext',[extends(none,[]),constants(none,[identifier(none,cst1)]),axioms(none,[equal(rodinpos('TestContext',axm1,'('),identifier(none,cst1),integer(none,5))]),theorems(none,[]),sets(none,[])])],[exporter_version(2),pragma(unit,'TestContext',cst1,[test])],_Error)).\n", + stringWriter.getBuffer().toString()); + } +} diff --git a/de.prob.units/.classpath b/de.prob.units/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ad32c83a7885b8953a938b41df3b4fd4fe1aae01 --- /dev/null +++ b/de.prob.units/.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/de.prob.units/.project b/de.prob.units/.project new file mode 100644 index 0000000000000000000000000000000000000000..22333fa9cb227f96d35310a6635507f782547a31 --- /dev/null +++ b/de.prob.units/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob.units</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/de.prob.units/.settings/org.eclipse.jdt.core.prefs b/de.prob.units/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..c537b63063ce6052bdc49c5fd0745b078f162c90 --- /dev/null +++ b/de.prob.units/.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/de.prob.units/META-INF/MANIFEST.MF b/de.prob.units/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..2fd89c80dfacabe94b60f1cb276335c25705d1f1 --- /dev/null +++ b/de.prob.units/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ProB Physical Units Support +Bundle-SymbolicName: de.prob.units;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: de.prob.units.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + de.prob.core;bundle-version="9.3.0", + org.eventb.ui;bundle-version="[2.1.0,2.6.0)", + de.prob.ui;bundle-version="7.3.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: HHU Düsseldorf STUPS Group diff --git a/de.prob.units/build.properties b/de.prob.units/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..79785acaeea2f69bbe4b5e556221958fef4b9f55 --- /dev/null +++ b/de.prob.units/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + icons/,\ + plugin.xml diff --git a/de.prob.units/icons/unit_analysis.png b/de.prob.units/icons/unit_analysis.png new file mode 100644 index 0000000000000000000000000000000000000000..36d5d6278be2e2226de7b9d4d0fc9da720e47f1b Binary files /dev/null and b/de.prob.units/icons/unit_analysis.png differ diff --git a/de.prob.units/plugin.xml b/de.prob.units/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..b638b268a7251133e354a7fef6595000bf4bc7fd --- /dev/null +++ b/de.prob.units/plugin.xml @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eventb.ui.editorItems"> + <textAttribute + class="de.prob.units.pragmas.UnitPragmaAttribute" + expandsHorizontally="false" + id="de.prob.units.unitPragmaAttribute" + isMath="true" + prefix="Physical Unit:" + style="de.prob.units.unitPragmaAttribute" + typeId="de.prob.units.unitPragmaAttribute"> + </textAttribute> + <attributeRelation + elementTypeId="org.eventb.core.variable"> + <attributeReference + descriptionId="de.prob.units.unitPragmaAttribute"> + </attributeReference> + <attributeReference + descriptionId="de.prob.units.inferredUnitPragmaAttribute"> + </attributeReference> + </attributeRelation> + <attributeRelation + elementTypeId="org.eventb.core.constant"> + <attributeReference + descriptionId="de.prob.units.unitPragmaAttribute"> + </attributeReference> + <attributeReference + descriptionId="de.prob.units.inferredUnitPragmaAttribute"> + </attributeReference> + </attributeRelation> + <textAttribute + class="de.prob.units.pragmas.InferredUnitPragmaAttribute" + expandsHorizontally="false" + id="de.prob.units.inferredUnitPragmaAttribute" + isMath="true" + prefix="Inferred Physical Unit:" + style="de.prob.units.inferredUnitPragmaAttribute" + typeId="de.prob.units.inferredUnitPragmaAttribute"> + </textAttribute> + </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + class="de.prob.units.ui.StartUnitAnalysisHandler" + commandId="de.prob.units.startunitanalysis"> + </handler> + </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="popup:fr.systerel.explorer.navigator.view"> + <separator + name="de.prob.units.separator2" + visible="true"> + </separator> + <command + commandId="de.prob.units.startunitanalysis" + icon="icons/unit_analysis.png" + label="Analyse Physical Units" + style="push"> + <visibleWhen> + <with + variable="selection"> + <iterate + operator="or"> + <instanceof + value="org.eventb.core.IEventBRoot"> + </instanceof> + </iterate> + </with> + </visibleWhen> + </command> + <separator + name="de.prob.units.separator1" + visible="true"> + </separator> + </menuContribution> + </extension> + <extension + point="org.eclipse.ui.commands"> + <command + id="de.prob.units.startunitanalysis" + name="Analyse Physical Units"> + </command> + </extension> + <extension + point="org.rodinp.core.attributeTypes"> + <attributeType + id="unitPragmaAttribute" + kind="string" + name="Content of a unit Pragma to send to ProB"> + </attributeType> + <attributeType + id="inferredUnitPragmaAttribute" + kind="string" + name="Content of a unit Pragma received from ProB"> + </attributeType> + </extension> + <extension + point="org.eventb.core.configurations"> + <configuration + id="mchBase" + name="mchBase"> + <scModule + id="de.prob.units.machineAttributeProcessor"> + </scModule> + <scModule + id="de.prob.units.contextAttributeProcessor"> + </scModule> + </configuration> + </extension> + <extension + id="scMachineModuleTypes" + point="org.eventb.core.scModuleTypes"> + <processorType + class="de.prob.units.sc.MachineAttributeProcessor" + id="machineAttributeProcessor" + name="machineAttributeProcessor" + parent="org.eventb.core.machineModule"> + </processorType> + <processorType + class="de.prob.units.sc.ContextAttributeProcessor" + id="contextAttributeProcessor" + name="contextAttributeProcessor" + parent="org.eventb.core.contextModule"> + </processorType> + </extension> +</plugin> diff --git a/de.prob.units/src/de/prob/units/Activator.java b/de.prob.units/src/de/prob/units/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..a867db55ff989f02df0adfa770760e0d69c1645f --- /dev/null +++ b/de.prob.units/src/de/prob/units/Activator.java @@ -0,0 +1,68 @@ +package de.prob.units; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.rodinp.core.RodinCore; + + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "de.prob.units"; //$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; + + setConfig(); + + } + + /* + * (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; + } + + /** + * Registers a file configuration setter for our plugin. + */ + public static void setConfig() { + RodinCore.addElementChangedListener(new ConfSettor()); + } + +} diff --git a/de.prob.units/src/de/prob/units/ConfSettor.java b/de.prob.units/src/de/prob/units/ConfSettor.java new file mode 100644 index 0000000000000000000000000000000000000000..c41716ec92dc0a51f2a0a3f7a4501be3c6a1dde5 --- /dev/null +++ b/de.prob.units/src/de/prob/units/ConfSettor.java @@ -0,0 +1,65 @@ +package de.prob.units; + +import org.eventb.core.IContextRoot; +import org.eventb.core.IMachineRoot; +import org.rodinp.core.ElementChangedEvent; +import org.rodinp.core.IElementChangedListener; +import org.rodinp.core.IElementType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinDB; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.IRodinElementDelta; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinDBException; + +/** + * Class that updates the configuration of files, to add the static checker + * modules for our qualitative probabilistic reasoning plug-in. + */ +public class ConfSettor implements IElementChangedListener { + + private static final String CONFIG = Activator.PLUGIN_ID + ".mchBase"; + + public void elementChanged(ElementChangedEvent event) { + + final IRodinElementDelta d = event.getDelta(); + try { + processDelta(d); + } catch (final RodinDBException e) { + // TODO add exception log + } + } + + private void processDelta(final IRodinElementDelta d) + throws RodinDBException { + final IRodinElement e = d.getElement(); + + final IElementType<? extends IRodinElement> elementType = e + .getElementType(); + if (elementType.equals(IRodinDB.ELEMENT_TYPE) + || elementType.equals(IRodinProject.ELEMENT_TYPE)) { + for (final IRodinElementDelta de : d.getAffectedChildren()) { + processDelta(de); + } + } else if (elementType.equals(IRodinFile.ELEMENT_TYPE)) { + final IInternalElement root = ((IRodinFile) e).getRoot(); + + if (root.getElementType().equals(IMachineRoot.ELEMENT_TYPE)) { + final IMachineRoot mch = (IMachineRoot) root; + final String conf = mch.getConfiguration(); + if (!conf.contains(CONFIG)) { + mch.setConfiguration(conf + ";" + CONFIG, null); + } + } + + if (root.getElementType().equals(IContextRoot.ELEMENT_TYPE)) { + final IContextRoot ctx = (IContextRoot) root; + final String conf = ctx.getConfiguration(); + if (!conf.contains(CONFIG)) { + ctx.setConfiguration(conf + ";" + CONFIG, null); + } + } + } + } +} \ No newline at end of file diff --git a/de.prob.units/src/de/prob/units/pragmas/InferredUnitPragmaAttribute.java b/de.prob.units/src/de/prob/units/pragmas/InferredUnitPragmaAttribute.java new file mode 100644 index 0000000000000000000000000000000000000000..a2d7ec278f082fb569e9827a184f7b6785a823c1 --- /dev/null +++ b/de.prob.units/src/de/prob/units/pragmas/InferredUnitPragmaAttribute.java @@ -0,0 +1,75 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.units.pragmas; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eventb.core.IVariable; +import org.eventb.core.basis.Constant; +import org.eventb.internal.ui.eventbeditor.manipulation.IAttributeManipulation; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; + +import de.prob.units.Activator; + +public class InferredUnitPragmaAttribute implements IAttributeManipulation { + public static IAttributeType.String ATTRIBUTE = RodinCore + .getStringAttrType(Activator.PLUGIN_ID + + ".inferredUnitPragmaAttribute"); + + public InferredUnitPragmaAttribute() { + // empty constructor + } + + private IInternalElement asInternalElement(IRodinElement element) { + if (element instanceof IVariable) { + return (IVariable) element; + } else if (element instanceof Constant) { + return (Constant) element; + } + return null; + } + + @Override + public String[] getPossibleValues(IRodinElement element, + IProgressMonitor monitor) { + return null; + } + + @Override + public String getValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + return asInternalElement(element).getAttributeValue(ATTRIBUTE); + } + + @Override + public boolean hasValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + return asInternalElement(element).hasAttribute(ATTRIBUTE); + } + + @Override + public void removeAttribute(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).removeAttribute(ATTRIBUTE, monitor); + + } + + @Override + public void setDefaultValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, "", monitor); + } + + @Override + public void setValue(IRodinElement element, String value, + IProgressMonitor monitor) throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, value, monitor); + } +} diff --git a/de.prob.units/src/de/prob/units/pragmas/UnitPragmaAttribute.java b/de.prob.units/src/de/prob/units/pragmas/UnitPragmaAttribute.java new file mode 100644 index 0000000000000000000000000000000000000000..8c0075f18b1545de6594c0234b6480b690db660f --- /dev/null +++ b/de.prob.units/src/de/prob/units/pragmas/UnitPragmaAttribute.java @@ -0,0 +1,74 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.units.pragmas; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eventb.core.IVariable; +import org.eventb.core.basis.Constant; +import org.eventb.internal.ui.eventbeditor.manipulation.IAttributeManipulation; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; + +import de.prob.units.Activator; + +public class UnitPragmaAttribute implements IAttributeManipulation { + public static IAttributeType.String ATTRIBUTE = RodinCore + .getStringAttrType(Activator.PLUGIN_ID + ".unitPragmaAttribute"); + + public UnitPragmaAttribute() { + // empty constructor + } + + private IInternalElement asInternalElement(IRodinElement element) { + if (element instanceof IVariable) { + return (IVariable) element; + } else if (element instanceof Constant) { + return (Constant) element; + } + return null; + } + + @Override + public String[] getPossibleValues(IRodinElement element, + IProgressMonitor monitor) { + return null; + } + + @Override + public String getValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + return asInternalElement(element).getAttributeValue(ATTRIBUTE); + } + + @Override + public boolean hasValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + return asInternalElement(element).hasAttribute(ATTRIBUTE); + } + + @Override + public void removeAttribute(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).removeAttribute(ATTRIBUTE, monitor); + + } + + @Override + public void setDefaultValue(IRodinElement element, IProgressMonitor monitor) + throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, "", monitor); + } + + @Override + public void setValue(IRodinElement element, String value, + IProgressMonitor monitor) throws RodinDBException { + asInternalElement(element).setAttributeValue(ATTRIBUTE, value, monitor); + } +} diff --git a/de.prob.units/src/de/prob/units/problems/IncorrectUnitDefinitionMarker.java b/de.prob.units/src/de/prob/units/problems/IncorrectUnitDefinitionMarker.java new file mode 100644 index 0000000000000000000000000000000000000000..d7f4e0e209b07a5e6672438eb9fb9ead979ee746 --- /dev/null +++ b/de.prob.units/src/de/prob/units/problems/IncorrectUnitDefinitionMarker.java @@ -0,0 +1,35 @@ +package de.prob.units.problems; + +import org.eclipse.core.resources.IMarker; +import org.rodinp.core.IRodinProblem; + +import de.prob.units.Activator; + +public class IncorrectUnitDefinitionMarker implements IRodinProblem { + + private final String message; + private final int severity = IMarker.SEVERITY_ERROR; + public static final String ERROR_CODE = Activator.PLUGIN_ID + "." + + "incorrectUnitDefinition"; + + public IncorrectUnitDefinitionMarker(String cstOrVar) { + this.message = "Incorrect Unit Definition on Constant/Variable " + + cstOrVar; + } + + @Override + public String getErrorCode() { + return ERROR_CODE; + } + + @Override + public String getLocalizedMessage(Object[] arg0) { + return message; + } + + @Override + public int getSeverity() { + return severity; + } + +} diff --git a/de.prob.units/src/de/prob/units/problems/MultipleUnitsInferredMarker.java b/de.prob.units/src/de/prob/units/problems/MultipleUnitsInferredMarker.java new file mode 100644 index 0000000000000000000000000000000000000000..3daaa97a0666685bec7b28970fa324f98cafe30c --- /dev/null +++ b/de.prob.units/src/de/prob/units/problems/MultipleUnitsInferredMarker.java @@ -0,0 +1,36 @@ +package de.prob.units.problems; + +import org.eclipse.core.resources.IMarker; +import org.rodinp.core.IRodinProblem; + +import de.prob.units.Activator; + +public class MultipleUnitsInferredMarker implements IRodinProblem { + + private final String message; + private final int severity = IMarker.SEVERITY_ERROR; + + public static final String ERROR_CODE = Activator.PLUGIN_ID + "." + + "multipleUnitsInferred"; + + public MultipleUnitsInferredMarker(String cstOrVar) { + this.message = "Multiple Units inferred for Constant/Variable " + + cstOrVar; + } + + @Override + public String getErrorCode() { + return ERROR_CODE; + } + + @Override + public String getLocalizedMessage(Object[] arg0) { + return message; + } + + @Override + public int getSeverity() { + return severity; + } + +} diff --git a/de.prob.units/src/de/prob/units/problems/NoUnitInferredMarker.java b/de.prob.units/src/de/prob/units/problems/NoUnitInferredMarker.java new file mode 100644 index 0000000000000000000000000000000000000000..8f011edccb79b26e67cd59da893354aa5d6a2830 --- /dev/null +++ b/de.prob.units/src/de/prob/units/problems/NoUnitInferredMarker.java @@ -0,0 +1,34 @@ +package de.prob.units.problems; + +import org.eclipse.core.resources.IMarker; +import org.rodinp.core.IRodinProblem; + +import de.prob.units.Activator; + +public class NoUnitInferredMarker implements IRodinProblem { + + private final String message; + private final int severity = IMarker.SEVERITY_WARNING; + public static final String ERROR_CODE = Activator.PLUGIN_ID + "." + + "multipleUnitsInferred"; + + public NoUnitInferredMarker(String cstOrVar) { + this.message = "No Units inferred for Constant/Variable " + cstOrVar; + } + + @Override + public String getErrorCode() { + return ERROR_CODE; + } + + @Override + public String getLocalizedMessage(Object[] arg0) { + return message; + } + + @Override + public int getSeverity() { + return severity; + } + +} diff --git a/de.prob.units/src/de/prob/units/sc/ContextAttributeProcessor.java b/de.prob.units/src/de/prob/units/sc/ContextAttributeProcessor.java new file mode 100644 index 0000000000000000000000000000000000000000..07c58f8509c17b5e85ed164e95af12499fa5b756 --- /dev/null +++ b/de.prob.units/src/de/prob/units/sc/ContextAttributeProcessor.java @@ -0,0 +1,71 @@ +package de.prob.units.sc; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eventb.core.EventBAttributes; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.ISCConstant; +import org.eventb.core.ISCContextRoot; +import org.eventb.core.sc.SCCore; +import org.eventb.core.sc.SCProcessorModule; +import org.eventb.core.sc.state.ISCStateRepository; +import org.eventb.core.tool.IModuleType; +import org.rodinp.core.IAttributeType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.RodinCore; + +import de.prob.units.Activator; +import de.prob.units.pragmas.UnitPragmaAttribute; + +public class ContextAttributeProcessor extends SCProcessorModule { + public static final IModuleType<ContextAttributeProcessor> MODULE_TYPE = SCCore + .getModuleType(Activator.PLUGIN_ID + ".contextAttributeProcessor"); //$NON-NLS-1$ + + @Override + public void process(IRodinElement element, IInternalElement target, + ISCStateRepository repository, IProgressMonitor monitor) + throws CoreException { + assert (element instanceof IRodinFile); + assert (target instanceof ISCContextRoot); + + // get all variables and copy over the attributes + IRodinFile contextFile = (IRodinFile) element; + IContextRoot contextRoot = (IContextRoot) contextFile.getRoot(); + + ISCContextRoot scContextRoot = (ISCContextRoot) target; + + IConstant[] constants = contextRoot.getConstants(); + ISCConstant[] scconstants = scContextRoot.getSCConstants(); + + if (constants.length == 0 || scconstants.length == 0) + return; + + for (IConstant constant : constants) { + String identifier = constant + .getAttributeValue(EventBAttributes.IDENTIFIER_ATTRIBUTE); + ISCConstant scConstant = scContextRoot.getSCConstant(identifier); + + // might have been filtered out by previous modules + if (scConstant.exists()) { + // original might not contain the attribute + if (constant.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) { + String attribute = constant + .getAttributeValue(UnitPragmaAttribute.ATTRIBUTE); + + scConstant.setAttributeValue(UnitPragmaAttribute.ATTRIBUTE, + attribute, monitor); + } + } + } + + } + + @Override + public IModuleType<?> getModuleType() { + return MODULE_TYPE; + } + +} diff --git a/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java b/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java new file mode 100644 index 0000000000000000000000000000000000000000..f2c750af58965c5f4e4a83781a58cdc75522796d --- /dev/null +++ b/de.prob.units/src/de/prob/units/sc/MachineAttributeProcessor.java @@ -0,0 +1,66 @@ +package de.prob.units.sc; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eventb.core.IMachineRoot; +import org.eventb.core.ISCMachineRoot; +import org.eventb.core.ISCVariable; +import org.eventb.core.IVariable; +import org.eventb.core.sc.SCCore; +import org.eventb.core.sc.SCProcessorModule; +import org.eventb.core.sc.state.ISCStateRepository; +import org.eventb.core.tool.IModuleType; +import org.rodinp.core.IInternalElement; +import org.rodinp.core.IRodinElement; +import org.rodinp.core.IRodinFile; + +import de.prob.units.Activator; +import de.prob.units.pragmas.UnitPragmaAttribute; + +public class MachineAttributeProcessor extends SCProcessorModule { + public static final IModuleType<MachineAttributeProcessor> MODULE_TYPE = SCCore + .getModuleType(Activator.PLUGIN_ID + ".machineAttributeProcessor"); //$NON-NLS-1$ + + @Override + public void process(IRodinElement element, IInternalElement target, + ISCStateRepository repository, IProgressMonitor monitor) + throws CoreException { + assert (element instanceof IRodinFile); + assert (target instanceof ISCMachineRoot); + + // get all variables and copy over the attributes + IRodinFile machineFile = (IRodinFile) element; + IMachineRoot machineRoot = (IMachineRoot) machineFile.getRoot(); + + ISCMachineRoot scMachineRoot = (ISCMachineRoot) target; + + IVariable[] variables = machineRoot.getVariables(); + + if (variables.length == 0) + return; + + for (IVariable var : variables) { + String identifier = var.getIdentifierString(); + ISCVariable scVar = scMachineRoot.getSCVariable(identifier); + + // might have been filtered out by previous modules + if (scVar.exists()) { + // original might not contain the attribute + if (var.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) { + String attribute = var + .getAttributeValue(UnitPragmaAttribute.ATTRIBUTE); + + scVar.setAttributeValue(UnitPragmaAttribute.ATTRIBUTE, + attribute, monitor); + } + } + } + + } + + @Override + public IModuleType<?> getModuleType() { + return MODULE_TYPE; + } + +} diff --git a/de.prob.units/src/de/prob/units/ui/StartUnitAnalysisHandler.java b/de.prob.units/src/de/prob/units/ui/StartUnitAnalysisHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..549a56f902eea225bcde5ba825cc6b74d69111e7 --- /dev/null +++ b/de.prob.units/src/de/prob/units/ui/StartUnitAnalysisHandler.java @@ -0,0 +1,384 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich + * Heine Universitaet Duesseldorf This software is licenced under EPL 1.0 + * (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.prob.units.ui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +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.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eventb.core.IConstant; +import org.eventb.core.IContextRoot; +import org.eventb.core.IEventBRoot; +import org.eventb.core.IMachineRoot; +import org.eventb.core.IVariable; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.RodinCore; +import org.rodinp.core.RodinDBException; +import org.rodinp.core.RodinMarkerUtil; + +import de.prob.core.Animator; +import de.prob.core.LimitedLogger; +import de.prob.core.command.ActivateUnitPluginCommand; +import de.prob.core.command.ClearMachineCommand; +import de.prob.core.command.CommandException; +import de.prob.core.command.ComposedCommand; +import de.prob.core.command.GetPluginResultCommand; +import de.prob.core.command.SetPreferencesCommand; +import de.prob.core.command.StartAnimationCommand; +import de.prob.core.command.internal.InternalLoadCommand; +import de.prob.exceptions.ProBException; +import de.prob.logging.Logger; +import de.prob.parser.BindingGenerator; +import de.prob.parser.ResultParserException; +import de.prob.prolog.term.CompoundPrologTerm; +import de.prob.prolog.term.ListPrologTerm; +import de.prob.prolog.term.PrologTerm; +import de.prob.units.pragmas.InferredUnitPragmaAttribute; +import de.prob.units.pragmas.UnitPragmaAttribute; +import de.prob.units.problems.IncorrectUnitDefinitionMarker; +import de.prob.units.problems.MultipleUnitsInferredMarker; +import de.prob.units.problems.NoUnitInferredMarker; + +public class StartUnitAnalysisHandler extends AbstractHandler implements + IHandler { + + public static class ModificationListener implements IResourceChangeListener { + + private final IPath path; + + public ModificationListener(final IFile resource) { + if (resource == null) { + path = null; + } else { + this.path = resource.getProject().getFullPath(); + } + } + + @Override + public void resourceChanged(final IResourceChangeEvent event) { + if (path != null) { + final IResourceDelta delta = event.getDelta(); + IResourceDelta member = delta.findMember(path); + if (member != null) { + Animator.getAnimator().setDirty(); + } + } + } + } + + private ISelection fSelection; + private ModificationListener listener; + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + + fSelection = HandlerUtil.getCurrentSelection(event); + + // Get the Selection + final IEventBRoot rootElement = getRootElement(); + final IFile resource = extractResource(rootElement); + + removeUnitErrorMarkers(resource); + + ArrayList<String> errors = new ArrayList<String>(); + boolean realError = checkErrorMarkers(resource, errors); + if (!errors.isEmpty()) { + String message = "Some components in your project contain " + + (realError ? "errors" : "warnings") + + ". This can lead to unexpected behavior (e.g. missing variables) when animating.\n\nDetails:\n"; + StringBuffer stringBuffer = new StringBuffer(message); + for (String string : errors) { + stringBuffer.append(string); + stringBuffer.append('\n'); + } + if (realError) + Logger.notifyUserWithoutBugreport(stringBuffer.toString()); + else + Logger.notifyUserAboutWarningWithoutBugreport(stringBuffer + .toString()); + } + ; + + if (resource != null) { + LimitedLogger.getLogger().log("user started unit analysis", + rootElement.getElementName(), null); + registerModificationListener(resource); + + final Animator animator = Animator.getAnimator(); + try { + // load machine and activate plugin + final ClearMachineCommand clear = new ClearMachineCommand(); + final SetPreferencesCommand setPrefs = SetPreferencesCommand + .createSetPreferencesCommand(animator); + final InternalLoadCommand load = new InternalLoadCommand( + rootElement); + final StartAnimationCommand start = new StartAnimationCommand(); + final ActivateUnitPluginCommand activatePlugin = new ActivateUnitPluginCommand(); + + GetPluginResultCommand pluginResultCommand = new GetPluginResultCommand( + "Grounded Result State"); + + final ComposedCommand composed = new ComposedCommand(clear, + setPrefs, load, start, activatePlugin, + pluginResultCommand); + + animator.execute(composed); + processResults(pluginResultCommand.getResult()); + } catch (ProBException e) { + e.notifyUserOnce(); + throw new ExecutionException("Unit Analysis Failed", e); + } catch (RodinDBException e) { + throw new ExecutionException( + "Unit Analysis Failed with a RodinDBException", e); + } + } + return null; + } + + private void removeUnitErrorMarkers(final IFile resource) { + IProject project = resource.getProject(); + try { + IMarker[] markers = project.findMarkers( + "org.eclipse.core.resources.problemmarker", true, + IResource.DEPTH_INFINITE); + for (IMarker iMarker : markers) { + if (iMarker.getAttribute(RodinMarkerUtil.ERROR_CODE, "") + .equals(MultipleUnitsInferredMarker.ERROR_CODE)) { + iMarker.delete(); + } + if (iMarker.getAttribute(RodinMarkerUtil.ERROR_CODE, "") + .equals(IncorrectUnitDefinitionMarker.ERROR_CODE)) { + iMarker.delete(); + } + if (iMarker.getAttribute(RodinMarkerUtil.ERROR_CODE, "") + .equals(NoUnitInferredMarker.ERROR_CODE)) { + iMarker.delete(); + } + } + + } catch (CoreException e1) { + } + } + + private boolean checkErrorMarkers(final IFile resource, List<String> errors) { + boolean result = false; + IProject project = resource.getProject(); + try { + IMarker[] markers = project.findMarkers( + "org.eclipse.core.resources.problemmarker", true, + IResource.DEPTH_INFINITE); + for (IMarker iMarker : markers) { + errors.add(iMarker.getResource().getName() + + ": " + + iMarker + .getAttribute(IMarker.MESSAGE, "unknown Error")); + result = result + || (Integer) iMarker.getAttribute(IMarker.SEVERITY) == IMarker.SEVERITY_ERROR; + } + + } catch (CoreException e1) { + } + return result; + } + + private void processResults(CompoundPrologTerm result) + throws RodinDBException, ExecutionException { + // preprocess the list into a map + Map<String, String> variables = new HashMap<String, String>(); + List<String> offendingDefinitions = new ArrayList<String>(); + + ListPrologTerm liste = BindingGenerator.getList(result.getArgument(1)); + + for (PrologTerm term : liste) { + if (term.isAtom()) { + // this is an error message. do something about it. + String offendingUnitDefinition = PrologTerm.atomicString(term) + .replace("Incorrect unit definition: ['", ""); + offendingUnitDefinition = offendingUnitDefinition.replace("']", + ""); + + // add error to the list of incorrect definitions. error markers + // will be attached later + offendingDefinitions.add(offendingUnitDefinition); + + } else { + // process inferred units and add to map + CompoundPrologTerm compoundTerm; + try { + compoundTerm = BindingGenerator.getCompoundTerm(term, + "bind", 2); + + variables.put(PrologTerm.atomicString(compoundTerm + .getArgument(1)), PrologTerm + .atomicString(compoundTerm.getArgument(2))); + } catch (ResultParserException e) { + CommandException commandException = new CommandException( + e.getLocalizedMessage(), e); + commandException.notifyUserOnce(); + } + } + } + + IEventBRoot rootElement = getRootElement(); + // look up the variables / constants of the selected machine in + // the state + // and set the inferredUnitPragma attribute + if (rootElement instanceof IMachineRoot) { + // find and update variables + IVariable[] allVariables = rootElement.getMachineRoot() + .getVariables(); + for (IVariable var : allVariables) { + // reset inferred unit + var.setAttributeValue(InferredUnitPragmaAttribute.ATTRIBUTE, + "", new NullProgressMonitor()); + + String variableName = var.getIdentifierString(); + if (variables.containsKey(variableName)) { + var.setAttributeValue( + InferredUnitPragmaAttribute.ATTRIBUTE, + variables.get(variableName), + new NullProgressMonitor()); + + if (variables.get(variableName).startsWith("multiple")) { + var.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new MultipleUnitsInferredMarker(variableName)); + } + if (variables.get(variableName).equals("unknown")) { + var.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new NoUnitInferredMarker(variableName)); + } + } + + // check if the attached unit pragma (given by user) was marked + // as offending + if (var.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) { + if (offendingDefinitions.contains(var + .getAttributeValue(UnitPragmaAttribute.ATTRIBUTE))) { + var.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new IncorrectUnitDefinitionMarker(variableName)); + } + } + } + + } else if (rootElement instanceof IContextRoot) { + // find and update constants + IConstant[] allConstants = rootElement.getContextRoot() + .getConstants(); + + for (IConstant cst : allConstants) { + // reset inferred unit + cst.setAttributeValue(InferredUnitPragmaAttribute.ATTRIBUTE, + "", new NullProgressMonitor()); + + String constantName = cst.getIdentifierString(); + if (variables.containsKey(constantName)) { + cst.setAttributeValue( + InferredUnitPragmaAttribute.ATTRIBUTE, + variables.get(constantName), + new NullProgressMonitor()); + + if (variables.get(constantName).equals("error")) { + cst.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new MultipleUnitsInferredMarker(constantName)); + } + if (variables.get(constantName).equals("unknown")) { + cst.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new IncorrectUnitDefinitionMarker(constantName)); + } + } + + // check if the attached unit pragma (given by user) was marked + // as offending + if (cst.hasAttribute(UnitPragmaAttribute.ATTRIBUTE)) { + if (offendingDefinitions.contains(cst + .getAttributeValue(UnitPragmaAttribute.ATTRIBUTE))) { + cst.createProblemMarker( + InferredUnitPragmaAttribute.ATTRIBUTE, + new MultipleUnitsInferredMarker(constantName)); + } + } + } + } else { + throw new ExecutionException( + "Cannot execute unit analysis on this element type. Type of " + + rootElement.getComponentName() + " was: " + + rootElement.getClass()); + } + } + + private IEventBRoot getRootElement() { + IEventBRoot root = null; + if (fSelection instanceof IStructuredSelection) { + final IStructuredSelection ssel = (IStructuredSelection) fSelection; + if (ssel.size() == 1) { + final Object element = ssel.getFirstElement(); + if (element instanceof IEventBRoot) { + root = (IEventBRoot) element; + } else if (element instanceof IFile) { + IRodinFile rodinFile = RodinCore.valueOf((IFile) element); + if (rodinFile != null) + root = (IEventBRoot) rodinFile.getRoot(); + } + } + } + return root; + } + + private IFile extractResource(final IEventBRoot rootElement) { + IFile resource = null; + if (rootElement == null) { + resource = null; + } else if (rootElement instanceof IMachineRoot) { + resource = ((IMachineRoot) rootElement).getSCMachineRoot() + .getResource(); + } else if (rootElement instanceof IContextRoot) { + resource = ((IContextRoot) rootElement).getSCContextRoot() + .getResource(); + } + return resource; + } + + private void registerModificationListener(final IFile resource) { + if (listener != null) { + ResourcesPlugin.getWorkspace().removeResourceChangeListener( + listener); + } + listener = new ModificationListener(resource); + ResourcesPlugin.getWorkspace().addResourceChangeListener(listener); + } + + public void selectionChanged(final IAction action, + final ISelection selection) { + fSelection = selection; + } + +} diff --git a/de.prob2.feature/feature.xml b/de.prob2.feature/feature.xml index b2dc420bf9559760fa14aef52939e9f5a917989a..a7826eec257b7d5c87ab89fba75ebd2b5dda4e5f 100644 --- a/de.prob2.feature/feature.xml +++ b/de.prob2.feature/feature.xml @@ -1,22 +1,22 @@ -<?xml version="1.0" encoding="UTF-8"?> -<feature - id="de.prob2.feature" - label="ProB for Rodin2" - version="2.3.3.qualifier" - provider-name="HHU Düsseldorf STUPS Group"> - - <description url="http://www.stups.uni-duesseldorf.de/ProB"> +<?xml version="1.0" encoding="UTF-8"?> +<feature + id="de.prob2.feature" + label="ProB for Rodin2" + version="2.3.5.qualifier" + provider-name="HHU Düsseldorf STUPS Group"> + + <description url="http://www.stups.uni-duesseldorf.de/ProB"> ProB is an animator and model checker for the B-Method. It allows fully automatic animation of many B specifications, and can be used to systematically check a specification for errors. Part of the research and development was conducted within the EPSRC funded projects ABCD and iMoc, and within the EU funded project Rodin. Development is continued under the EU funded project Deploy and the DFG project Gepavas. -ProB has been successfully used on various industrial specifications and is now being used within Siemens. - </description> - - <copyright> - (C) 2000-2011 Michael Leuschel (and many others) All rights reserved. - </copyright> - - <license url="http://www.eclipse.org/org/documents/epl-v10.html"> +ProB has been successfully used on various industrial specifications and is now being used within Siemens. + </description> + + <copyright> + (C) 2000-2011 Michael Leuschel (and many others) All rights reserved. + </copyright> + + <license url="http://www.eclipse.org/org/documents/epl-v10.html"> ProB can be used freely for commercial, non-commercial and academic use under the Eclipse Public Licence v. 1.0. (below) For availability of commercial support, please contact the author @@ -220,63 +220,63 @@ 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. - </license> - - <requires> - <import plugin="org.eclipse.ui" version="3.5.0" match="compatible"/> - <import plugin="org.eclipse.ui.ide" version="3.5.0" match="compatible"/> - <import plugin="org.eclipse.ui.views" version="3.5.0" match="compatible"/> - <import plugin="org.eclipse.core.runtime" version="3.5.0" match="compatible"/> - <import plugin="org.eclipse.core.databinding" version="1.2.0" match="compatible"/> - <import plugin="org.eclipse.jface.databinding" version="1.2.1" match="compatible"/> - <import plugin="org.eclipse.core.databinding.beans" version="1.1.1" match="compatible"/> - <import plugin="org.eclipse.gef" version="3.7.0" match="compatible"/> - <import plugin="de.prob.core" version="9.3.0" match="equivalent"/> - <import plugin="org.eventb.core" version="2.1.0"/> - <import plugin="org.rodinp.core" version="1.3.1"/> - <import plugin="de.prob.ui" version="7.3.0" match="equivalent"/> - <import plugin="org.eclipse.core.resources" version="3.5.0" match="compatible"/> - <import plugin="org.eclipse.core.expressions" version="3.4.101" match="compatible"/> - <import plugin="org.eclipse.gef" version="3.5.0" match="compatible"/> - <import plugin="org.eclipse.ui.navigator" version="3.5.0" match="greaterOrEqual"/> - <import plugin="de.bmotionstudio.gef.editor" version="5.4.0" match="equivalent"/> - </requires> - - <plugin - id="de.bmotionstudio.gef.editor" - download-size="0" - install-size="0" - version="0.0.0" - unpack="false"/> - - <plugin - id="de.prob.core" - download-size="0" - install-size="0" - version="0.0.0"/> - - <plugin - id="de.prob.plugin" - download-size="0" - install-size="0" - version="0.0.0" - fragment="true" - unpack="false"/> - - <plugin - id="de.prob.ui" - download-size="0" - install-size="0" - version="0.0.0" - unpack="false"/> - - <plugin - id="de.bmotionstudio.rodin" - download-size="0" - install-size="0" - version="0.0.0" - fragment="true" - unpack="false"/> - -</feature> +litigation. + </license> + + <requires> + <import plugin="org.eclipse.ui" version="3.5.0" match="compatible"/> + <import plugin="org.eclipse.ui.ide" version="3.5.0" match="compatible"/> + <import plugin="org.eclipse.ui.views" version="3.5.0" match="compatible"/> + <import plugin="org.eclipse.core.runtime" version="3.5.0" match="compatible"/> + <import plugin="org.eclipse.core.databinding" version="1.2.0" match="compatible"/> + <import plugin="org.eclipse.jface.databinding" version="1.2.1" match="compatible"/> + <import plugin="org.eclipse.core.databinding.beans" version="1.1.1" match="compatible"/> + <import plugin="org.eclipse.gef" version="3.7.0" match="compatible"/> + <import plugin="de.prob.core" version="9.3.0" match="equivalent"/> + <import plugin="org.eventb.core" version="2.1.0"/> + <import plugin="org.rodinp.core" version="1.3.1"/> + <import plugin="de.prob.ui" version="7.3.0" match="equivalent"/> + <import plugin="org.eclipse.core.resources" version="3.5.0" match="compatible"/> + <import plugin="org.eclipse.core.expressions" version="3.4.101" match="compatible"/> + <import plugin="org.eclipse.gef" version="3.5.0" match="compatible"/> + <import plugin="org.eclipse.ui.navigator" version="3.5.0" match="greaterOrEqual"/> + <import plugin="de.bmotionstudio.gef.editor" version="5.4.0" match="equivalent"/> + </requires> + + <plugin + id="de.bmotionstudio.gef.editor" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="de.prob.core" + download-size="0" + install-size="0" + version="0.0.0"/> + + <plugin + id="de.prob.plugin" + download-size="0" + install-size="0" + version="0.0.0" + fragment="true" + unpack="false"/> + + <plugin + id="de.prob.ui" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="de.bmotionstudio.rodin" + download-size="0" + install-size="0" + version="0.0.0" + fragment="true" + unpack="false"/> + +</feature> diff --git a/de.prob2.units.feature/.project b/de.prob2.units.feature/.project new file mode 100644 index 0000000000000000000000000000000000000000..96b7c78653fba0643a8efc26c06b6a3f61c66bd7 --- /dev/null +++ b/de.prob2.units.feature/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>de.prob2.units.feature</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.pde.FeatureBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.FeatureNature</nature> + </natures> +</projectDescription> diff --git a/de.prob2.units.feature/.settings/org.eclipse.core.resources.prefs b/de.prob2.units.feature/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000000000000000000000000000000000..ae8dfb5865c1107f8366e1e8c2af6ad2d1a7a9f1 --- /dev/null +++ b/de.prob2.units.feature/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Tue Nov 29 16:17:25 CET 2011 +eclipse.preferences.version=1 +encoding/<project>=UTF-8 diff --git a/de.prob2.units.feature/.settings/org.eclipse.core.runtime.prefs b/de.prob2.units.feature/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000000000000000000000000000000000000..57a8ae0b2a629cab658cebb8c79bd02f33f25fb0 --- /dev/null +++ b/de.prob2.units.feature/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,3 @@ +#Tue Nov 29 16:17:25 CET 2011 +eclipse.preferences.version=1 +line.separator=\n diff --git a/de.prob2.units.feature/build.properties b/de.prob2.units.feature/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..64f93a9f0b7328eb563aa5ad6cec7f828020e124 --- /dev/null +++ b/de.prob2.units.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/de.prob2.units.feature/feature.xml b/de.prob2.units.feature/feature.xml new file mode 100644 index 0000000000000000000000000000000000000000..f02638a4f1ecfd6fc2843745fa8b2e45422ac453 --- /dev/null +++ b/de.prob2.units.feature/feature.xml @@ -0,0 +1,237 @@ +<?xml version="1.0" encoding="UTF-8"?> +<feature + id="de.prob2.units.feature" + label="ProB for Rodin2 - Physical Units Support" + version="2.3.5.qualifier" + provider-name="HHU Düsseldorf STUPS Group"> + + <description url="http://www.stups.uni-duesseldorf.de/ProB"> + ProB is an animator and model checker for the B-Method. It allows fully automatic animation of many B specifications, and can be used to systematically check a specification for errors. +Part of the research and development was conducted within the EPSRC funded projects ABCD and iMoc, and within the EU funded project Rodin. +Development is continued under the EU funded project Deploy and the DFG project Gepavas. +ProB has been successfully used on various industrial specifications and is now being used within Siemens. + </description> + + <copyright> + (C) 2000-2011 Michael Leuschel (and many others) All rights reserved. + </copyright> + + <license url="http://www.eclipse.org/org/documents/epl-v10.html"> + ProB can be used freely for commercial, non-commercial and academic +use under the Eclipse Public Licence v. 1.0. (below) +For availability of commercial support, please contact the author +(http://www.stups.uni-duesseldorf.de/~leuschel). +Use of ProB's nauty library for symmetry reduction implies further +restrictions (no applications with nontrivial military significance, +see http://cs.anu.edu.au/~bdm/nauty/). +--- +Eclipse Public License - v. 1.0 +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS +ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE +OF THIS AGREEMENT. +1. DEFINITIONS +"Contribution" means: +a) in the case of the initial Contributor, the initial code and +documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +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. +"Contributor" means any person or entity that distributes the +Program. +"Licensed Patents" 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. +"Program" means the Contributions distributed in accordance with +this Agreement. +"Recipient" means anyone who receives the Program under this +Agreement, including all Contributors. +2. GRANT OF RIGHTS +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. +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. +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. +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. +3. REQUIREMENTS +A Contributor may choose to distribute the Program in object +code form under its own license agreement, provided that: +a) it complies with the terms and conditions of this Agreement; +and +b) its license agreement: +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; +ii) effectively excludes on behalf of all Contributors all liability +for damages, including direct, indirect, special, incidental +and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement +are offered by that Contributor alone and not by any other party; +and +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. +When the Program is made available in source code form: +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of +the Program. +Contributors may not remove or alter any copyright notices contained +within the Program. +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. +4. COMMERCIAL DISTRIBUTION +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 +("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any +losses, damages and costs (collectively "Losses") 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. +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. +5. NO WARRANTY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM +IS PROVIDED ON AN "AS IS" 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. +6. DISCLAIMER OF LIABILITY +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. +7. GENERAL +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. +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. +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. +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. +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. + </license> + + <requires> + <import feature="de.prob2.feature" version="2.3.5" match="greaterOrEqual"/> + </requires> + + <plugin + id="de.prob.units" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + +</feature> diff --git a/settings.gradle b/settings.gradle index bb2187c38344f1fac923b7dee971552ee4cdd523..2999825e4166d18ddb81985fd572577f4c160833 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -include 'de.prob.core', 'de.bmotionstudio.gef.editor' ,'de.bmotionstudio.rodin', 'de.bmotionstudio.help' , 'de.prob.plugin', 'de.prob.ui', 'de.prob2.feature' +include 'de.prob.core', 'de.prob.core.tests', 'de.bmotionstudio.gef.editor' ,'de.bmotionstudio.rodin', 'de.bmotionstudio.help' , 'de.prob.plugin', 'de.prob.ui', 'de.prob2.feature', 'de.prob.units', 'de.prob2.units.feature' diff --git a/tycho_build.gradle b/tycho_build.gradle index 6ecc2f2214b82fd47e6a3cbd62cdc5b634b9009c..2deeab5a38cd8acfdcb426cd8f6703cb38d28ea6 100644 --- a/tycho_build.gradle +++ b/tycho_build.gradle @@ -1,3 +1,4 @@ +import org.apache.tools.ant.taskdefs.condition.Os /* Build Script can be executed via 'gradle install' Build Script Dependencies can be downloaded via 'gradle collectDepenencies' @@ -13,20 +14,32 @@ apply plugin: 'base' import groovy.io.FileType -tychoVersion = "0.14.1" +project.ext.tychoVersion = "0.15.0" + +try{ + excludeFromTychoBuild = excludeFromTychoBuild +}catch(MissingPropertyException e){ + project.ext.excludeFromTychoBuild = [] +} + +try{ + excludeFromClassPath = excludeFromClassPath +}catch(MissingPropertyException e){ + project.ext.excludeFromClassPath = [] +} try{ workspacePath = workspacePath }catch(MissingPropertyException e){ - workspacePath = "" + project.ext.workspacePath = "" } try{ dependencyFolder = dependencyFolder }catch(MissingPropertyException e){ - dependencyFolder = "lib/dependencies/" // Folder in each subproject where + project.ext.dependencyFolder = "lib/dependencies/" // Folder in each subproject where } try{ @@ -47,8 +60,8 @@ try{ } - groupID = "group" - for( i = 0; i < folderNames.size(); i++ ){ + project.ext.groupID = "group" + for( int i = 0; i < folderNames.size(); i++ ){ if( folderNames[i] ==~ /.*\.[rR]eleng/ ){ groupID = folderNames[i] @@ -64,8 +77,8 @@ try{ features = features }catch(MissingPropertyException e){ - features = [] - for( i = 0; i < subprojects.name.size(); i++ ){ + project.ext.features = [] + for( int i = 0; i < subprojects.name.size(); i++ ){ if( subprojects.name[i] ==~ /.*\.[fF]eature/ ){ features.add( subprojects.name[i] ) } @@ -77,13 +90,13 @@ try{ try{ repositoryName = repositoryName }catch(MissingPropertyException e){ - repositoryName = groupID+".repository" + project.ext.repositoryName = groupID+".repository" } try{ parentID = parentID }catch(MissingPropertyException e){ - parentID = groupID+".parent" + project.ext.parentID = groupID+".parent" } Boolean noDescriptions = false // in case of using own CategoryDescription Map @@ -91,21 +104,21 @@ Boolean noDescriptions = false // in case of using own CategoryDescription M try{ categoryDescriptions = categoryDescriptions }catch(MissingPropertyException e){ - categoryDescriptions = [ [:],[:] ] // label and descriptions of the features + project.ext.categoryDescriptions = [ [:],[:] ] // label and descriptions of the features noDescriptions = true } // categoryDescriptions = [["feature": "labelName","feature2": "label"],["feature": "featureDescription","feature2": "feature2Description"]] // label and descriptions of the features try{ targetRepositories = targetRepositories }catch(MissingPropertyException e){ - targetRepositories = ["http://download.eclipse.org/releases/indigo/"] + project.ext.targetRepositories = ["http://download.eclipse.org/releases/indigo/"] } try{ buildProduct = buildProduct }catch(MissingPropertyException e){ - buildProduct = false + project.ext.buildProduct = false } @@ -307,6 +320,7 @@ subprojects { task collectDependencies(type: Copy) { from configurations.compile + from configurations.runtime into "${dependencyFolder}" @@ -315,32 +329,32 @@ subprojects { task setClassPath(dependsOn: 'collectDependencies')<<{ description = "\tAdds all your Dependencies from your local lib folder in each project to it's classpath" - //if(project.name ==~ /birkhoff.bundle.*/){ - def dependencyList = [] - try{ - def dir = new File(workspacePath+project.name+"/"+dependencyFolder).eachFile() { file-> - if( !(file.getName() ==~/.*\.txt/) ){ - dependencyList << file.getName() + if( excludeFromClassPath.every{ it != project.name }){ + def dependencyList = [] + try{ + def dir = new File(workspacePath+project.name+"/"+dependencyFolder).eachFile() { file-> + if( !(file.getName() ==~/.*\.txt/) ){ + dependencyList << file.getName() + } } - } - if(features.every{ it != project.name }){ - boolean BundleClassPathPresent = checkForRunTimeLibs(project.name) - for(int icp = 0; icp < dependencyList.size; icp++){ - addLibToCP(project.name, dependencyList[icp]) //Adds Lib to .classPath file + if(features.every{ it != project.name }){ + boolean BundleClassPathPresent = checkForRunTimeLibs(project.name) + for(int icp = 0; icp < dependencyList.size; icp++){ + addLibToCP(project.name, dependencyList[icp]) //Adds Lib to .classPath file - if(!BundleClassPathPresent){ // Adds Lib to Manifest File - createRunTimeLib(dependencyList[icp], project.name) - BundleClassPathPresent = true - }else{ - if(!checkRunTimeLib(dependencyList[icp], project.name)){ // if library not present add it to RunTimeLibrary - addRunTimeLib( dependencyList[icp], project.name) + if(!BundleClassPathPresent){ // Adds Lib to Manifest File + createRunTimeLib(dependencyList[icp], project.name) + BundleClassPathPresent = true + }else{ + if(!checkRunTimeLib(dependencyList[icp], project.name)){ // if library not present add it to RunTimeLibrary + addRunTimeLib( dependencyList[icp], project.name) + } } } - } - /*dependencyList.each{ dep-> + /*dependencyList.each{ dep-> println project.name+": "+ dep // could still be usefull for debugging, that's why it's not deleted - }*/ + }*/ } def warningReadMe = new File(workspacePath+project.name+"/"+dependencyFolder+"_README.txt") warningReadMe.delete() @@ -349,10 +363,10 @@ subprojects { warningReadMe << "If any error concerning missing dependencies should occur please run 'gradle deleteFromClassPath setClassPath' in your workspace folder from your shell." - }catch(Exception e){ - println project.name+" has no dependencies in '${dependencyFolder}' defined: Classpath will not be changed" - } - //}// if projectAbfrage + }catch(Exception e){ + println project.name+" has no dependencies in '${dependencyFolder}' defined: Classpath will not be changed" + } + }// if exclude projectAbfrage }// setClassPath @@ -399,9 +413,9 @@ subprojects { if(features.every{ it != project.name }){ // Generating Poms for sub projects except features - content = new File(workspacePath+"${project.name}/META-INF/MANIFEST.MF").getText("UTF-8") + def content = new File(workspacePath+"${project.name}/META-INF/MANIFEST.MF").getText("UTF-8") - printFileLine = { + def printFileLine = { if( it ==~ /Bundle-Version.+qualifier/ ){ versionNumber = it.substring(16) // possibile error: cuts off first 16 chars @@ -490,7 +504,11 @@ task createParent() << { f << endRepos() f << moduleStart() for(int i = 0; i < numberOfProjects(); i++){ - f << module(projects(i)) + + if( excludeFromTychoBuild.every{ it != projects(i) } ){ + + f << module(projects(i)) + } } f << module(repositoryName) f << endParent() @@ -556,6 +574,11 @@ task completeInstall(dependsOn: [subprojects.collectDependencies, createPoms], t commandLine 'mvn', 'install', '-f', workspacePath+parentID+'/pom.xml' } +task tycho(dependsOn: [createPoms] , type:Exec) { + description = "\tExecutes a 'mvn install' of the parent pom.xml and auto-generates Tycho Poms" + commandLine 'mvn', 'install', '-f', workspacePath+parentID+'/pom.xml' +} + //--- Defining Tycho POM parts --// @@ -568,11 +591,33 @@ task completeInstall(dependsOn: [subprojects.collectDependencies, createPoms], t """ } def testArtifact(artifactId,versionNumber) { """ - <groupId>${groupId()}</groupId> - <artifactId>${artifactId}</artifactId> - <version>${versionNumber}</version> - <packaging>eclipse-test-plugin</packaging> - """ } + <groupId>${groupId()}</groupId> + <artifactId>${artifactId}</artifactId> + <version>${versionNumber}</version> + <packaging>eclipse-test-plugin</packaging> + <build> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-surefire-plugin</artifactId> + <configuration> + <!-- <useUIHarness>true</useUIHarness> --> + <!-- <useUIThread>true</useUIThread> --> + ${macTestArguments()} + <!-- <product>org.rodinp.platform.product</product> --> + </configuration> + </plugin> + </plugins> + </build> + """ } + + String macTestArguments() { + if ( Os.isFamily(Os.FAMILY_MAC) ){ + return "<argLine>-XstartOnFirstThread</argLine>\n" + }else{ + return "\n" + } + } def start() { """<?xml version="1.0" encoding="UTF-8"?>