Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-03-28 10:30:00 +0000
committerHenrik Rentz-Reichert2011-03-28 10:30:00 +0000
commit700c5efa549f24955234180d1bc61fe6bd396689 (patch)
tree066e50b70a9801de923db94ebd486de434b613ef /plugins/org.eclipse.etrice.ui.commands
parent7a600ee042a89836d92822d620925dab9a79e346 (diff)
parent081e859ef73c56567aaee024ecccac1717324932 (diff)
downloadorg.eclipse.etrice-700c5efa549f24955234180d1bc61fe6bd396689.tar.gz
org.eclipse.etrice-700c5efa549f24955234180d1bc61fe6bd396689.tar.xz
org.eclipse.etrice-700c5efa549f24955234180d1bc61fe6bd396689.zip
Merge branch 'before_indigo' of https://git.eclipse.org/gitroot/etrice/org.eclipse.etrice
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.commands')
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/.classpath7
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/.gitignore1
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/.project28
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/META-INF/MANIFEST.MF23
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/build.properties6
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/icons/Behavior.gifbin0 -> 119 bytes
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/icons/RoomModel.gifbin0 -> 145 bytes
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/icons/Structure.gifbin0 -> 137 bytes
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/plugin.xml178
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/Activator.java61
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/AbstractEditHandler.java168
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditBehaviorHandler.java221
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditModelHandler.java70
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditStructureHandler.java48
15 files changed, 819 insertions, 0 deletions
diff --git a/plugins/org.eclipse.etrice.ui.commands/.classpath b/plugins/org.eclipse.etrice.ui.commands/.classpath
new file mode 100644
index 000000000..8a8f1668c
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.etrice.ui.commands/.gitignore b/plugins/org.eclipse.etrice.ui.commands/.gitignore
new file mode 100644
index 000000000..092357e47
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/.gitignore
@@ -0,0 +1 @@
+bin
diff --git a/plugins/org.eclipse.etrice.ui.commands/.project b/plugins/org.eclipse.etrice.ui.commands/.project
new file mode 100644
index 000000000..c3a385f70
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.etrice.ui.commands</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.etrice.ui.commands/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.ui.commands/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..c23e01803
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Sun Mar 13 09:32:41 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/plugins/org.eclipse.etrice.ui.commands/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.commands/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..000ccd919
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: eTrice Commands
+Bundle-SymbolicName: org.eclipse.etrice.ui.commands; singleton:=true
+Bundle-Version: 0.1.0
+Bundle-Activator: org.eclipse.etrice.ui.commands.Activator
+Bundle-Vendor: eTrice (Incubation)
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.etrice.core.room;bundle-version="0.1.0",
+ org.eclipse.etrice.core.room.ui;bundle-version="0.1.0",
+ org.eclipse.etrice.ui.structure;bundle-version="0.1.0",
+ org.eclipse.etrice.ui.behavior;bundle-version="0.1.0",
+ org.eclipse.etrice.ui.common;bundle-version="0.1.0",
+ org.eclipse.graphiti;bundle-version="0.7.0",
+ org.eclipse.graphiti.ui;bundle-version="0.7.0",
+ org.eclipse.emf.edit;bundle-version="2.6.0",
+ org.eclipse.emf.edit.ui;bundle-version="2.6.0",
+ org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100",
+ org.eclipse.gef;bundle-version="3.6.1",
+ org.eclipse.xtext.ui;bundle-version="1.0.1"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.eclipse.etrice.ui.commands/build.properties b/plugins/org.eclipse.etrice.ui.commands/build.properties
new file mode 100644
index 000000000..4b8162ab8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/
diff --git a/plugins/org.eclipse.etrice.ui.commands/icons/Behavior.gif b/plugins/org.eclipse.etrice.ui.commands/icons/Behavior.gif
new file mode 100644
index 000000000..48918e82f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/icons/Behavior.gif
Binary files differ
diff --git a/plugins/org.eclipse.etrice.ui.commands/icons/RoomModel.gif b/plugins/org.eclipse.etrice.ui.commands/icons/RoomModel.gif
new file mode 100644
index 000000000..414613ba8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/icons/RoomModel.gif
Binary files differ
diff --git a/plugins/org.eclipse.etrice.ui.commands/icons/Structure.gif b/plugins/org.eclipse.etrice.ui.commands/icons/Structure.gif
new file mode 100644
index 000000000..ab2f7c013
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/icons/Structure.gif
Binary files differ
diff --git a/plugins/org.eclipse.etrice.ui.commands/plugin.xml b/plugins/org.eclipse.etrice.ui.commands/plugin.xml
new file mode 100644
index 000000000..cf0a1c902
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/plugin.xml
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <category
+ name="eTrice Commands"
+ id="org.eclipse.etrice.ui.commands.category">
+ </category>
+ <command
+ name="open associated textual model"
+ categoryId="org.eclipse.etrice.ui.commands.category"
+ id="org.eclipse.etrice.ui.commands.commands.editModel">
+ </command>
+ <command
+ description="open this ActorClass&apos;s structure as diagram"
+ id="org.eclipse.etrice.core.room.ui.editStructure"
+ name="Edit Structure">
+ </command>
+ <command
+ description="open this ActorClass&apos;s state machine as diagram"
+ id="org.eclipse.etrice.core.room.ui.editBehavior"
+ name="Edit Behavior">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ commandId="org.eclipse.etrice.core.room.ui.editBehavior"
+ class="org.eclipse.etrice.ui.commands.handlers.EditBehaviorHandler">
+ <activeWhen>
+ <with variable="activeEditorId">
+ <or>
+ <equals
+ value="org.eclipse.etrice.ui.structure.editor.StructureEditor">
+ </equals>
+ <equals
+ value="org.eclipse.etrice.core.Room">
+ </equals>
+ </or>
+ </with>
+ </activeWhen>
+ </handler>
+ <handler
+ commandId="org.eclipse.etrice.core.room.ui.editStructure"
+ class="org.eclipse.etrice.ui.commands.handlers.EditStructureHandler">
+ <activeWhen>
+ <with
+ variable="activeEditorId">
+ <or>
+ <equals
+ value="org.eclipse.etrice.ui.behavior.editor.BehaviorEditor">
+ </equals>
+ <equals
+ value="org.eclipse.etrice.core.Room">
+ </equals>
+ </or>
+ </with>
+ </activeWhen>
+ </handler>
+ <handler
+ commandId="org.eclipse.etrice.ui.commands.commands.editModel"
+ class="org.eclipse.etrice.ui.commands.handlers.EditModelHandler">
+ <activeWhen>
+ <or>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.etrice.ui.behavior.editor.BehaviorEditor">
+ </equals>
+ </with>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.etrice.ui.structure.editor.StructureEditor">
+ </equals>
+ </with>
+ </or>
+ </activeWhen>
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.bindings">
+ <key
+ commandId="org.eclipse.etrice.core.room.ui.editBehavior"
+ contextId="org.eclipse.ui.contexts.window"
+ sequence="M3+B"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ <key
+ commandId="org.eclipse.etrice.core.room.ui.editStructure"
+ contextId="org.eclipse.ui.contexts.window"
+ sequence="M3+S"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ <key
+ commandId="org.eclipse.etrice.ui.commands.commands.editModel"
+ contextId="org.eclipse.ui.contexts.window"
+ sequence="M3+M"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
+ </key>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="menu:org.eclipse.ui.main.menu?after=additions">
+ <menu
+ label="eTrice"
+ mnemonic="T"
+ id="org.eclipse.etrice.ui.commands.menus.eTrice">
+ <command
+ commandId="org.eclipse.etrice.core.room.ui.editBehavior"
+ icon="icons/Behavior.gif"
+ id="org.eclipse.etrice.ui.commands.menus.editBehavior"
+ label="Open Behavior"
+ mnemonic="B">
+ </command>
+ <command
+ commandId="org.eclipse.etrice.core.room.ui.editStructure"
+ icon="icons/Structure.gif"
+ id="org.eclipse.etrice.ui.commands.menus.editStructure"
+ label="Open Structure"
+ mnemonic="S">
+ </command>
+ <command
+ commandId="org.eclipse.etrice.ui.commands.commands.editModel"
+ icon="icons/RoomModel.gif"
+ id="org.eclipse.etrice.ui.commands.menus.openModel"
+ label="Open Model"
+ mnemonic="M">
+ </command>
+ </menu>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.xtext.ui.outline?after=additions">
+ <command
+ commandId="org.eclipse.etrice.core.room.ui.editBehavior"
+ label="Edit Behavior"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <iterate>
+ <adapt
+ type="org.eclipse.etrice.core.room.ActorClass">
+ </adapt>
+ </iterate>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.xtext.ui.outline?after=additions">
+ <command
+ commandId="org.eclipse.etrice.core.room.ui.editStructure"
+ label="Edit Structure"
+ style="push">
+ <visibleWhen>
+ <iterate operator="and" ifEmpty="false">
+ <or>
+ <adapt
+ type="org.eclipse.etrice.core.room.ActorClass">
+ </adapt>
+ <adapt
+ type="org.eclipse.etrice.core.room.SubSystemClass">
+ </adapt>
+ <adapt
+ type="org.eclipse.etrice.core.room.LogicalSystem">
+ </adapt>
+ </or>
+ </iterate>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/Activator.java b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/Activator.java
new file mode 100644
index 000000000..512081655
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/Activator.java
@@ -0,0 +1,61 @@
+package org.eclipse.etrice.ui.commands;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.etrice.ui.commands"; //$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;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/AbstractEditHandler.java b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/AbstractEditHandler.java
new file mode 100644
index 000000000..c34418cdc
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/AbstractEditHandler.java
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.commands.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.ui.RoomUiModule;
+import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
+import org.eclipse.etrice.ui.structure.editor.StructureEditor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.xtext.resource.EObjectAtOffsetHelper;
+import org.eclipse.xtext.resource.IFragmentProvider;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+import org.eclipse.xtext.ui.editor.outline.ContentOutlineNode;
+import org.eclipse.xtext.ui.editor.utils.EditorUtils;
+import org.eclipse.xtext.util.CancelIndicator;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+import org.eclipse.xtext.validation.CheckMode;
+import org.eclipse.xtext.validation.IResourceValidator;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+/**
+ * description
+ *
+ * @author Henrik Rentz-Reichert initial contribution and API
+ *
+ */
+public abstract class AbstractEditHandler extends AbstractHandler {
+
+ @Inject
+ protected IResourceValidator resourceValidator;
+
+ @Inject IFragmentProvider fragmentProvider;
+
+ public AbstractEditHandler() {
+ super();
+
+ Injector injector = RoomUiModule.getInjector();
+ injector.injectMembers(this);
+ }
+
+ abstract protected boolean prepare(XtextEditor xtextEditor, final String fragment);
+ abstract protected void openEditor(EObject object);
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ IEditorPart editor = window.getActivePage().getActiveEditor();
+ if (editor instanceof XtextEditor) {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ // event from the xtext editor's outline view
+ IStructuredSelection ss = (IStructuredSelection) selection;
+ Object sel = ss.getFirstElement();
+ if (sel instanceof ContentOutlineNode) {
+ XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
+ IXtextDocument document = xtextEditor.getDocument();
+ final String fragment = ((ContentOutlineNode) sel).getURI().fragment();
+ if (checkPrerequisites(xtextEditor, document, fragment)) {
+ openEditor(document, fragment);
+ }
+ }
+ }
+ else if (selection instanceof ITextSelection) {
+ // event from the xtext editor itself
+ final ITextSelection ss = (ITextSelection) selection;
+ XtextEditor xed = (XtextEditor) editor;
+ IXtextDocument document = xed.getDocument();
+ String fragment = document.readOnly(new IUnitOfWork<String, XtextResource>() {
+ @Override
+ public String exec(XtextResource resource) throws Exception {
+ EObject obj = EObjectAtOffsetHelper.resolveElementAt(resource, ss.getOffset(), null);
+ while (obj!=null) {
+ if (obj instanceof ActorClass) {
+ return fragmentProvider.getFragment(obj, null);
+ }
+ obj = obj.eContainer();
+ }
+ return "";
+ }
+ });
+ if (checkPrerequisites(xed, document, fragment)) {
+ openEditor(document, fragment);
+ }
+ }
+ }
+ else if (editor instanceof StructureEditor) {
+ StructureClass sc = ((StructureEditor)editor).getStructureClass();
+ if (sc instanceof ActorClass) {
+ openEditor(sc);
+ }
+ }
+ else if (editor instanceof BehaviorEditor) {
+ ActorClass ac = ((BehaviorEditor)editor).getActorClass();
+ openEditor(ac);
+ }
+ return null;
+ }
+
+ protected void openEditor(IXtextDocument document, final String fragment) {
+ document.readOnly(new IUnitOfWork.Void<XtextResource>() {
+ @Override
+ public void process(XtextResource resource) throws Exception {
+ if (resource != null) {
+ EObject object = resource.getEObject(fragment);
+ openEditor(object);
+ }
+ }
+ });
+ }
+
+ protected boolean checkPrerequisites(XtextEditor xtextEditor,
+ IXtextDocument document, final String fragment) {
+ if (hasIssues(document, new NullProgressMonitor())) {
+ MessageDialog.openError(xtextEditor.getSite().getShell(), "Validation Errors", "The editor has validation errors.\nCannot open diagram!");
+ return false;
+ }
+ if (xtextEditor.isDirty()) {
+ if (!MessageDialog.openQuestion(xtextEditor.getSite().getShell(), "Save model file", "The editor will be saved before opening the diagram editor.\nProceed?"))
+ return false;
+ // postpone save to avoid doing it twice
+ }
+ if (!prepare(xtextEditor, fragment))
+ return false;
+ if (xtextEditor.isDirty()) {
+ xtextEditor.doSave(new NullProgressMonitor());
+ }
+ return true;
+ }
+
+ public boolean hasIssues(IXtextDocument xtextDocument, final IProgressMonitor monitor) {
+ final boolean issues = xtextDocument
+ .readOnly(new IUnitOfWork<Boolean, XtextResource>() {
+ public Boolean exec(XtextResource resource) throws Exception {
+ if (resource == null)
+ return false;
+ return !resourceValidator.validate(resource, CheckMode.NORMAL_AND_FAST, new CancelIndicator() {
+ public boolean isCanceled() {
+ return monitor.isCanceled();
+ }
+ }).isEmpty();
+ }
+ });
+ return issues;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditBehaviorHandler.java b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditBehaviorHandler.java
new file mode 100644
index 000000000..bc2d8dfab
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditBehaviorHandler.java
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.commands.handlers;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.naming.RoomFragmentProvider;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.StateGraph;
+import org.eclipse.etrice.core.room.Transition;
+import org.eclipse.etrice.core.ui.RoomUiModule;
+import org.eclipse.etrice.ui.behavior.DiagramAccess;
+import org.eclipse.jface.dialogs.MessageDialog;
+<<<<<<< HEAD:plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/outline/EditBehaviorHandler.java
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.views.contentoutline.ContentOutline;
+=======
+>>>>>>> FETCH_HEAD:plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditBehaviorHandler.java
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.outline.impl.EObjectNode;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+<<<<<<< HEAD:plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/outline/EditBehaviorHandler.java
+import org.eclipse.xtext.ui.editor.utils.EditorUtils;
+=======
+import org.eclipse.xtext.ui.editor.model.edit.DefaultDocumentEditor;
+>>>>>>> FETCH_HEAD:plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditBehaviorHandler.java
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+
+import com.google.inject.Injector;
+
+/**
+ * Handler for outline menu item to open behavior editor.
+ * The handler will ask to save unsaved editor before opening the diagram.
+ *
+ * If there are unnamed transitions they will be named with unique names.
+ *
+ * @author Henrik Rentz-Reichert initial contribution and API
+ *
+ */
+public class EditBehaviorHandler extends AbstractEditHandler {
+
+<<<<<<< HEAD:plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/outline/EditBehaviorHandler.java
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection) selection;
+ Object sel = ss.getFirstElement();
+ if (sel instanceof EObjectNode) {
+ final EObjectNode node = (EObjectNode) sel;
+ XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
+ if (xtextEditor.isDirty()) {
+ if (!MessageDialog.openQuestion(xtextEditor.getSite().getShell(), "Save model file", "The editor will be saved before opening the diagram editor.\nProceed?"))
+ return null;
+ // postpone save to avoid doing it twice
+ }
+ if (hasUnnamedTransitions(xtextEditor.getDocument(), node.getEObjectURI().fragment())) {
+ if (!MessageDialog.openQuestion(xtextEditor.getSite().getShell(), "Create transition names", "Transition names will be created where missing.\nProceed?"))
+ return null;
+ createTransitionNames(xtextEditor.getDocument(), node.getEObjectURI().fragment());
+ xtextEditor.doSave(new NullProgressMonitor());
+ }
+ if (xtextEditor.isDirty()) {
+ xtextEditor.doSave(new NullProgressMonitor());
+ }
+ xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
+ @Override
+ public void process(XtextResource resource) throws Exception {
+ if (resource != null) {
+ EObject object = resource.getEObject(node.getEObjectURI().fragment());
+ if (object instanceof ActorClass) {
+ DiagramAccess diagramAccess = new DiagramAccess();
+ diagramAccess.openDiagramEditor((ActorClass) object);
+ }
+ }
+ }
+ });
+ }
+=======
+ protected boolean prepare(XtextEditor xtextEditor, final String fragment) {
+ if (hasUnnamedTransitions(xtextEditor.getDocument(), fragment)) {
+ if (!MessageDialog.openQuestion(xtextEditor.getSite().getShell(), "Create transition names", "Transition names will be created where missing.\nProceed?"))
+ return false;
+ createTransitionNames(xtextEditor.getDocument(), fragment);
+ xtextEditor.doSave(new NullProgressMonitor());
+>>>>>>> FETCH_HEAD:plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditBehaviorHandler.java
+ }
+ return true;
+ }
+
+ /**
+ * @param document
+ * @param fragment
+ */
+ private void createTransitionNames(IXtextDocument document, final String fragment) {
+ /* TODOHRR: make this work again
+ DefaultDocumentEditor edit = new DefaultDocumentEditor();
+ Injector injector = RoomUiModule.getInjector();
+ injector.injectMembers(edit);
+ edit.process(new IUnitOfWork.Void<XtextResource>() {
+ @Override
+ public void process(XtextResource resource) throws Exception {
+ if (resource != null) {
+ EObject object = resource.getEObject(fragment);
+ if (object instanceof ActorClass) {
+ createTransitionNames(((ActorClass) object).getStateMachine());
+ }
+ }
+ }
+
+ private void createTransitionNames(StateGraph sg) {
+ if (sg==null)
+ return;
+
+ for (Transition tr : sg.getTransitions()) {
+ if (tr.getName()==null || tr.getName().isEmpty()) {
+ tr.setName(RoomNameProvider.getUniqueTransitionName(sg));
+ }
+ }
+
+ for (State s : sg.getStates()) {
+ createTransitionNames(s.getSubgraph());
+ }
+ }
+
+ }, document);
+ */
+ }
+
+ /**
+ * @param document
+ * @param fragment
+ * @return
+ */
+ private boolean hasUnnamedTransitions(IXtextDocument document, final String fragment) {
+ return document.readOnly(new IUnitOfWork<Boolean, XtextResource>() {
+ @Override
+ public Boolean exec(XtextResource resource) throws Exception {
+ if (resource != null) {
+ EObject object = resource.getEObject(fragment);
+ if (object instanceof ActorClass) {
+ return hasUnnamedTransitions(((ActorClass) object).getStateMachine());
+ }
+ }
+ return false;
+ }
+
+ private boolean hasUnnamedTransitions(StateGraph sg) {
+ if (sg==null)
+ return false;
+
+ for (Transition tr : sg.getTransitions()) {
+ if (tr.getName()==null || tr.getName().isEmpty())
+ return true;
+ }
+
+ for (State s : sg.getStates()) {
+ if (hasUnnamedTransitions(s.getSubgraph()))
+ return true;
+ }
+
+ return false;
+ }
+ });
+ }
+
+<<<<<<< HEAD:plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/outline/EditBehaviorHandler.java
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ IWorkbenchPage page = win.getActivePage();
+ IWorkbenchPart part = page.getActivePart();
+ if (part instanceof ContentOutline) {
+ ISelection selection = ((ContentOutline)part).getSelection();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection) selection;
+ Object sel = ss.getFirstElement();
+ if (sel instanceof EObjectNode) {
+ EObjectNode node = (EObjectNode) sel;
+ if (RoomFragmentProvider.isActorClass(node.getEObjectURI().fragment()))
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+=======
+ protected void openEditor(EObject object) {
+ if (object instanceof ActorClass) {
+ DiagramAccess diagramAccess = new DiagramAccess();
+ diagramAccess.openDiagramEditor((ActorClass) object);
+ }
+ }
+
+>>>>>>> FETCH_HEAD:plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditBehaviorHandler.java
+}
diff --git a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditModelHandler.java b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditModelHandler.java
new file mode 100644
index 000000000..d0c5c4164
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditModelHandler.java
@@ -0,0 +1,70 @@
+package org.eclipse.etrice.ui.commands.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.edit.ui.util.EditUIUtil;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.ui.RoomUiModule;
+import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
+import org.eclipse.etrice.ui.structure.editor.StructureEditor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.xtext.resource.ILocationInFileProvider;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.util.TextLocation;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+/**
+ * Our sample handler extends AbstractHandler, an IHandler base class.
+ * @see org.eclipse.core.commands.IHandler
+ * @see org.eclipse.core.commands.AbstractHandler
+ */
+public class EditModelHandler extends AbstractHandler {
+
+ @Inject
+ ILocationInFileProvider locationProvider;
+
+ /**
+ * The constructor.
+ */
+ public EditModelHandler() {
+ Injector injector = RoomUiModule.getInjector();
+ injector.injectMembers(this);
+ }
+
+ /**
+ * the command has been executed, so extract extract the needed information
+ * from the application context.
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ IEditorPart editor = window.getActivePage().getActiveEditor();
+ StructureClass sc = null;
+ if (editor instanceof StructureEditor) {
+ sc = ((StructureEditor)editor).getStructureClass();
+ }
+ else if (editor instanceof BehaviorEditor) {
+ sc = ((BehaviorEditor)editor).getActorClass();
+ }
+ if (sc!=null) {
+ try {
+ if (EditUIUtil.openEditor(sc)) {
+ editor = window.getActivePage().getActiveEditor();
+ if (editor instanceof XtextEditor) {
+ XtextEditor xed = (XtextEditor) editor;
+ TextLocation location = locationProvider.getLocation(sc);
+ xed.selectAndReveal(location.getOffset(), location.getLength());
+ }
+ }
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditStructureHandler.java b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditStructureHandler.java
new file mode 100644
index 000000000..a3abdeb4e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/EditStructureHandler.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.commands.handlers;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+
+/**
+ * Handler for outline menu item to open structure editor.
+ * The handler will ask to save unsaved editor before opening the diagram.
+ *
+ * @author Henrik Rentz-Reichert initial contribution and API
+ *
+ */
+public class EditStructureHandler extends AbstractEditHandler {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.ui.outline.AbstractEditHandler#prepare(org.eclipse.xtext.ui.editor.XtextEditor, java.lang.String)
+ */
+ @Override
+ protected boolean prepare(XtextEditor xtextEditor, String fragment) {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.ui.outline.AbstractEditHandler#openEditor(org.eclipse.emf.ecore.EObject)
+ */
+ @Override
+ protected void openEditor(EObject object) {
+ if (object instanceof StructureClass) {
+ DiagramAccess diagramAccess = new DiagramAccess();
+ diagramAccess.openDiagramEditor((StructureClass) object);
+ }
+ }
+
+}

Back to the top