Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Chen2012-05-21 02:50:03 +0000
committerWilliam Chen2012-05-21 02:50:03 +0000
commit4a111f536d36aef81150a12dd878ff9263262184 (patch)
tree5b2bbdb8c7e5e41d1486b6d463d6abfd4a43ac99 /target_explorer/plugins
parent67bffd48e1070668c30f15fd4357deafd0ab2eda (diff)
downloadorg.eclipse.tcf-4a111f536d36aef81150a12dd878ff9263262184.tar.gz
org.eclipse.tcf-4a111f536d36aef81150a12dd878ff9263262184.tar.xz
org.eclipse.tcf-4a111f536d36aef81150a12dd878ff9263262184.zip
Target Explorer: Add missing comments and externalized strings for the
searching feature.
Diffstat (limited to 'target_explorer/plugins')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.properties3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/EditorSearchHandler.java7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/ViewSearchHandler.java3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.properties5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.xml8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/DelegateProgressMonitor.java90
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerSearchDialog.java282
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ILazyLoader.java22
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchMatcher.java30
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ITreeSearcher.java43
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/AbstractSearcher.java130
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/BreadthFirstSearcher.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/WidthTreeSearcher.java)29
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthFirstSearcher.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthTreeSearcher.java)46
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ITreeSearcher.java44
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties1
21 files changed, 487 insertions, 278 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties
index 32855ae86..e84b9981d 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties
@@ -114,4 +114,5 @@ propertyTab.advanced.label = Advanced
propertyTab.permission.label = Permissions
command.refresh.tooltip = Refresh the selected nodes
command.filter.label = Filter
-command.reset.label = Reset \ No newline at end of file
+command.reset.label = Reset
+command.search.label = Search... \ No newline at end of file
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml
index c75713bab..50d7c04d4 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.xml
@@ -542,6 +542,11 @@
label="%command.reset.label"
style="push">
</command>
+ <command
+ commandId="org.eclipse.tcf.te.ui.views.command.search"
+ label="%command.search.label"
+ style="push">
+ </command>
<separator name="group.properties" visible="true"/>
<command
commandId="org.eclipse.ui.file.properties"
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.properties
index 40560d378..00298f8fd 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.properties
@@ -73,4 +73,5 @@ command.terminate.label = Terminate
command.terminate.tooltip = Terminate the selected process
command.terminate.name = Terminate
command.filter.label = Filter
-command.reset.label = Reset \ No newline at end of file
+command.reset.label = Reset
+command.search.label = Search... \ No newline at end of file
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml
index e96f75d5c..56e26f335 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml
@@ -203,6 +203,11 @@
label="%command.reset.label"
style="push">
</command>
+ <command
+ commandId="org.eclipse.tcf.te.ui.views.command.search"
+ label="%command.search.label"
+ style="push">
+ </command>
<separator
name="group.properties"
visible="true">
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties
index 73fa3fb90..7a9052f04 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.properties
@@ -64,4 +64,6 @@ menu.categories.removefrom.label=Remove From
command.showin.name = Show In Group
command.filter.label = Filter
-command.reset.label = Reset \ No newline at end of file
+command.reset.label = Reset
+menu.search.label = Search...
+command.search.name = Search... \ No newline at end of file
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
index d59c44f2f..e7bf0a2a6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/plugin.xml
@@ -327,7 +327,7 @@
</command>
<command
commandId="org.eclipse.tcf.te.ui.views.command.search"
- label="Search..."
+ label="%menu.search.label"
style="push">
</command>
</menuContribution>
@@ -373,7 +373,7 @@
<command
categoryId="org.eclipse.tcf.te.ui.commands.category"
id="org.eclipse.tcf.te.ui.views.command.search"
- name="Search...">
+ name="%command.search.name">
</command>
</extension>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/EditorSearchHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/EditorSearchHandler.java
index ab34d8377..52547332a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/EditorSearchHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/EditorSearchHandler.java
@@ -20,7 +20,14 @@ import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.IFormPage;
import org.eclipse.ui.handlers.HandlerUtil;
+/**
+ * The search handler to search elements in the tree of the properties editor.
+ */
public class EditorSearchHandler extends AbstractHandler {
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart part = HandlerUtil.getActiveEditorChecked(event);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/ViewSearchHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/ViewSearchHandler.java
index 30036e51e..967dda8a6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/ViewSearchHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/handler/ViewSearchHandler.java
@@ -18,6 +18,9 @@ import org.eclipse.tcf.te.ui.views.internal.View;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
+/**
+ * The search handler to search elements in the tree of Target Explorer view.
+ */
public class ViewSearchHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.properties
index 6197f546a..100cfddff 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.properties
@@ -50,3 +50,8 @@ SWTDisplayExecutorUtilDelegate.label=SWT Display Executor Utility Delegate
# ***** Preference Pages *****
preference.page.name=Target Explorer
+
+command.filter.description = Filter elements in the tree viewer
+command.filter.name = Filter tree elements
+command.reset.description = Reset the quick filter in the tree viewer
+command.reset.name = Reset the quick filter \ No newline at end of file
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.xml
index 9f190b649..3a8c49457 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/plugin.xml
@@ -40,15 +40,15 @@
</command>
<command
categoryId="org.eclipse.tcf.te.ui.commands.category"
- description="Filter elements in the tree viewer"
+ description="%command.filter.description"
id="org.eclipse.tcf.te.ui.command.quickfilter"
- name="Filter tree elements">
+ name="%command.filter.name">
</command>
<command
categoryId="org.eclipse.tcf.te.ui.commands.category"
- description="Reset the quick filter in the tree viewer"
+ description="%command.reset.description"
id="org.eclipse.tcf.te.ui.command.resetfilter"
- name="Reset the quick filter">
+ name="%command.reset.name">
</command>
</extension>
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/dialogs/DelegateProgressMonitor.java
index 63c35339c..0284f9d0e 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/dialogs/DelegateProgressMonitor.java
@@ -15,109 +15,155 @@ import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
+/**
+ * A progress monitor delegate that wraps the parent monitor
+ * and delegates to a progress monitor part.
+ */
class DelegateProgressMonitor extends ProgressMonitorWrapper {
- ProgressMonitorPart fProgressMonitor;
- public DelegateProgressMonitor(IProgressMonitor monitor, ProgressMonitorPart monitorPart) {
- super(monitor);
- fProgressMonitor = monitorPart;
+ // The progress monitor part to delegate the monitor call.
+ ProgressMonitorPart fPmPart;
+
+ /**
+ * Create an instance with the parent monitor and a progress
+ * monitor part.
+ *
+ * @param parent a parent monitor to wrap
+ * @param mpart a progress monitor part to delegate to.
+ */
+ public DelegateProgressMonitor(IProgressMonitor parent, ProgressMonitorPart mpart) {
+ super(parent);
+ fPmPart = mpart;
safeRun(new Runnable() {
@Override
public void run() {
- if (!fProgressMonitor.isDisposed()) {
- fProgressMonitor.attachToCancelComponent(null);
- fProgressMonitor.setCanceled(false);
- fProgressMonitor.setVisible(true);
+ if (!fPmPart.isDisposed()) {
+ fPmPart.attachToCancelComponent(null);
+ fPmPart.setCanceled(false);
+ fPmPart.setVisible(true);
}
}
});
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#beginTask(java.lang.String, int)
+ */
@Override
public void beginTask(final String name, final int totalWork) {
super.beginTask(name, totalWork);
safeRun(new Runnable() {
@Override
public void run() {
- if (!fProgressMonitor.isDisposed()) {
- fProgressMonitor.beginTask(name, totalWork);
+ if (!fPmPart.isDisposed()) {
+ fPmPart.beginTask(name, totalWork);
}
}
});
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#isCanceled()
+ */
@Override
public boolean isCanceled() {
- boolean cancel = fProgressMonitor.isCanceled();
+ boolean cancel = fPmPart.isCanceled();
return cancel || super.isCanceled();
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#subTask(java.lang.String)
+ */
@Override
public void subTask(final String name) {
super.subTask(name);
safeRun(new Runnable() {
@Override
public void run() {
- if (!fProgressMonitor.isDisposed()) {
- fProgressMonitor.subTask(name);
+ if (!fPmPart.isDisposed()) {
+ fPmPart.subTask(name);
}
}
});
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#done()
+ */
@Override
public void done() {
super.done();
safeRun(new Runnable() {
@Override
public void run() {
- if (!fProgressMonitor.isDisposed()) {
- fProgressMonitor.done();
- fProgressMonitor.setVisible(false);
+ if (!fPmPart.isDisposed()) {
+ fPmPart.done();
+ fPmPart.setVisible(false);
}
}
});
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#setTaskName(java.lang.String)
+ */
@Override
public void setTaskName(final String name) {
super.setTaskName(name);
safeRun(new Runnable() {
@Override
public void run() {
- if (!fProgressMonitor.isDisposed()) {
- fProgressMonitor.setTaskName(name);
+ if (!fPmPart.isDisposed()) {
+ fPmPart.setTaskName(name);
}
}
});
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#setCanceled(boolean)
+ */
@Override
public void setCanceled(final boolean b) {
super.setCanceled(b);
safeRun(new Runnable() {
@Override
public void run() {
- if (!fProgressMonitor.isDisposed()) {
- fProgressMonitor.setCanceled(b);
+ if (!fPmPart.isDisposed()) {
+ fPmPart.setCanceled(b);
}
}
});
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.ProgressMonitorWrapper#worked(int)
+ */
@Override
public void worked(final int work) {
super.worked(work);
safeRun(new Runnable() {
@Override
public void run() {
- if (!fProgressMonitor.isDisposed()) {
- fProgressMonitor.worked(work);
+ if (!fPmPart.isDisposed()) {
+ fPmPart.worked(work);
}
}
});
}
+ /**
+ * Run the runnable in a UI thread asynchronously.
+ *
+ * @param runnable The runnable to schedule.
+ */
void safeRun(Runnable runnable) {
if(Display.getCurrent() != null) {
runnable.run();
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/dialogs/TreeViewerSearchDialog.java
index a37c08777..194976e6f 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/dialogs/TreeViewerSearchDialog.java
@@ -18,8 +18,8 @@ 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.ITableLabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
@@ -37,6 +37,7 @@ 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;
@@ -44,10 +45,11 @@ 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.DepthTreeSearcher;
-import org.eclipse.tcf.te.ui.internal.WidthTreeSearcher;
+import org.eclipse.tcf.te.ui.internal.DepthFirstSearcher;
+import org.eclipse.tcf.te.ui.internal.BreadthFirstSearcher;
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.
@@ -56,16 +58,18 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
// A new search button's ID.
private static final int SEARCH_ID = 31;
+
// The viewer being searched.
- private TreeViewer fViewer;
+ TreeViewer fViewer;
// The input field for searching conditions.
private Text fSearchField;
// The text to be searched.
private String fSearchTarget;
-
- private Button fBtnDeep;
+ // The radio button of depth-first algorithm.
+ private Button fBtnDepth;
+ // The radio button of breadth-first algorithm.
+ private Button fBtnBreadth;
// The case sensitive check box.
- private Button fBtnWidth;
private Button fBtnCase;
// The wrap search check box.
private Button fBtnWrap;
@@ -73,7 +77,9 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
private Button fBtnMatch;
// The searching orientation check box.
private Button fBtnBackward;
+ // The progress monitor part that controls the searching job.
ProgressMonitorPart fPmPart;
+
// Whether it is case sensitive
private boolean fCaseSensitive;
// Whether it is wrap search.
@@ -82,65 +88,101 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
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;
- // If the search algorithm is depth preferable
- private boolean fDeep;
// The searching job.
protected Job fSearchJob;
+ // The search matcher used to match tree nodes during traversing.
private ISearchMatcher fMatcher;
- TreePath fStartPath;
/**
- * Create a searching dialog using the specified parent and viewer.
+ * Create a searching dialog using the default algorithm and
+ * the default matcher.
*
- * @param parent The parent shell.
- * @param viewer The execution context viewer.
+ * @param viewer The tree viewer to search in.
*/
public TreeViewerSearchDialog(TreeViewer viewer) {
this(viewer, false);
}
/**
- * ow Create a searching dialog using the specified parent and viewer.
+ * Create a searching dialog using the default matcher.
*
- * @param parent The parent shell.
- * @param viewer The execution context viewer.
+ * @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 deep) {
- this(viewer, deep, null);
+ public TreeViewerSearchDialog(TreeViewer viewer, boolean depthFirst) {
+ this(viewer, depthFirst, null);
}
/**
- * Create a searching dialog using the specified parent and viewer.
+ * Create a searching dialog.
*
- * @param parent The parent shell.
- * @param viewer The execution context viewer.
+ * @param viewer The tree viewer to search in.
+ * @param depthFirst if the default algorithm used is depth-first search (DFS).
+ * @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 deep, ISearchMatcher matcher) {
+ protected TreeViewerSearchDialog(TreeViewer viewer, boolean depthFirst, ISearchMatcher matcher) {
super(viewer.getTree().getShell());
- fDeep = deep;
+ fDepthFirst = depthFirst;
fViewer = viewer;
fViewer.getTree().addSelectionListener(this);
setShellStyle(SWT.DIALOG_TRIM | SWT.MODELESS);
if (matcher == null) matcher = this;
fMatcher = matcher;
- fSearcher = fDeep ? new DepthTreeSearcher(fViewer, fMatcher) : new WidthTreeSearcher(fViewer, fMatcher);
+ fSearcher = fDepthFirst ? new DepthFirstSearcher(fViewer, fMatcher) : new BreadthFirstSearcher(fViewer, fMatcher);
this.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 = fSearcher.getElementText(path.getLastSegment());
+ 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)
- * @see org.eclipse.jface.dialogs.Dialog#close()
+ * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#close()
*/
@Override
public boolean close() {
@@ -156,7 +198,7 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
protected void buttonPressed(int buttonId) {
switch (buttonId) {
case SEARCH_ID:
- searchNext();
+ searchButtonPressed();
break;
default:
super.buttonPressed(buttonId);
@@ -176,7 +218,10 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
super.cancelPressed();
}
- private void searchNext() {
+ /**
+ * Called when search button is pressed to start a new search.
+ */
+ private void searchButtonPressed() {
fSearchTarget = fSearchField.getText().trim();
getButton(SEARCH_ID).setEnabled(false);
final TreePath[] result = new TreePath[1];
@@ -203,8 +248,13 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
};
fSearchJob.addJobChangeListener(new JobChangeAdapter() {
@Override
- public void done(IJobChangeEvent event) {
- safeSearchDone(event.getResult(), result[0]);
+ public void done(final IJobChangeEvent event) {
+ fViewer.getTree().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ searchDone(event.getResult(), result[0]);
+ }
+ });
}
});
fSearchJob.schedule();
@@ -212,14 +262,12 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
/*
* (non-Javadoc)
- * @see
- * com.windriver.scopetools.common.ui.phoenix.interfaces.ISearchMatcher#match(com.windriver.
- * scopetools.common.core.phoenix.interfaces.IExecutionContext)
+ * @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 = getTreeColumnText(context);
+ String text = getElementText(context);
if (text == null) return false;
String target = fSearchTarget;
if (!fCaseSensitive) {
@@ -230,22 +278,13 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
return text.indexOf(target) != -1;
}
- String getTreeColumnText(final Object context) {
- if (fViewer.getTree().getDisplay().getThread() == Thread.currentThread()) {
- ITableLabelProvider labelProvider = (ITableLabelProvider) fViewer.getLabelProvider();
- return labelProvider != null ? labelProvider.getColumnText(context, 0) : context
- .toString();
- }
- final String[] result = new String[1];
- fViewer.getTree().getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- result[0] = getTreeColumnText(context);
- }
- });
- return result[0];
- }
-
+ /**
+ * 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.
+ */
void searchDone(IStatus status, TreePath path) {
Button btn = getButton(SEARCH_ID);
if (btn != null && !btn.isDisposed()) {
@@ -266,7 +305,7 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
}
}
else {
- setErrorMessage(Messages.TreeViewerSearchDialog_NoSuchNode1);
+ setErrorMessage(Messages.TreeViewerSearchDialog_NoSuchNode);
}
}
else {
@@ -282,15 +321,6 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
fSearchJob = null;
}
- void safeSearchDone(final IStatus status, final TreePath path) {
- fViewer.getTree().getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- searchDone(status, path);
- }
- });
- }
-
/*
* (non-Javadoc)
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
@@ -303,8 +333,7 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
/*
* (non-Javadoc)
- * @see
- * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
@@ -315,32 +344,36 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
/*
* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ * @see org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
- // set margins of dialog and apply dialog font
- Composite container = (Composite) super.createDialogArea(parent);
- Composite composite = new Composite(container, SWT.NONE);
+ // Create the main container
+ Composite composite = (Composite) super.createDialogArea(parent);
+ Composite container = new Composite(composite, SWT.NONE);
GridLayout glayout = new GridLayout(2, false);
glayout.marginHeight = 10;
glayout.marginWidth = 10;
glayout.verticalSpacing = 10;
glayout.horizontalSpacing = 10;
- composite.setLayout(glayout);
- composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- Label label = new Label(composite, SWT.NONE);
+ container.setLayout(glayout);
+ container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // Searching field.
+ Label label = new Label(container, SWT.NONE);
label.setText(Messages.TreeViewerSearchDialog_LblCancelText);
- fSearchField = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ fSearchField = new Text(container, SWT.SINGLE | SWT.BORDER);
fSearchField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
fSearchField.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
- updateButton();
+ updateSearchButton();
setStartPath(fStartPath);
}
});
- Group group = new Group(composite, SWT.SHADOW_ETCHED_IN);
+
+ // Search Algoritm Selection Group.
+ Group group = new Group(container, SWT.SHADOW_ETCHED_IN);
group.setText(Messages.TreeViewerSearchDialog_SearchAlgorithm);
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
data.horizontalSpan = 2;
@@ -354,45 +387,65 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
}
};
- fBtnWidth = new Button(group, SWT.RADIO);
- fBtnWidth.setText(Messages.TreeViewerSearchDialog_BreadthFirst);
- fBtnWidth.setSelection(true);
- fBtnWidth.addSelectionListener(l);
- fBtnWidth.setLayoutData(new GridData());
+ // Breadth-first search
+ fBtnBreadth = new Button(group, SWT.RADIO);
+ fBtnBreadth.setText(Messages.TreeViewerSearchDialog_BreadthFirst);
+ fBtnBreadth.setSelection(!fDepthFirst);
+ fBtnBreadth.addSelectionListener(l);
+ fBtnBreadth.setLayoutData(new GridData());
- fBtnDeep = new Button(group, SWT.RADIO);
- fBtnDeep.setText(Messages.TreeViewerSearchDialog_DepthFirst);
- fBtnDeep.addSelectionListener(l);
- fBtnDeep.setLayoutData(new GridData());
+ // Depth-first search
+ fBtnDepth = new Button(group, SWT.RADIO);
+ fBtnDepth.setText(Messages.TreeViewerSearchDialog_DepthFirst);
+ fBtnDepth.setSelection(fDepthFirst);
+ fBtnDepth.addSelectionListener(l);
+ fBtnDepth.setLayoutData(new GridData());
- group = new Group(composite, SWT.SHADOW_ETCHED_IN);
+ // Search Options Group
+ group = new Group(container, SWT.SHADOW_ETCHED_IN);
group.setText(Messages.TreeViewerSearchDialog_GrpOptionsText);
data = new GridData(SWT.FILL, SWT.CENTER, true, false);
data.horizontalSpan = 2;
group.setLayoutData(data);
group.setLayout(new GridLayout(4, false));
+ // Case sensitive
fBtnCase = new Button(group, SWT.CHECK);
fBtnCase.setText(Messages.TreeViewerSearchDialog_BtnCaseText);
fBtnCase.addSelectionListener(l);
+
+ // Matching precisely
fBtnMatch = new Button(group, SWT.CHECK);
fBtnMatch.setText(Messages.TreeViewerSearchDialog_BtnPreciseText);
fBtnMatch.addSelectionListener(l);
+
+ // Wrap search
fBtnWrap = new Button(group, SWT.CHECK);
fBtnWrap.setText(Messages.TreeViewerSearchDialog_BtnWrapText);
fBtnWrap.addSelectionListener(l);
+
+ // Search backward.
fBtnBackward = new Button(group, SWT.CHECK);
fBtnBackward.setText(Messages.TreeViewerSearchDialog_BtnBackText);
fBtnBackward.addSelectionListener(l);
- fBtnBackward.setVisible(fDeep);
- fPmPart = new ProgressMonitorPart(composite, null, true);
+ // Hidden if it is breadth-first search
+ fBtnBackward.setVisible(fDepthFirst);
+
+ // Progress monitor part to display or cancel searching process.
+ fPmPart = new ProgressMonitorPart(container, null, true);
data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
data.horizontalSpan = 2;
fPmPart.setLayoutData(data);
fPmPart.setVisible(false);
- return container;
+
+ return composite;
}
+ /**
+ * Event handler to process a button selection event.
+ *
+ * @param e The selection event.
+ */
void optionChecked(SelectionEvent e) {
Object src = e.getSource();
if (src == fBtnCase) {
@@ -405,58 +458,58 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
fMatch = fBtnMatch.getSelection();
}
else if (src == fBtnBackward) {
- endSearch();
+ clearJob();
setStartPath(fLastResult);
- if(fDeep) {
- ((DepthTreeSearcher) fSearcher).setForeward(!fBtnBackward.getSelection());
+ if(fDepthFirst) {
+ ((DepthFirstSearcher) fSearcher).setForeward(!fBtnBackward.getSelection());
}
}
- else if (src == fBtnDeep || src == fBtnWidth) {
- if (src == fBtnDeep) {
- fBtnDeep.setSelection(true);
- fBtnWidth.setSelection(false);
+ else if (src == fBtnDepth || src == fBtnBreadth) {
+ if (src == fBtnDepth) {
+ fBtnDepth.setSelection(true);
+ fBtnBreadth.setSelection(false);
}
- else if (src == fBtnWidth) {
- fBtnWidth.setSelection(true);
- fBtnDeep.setSelection(false);
+ else if (src == fBtnBreadth) {
+ fBtnBreadth.setSelection(true);
+ fBtnDepth.setSelection(false);
}
- endSearch();
- fDeep = fBtnDeep.getSelection();
- fBtnBackward.setVisible(fDeep);
- fSearcher = fDeep ? new DepthTreeSearcher(fViewer, fMatcher) : new WidthTreeSearcher(fViewer, fMatcher);
+ clearJob();
+ fDepthFirst = fBtnDepth.getSelection();
+ fBtnBackward.setVisible(fDepthFirst);
+ fSearcher = fDepthFirst ? new DepthFirstSearcher(fViewer, fMatcher) : new BreadthFirstSearcher(fViewer, fMatcher);
setStartPath(fStartPath);
- if (fDeep) {
- ((DepthTreeSearcher) fSearcher).setForeward(!fBtnBackward.getSelection());
+ if (fDepthFirst) {
+ ((DepthFirstSearcher) fSearcher).setForeward(!fBtnBackward.getSelection());
}
}
}
- void endSearch() {
+ /**
+ * Clear searching job.
+ */
+ void clearJob() {
if (fSearchJob != null) {
fSearchJob.cancel();
fSearchJob = null;
}
}
- void updateButton() {
- boolean valid = isInputValid();
- getButton(SEARCH_ID).setEnabled(valid);
- }
-
- private boolean isInputValid() {
+ /**
+ * Update the enablement of search button.
+ */
+ void updateSearchButton() {
String txt = fSearchField.getText();
- return txt != null && txt.trim().length() > 0;
+ boolean valid = txt != null && txt.trim().length() > 0;
+ getButton(SEARCH_ID).setEnabled(valid);
}
/*
* (non-Javadoc)
- * @see
- * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent
- * )
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
- endSearch();
+ clearJob();
ISelection sel = fViewer.getSelection();
if (sel == null || sel.isEmpty()) {
setStartPath(fStartPath);
@@ -476,8 +529,7 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel
/*
* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.
- * SelectionEvent)
+ * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetDefaultSelected(SelectionEvent e) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ILazyLoader.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ILazyLoader.java
index 4ee75cd65..69455d0ae 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ILazyLoader.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ILazyLoader.java
@@ -13,9 +13,31 @@ import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
+/**
+ * The interface to define a loader for certain tree nodes which
+ * are lazily loaded when they are expanded in the tree.
+ */
public interface ILazyLoader {
+ /**
+ * If the data of the tree node has been loaded.
+ *
+ * @return true if it is already loaded or else false.
+ */
public boolean isDataLoaded();
+ /**
+ * Load the data of the tree node including its children.
+ * A request to cancel the operation should be honored and acknowledged
+ * by throwing <code>InterruptedException</code>.
+ *
+ * @param monitor The monitor to report the progress. Must not be null.
+ * @exception InvocationTargetException if the run method must propagate a checked exception,
+ * it should wrap it inside an <code>InvocationTargetException</code>; runtime exceptions are automatically
+ * wrapped in an <code>InvocationTargetException</code> by the calling context
+ * @exception InterruptedException if the operation detects a request to cancel,
+ * using <code>IProgressMonitor.isCanceled()</code>, it should exit by throwing
+ * <code>InterruptedException</code>
+ */
public void loadData(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchMatcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchMatcher.java
index 845225de1..367d65536 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchMatcher.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchMatcher.java
@@ -1,30 +1,28 @@
-/*
- * ISearchMatcher.java
- * Created on Feb 15, 2011
+/*******************************************************************************
+ * 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
*
- * Copyright 2008 Wind River Systems Inc. All rights reserved.
- */
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
package org.eclipse.tcf.te.ui.interfaces;
/**
* The search matcher interface. A class implementing this interface defines
- * the searching rule. It is used by {@link ExecutionContextViewer#searchNext}
- * to find context nodes which matches the rule.
- *
- * @see ISearchCallback
- * @see ExecutionContextViewer
- * @author william.chen@windriver.com
- *
+ * the searching rule.
*/
public interface ISearchMatcher {
+
/**
- * If the current context node matches the matching rule.
+ * If the element matches the matching rule.
*
- * @param context
- * The execution context node to be examined.
+ * @param element
+ * The element to be examined.
* @return true if it matches or else false.
*/
- public boolean match(Object context);
+ public boolean match(Object element);
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ITreeSearcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ITreeSearcher.java
new file mode 100644
index 000000000..09b0154d2
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ITreeSearcher.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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 java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.TreePath;
+
+/**
+ * The interface to define a search engine for the tree viewer.
+ */
+public interface ITreeSearcher {
+
+ /**
+ * Set the path to start searching from.
+ *
+ * @param path The path from which to start searching.
+ */
+ public void setStartPath(TreePath path);
+
+ /**
+ * Search the viewer for the next target which matches the condition defined by the matcher.
+ * A request to cancel the operation should be honored and acknowledged
+ * by throwing <code>InterruptedException</code>.
+ *
+ * @param monitor the progress monitor used to report searching progress, must not be null.
+ * @exception InvocationTargetException if the run method must propagate a checked exception,
+ * it should wrap it inside an <code>InvocationTargetException</code>; runtime exceptions are automatically
+ * wrapped in an <code>InvocationTargetException</code> by the calling context
+ * @exception InterruptedException if the operation detects a request to cancel,
+ * using <code>IProgressMonitor.isCanceled()</code>, it should exit by throwing
+ * <code>InterruptedException</code>
+ */
+ public TreePath searchNext(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
+}
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/AbstractSearcher.java
index a89abe571..877d91b36 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/AbstractSearcher.java
@@ -13,50 +13,75 @@ import java.lang.reflect.Method;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tcf.te.ui.interfaces.ILazyLoader;
import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
+import org.eclipse.tcf.te.ui.interfaces.ITreeSearcher;
import org.eclipse.tcf.te.ui.trees.Pending;
import org.eclipse.ui.PlatformUI;
+/**
+ * The abstract implementation of ITreeSearcher which provides common utility methods
+ * for traversing.
+ */
public abstract class AbstractSearcher implements ITreeSearcher {
- private static Method methodGetSortedChildren;
+ // The method to access AbstractTreeViewer#getSortedChildren in order to the children visually on the tree.
+ static Method methodGetSortedChildren;
static {
- try {
- methodGetSortedChildren = AbstractTreeViewer.class.getDeclaredMethod("getSortedChildren", new Class[]{Object.class}); //$NON-NLS-1$
- methodGetSortedChildren.setAccessible(true);
- }
- catch (Exception e) {
- }
+ SafeRunner.run(new ISafeRunnable(){
+ @Override
+ public void handleException(Throwable exception) {
+ // Ignore on purpose.
+ }
+ @Override
+ public void run() throws Exception {
+ // Initialize the method object.
+ methodGetSortedChildren = AbstractTreeViewer.class.
+ getDeclaredMethod("getSortedChildren", new Class[]{Object.class}); //$NON-NLS-1$
+ // Because "getSortedChildren" is a protected method, we need to make it accessible.
+ methodGetSortedChildren.setAccessible(true);
+ }});
}
+ // The tree viewer to be searched.
protected TreeViewer fViewer;
// The label provider of the tree viewer.
- private ILabelProvider fLabelProvider;
+ protected ILabelProvider fLabelProvider;
+ // The matcher used to match eacho tree nodes.
protected ISearchMatcher fMatcher;
- public AbstractSearcher(TreeViewer viewer, ISearchMatcher matcher) {
+
+ /**
+ * Create a searcher with the specified viewer and matcher.
+ *
+ * @param viewer The tree viewer to be searched.
+ * @param matcher The matcher used to match tree nodes.
+ */
+ protected AbstractSearcher(TreeViewer viewer, ISearchMatcher matcher) {
fViewer = viewer;
fLabelProvider = (ILabelProvider) fViewer.getLabelProvider();
fMatcher = matcher;
}
- abstract public void setStartPath(TreePath path);
-
- public String getElementText(final Object element) {
+ /**
+ * 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.
+ */
+ protected String getElementText(final Object element) {
if (Display.getCurrent() != null) {
if(element == fViewer.getInput()) return "the root"; //$NON-NLS-1$
- String elementText;
if (fLabelProvider != null) {
- elementText = fLabelProvider.getText(element);
- }
- else {
- elementText = element == null ? "" : element.toString(); //$NON-NLS-1$
+ return fLabelProvider.getText(element);
}
- return elementText;
+ return element == null ? "" : element.toString(); //$NON-NLS-1$
}
final String[] result = new String[1];
fViewer.getTree().getDisplay().syncExec(new Runnable() {
@@ -67,11 +92,16 @@ public abstract class AbstractSearcher implements ITreeSearcher {
});
return result[0];
}
-
- protected void advance(String msg, IProgressMonitor monitor) {
- monitor.subTask(msg);
- }
+ /**
+ * Update the children of the specified parent. If the data of the parent
+ * is lazily loaded and not loaded yet, then load the data first, before getting
+ * the children.
+ *
+ * @param parent The parent node to get the updated children from.
+ * @param monitor The progress monitor used while loading data.
+ * @return The updated children of the parent node.
+ */
protected Object[] getUpdatedChildren(final Object parent, final IProgressMonitor monitor) {
if (parent instanceof Pending) return new Object[0];
final ILazyLoader lazyLoader = getLazyLoader(parent);
@@ -88,36 +118,52 @@ public abstract class AbstractSearcher implements ITreeSearcher {
return children;
}
- Object[] getSortedChildren(final Object parentElementOrTreePath) {
- if(Display.getCurrent() != null) {
- try {
- if (methodGetSortedChildren != null) {
- return (Object[]) methodGetSortedChildren.invoke(fViewer, parentElementOrTreePath);
+ /**
+ * Get the current visible/sorted children under the specified parent element or path
+ * by invoking the reflective method. This method is UI thread-safe.
+ *
+ * @param parentElementOrTreePath The parent element or path.
+ * @return The current visible/sorted children of the parent path/element.
+ */
+ protected Object[] getSortedChildren(final Object parentElementOrTreePath) {
+ if (Display.getCurrent() != null) {
+ try {
+ if (methodGetSortedChildren != null) {
+ return (Object[]) methodGetSortedChildren
+ .invoke(fViewer, parentElementOrTreePath);
+ }
}
+ catch (Exception e) {
+ }
+ return new Object[0];
}
- catch (Exception e) {
- }
- return new Object[0];
- }
- final Object[][]result = new Object[1][];
- PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable(){
+ final Object[][] result = new Object[1][];
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
- public void run() {
+ public void run() {
result[0] = getSortedChildren(parentElementOrTreePath);
- }});
+ }
+ });
return result[0];
}
- private ILazyLoader getLazyLoader(Object parent) {
+ /**
+ * Get a lazy loader from the specified element if it could be
+ * adapted to a lazy loader.
+ *
+ * @param element The element to get the lazy loader from.
+ * @return A lazy loader or null if it is not adapted to a lazy loader.
+ */
+ private ILazyLoader getLazyLoader(Object element) {
ILazyLoader loader = null;
- if(parent instanceof ILazyLoader) {
- loader = (ILazyLoader) parent;
+ if(element instanceof ILazyLoader) {
+ loader = (ILazyLoader) element;
}
- if(loader == null && parent instanceof IAdaptable) {
- loader = (ILazyLoader)((IAdaptable)parent).getAdapter(ILazyLoader.class);
+ if(loader == null && element instanceof IAdaptable) {
+ loader = (ILazyLoader)((IAdaptable)element).getAdapter(ILazyLoader.class);
}
if(loader == null) {
- loader = (ILazyLoader) Platform.getAdapterManager().getAdapter(parent, ILazyLoader.class);
+ loader = (ILazyLoader) Platform.getAdapterManager().getAdapter(element, ILazyLoader.class);
}
return loader;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/WidthTreeSearcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/BreadthFirstSearcher.java
index ec57e0d89..735914a7c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/WidthTreeSearcher.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/BreadthFirstSearcher.java
@@ -18,18 +18,41 @@ import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
-public class WidthTreeSearcher extends AbstractSearcher{
+/**
+ * The search engine which uses BFS(breadth-first search) algorithm
+ * to search elements that matches a specified matcher.
+ */
+public class BreadthFirstSearcher extends AbstractSearcher{
+ // The queue to pre-populate the nodes to be matched
private Queue<TreePath> queue;
- public WidthTreeSearcher(TreeViewer viewer, ISearchMatcher matcher){
+
+ /**
+ * Create a breadth-first searcher with the specified viewer and a
+ * matcher.
+ *
+ * @param viewer The tree viewer.
+ * @param matcher The search matcher used match a single tree node.
+ */
+ public BreadthFirstSearcher(TreeViewer viewer, ISearchMatcher matcher){
super(viewer, matcher);
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.interfaces.ITreeSearcher#setStartPath(org.eclipse.jface.viewers.TreePath)
+ */
@Override
public void setStartPath(TreePath path) {
this.queue = new ConcurrentLinkedQueue<TreePath>();
this.queue.offer(path);
}
+ /**
+ * Search the tree using a matcher using BFS algorithm.
+ *
+ * @param monitor The monitor reporting the progress.
+ * @return The tree path whose leaf node satisfies the searching rule.
+ */
@Override
public TreePath searchNext(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException{
TreePath result = null;
@@ -44,7 +67,7 @@ public class WidthTreeSearcher extends AbstractSearcher{
}
}
String elementText = getElementText(element);
- advance(elementText, monitor);
+ monitor.subTask(elementText);
if(fMatcher.match(element)) {
result = path;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthTreeSearcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthFirstSearcher.java
index 0b4cc3761..ef326c411 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthTreeSearcher.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthFirstSearcher.java
@@ -19,20 +19,10 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
/**
- * The search engine for the execution context viewer. It has three methods
- * which defines the process of searching elements in the viewer:
- * <ol>
- * <li><code>startSearch</code> with an initial path to prepare the searching
- * context.</li>
- * <li><code>searchNext</code> to search an element with a rule defined by
- * ISearchMatcher.</li>
- * <li><code>endSearch</code> to clear up the searching context.</li>
- * </ol>
- *
- * @see ISearchMatcher
- * @see ISearchCallback
+ * The search engine which uses DFS(depth-first search) algorithm
+ * to search elements that matches a specified matcher.
*/
-public class DepthTreeSearcher extends AbstractSearcher {
+public class DepthFirstSearcher extends AbstractSearcher {
private static final int START_INDEX = -1;
private static final int END_INDEX = -2;
@@ -48,21 +38,24 @@ public class DepthTreeSearcher extends AbstractSearcher {
}
// The searching stack in which searching contexts are stored.
private LinkedList<StackElement> fSearchStack;
+ // The searching direction.
private boolean fForeward;
/**
- * Create an execution context searcher with the specified viewer and its
- * controller.
+ * Create a depth-first searcher with the specified viewer and a
+ * matcher.
*
- * @param viewer
- * The execution context viewer.
- * @param controller
- * The controller of the execution context viewer.
+ * @param viewer The tree viewer.
+ * @param matcher The search matcher used match a single tree node.
*/
- public DepthTreeSearcher(TreeViewer viewer, ISearchMatcher matcher) {
+ public DepthFirstSearcher(TreeViewer viewer, ISearchMatcher matcher) {
super(viewer, matcher);
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.interfaces.ITreeSearcher#setStartPath(org.eclipse.jface.viewers.TreePath)
+ */
@Override
public void setStartPath(TreePath path) {
fSearchStack = new LinkedList<StackElement>();
@@ -73,6 +66,11 @@ public class DepthTreeSearcher extends AbstractSearcher {
initSearchContext(path);
}
+ /**
+ * Set the searching direction.
+ *
+ * @param foreward searching direction.
+ */
public void setForeward(boolean foreward) {
fForeward = foreward;
}
@@ -105,12 +103,10 @@ public class DepthTreeSearcher extends AbstractSearcher {
}
/**
- * Search the tree using a matcher when the data model is not lazy.
+ * Search the tree using a matcher using DFS algorithm.
*
- * @param forward Forward search or backward search.
- * @param matcher The matcher defining the searching rule.
* @param monitor The monitor reporting the progress.
- * @return The tree path whose leaf node statisfies the searching rule.
+ * @return The tree path whose leaf node satisfies the searching rule.
*/
@Override
public TreePath searchNext(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
@@ -119,7 +115,7 @@ public class DepthTreeSearcher extends AbstractSearcher {
StackElement top = fSearchStack.getLast(); //Get the top stack element.
if(!fForeward && top.index == END_INDEX || fForeward && top.index == START_INDEX){
String elementText = getElementText(top.node);
- advance(elementText, monitor);
+ monitor.subTask(elementText);
result = fMatcher.match(top.node) ? this.createContextPath() : null;
}
if (top.index == END_INDEX) {//If the top index is END_INDEX, it means the node has been finished.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ITreeSearcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ITreeSearcher.java
deleted file mode 100644
index d1c20dd08..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ITreeSearcher.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * 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;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.viewers.TreePath;
-import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
-
-/**
- * The interface to define a search engine for the tree viewer.
- * It has three methods which defines the process of searching
- * elements in the viewer:
- * <ol>
- * <li><code>startSearch</code> with an initial path to prepare the searching
- * context.</li>
- * <li><code>searchNext</code> to search an element with a rule defined by
- * ISearchMatcher.</li>
- * <li><code>endSearch</code> to clear up the searching context.</li>
- * </ol>
- *
- * @see ISearchMatcher
- * @see ISearchCallback
- */
-public interface ITreeSearcher {
-
- /**
- * Search the viewer for the next target which matches the condition defined by the matcher. The
- * searching process is asynchronous. The call will return immediately. Once the target is
- * found, it will invoke the passed callback to notify the caller the result.
- *
- * @param matcher The matcher defining the searching condition. It must not be null.
- * @param callback The callback invoked when the next target is done. It must not be null.
- */
- public TreePath searchNext(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;
-}
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 1ab403c73..c56b8f946 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
@@ -84,7 +84,6 @@ public class Messages extends NLS {
public static String TreeViewerSearchDialog_LblCancelText;
public static String TreeViewerSearchDialog_MainTaskName;
public static String TreeViewerSearchDialog_NoSuchNode;
- public static String TreeViewerSearchDialog_NoSuchNode1;
public static String TreeViewerSearchDialog_SearchAlgorithm;
public static String TreeViewerSearchDialog_BreadthFirst;
public static String ViewerStateManager_MkdirFailed;
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 3836041e8..2204e61a9 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
@@ -76,7 +76,6 @@ TreeViewerSearchDialog_JobName=Searcher
TreeViewerSearchDialog_LblCancelText=Search:
TreeViewerSearchDialog_MainTaskName=Searching
TreeViewerSearchDialog_NoSuchNode=No such node\!
-TreeViewerSearchDialog_NoSuchNode1=No such node\!
TreeViewerSearchDialog_SearchAlgorithm=Algorithm
TreeViewerSearchDialog_BreadthFirst=Breadth-First Search
ViewerStateManager_MkdirFailed=Making the directory for viewerstate.xml failed\!

Back to the top