Implemented "Next match" Navigation.
diff --git a/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Next_Result.png b/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Next_Result.png
new file mode 100644
index 0000000..33a59dc
--- /dev/null
+++ b/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Next_Result.png
Binary files differ
diff --git a/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Prev_Result.png b/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Prev_Result.png
new file mode 100644
index 0000000..66278e7
--- /dev/null
+++ b/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Prev_Result.png
Binary files differ
diff --git a/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Result.xcf b/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Result.xcf
new file mode 100644
index 0000000..0397cb6
--- /dev/null
+++ b/org.eclipse.rmf.reqif10.search.ui/icons/full/obj16/Result.xcf
Binary files differ
diff --git a/org.eclipse.rmf.reqif10.search.ui/plugin.xml b/org.eclipse.rmf.reqif10.search.ui/plugin.xml
index e425e2b..af7e37c 100644
--- a/org.eclipse.rmf.reqif10.search.ui/plugin.xml
+++ b/org.eclipse.rmf.reqif10.search.ui/plugin.xml
@@ -7,6 +7,40 @@
<plugin>
<extension
+ point="org.eclipse.ui.editorActions">
+ <editorContribution
+ id="org.eclipse.rmf.reqif10.search.ui.SpecificationEditorSearchNavigation"
+ targetID="org.eclipse.rmf.reqif10.pror.SpecificationEditor">
+ <action
+ class="org.eclipse.rmf.reqif10.search.ui.ResultNavigator"
+ enablesFor="999999"
+ icon="icons/full/obj16/Next_Result.png"
+ id="org.eclipse.rmf.reqif10.search.next"
+ label="Next Search Result"
+ menubarPath="org.eclipse.rmf.reqif10MenuID/additions"
+ style="push"
+ toolbarPath="additions">
+ <class
+ class="org.eclipse.rmf.reqif10.search.ui.ResultNavigator">
+ </class>
+ </action>
+ <action
+ class="org.eclipse.rmf.reqif10.search.ui.ResultNavigator"
+ enablesFor="999999"
+ icon="icons/full/obj16/Prev_Result.png"
+ id="org.eclipse.rmf.reqif10.search.prev"
+ label="Previous Search Result"
+ menubarPath="org.eclipse.rmf.reqif10MenuID/additions"
+ style="push"
+ toolbarPath="additions">
+ <class
+ class="org.eclipse.rmf.reqif10.search.ui.ResultNavigator">
+ </class>
+ </action>
+ </editorContribution>
+ </extension>
+
+ <extension
point="org.eclipse.search.searchResultViewPages">
<viewPage
class="org.eclipse.rmf.reqif10.search.ui.ReqIFSearchResultPage"
@@ -41,5 +75,4 @@
plugin="org.eclipse.rmf.reqif10.search.ui">
</contexts>
</extension>
-
</plugin>
diff --git a/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/ui/ResultNavigator.java b/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/ui/ResultNavigator.java
new file mode 100644
index 0000000..788e680
--- /dev/null
+++ b/org.eclipse.rmf.reqif10.search.ui/src/org/eclipse/rmf/reqif10/search/ui/ResultNavigator.java
@@ -0,0 +1,183 @@
+package org.eclipse.rmf.reqif10.search.ui;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.rmf.reqif10.SpecHierarchy;
+import org.eclipse.rmf.reqif10.Specification;
+import org.eclipse.rmf.reqif10.pror.editor.presentation.SpecificationEditor;
+import org.eclipse.search.ui.ISearchResultViewPart;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+
+public class ResultNavigator implements IEditorActionDelegate, IExecutableExtension {
+
+ final static String NEXT_ID = "org.eclipse.rmf.reqif10.search.next";
+ final static String PREV_ID = "org.eclipse.rmf.reqif10.search.prev";
+
+ private Specification spec;
+ private SpecHierarchy selectedSpecHierarchy;
+ private SpecificationEditor editor;
+
+ @Override
+ public void run(IAction action) {
+ editor.setFocus();
+ SpecHierarchy match = null;
+ if (action.getId().equals(NEXT_ID)) {
+ match = next();
+ } else if (action.getId().equals(PREV_ID)) {
+// match = prev();
+ MessageDialog.openInformation(editor.getSite().getShell(),
+ "No implemented", "Previous not yet implemented.");
+ return;
+ } else {
+ throw new IllegalStateException(action + "");
+ }
+
+ if (match != null) {
+ ISelection selection = new StructuredSelection(match);
+ editor.getSite().getSelectionProvider().setSelection(selection);
+ } else {
+ MessageDialog.openInformation(editor.getSite().getShell(),
+ "No more elements", "No more elements in this direction.");
+ }
+ }
+
+ @Override
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (! (selection instanceof IStructuredSelection)) {
+ action.setEnabled(false);
+ return;
+ }
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+ if (! (element instanceof SpecHierarchy)) {
+ action.setEnabled(false);
+ return;
+ }
+ action.setEnabled(specInSearchResult());
+ this.selectedSpecHierarchy = (SpecHierarchy) element;
+ }
+
+ @Override
+ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+ System.out.println("Activated:" + action);
+ if (targetEditor instanceof SpecificationEditor) {
+ this.editor = (SpecificationEditor)targetEditor;
+ this.spec = ((SpecificationEditor)targetEditor).getSpecification();
+ } else {
+ this.spec = null;
+ this.editor = null;
+ }
+ }
+
+ private boolean specInSearchResult() {
+ for (SpecHierarchy sh : getMatchingSpecsHierarchies()) {
+ Specification s = getSpecForSpecHierarchy(sh);
+ if (s == spec) return true;
+ }
+ return false;
+ }
+
+ private Set<SpecHierarchy> getMatchingSpecsHierarchies() {
+ HashSet<SpecHierarchy> set = new HashSet<SpecHierarchy>();
+
+ ISearchResultViewPart view = NewSearchUI.getSearchResultView();
+ if (view != null && view.getActivePage() instanceof ReqIFSearchResultPage) {
+ ReqIFSearchResultPage page = (ReqIFSearchResultPage)view.getActivePage();
+ UsageSearchResult result = page.getSearchResult();
+ Collection<EObject> entries = result.getSearchEntries().get(spec.eResource());
+ for (EObject entry: entries) {
+ if (entry instanceof SpecHierarchy) {
+ set.add((SpecHierarchy) entry);
+ }
+ }
+ }
+ return set;
+ }
+
+ private Specification getSpecForSpecHierarchy(SpecHierarchy entry) {
+ while (true) {
+ if (entry.eContainer() instanceof Specification) {
+ return (Specification) entry.eContainer();
+ } else if (entry.eContainer() instanceof SpecHierarchy) {
+ entry = (SpecHierarchy) entry.eContainer();
+ } else {
+ return null;
+ }
+ }
+ }
+
+ @Override
+ public void setInitializationData(IConfigurationElement config,
+ String propertyName, Object data) throws CoreException {
+ // Not used, but interface implemented to ensure proper class loading.
+ }
+
+ private SpecHierarchy next() {
+ Set<SpecHierarchy> bag = getMatchingSpecsHierarchies();
+ SpecHierarchy next = oneDown(selectedSpecHierarchy);
+ while (next != null) {
+ if (bag.contains(next)) return next;
+ next = oneDown(next);
+ }
+ return null;
+ }
+
+ private SpecHierarchy oneDown(SpecHierarchy sh) {
+ // If there are children, go down the hierarchy.
+ if (sh.getChildren().size() > 0) {
+ return sh.getChildren().get(0);
+ }
+
+ EObject element = sh;
+ while (element instanceof SpecHierarchy) {
+ EObject container = element.eContainer();
+ int pos = container.eContents().indexOf(element);
+ if (pos < container.eContents().size() - 1) {
+ return (SpecHierarchy) container.eContents().get(pos +1);
+ } else {
+ element = container;
+ }
+ }
+ return null;
+ }
+
+ private SpecHierarchy prev() {
+ Set<SpecHierarchy> bag = getMatchingSpecsHierarchies();
+ SpecHierarchy next = oneUp(selectedSpecHierarchy);
+ while (next != null) {
+ if (bag.contains(next)) return next;
+ next = oneUp(next);
+ }
+ return null;
+ }
+
+ /**
+ * FIXME not working yet.
+ */
+ private SpecHierarchy oneUp(SpecHierarchy sh) {
+ EObject element = sh;
+ while (element instanceof SpecHierarchy) {
+ EObject container = element.eContainer();
+ int pos = container.eContents().indexOf(element);
+ if (pos > 0) {
+ return (SpecHierarchy) container.eContents().get(pos - 1);
+ } else {
+ element = container;
+ }
+ }
+ return null;
+ }
+
+}