Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/FilteredCheckedListDialog.java1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchCallback.java24
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/AbstractSearcher.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/AbstractSearcher.java)2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/BreadthFirstSearcher.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/BreadthFirstSearcher.java)2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/DelegateProgressMonitor.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/DelegateProgressMonitor.java)19
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/DepthFirstSearcher.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthFirstSearcher.java)2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/QuickFilter.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/QuickFilter.java)14
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/QuickFilterPopup.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/QuickFilterPopup.java)4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/SearchEngine.java254
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/SearchMatcher.java111
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/StringMatcher.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/StringMatcher.java)4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TablePatternFilter.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TablePatternFilter.java)17
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TreeViewerSearchDialog.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerSearchDialog.java)309
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerComparator.java3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/utils/TreeViewerUtil.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerUtil.java)14
18 files changed, 513 insertions, 272 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/FilteredCheckedListDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/FilteredCheckedListDialog.java
index 40c49ebca..d1fb88108 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/FilteredCheckedListDialog.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/FilteredCheckedListDialog.java
@@ -49,6 +49,7 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.tcf.te.ui.activator.UIPlugin;
+import org.eclipse.tcf.te.ui.internal.utils.TablePatternFilter;
import org.eclipse.tcf.te.ui.nls.Messages;
import org.eclipse.ui.dialogs.SelectionStatusDialog;
import org.eclipse.ui.navigator.IDescriptionProvider;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchCallback.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchCallback.java
new file mode 100644
index 000000000..66a6868fd
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchCallback.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.interfaces;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.viewers.TreePath;
+
+public interface ISearchCallback {
+ /**
+ * The callback invoked when the searching job is done, to process
+ * the path found.
+ *
+ * @param status The searching resulting status.
+ * @param path The tree path found or null if no appropriate node is found.
+ */
+ public void searchDone(IStatus status, TreePath treePath);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/AbstractSearcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/AbstractSearcher.java
index 877d91b36..6f4364543 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/AbstractSearcher.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/AbstractSearcher.java
@@ -7,7 +7,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.internal;
+package org.eclipse.tcf.te.ui.internal.utils;
import java.lang.reflect.Method;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/BreadthFirstSearcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/BreadthFirstSearcher.java
index 735914a7c..f304b5d5a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/BreadthFirstSearcher.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/BreadthFirstSearcher.java
@@ -7,7 +7,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.internal;
+package org.eclipse.tcf.te.ui.internal.utils;
import java.lang.reflect.InvocationTargetException;
import java.util.Queue;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/DelegateProgressMonitor.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/DelegateProgressMonitor.java
index 0284f9d0e..a8ee84759 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/DelegateProgressMonitor.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/DelegateProgressMonitor.java
@@ -7,7 +7,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.dialogs;
+package org.eclipse.tcf.te.ui.internal.utils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ProgressMonitorWrapper;
@@ -36,7 +36,7 @@ class DelegateProgressMonitor extends ProgressMonitorWrapper {
safeRun(new Runnable() {
@Override
public void run() {
- if (!fPmPart.isDisposed()) {
+ if (fPmPart != null && !fPmPart.isDisposed()) {
fPmPart.attachToCancelComponent(null);
fPmPart.setCanceled(false);
fPmPart.setVisible(true);
@@ -55,7 +55,7 @@ class DelegateProgressMonitor extends ProgressMonitorWrapper {
safeRun(new Runnable() {
@Override
public void run() {
- if (!fPmPart.isDisposed()) {
+ if (fPmPart != null && !fPmPart.isDisposed()) {
fPmPart.beginTask(name, totalWork);
}
}
@@ -68,8 +68,7 @@ class DelegateProgressMonitor extends ProgressMonitorWrapper {
*/
@Override
public boolean isCanceled() {
- boolean cancel = fPmPart.isCanceled();
- return cancel || super.isCanceled();
+ return fPmPart != null && fPmPart.isCanceled() || super.isCanceled();
}
/*
@@ -82,7 +81,7 @@ class DelegateProgressMonitor extends ProgressMonitorWrapper {
safeRun(new Runnable() {
@Override
public void run() {
- if (!fPmPart.isDisposed()) {
+ if (fPmPart != null && !fPmPart.isDisposed()) {
fPmPart.subTask(name);
}
}
@@ -99,7 +98,7 @@ class DelegateProgressMonitor extends ProgressMonitorWrapper {
safeRun(new Runnable() {
@Override
public void run() {
- if (!fPmPart.isDisposed()) {
+ if (fPmPart != null && !fPmPart.isDisposed()) {
fPmPart.done();
fPmPart.setVisible(false);
}
@@ -117,7 +116,7 @@ class DelegateProgressMonitor extends ProgressMonitorWrapper {
safeRun(new Runnable() {
@Override
public void run() {
- if (!fPmPart.isDisposed()) {
+ if (fPmPart != null && !fPmPart.isDisposed()) {
fPmPart.setTaskName(name);
}
}
@@ -135,7 +134,7 @@ class DelegateProgressMonitor extends ProgressMonitorWrapper {
safeRun(new Runnable() {
@Override
public void run() {
- if (!fPmPart.isDisposed()) {
+ if (fPmPart != null && !fPmPart.isDisposed()) {
fPmPart.setCanceled(b);
}
}
@@ -152,7 +151,7 @@ class DelegateProgressMonitor extends ProgressMonitorWrapper {
safeRun(new Runnable() {
@Override
public void run() {
- if (!fPmPart.isDisposed()) {
+ if (fPmPart != null && !fPmPart.isDisposed()) {
fPmPart.worked(work);
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthFirstSearcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/DepthFirstSearcher.java
index ef326c411..6594adda1 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthFirstSearcher.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/DepthFirstSearcher.java
@@ -7,7 +7,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.internal;
+package org.eclipse.tcf.te.ui.internal.utils;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/QuickFilter.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/QuickFilter.java
index 3ae3f2966..eff7ac068 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/QuickFilter.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/QuickFilter.java
@@ -7,7 +7,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.dialogs;
+package org.eclipse.tcf.te.ui.internal.utils;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.TreePath;
@@ -22,7 +22,7 @@ import org.eclipse.swt.widgets.TreeItem;
* which has the specified name pattern, under a certain tree path.
* Other elements outside of this tree path is ignored.
*/
-class QuickFilter extends TablePatternFilter {
+public class QuickFilter extends TablePatternFilter {
// The tree viewer to filter.
private TreeViewer viewer;
// The root path to select from.
@@ -31,7 +31,7 @@ class QuickFilter extends TablePatternFilter {
/**
* Create a quick filter for the specified viewer.
*/
- QuickFilter(TreeViewer viewer) {
+ public QuickFilter(TreeViewer viewer) {
super((ILabelProvider) viewer.getLabelProvider());
this.viewer = viewer;
}
@@ -41,7 +41,7 @@ class QuickFilter extends TablePatternFilter {
*
* @param root The root path to filter from.
*/
- void showFilterPopup(Object root) {
+ public void showFilterPopup(Object root) {
this.root = root;
if (!isFiltering()) {
viewer.addFilter(this);
@@ -68,9 +68,9 @@ class QuickFilter extends TablePatternFilter {
}
/**
- * Reset the tree viewer to the ogriginal view by removing this filter.
+ * Reset the tree viewer to the original view by removing this filter.
*/
- void resetViewer() {
+ public void resetViewer() {
viewer.removeFilter(this);
root = null;
setPattern(null);
@@ -81,7 +81,7 @@ class QuickFilter extends TablePatternFilter {
*
* @return true if it has this filter.
*/
- boolean isFiltering() {
+ public boolean isFiltering() {
ViewerFilter[] filters = viewer.getFilters();
if (filters != null) {
for (ViewerFilter filter : filters) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/QuickFilterPopup.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/QuickFilterPopup.java
index 3b9031b20..ce29a2dbe 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/QuickFilterPopup.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/QuickFilterPopup.java
@@ -7,7 +7,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.dialogs;
+package org.eclipse.tcf.te.ui.internal.utils;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.jface.viewers.ISelection;
@@ -39,7 +39,7 @@ import org.eclipse.tcf.te.ui.nls.Messages;
* The filter will to listen to the change of the input and
* filter the tree viewer accordingly.
*/
-class QuickFilterPopup extends PopupDialog {
+public class QuickFilterPopup extends PopupDialog {
// The quick filter used filter the content of the tree viewer.
QuickFilter quickFilter;
// The text field used to enter filters.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/SearchEngine.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/SearchEngine.java
new file mode 100644
index 000000000..1cdd78f5b
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/SearchEngine.java
@@ -0,0 +1,254 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.internal.utils;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.wizard.ProgressMonitorPart;
+import org.eclipse.tcf.te.ui.activator.UIPlugin;
+import org.eclipse.tcf.te.ui.interfaces.ISearchCallback;
+import org.eclipse.tcf.te.ui.nls.Messages;
+
+/**
+ * The search engine used to search a tree viewer.
+ */
+public class SearchEngine {
+ // The search engine used search the tree
+ AbstractSearcher fSearcher;
+ // The searching job.
+ Job fSearchJob;
+ // The viewer being searched.
+ TreeViewer fViewer;
+ // If the search algorithm is depth preferable
+ boolean fDepthFirst;
+ // The search matcher used to match tree nodes during traversing.
+ SearchMatcher fMatcher;
+ // The current starting path of the searcher engine.
+ TreePath fStartPath;
+ // Whether it is wrap search.
+ boolean fWrap;
+ // The last result being searched.
+ TreePath fLastResult;
+
+ /**
+ * Create an instance for the tree viewer.
+ *
+ * @param viewer The tree viewer.
+ */
+ private SearchEngine(TreeViewer viewer) {
+ fViewer = viewer;
+ fMatcher = new SearchMatcher(viewer);
+ fSearcher = new BreadthFirstSearcher(fViewer, fMatcher);
+ }
+
+ /**
+ * Get a singleton search engine for a tree viewer. If
+ * it does not exist then create one and store it.
+ *
+ * @param viewer The tree viewer.
+ * @return A search engine.
+ */
+ public static SearchEngine getSearchEngine(TreeViewer viewer) {
+ SearchEngine searcher = (SearchEngine) viewer.getData("search.engine"); //$NON-NLS-1$
+ if (searcher == null) {
+ searcher = new SearchEngine(viewer);
+ viewer.setData("search.engine", searcher); //$NON-NLS-1$
+ }
+ return searcher;
+ }
+
+ /**
+ * If the current algorithm is DFS.
+ *
+ * @return true if it is DFS.
+ */
+ public boolean isDepthFirst() {
+ return fDepthFirst;
+ }
+
+ /**
+ * Set the algorithm to depth-first according the boolean.
+ *
+ * @param depthFirst
+ */
+ public void setDepthFirst(boolean depthFirst) {
+ if (fDepthFirst != depthFirst) {
+ fDepthFirst = depthFirst;
+ fSearcher = fDepthFirst ? new DepthFirstSearcher(fViewer, fMatcher) : new BreadthFirstSearcher(fViewer, fMatcher);
+ }
+ }
+
+ /**
+ * Get the current matcher used.
+ *
+ * @return the current matcher
+ */
+ public SearchMatcher getMatcher() {
+ return fMatcher;
+ }
+
+ /**
+ * Set the initial searching path.
+ *
+ * @param path The initial searching path.
+ */
+ public void setStartPath(TreePath path) {
+ fStartPath = path;
+ if (fSearcher != null) {
+ fSearcher.setStartPath(path);
+ }
+ }
+
+ /**
+ * Reset the searching path.
+ */
+ public void resetPath() {
+ if (fSearcher != null) {
+ fSearcher.setStartPath(fStartPath);
+ }
+ }
+
+ /**
+ * Clean up the searching job.
+ */
+ public void endSearch() {
+ if (fSearchJob != null) {
+ fSearchJob.cancel();
+ fSearchJob = null;
+ }
+ }
+
+ /**
+ * Start searching using the progress monitor part and invoke the callback
+ * after a node is found.
+ *
+ * @param callback The callback to invoked.
+ * @param pmpart The progress monitor part.
+ */
+ public void startSearch(final ISearchCallback callback, final ProgressMonitorPart pmpart) {
+ final TreePath[] result = new TreePath[1];
+ fSearchJob = new Job(Messages.TreeViewerSearchDialog_JobName) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor = new DelegateProgressMonitor(monitor, pmpart);
+ monitor.beginTask(Messages.TreeViewerSearchDialog_MainTaskName, IProgressMonitor.UNKNOWN);
+ try {
+ result[0] = fSearcher.searchNext(monitor);
+ }
+ catch (InvocationTargetException e) {
+ Status status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), e.getMessage(), e);
+ return status;
+ }
+ catch (InterruptedException e) {
+ return Status.CANCEL_STATUS;
+ }
+ finally {
+ monitor.done();
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ fSearchJob.addJobChangeListener(new JobChangeAdapter() {
+ @Override
+ public void done(final IJobChangeEvent event) {
+ fViewer.getTree().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ IStatus status = event.getResult();
+ TreePath treePath = result[0];
+ if (callback != null) callback.searchDone(status, treePath);
+ searchDone(status, treePath);
+ fSearchJob = null;
+ if (status.isOK() && treePath == null && fWrap && fLastResult != null) {
+ fLastResult = null;
+ startSearch(callback, pmpart);
+ }
+ }
+ });
+ }
+ });
+ fSearchJob.schedule();
+ }
+
+ /**
+ * Set the searching direction, only valid for DFS.
+ *
+ * @param foreward The searching direction.
+ */
+ public void setForeward(boolean foreward) {
+ if (fDepthFirst) {
+ ((DepthFirstSearcher) fSearcher).setForeward(foreward);
+ }
+ }
+
+ /**
+ * The method called after the searching is done.
+ *
+ * @param status The searching result status.
+ * @param path The searching result, or null if no path is found.
+ */
+ void searchDone(IStatus status, TreePath path) {
+ if (status.isOK()) {
+ if (path != null) {
+ fLastResult = path;
+ fViewer.expandToLevel(path, 0);
+ fViewer.setSelection(new StructuredSelection(new Object[] { path }), true);
+ }
+ else if (fWrap && fLastResult != null) {
+ setStartPath(fLastResult);
+ }
+ }
+ }
+
+ /**
+ * If the current search is wrap search.
+ *
+ * @return true if it is wrap search.
+ */
+ public boolean isWrap() {
+ return fWrap;
+ }
+
+ /**
+ * Set the current searching to wrap search.
+ *
+ * @param w
+ */
+ public void setWrap(boolean w) {
+ fWrap = w;
+ }
+
+ /**
+ * Set the last searching result.
+ *
+ * @param path The last searched tree path.
+ */
+ public void setLastResult(TreePath path) {
+ fLastResult = path;
+ }
+
+ /**
+ * Get the last searched path.
+ *
+ * @return The last searched path.
+ */
+ public TreePath getLastResult() {
+ return fLastResult;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/SearchMatcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/SearchMatcher.java
new file mode 100644
index 000000000..18b1e8f60
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/SearchMatcher.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.internal.utils;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * A search matcher implementation that support
+ * common searching options.
+ */
+public class SearchMatcher implements ISearchMatcher {
+ // The text to be searched.
+ private String fSearchTarget;
+ // Whether it is case sensitive
+ private boolean fCaseSensitive;
+ // Whether it is precise matching.
+ private boolean fMatchPrecise;
+ // The viewer being searched.
+ private TreeViewer fViewer;
+
+ /**
+ * Create a search matcher with the tree viewer.
+ *
+ * @param viewer The tree viewer to create a matcher for.
+ */
+ public SearchMatcher(TreeViewer viewer) {
+ fViewer = viewer;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.interfaces.ISearchMatcher#match(java.lang.Object)
+ */
+ @Override
+ public boolean match(Object context) {
+ if (context == null) return false;
+ String text = getElementText(context);
+ if (text == null) return false;
+ String target = fSearchTarget;
+ if (!fCaseSensitive) {
+ text = text.toLowerCase();
+ target = fSearchTarget.toLowerCase();
+ }
+ if (fMatchPrecise) return text.equals(target);
+ return text.indexOf(target) != -1;
+ }
+
+ /**
+ * Get the text representation of a element using the label provider of the tree viewer. Note:
+ * this method could be called at any thread.
+ *
+ * @param element The element.
+ * @return The text representation.
+ */
+ public String getElementText(final Object element) {
+ if (Display.getCurrent() != null) {
+ if (element == fViewer.getInput()) return "the root"; //$NON-NLS-1$
+ ILabelProvider labelProvider = (ILabelProvider) fViewer.getLabelProvider();
+ if (labelProvider != null) {
+ return labelProvider.getText(element);
+ }
+ return element == null ? "" : element.toString(); //$NON-NLS-1$
+ }
+ final String[] result = new String[1];
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ result[0] = getElementText(element);
+ }
+ });
+ return result[0];
+ }
+
+ /**
+ * Set the searching target.
+ *
+ * @param target The target node's matching string.
+ */
+ public void setMatchTarget(String target) {
+ fSearchTarget = target;
+ }
+
+ /**
+ * Set if the searching is case-sensitive.
+ *
+ * @param caseSensitive
+ */
+ public void setCaseSensitive(boolean caseSensitive) {
+ fCaseSensitive = caseSensitive;
+ }
+
+ /**
+ * Set if the searching is to match precisely.
+ *
+ * @param matchPrecise
+ */
+ public void setMatchPrecise(boolean matchPrecise) {
+ fMatchPrecise = matchPrecise;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/StringMatcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/StringMatcher.java
index 2591c88ac..6117101d5 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/StringMatcher.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/StringMatcher.java
@@ -8,12 +8,12 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.dialogs;
+package org.eclipse.tcf.te.ui.internal.utils;
import java.util.Vector;
/**
- * A string pattern matcher, suppporting "*" and "?" wildcards.
+ * A string pattern matcher, supporting "*" and "?" wild cards.
*
* @since 1.0.0 Copied from org.eclipse.ui.internal.navigator.StringMatcher
*/
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TablePatternFilter.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TablePatternFilter.java
index 74b3a88dd..feb7eb67c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TablePatternFilter.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TablePatternFilter.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.dialogs;
+package org.eclipse.tcf.te.ui.internal.utils;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.Viewer;
@@ -18,11 +18,11 @@ import org.eclipse.jface.viewers.ViewerFilter;
* The viewer filter to select those elements which matches the given filter pattern.
* @since 1.0.0 Copied from org.eclipse.ui.internal.navigator.filters.CommonFiltersTab$TablePatternFilter
*/
-class TablePatternFilter extends ViewerFilter {
+public class TablePatternFilter extends ViewerFilter {
private static final String ALL = "*"; //$NON-NLS-1$
- private StringMatcher matcher = null;
- private ILabelProvider labelProvider;
+ protected StringMatcher matcher = null;
+ protected ILabelProvider labelProvider;
public TablePatternFilter(ILabelProvider labelProvider) {
this.labelProvider = labelProvider;
@@ -38,7 +38,12 @@ class TablePatternFilter extends ViewerFilter {
return match(labelProvider.getText(element));
}
- protected void setPattern(String newPattern) {
+ /**
+ * Set a new pattern to filter elements.
+ *
+ * @param newPattern The new pattern
+ */
+ public void setPattern(String newPattern) {
if (newPattern == null || newPattern.trim().length() == 0) {
matcher = new StringMatcher(ALL, true, false);
}
@@ -55,7 +60,7 @@ class TablePatternFilter extends ViewerFilter {
*
* @return whether the string matches the pattern
*/
- protected boolean match(String input) {
+ public boolean match(String input) {
if (input == null) {
return false;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerSearchDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TreeViewerSearchDialog.java
index 194976e6f..c0a4eee79 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerSearchDialog.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TreeViewerSearchDialog.java
@@ -7,20 +7,11 @@
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.dialogs;
+package org.eclipse.tcf.te.ui.internal.utils;
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
@@ -37,34 +28,24 @@ 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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.tcf.te.ui.activator.UIPlugin;
-import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
-import org.eclipse.tcf.te.ui.internal.AbstractSearcher;
-import org.eclipse.tcf.te.ui.internal.DepthFirstSearcher;
-import org.eclipse.tcf.te.ui.internal.BreadthFirstSearcher;
+import org.eclipse.tcf.te.ui.interfaces.ISearchCallback;
import org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog;
import org.eclipse.tcf.te.ui.nls.Messages;
-import org.eclipse.ui.PlatformUI;
/**
* The searching dialog used to get the searching input.
*/
-public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements SelectionListener, ISearchMatcher {
+public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements SelectionListener, ISearchCallback {
// A new search button's ID.
private static final int SEARCH_ID = 31;
- // The viewer being searched.
- TreeViewer fViewer;
// The input field for searching conditions.
private Text fSearchField;
- // The text to be searched.
- private String fSearchTarget;
// The radio button of depth-first algorithm.
private Button fBtnDepth;
// The radio button of breadth-first algorithm.
@@ -78,26 +59,12 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
// The searching orientation check box.
private Button fBtnBackward;
// The progress monitor part that controls the searching job.
- ProgressMonitorPart fPmPart;
+ private ProgressMonitorPart fPmPart;
- // Whether it is case sensitive
- private boolean fCaseSensitive;
- // Whether it is wrap search.
- private boolean fWrap;
- // Whether it is precise matching.
- private boolean fMatch;
- // The last result being searched.
- private TreePath fLastResult;
- // The current starting path of the searcher engine.
- TreePath fStartPath;
- // If the search algorithm is depth preferable
- private boolean fDepthFirst;
- // The search engine used search the tree
- AbstractSearcher fSearcher;
- // The searching job.
- protected Job fSearchJob;
- // The search matcher used to match tree nodes during traversing.
- private ISearchMatcher fMatcher;
+ // The search engine used to do the searching.
+ SearchEngine fSearcher;
+ // The tree viewer to be searched.
+ TreeViewer fViewer;
/**
* Create a searching dialog using the default algorithm and
@@ -110,16 +77,6 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
}
/**
- * Create a searching dialog using the default matcher.
- *
- * @param viewer The tree viewer to search in.
- * @param depthFirst if the default algorithm used is depth-first search (DFS).
- */
- public TreeViewerSearchDialog(TreeViewer viewer, boolean depthFirst) {
- this(viewer, depthFirst, null);
- }
-
- /**
* Create a searching dialog.
*
* @param viewer The tree viewer to search in.
@@ -127,58 +84,16 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
* @param matcher the search matcher used to matching each tree node during searching, or null
* if the default matcher should be used.
*/
- protected TreeViewerSearchDialog(TreeViewer viewer, boolean depthFirst, ISearchMatcher matcher) {
+ protected TreeViewerSearchDialog(TreeViewer viewer, boolean depthFirst) {
super(viewer.getTree().getShell());
- fDepthFirst = depthFirst;
+ setShellStyle(SWT.DIALOG_TRIM | SWT.MODELESS);
fViewer = viewer;
+ fSearcher = SearchEngine.getSearchEngine(fViewer);
+ fSearcher.setDepthFirst(depthFirst);
fViewer.getTree().addSelectionListener(this);
- setShellStyle(SWT.DIALOG_TRIM | SWT.MODELESS);
- if (matcher == null) matcher = this;
- fMatcher = matcher;
- fSearcher = fDepthFirst ? new DepthFirstSearcher(fViewer, fMatcher) : new BreadthFirstSearcher(fViewer, fMatcher);
- this.setTitle(Messages.TreeViewerSearchDialog_DialogTitleMessage);
+ setTitle(Messages.TreeViewerSearchDialog_DialogTitleMessage);
}
- /**
- * Set the initial path to search from.
- *
- * @param path The path from which to start the search.
- */
- public void setStartPath(TreePath path) {
- fStartPath = path;
- fSearcher.setStartPath(path);
- if(fSearcher != null) {
- String text = getElementText(path.getLastSegment());
- this.setDefaultMessage(NLS.bind(Messages.TreeViewerSearchDialog_DialogPromptMessage, text), NONE);
- }
- }
-
- /**
- * Get the text representation of a element using the label provider
- * of the tree viewer.
- * Note: this method could be called at any thread.
- *
- * @param element The element.
- * @return The text representation.
- */
- String getElementText(final Object element) {
- if (Display.getCurrent() != null) {
- if (element == fViewer.getInput()) return "the root"; //$NON-NLS-1$
- ILabelProvider labelProvider = (ILabelProvider) fViewer.getLabelProvider();
- if (labelProvider != null) {
- return labelProvider.getText(element);
- }
- return element == null ? "" : element.toString(); //$NON-NLS-1$
- }
- final String[] result = new String[1];
- PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- result[0] = getElementText(element);
- }
- });
- return result[0];
- }
/*
* (non-Javadoc)
@@ -200,92 +115,56 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
case SEARCH_ID:
searchButtonPressed();
break;
+ case IDialogConstants.CLOSE_ID:
+ closePressed();
+ break;
default:
super.buttonPressed(buttonId);
}
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
- */
- @Override
- protected void cancelPressed() {
- if (fSearchJob != null) {
- fSearchJob.cancel();
- fSearchJob = null;
- }
- super.cancelPressed();
+ protected void closePressed() {
+ fSearcher.endSearch();
+ setReturnCode(OK);
+ close();
}
/**
* Called when search button is pressed to start a new search.
*/
private void searchButtonPressed() {
- fSearchTarget = fSearchField.getText().trim();
+ fSearcher.getMatcher().setMatchTarget(fSearchField.getText().trim());
getButton(SEARCH_ID).setEnabled(false);
- final TreePath[] result = new TreePath[1];
- fSearchJob = new Job(Messages.TreeViewerSearchDialog_JobName) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- monitor = new DelegateProgressMonitor(monitor, fPmPart);
- monitor.beginTask(Messages.TreeViewerSearchDialog_MainTaskName, IProgressMonitor.UNKNOWN);
- try {
- result[0] = fSearcher.searchNext(monitor);
- }
- catch (InvocationTargetException e) {
- Status status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), e.getMessage(), e);
- return status;
- }
- catch (InterruptedException e) {
- return Status.CANCEL_STATUS;
- }
- finally {
- monitor.done();
- }
- return Status.OK_STATUS;
- }
- };
- fSearchJob.addJobChangeListener(new JobChangeAdapter() {
- @Override
- public void done(final IJobChangeEvent event) {
- fViewer.getTree().getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- searchDone(event.getResult(), result[0]);
- }
- });
- }
- });
- fSearchJob.schedule();
+ fSearcher.startSearch(this, fPmPart);
}
+
/*
* (non-Javadoc)
- * @see org.eclipse.tcf.te.ui.interfaces.ISearchMatcher#match(java.lang.Object)
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
@Override
- public boolean match(Object context) {
- if (context == null) return false;
- String text = getElementText(context);
- if (text == null) return false;
- String target = fSearchTarget;
- if (!fCaseSensitive) {
- text = text.toLowerCase();
- target = fSearchTarget.toLowerCase();
- }
- if (fMatch) return text.equals(target);
- return text.indexOf(target) != -1;
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(Messages.TreeViewerSearchDialog_DialogTitle);
}
- /**
- * The callback invoked when the searching job is done, to process
- * the path found.
- *
- * @param status The searching resulting status.
- * @param path The tree path found or null if no appropriate node is found.
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, SEARCH_ID, Messages.TreeViewerSearchDialog_BtnSearchText, true);
+ createButton(parent, IDialogConstants.CLOSE_ID, Messages.TreeViewerSearchDialog_BtnCloseText, false);
+ getButton(SEARCH_ID).setEnabled(false);
+ }
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.dialogs.ISearchCallback#searchDone(org.eclipse.core.runtime.IStatus, org.eclipse.jface.viewers.TreePath)
*/
- void searchDone(IStatus status, TreePath path) {
+ @Override
+ public void searchDone(IStatus status, TreePath path) {
Button btn = getButton(SEARCH_ID);
if (btn != null && !btn.isDisposed()) {
btn.setEnabled(true);
@@ -293,16 +172,10 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
}
if (status.isOK()) {
if (path == null) {
- if (fWrap) {
- if (fLastResult == null) {
+ if (fSearcher.isWrap()) {
+ if (fSearcher.getLastResult() == null) {
setErrorMessage(Messages.TreeViewerSearchDialog_NoSuchNode);
}
- else {
- setStartPath(fLastResult);
- fLastResult = null;
- buttonPressed(SEARCH_ID);
- return;
- }
}
else {
setErrorMessage(Messages.TreeViewerSearchDialog_NoSuchNode);
@@ -310,38 +183,12 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
}
else {
setMessage(null);
- fLastResult = path;
- fViewer.expandToLevel(path, 0);
- fViewer.setSelection(new StructuredSelection(new Object[] { path }), true);
}
}
else {
setMessage(null);
}
- fSearchJob = null;
}
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
- */
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(Messages.TreeViewerSearchDialog_DialogTitle);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected void createButtonsForButtonBar(Composite parent) {
- createButton(parent, SEARCH_ID, Messages.TreeViewerSearchDialog_BtnSearchText, true);
- createButton(parent, IDialogConstants.CANCEL_ID, Messages.TreeViewerSearchDialog_BtnCancelText, false);
- getButton(SEARCH_ID).setEnabled(false);
- }
-
/*
* (non-Javadoc)
* @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
@@ -368,7 +215,7 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
@Override
public void modifyText(ModifyEvent e) {
updateSearchButton();
- setStartPath(fStartPath);
+ fSearcher.resetPath();
}
});
@@ -390,14 +237,14 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
// Breadth-first search
fBtnBreadth = new Button(group, SWT.RADIO);
fBtnBreadth.setText(Messages.TreeViewerSearchDialog_BreadthFirst);
- fBtnBreadth.setSelection(!fDepthFirst);
+ fBtnBreadth.setSelection(!fSearcher.isDepthFirst());
fBtnBreadth.addSelectionListener(l);
fBtnBreadth.setLayoutData(new GridData());
// Depth-first search
fBtnDepth = new Button(group, SWT.RADIO);
fBtnDepth.setText(Messages.TreeViewerSearchDialog_DepthFirst);
- fBtnDepth.setSelection(fDepthFirst);
+ fBtnDepth.setSelection(fSearcher.isDepthFirst());
fBtnDepth.addSelectionListener(l);
fBtnDepth.setLayoutData(new GridData());
@@ -429,7 +276,7 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
fBtnBackward.setText(Messages.TreeViewerSearchDialog_BtnBackText);
fBtnBackward.addSelectionListener(l);
// Hidden if it is breadth-first search
- fBtnBackward.setVisible(fDepthFirst);
+ fBtnBackward.setVisible(fSearcher.isDepthFirst());
// Progress monitor part to display or cancel searching process.
fPmPart = new ProgressMonitorPart(container, null, true);
@@ -449,20 +296,18 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
void optionChecked(SelectionEvent e) {
Object src = e.getSource();
if (src == fBtnCase) {
- fCaseSensitive = fBtnCase.getSelection();
+ fSearcher.getMatcher().setCaseSensitive(fBtnCase.getSelection());
}
else if (src == fBtnWrap) {
- fWrap = fBtnWrap.getSelection();
+ fSearcher.setWrap(fBtnWrap.getSelection());
}
else if (src == fBtnMatch) {
- fMatch = fBtnMatch.getSelection();
+ fSearcher.getMatcher().setMatchPrecise(fBtnMatch.getSelection());
}
else if (src == fBtnBackward) {
- clearJob();
- setStartPath(fLastResult);
- if(fDepthFirst) {
- ((DepthFirstSearcher) fSearcher).setForeward(!fBtnBackward.getSelection());
- }
+ fSearcher.endSearch();
+ fSearcher.setStartPath(fSearcher.getLastResult());
+ fSearcher.setForeward(!fBtnBackward.getSelection());
}
else if (src == fBtnDepth || src == fBtnBreadth) {
if (src == fBtnDepth) {
@@ -473,24 +318,12 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
fBtnBreadth.setSelection(true);
fBtnDepth.setSelection(false);
}
- clearJob();
- fDepthFirst = fBtnDepth.getSelection();
- fBtnBackward.setVisible(fDepthFirst);
- fSearcher = fDepthFirst ? new DepthFirstSearcher(fViewer, fMatcher) : new BreadthFirstSearcher(fViewer, fMatcher);
- setStartPath(fStartPath);
- if (fDepthFirst) {
- ((DepthFirstSearcher) fSearcher).setForeward(!fBtnBackward.getSelection());
- }
- }
- }
-
- /**
- * Clear searching job.
- */
- void clearJob() {
- if (fSearchJob != null) {
- fSearchJob.cancel();
- fSearchJob = null;
+ fSearcher.endSearch();
+ boolean selection = fBtnDepth.getSelection();
+ fSearcher.setDepthFirst(selection);
+ fBtnBackward.setVisible(selection);
+ fSearcher.resetPath();
+ fSearcher.setForeward(!fBtnBackward.getSelection());
}
}
@@ -503,28 +336,34 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
getButton(SEARCH_ID).setEnabled(valid);
}
+ public void setStartPath(TreePath rootPath) {
+ fSearcher.setStartPath(rootPath);
+ String text = fSearcher.getMatcher().getElementText(rootPath.getLastSegment());
+ this.setDefaultMessage(NLS.bind(Messages.TreeViewerSearchDialog_DialogPromptMessage, text), NONE);
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetSelected(SelectionEvent e) {
- clearJob();
+ public void widgetSelected(SelectionEvent e) {
+ fSearcher.endSearch();
ISelection sel = fViewer.getSelection();
if (sel == null || sel.isEmpty()) {
- setStartPath(fStartPath);
+ fSearcher.resetPath();
}
else {
TreeSelection iss = (TreeSelection) sel;
TreePath[] paths = iss.getPaths();
if (paths == null || paths.length == 0) {
- setStartPath(fStartPath);
+ fSearcher.resetPath();
}
else {
- setStartPath(paths[0]);
+ fSearcher.setStartPath(paths[0]);
}
}
- fLastResult = null;
+ fSearcher.setLastResult(null);
}
/*
@@ -532,6 +371,6 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java
index c56b8f946..533246f33 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java
@@ -70,7 +70,7 @@ public class Messages extends NLS {
public static String PreferencePage_label;
public static String QuickFilterPopup_PromptMessage;
public static String TreeViewerSearchDialog_BtnBackText;
- public static String TreeViewerSearchDialog_BtnCancelText;
+ public static String TreeViewerSearchDialog_BtnCloseText;
public static String TreeViewerSearchDialog_BtnCaseText;
public static String TreeViewerSearchDialog_BtnPreciseText;
public static String TreeViewerSearchDialog_BtnSearchText;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties
index 2204e61a9..70f527ce5 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties
@@ -62,7 +62,7 @@ NameValuePairDialog_usedOrIllegalName_error=The name ''{0}'' is reserved or alre
PreferencePage_label=General settings for Target Explorer:
QuickFilterPopup_PromptMessage=<RETURN> to confirm, <ESC> to reset
TreeViewerSearchDialog_BtnBackText=Search backward
-TreeViewerSearchDialog_BtnCancelText=Cancel
+TreeViewerSearchDialog_BtnCloseText=Close
TreeViewerSearchDialog_BtnCaseText=Case sensitive
TreeViewerSearchDialog_BtnPreciseText=Precise matching
TreeViewerSearchDialog_BtnSearchText=Search
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerComparator.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerComparator.java
index ec98aa36a..43b01282e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerComparator.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerComparator.java
@@ -27,9 +27,6 @@ public class TreeViewerComparator extends ViewerComparator {
/**
* Constructor.
- *
- * @param viewer The parent viewer. Must not be <code>null</code>.
- * @param labelProvider The label provider. Must not be <code>null</code>.
*/
public TreeViewerComparator() {
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java
index 8ff9d7708..e9d122908 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java
@@ -61,7 +61,6 @@ public class TreeViewerExtension {
* column descriptors and filter descriptors for the specified viewer.
*
* @param viewerId The tree viewer's id.
- * @param viewer The tree viewer to parse the extension for.
*/
public TreeViewerExtension(String viewerId) {
this.viewerId = viewerId;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/utils/TreeViewerUtil.java
index 99dce32b0..62650aab2 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerUtil.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/utils/TreeViewerUtil.java
@@ -7,7 +7,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
-package org.eclipse.tcf.te.ui.dialogs;
+package org.eclipse.tcf.te.ui.utils;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -16,6 +16,9 @@ import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.tcf.te.ui.internal.utils.QuickFilter;
+import org.eclipse.tcf.te.ui.internal.utils.SearchEngine;
+import org.eclipse.tcf.te.ui.internal.utils.TreeViewerSearchDialog;
/**
* The utilities to search and filter a tree viewer.
*/
@@ -74,6 +77,15 @@ public class TreeViewerUtil {
dialog.setStartPath(rootPath);
dialog.open();
}
+
+ /**
+ * Search the next element in the tree viewer.
+ *
+ * @param viewer The tree viewer to be searched.
+ */
+ public static void doSearchNext(TreeViewer viewer) {
+ SearchEngine.getSearchEngine(viewer).startSearch(null, null);
+ }
/**
* Get the filter root for the viewer based on the root path.

Back to the top