Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-03-15 19:22:52 +0000
committerHenrik Rentz-Reichert2011-03-15 19:22:52 +0000
commit226bef496139eda78cc59238dcc5455a1fea2c0e (patch)
tree357cf4a6b6625165b32ef64ad68d37fa94599e3a /plugins/org.eclipse.etrice.ui.commands
parent6d1c62cbabc9c3cc354dbaa3a02ea3649cf6ca4e (diff)
downloadorg.eclipse.etrice-226bef496139eda78cc59238dcc5455a1fea2c0e.tar.gz
org.eclipse.etrice-226bef496139eda78cc59238dcc5455a1fea2c0e.tar.xz
org.eclipse.etrice-226bef496139eda78cc59238dcc5455a1fea2c0e.zip
ui.commands: open structure/behavior from xtext document
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.commands')
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/plugin.xml25
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenBehaviorHandler.java28
-rw-r--r--plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenStructureHandler.java29
3 files changed, 74 insertions, 8 deletions
diff --git a/plugins/org.eclipse.etrice.ui.commands/plugin.xml b/plugins/org.eclipse.etrice.ui.commands/plugin.xml
index 3a63bf606..018f81dee 100644
--- a/plugins/org.eclipse.etrice.ui.commands/plugin.xml
+++ b/plugins/org.eclipse.etrice.ui.commands/plugin.xml
@@ -40,11 +40,15 @@
commandId="org.eclipse.etrice.ui.commands.commands.openBehavior"
class="org.eclipse.etrice.ui.commands.handlers.OpenBehaviorHandler">
<activeWhen>
- <with
- variable="activeEditorId">
- <equals
- value="org.eclipse.etrice.ui.structure.editor.StructureEditor">
- </equals>
+ <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>
@@ -54,9 +58,14 @@
<activeWhen>
<with
variable="activeEditorId">
- <equals
- value="org.eclipse.etrice.ui.behavior.editor.BehaviorEditor">
- </equals>
+ <or>
+ <equals
+ value="org.eclipse.etrice.ui.behavior.editor.BehaviorEditor">
+ </equals>
+ <equals
+ value="org.eclipse.etrice.core.Room">
+ </equals>
+ </or>
</with>
</activeWhen>
</handler>
diff --git a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenBehaviorHandler.java b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenBehaviorHandler.java
index 81d64003a..432e4c358 100644
--- a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenBehaviorHandler.java
+++ b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenBehaviorHandler.java
@@ -3,13 +3,20 @@ 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.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.ui.behavior.DiagramAccess;
import org.eclipse.etrice.ui.structure.editor.StructureEditor;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
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.XtextResource;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
@@ -37,6 +44,27 @@ public class OpenBehaviorHandler extends AbstractHandler {
da.openDiagramEditor(sc);
}
}
+ else if (editor instanceof XtextEditor) {
+ XtextEditor xed = (XtextEditor) editor;
+ ISelection selection = xed.getSelectionProvider().getSelection();
+ if (selection instanceof ITextSelection) {
+ final ITextSelection ss = (ITextSelection) selection;
+ xed.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
+ @Override
+ public void process(XtextResource resource) throws Exception {
+ EObject obj = EObjectAtOffsetHelper.resolveElementAt(resource, ss.getOffset(), null);
+ while (obj!=null) {
+ if (obj instanceof ActorClass) {
+ DiagramAccess da = new DiagramAccess();
+ da.openDiagramEditor((ActorClass)obj);
+ break;
+ }
+ obj = obj.eContainer();
+ }
+ }
+ });
+ }
+ }
return null;
}
}
diff --git a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenStructureHandler.java b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenStructureHandler.java
index de2c1481b..0365adb15 100644
--- a/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenStructureHandler.java
+++ b/plugins/org.eclipse.etrice.ui.commands/src/org/eclipse/etrice/ui/commands/handlers/OpenStructureHandler.java
@@ -3,12 +3,20 @@ 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.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.ui.structure.DiagramAccess;
import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
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.XtextResource;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
@@ -34,6 +42,27 @@ public class OpenStructureHandler extends AbstractHandler {
DiagramAccess da = new DiagramAccess();
da.openDiagramEditor(ac);
}
+ else if (editor instanceof XtextEditor) {
+ XtextEditor xed = (XtextEditor) editor;
+ ISelection selection = xed.getSelectionProvider().getSelection();
+ if (selection instanceof ITextSelection) {
+ final ITextSelection ss = (ITextSelection) selection;
+ xed.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
+ @Override
+ public void process(XtextResource resource) throws Exception {
+ EObject obj = EObjectAtOffsetHelper.resolveElementAt(resource, ss.getOffset(), null);
+ while (obj!=null) {
+ if (obj instanceof StructureClass) {
+ DiagramAccess da = new DiagramAccess();
+ da.openDiagramEditor((StructureClass)obj);
+ break;
+ }
+ obj = obj.eContainer();
+ }
+ }
+ });
+ }
+ }
return null;
}
}

Back to the top