Enabling double clicking to open the right editor.
diff --git a/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/presentation/SpecificationEditor.java b/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/presentation/SpecificationEditor.java
index a4ecbd3..f5dfc45 100644
--- a/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/presentation/SpecificationEditor.java
+++ b/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/presentation/SpecificationEditor.java
@@ -160,6 +160,10 @@
}
buildContextMenu();
}
+
+ public Specification getSpecification() {
+ return specification;
+ }
/**
* Registers a command stack listener that updates the save state and
diff --git a/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/util/ProrEditorUtil.java b/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/util/ProrEditorUtil.java
index a7a7f49..41733bc 100644
--- a/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/util/ProrEditorUtil.java
+++ b/org.eclipse.rmf.reqif10.pror.editor/src/org/eclipse/rmf/reqif10/pror/editor/util/ProrEditorUtil.java
@@ -21,10 +21,12 @@
import org.eclipse.emf.common.command.CommandWrapper;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.rmf.reqif10.AttributeValue;
import org.eclipse.rmf.reqif10.DatatypeDefinition;
import org.eclipse.rmf.reqif10.EnumValue;
+import org.eclipse.rmf.reqif10.ReqIF;
import org.eclipse.rmf.reqif10.SpecHierarchy;
import org.eclipse.rmf.reqif10.SpecObject;
import org.eclipse.rmf.reqif10.Specification;
@@ -36,10 +38,19 @@
import org.eclipse.rmf.reqif10.pror.configuration.ProrPresentationConfiguration;
import org.eclipse.rmf.reqif10.pror.configuration.ProrSpecViewConfiguration;
import org.eclipse.rmf.reqif10.pror.configuration.UnifiedColumn;
+import org.eclipse.rmf.reqif10.pror.editor.presentation.Reqif10Editor;
+import org.eclipse.rmf.reqif10.pror.editor.presentation.ReqifSpecificationEditorInput;
+import org.eclipse.rmf.reqif10.pror.editor.presentation.SpecificationEditor;
import org.eclipse.rmf.reqif10.pror.editor.presentation.service.IProrCellRenderer;
import org.eclipse.rmf.reqif10.pror.editor.presentation.service.PresentationEditorInterface;
import org.eclipse.rmf.reqif10.pror.util.ConfigurationUtil;
import org.eclipse.rmf.reqif10.pror.util.ProrUtil;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
public class ProrEditorUtil {
@@ -49,21 +60,9 @@
String title = ConfigurationUtil.getSpecElementLabel(spec,
adapterFactory);
- // TODO does not work in headless mode.
- // Getting the file path is an absolute nightmare!
-// List<String> segments = spec.eResource().getURI().segmentsList();
-// IPath filepath = ResourcesPlugin.getWorkspace().getRoot()
-// .getRawLocation();
-// for (int i = 1; i < segments.size() - 1; i++) {
-// filepath = filepath.append(segments.get(i));
-// }
-// String baseURL = filepath.toPortableString() + "/";
- String baseURL = ".";
-
sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
sb.append("<html>\n");
sb.append("<head>\n");
- sb.append("<base href=\"" + baseURL + "\" />\n");
sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
sb.append("<meta name=\"GENERATOR\" content=\"ProR (www.pror.org)\">\n");
sb.append("<title>" + title + "</title>\n");
@@ -220,4 +219,66 @@
};
}
+ /**
+ * Attempts to find the {@link Reqif10Editor} or {@link SpecificationEditor}
+ * for the given EObject by walking up the parent hierarchy to the enclosing
+ * {@link ReqIF} or {@link Specification}. If the {@link Reqif10Editor} is
+ * found for a Specification, the corresponding editor will be opened.
+ *
+ * @return the Editor or null if none found.
+ */
+ public static IEditorPart getEditor(EObject eObject) {
+ ReqIF reqif = null;
+ Specification spec = null;
+ while (eObject != null) {
+ if (eObject instanceof Specification) {
+ spec = (Specification) eObject;
+ }
+ if (eObject instanceof ReqIF) {
+ reqif = (ReqIF) eObject;
+ break;
+ }
+ eObject = eObject.eContainer();
+ }
+ if (reqif == null) return null;
+
+ // Find the editor(s)
+ IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage();
+
+ IEditorReference[] eRefs = activePage.getEditorReferences();
+ for (IEditorReference eRef : eRefs) {
+ IEditorPart editor = eRef.getEditor(false);
+ if (editor instanceof SpecificationEditor) {
+ SpecificationEditor specEditor = (SpecificationEditor) editor;
+
+ // Case 1: We found the right SpecificationEditor
+ if (specEditor.getSpecification().equals(spec)) {
+ return specEditor;
+ }
+ }
+ if (editor instanceof Reqif10Editor) {
+ Reqif10Editor reqifEditor = (Reqif10Editor) editor;
+ if (reqifEditor.getReqif().equals(reqif)) {
+
+ // Case 2: We found the right Reqif10Editor
+ if (spec == null) return reqifEditor;
+
+ // Case 3: We found the Reqif10Editor, but need the SpecificationEditor
+ ReqifSpecificationEditorInput editorInput = new ReqifSpecificationEditorInput(
+ reqifEditor, spec);
+ try {
+ return IDE.openEditor(activePage, editorInput,
+ SpecificationEditor.EDITOR_ID, false);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ // Case 4: Nothing found
+ return null;
+ }
+
+
}
diff --git a/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/ui/ReqIFSearchResultPage.java b/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/ui/ReqIFSearchResultPage.java
index 7d9ee82..28673bd 100644
--- a/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/ui/ReqIFSearchResultPage.java
+++ b/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/ui/ReqIFSearchResultPage.java
@@ -27,13 +27,19 @@
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.rmf.reqif10.SpecHierarchy;
+import org.eclipse.rmf.reqif10.Specification;
import org.eclipse.rmf.reqif10.pror.configuration.provider.ConfigurationItemProviderAdapterFactory;
import org.eclipse.rmf.reqif10.pror.editor.propertiesview.ProrPropertySheetPage;
+import org.eclipse.rmf.reqif10.pror.editor.util.ProrEditorUtil;
import org.eclipse.rmf.reqif10.pror.provider.ReqIF10ItemProviderAdapterFactory;
import org.eclipse.rmf.reqif10.pror.provider.ReqIFContentItemProvider;
import org.eclipse.rmf.reqif10.pror.util.ProrUtil;
@@ -123,6 +129,39 @@
};
treeViewer.addFilter(viewerFilter);
getSite().setSelectionProvider(treeViewer);
+
+ treeViewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ // Only reacts on SpecHierarchies and Specifications
+ if (event.getSelection() instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection)event.getSelection();
+ showIfPossible(selection.getFirstElement());
+ }
+ }
+ });
+ }
+
+ /**
+ * If the provided object is a {@link SpecHierarchy} or
+ * {@link Specification}, then the corresponding {@link Specification} will
+ * be opened or activated, and the object will be selected.
+ */
+ protected void showIfPossible(Object object) {
+ if (object instanceof SpecHierarchy) {
+ SpecHierarchy sh = (SpecHierarchy)object;
+ while (sh.eContainer() instanceof SpecHierarchy) {
+ sh = (SpecHierarchy) sh.eContainer();
+ }
+ object = sh.eContainer();
+ }
+ if (object instanceof Specification) {
+ // Find the corresponding Editor
+
+ Specification spec = (Specification) object;
+ ProrEditorUtil.getEditor(spec);
+ }
}
@Override