diff options
6 files changed, 142 insertions, 30 deletions
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 index 681681f33..40e06111c 100644 --- 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 @@ -98,6 +98,15 @@ public class SearchEngine { fSearcher.setStartPath(path);
}
}
+
+ /**
+ * If the current searching scope is all.
+ */
+ public boolean isScopeAll() {
+ if(fStartPath == null) return true;
+ Object element = fStartPath.getLastSegment();
+ return element == fViewer.getInput();
+ }
/**
* Reset the searching path.
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 index 18b1e8f60..c2684faeb 100644 --- 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 @@ -65,7 +65,7 @@ public class SearchMatcher implements ISearchMatcher { */
public String getElementText(final Object element) {
if (Display.getCurrent() != null) {
- if (element == fViewer.getInput()) return "the root"; //$NON-NLS-1$
+ if (element == fViewer.getInput()) return null;
ILabelProvider labelProvider = (ILabelProvider) fViewer.getLabelProvider();
if (labelProvider != null) {
return labelProvider.getText(element);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TreeViewerSearchDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TreeViewerSearchDialog.java index fbff7b088..77e5e69f4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TreeViewerSearchDialog.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/utils/TreeViewerSearchDialog.java @@ -11,6 +11,7 @@ package org.eclipse.tcf.te.ui.internal.utils; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreeSelection; @@ -67,6 +68,11 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel // The tree viewer to be searched. TreeViewer fViewer; + // The scope all button + private Button fBtnScpAll; + // The scope selected button + private Button fBtnScpSel; + /** * Create a searching dialog using the default algorithm and * the default matcher. @@ -178,18 +184,20 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel if (path == null) { if (fSearcher.isWrap()) { if (fSearcher.getLastResult() == null) { - setErrorMessage(Messages.TreeViewerSearchDialog_NoSuchNode); + setMessage(Messages.TreeViewerSearchDialog_NoSuchNode, IMessageProvider.WARNING); } } else { - setErrorMessage(Messages.TreeViewerSearchDialog_NoSuchNode); + setMessage(Messages.TreeViewerSearchDialog_NoMoreNodeFound, IMessageProvider.WARNING); } } else { + this.setErrorMessage(null); setMessage(null); } } else { + this.setErrorMessage(null); setMessage(null); } } @@ -223,20 +231,40 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel } }); + SelectionListener l = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + optionChecked(e); + } + }; + // Search Algoritm Selection Group. Group group = new Group(container, SWT.SHADOW_ETCHED_IN); - group.setText(Messages.TreeViewerSearchDialog_SearchAlgorithm); + group.setText(Messages.TreeViewerSearchDialog_Scope); GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false); data.horizontalSpan = 2; group.setLayoutData(data); group.setLayout(new GridLayout(2, false)); - SelectionListener l = new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - optionChecked(e); - } - }; + fBtnScpAll = new Button(group, SWT.RADIO); + fBtnScpAll.setText(Messages.TreeViewerSearchDialog_All); + fBtnScpAll.setSelection(fSearcher.isScopeAll()); + fBtnScpAll.addSelectionListener(l); + fBtnScpAll.setLayoutData(new GridData()); + + fBtnScpSel = new Button(group, SWT.RADIO); + fBtnScpSel.setText(Messages.TreeViewerSearchDialog_Selected); + fBtnScpSel.setSelection(!fSearcher.isScopeAll()); + fBtnScpSel.addSelectionListener(l); + fBtnScpSel.setLayoutData(new GridData()); + + // Search Algoritm Selection Group. + group = new Group(container, SWT.SHADOW_ETCHED_IN); + group.setText(Messages.TreeViewerSearchDialog_SearchAlgorithm); + data = new GridData(SWT.FILL, SWT.CENTER, true, false); + data.horizontalSpan = 2; + group.setLayoutData(data); + group.setLayout(new GridLayout(2, false)); // Breadth-first search fBtnBreadth = new Button(group, SWT.RADIO); @@ -329,6 +357,24 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel fSearcher.resetPath(); fSearcher.setForeward(!fBtnBackward.getSelection()); } + else if (src == fBtnScpAll || src == fBtnScpSel) { + if(src == fBtnScpAll) { + fBtnScpAll.setSelection(true); + fBtnScpSel.setSelection(false); + } + else { + fBtnScpAll.setSelection(false); + fBtnScpSel.setSelection(true); + } + fSearcher.endSearch(); + boolean scpAll = fBtnScpAll.getSelection(); + if(scpAll) { + setStartPath(new TreePath(new Object[]{fViewer.getInput()})); + } + else { + treeSelected(); + } + } } /** @@ -348,8 +394,24 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel public void setStartPath(TreePath rootPath) { fSearcher.setStartPath(rootPath); String text = fSearcher.getMatcher().getElementText(rootPath.getLastSegment()); - this.setDefaultMessage(NLS.bind(Messages.TreeViewerSearchDialog_DialogPromptMessage, text), NONE); + if(text != null) { + this.setDefaultMessage(NLS.bind(Messages.TreeViewerSearchDialog_DialogPromptMessage, text), NONE); + } + else { + this.setDefaultMessage(Messages.TreeViewerSearchDialog_RootMsg, NONE); + } + updateScope(); } + + /** + * Update the state of the scope buttons + */ + private void updateScope() { + if (fBtnScpAll != null && fBtnScpSel != null && fSearcher != null) { + fBtnScpAll.setSelection(fSearcher.isScopeAll()); + fBtnScpSel.setSelection(!fSearcher.isScopeAll()); + } + } /* * (non-Javadoc) @@ -357,23 +419,32 @@ public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements Sel */ @Override public void widgetSelected(SelectionEvent e) { - fSearcher.endSearch(); + treeSelected(); + } + + /** + * Invoked while a tree node is selected. + */ + private void treeSelected() { + fSearcher.endSearch(); ISelection sel = fViewer.getSelection(); if (sel == null || sel.isEmpty()) { fSearcher.resetPath(); + updateScope(); } else { TreeSelection iss = (TreeSelection) sel; TreePath[] paths = iss.getPaths(); if (paths == null || paths.length == 0) { fSearcher.resetPath(); + updateScope(); } else { - fSearcher.setStartPath(paths[0]); + setStartPath(paths[0]); } } fSearcher.setLastResult(null); - } + } /* * (non-Javadoc) 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 533246f33..2a6ee09cc 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 @@ -69,6 +69,7 @@ public class Messages extends NLS { public static String PreferencePage_label; public static String QuickFilterPopup_PromptMessage; + public static String TreeViewerSearchDialog_All; public static String TreeViewerSearchDialog_BtnBackText; public static String TreeViewerSearchDialog_BtnCloseText; public static String TreeViewerSearchDialog_BtnCaseText; @@ -83,8 +84,12 @@ public class Messages extends NLS { public static String TreeViewerSearchDialog_JobName; public static String TreeViewerSearchDialog_LblCancelText; public static String TreeViewerSearchDialog_MainTaskName; + public static String TreeViewerSearchDialog_NoMoreNodeFound; public static String TreeViewerSearchDialog_NoSuchNode; + public static String TreeViewerSearchDialog_Scope; public static String TreeViewerSearchDialog_SearchAlgorithm; + public static String TreeViewerSearchDialog_Selected; public static String TreeViewerSearchDialog_BreadthFirst; + public static String TreeViewerSearchDialog_RootMsg; 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 70f527ce5..5122137ae 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 @@ -61,6 +61,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_All=All Scope TreeViewerSearchDialog_BtnBackText=Search backward TreeViewerSearchDialog_BtnCloseText=Close TreeViewerSearchDialog_BtnCaseText=Case sensitive @@ -68,14 +69,18 @@ TreeViewerSearchDialog_BtnPreciseText=Precise matching TreeViewerSearchDialog_BtnSearchText=Search TreeViewerSearchDialog_BtnWrapText=Wrap search TreeViewerSearchDialog_DepthFirst=Depth-First Search -TreeViewerSearchDialog_DialogPromptMessage=Search the element from "{0}".\nNote: You can change the starting point by selecting a tree node without disposing this dialog\! +TreeViewerSearchDialog_DialogPromptMessage=Search elements under the node "{0}".\nNote: You can change the starting point by selecting a tree node without disposing this dialog\! TreeViewerSearchDialog_DialogTitle=Search Element Dialog TreeViewerSearchDialog_DialogTitleMessage=Search Elements TreeViewerSearchDialog_GrpOptionsText=Options TreeViewerSearchDialog_JobName=Searcher TreeViewerSearchDialog_LblCancelText=Search: TreeViewerSearchDialog_MainTaskName=Searching +TreeViewerSearchDialog_NoMoreNodeFound=No more node is found\! TreeViewerSearchDialog_NoSuchNode=No such node\! +TreeViewerSearchDialog_Scope=Scope TreeViewerSearchDialog_SearchAlgorithm=Algorithm +TreeViewerSearchDialog_Selected=Selected Scope TreeViewerSearchDialog_BreadthFirst=Breadth-First Search +TreeViewerSearchDialog_RootMsg=Search elements in the whole tree.\nNote: You can change the starting point by selecting a tree node without disposing this dialog\! ViewerStateManager_MkdirFailed=Making the directory for viewerstate.xml failed\! diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/utils/TreeViewerUtil.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/utils/TreeViewerUtil.java index 24eb9cff5..2b69ed166 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/utils/TreeViewerUtil.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/utils/TreeViewerUtil.java @@ -86,9 +86,7 @@ public class TreeViewerUtil { */
public static void doSearch(TreeViewer viewer) {
TreePath rootPath = getSelectedPath(viewer);
- if (rootPath == null) {
- rootPath = new TreePath(new Object[] { viewer.getInput() });
- }
+ rootPath = getSearchRoot(viewer, rootPath);
TreeViewerSearchDialog dialog = new TreeViewerSearchDialog(viewer);
dialog.setStartPath(rootPath);
dialog.open();
@@ -146,7 +144,23 @@ public class TreeViewerUtil { viewer.setSelection(StructuredSelection.EMPTY);
return viewer.getInput();
}
-
+
+ /**
+ * Reposition the starting search path.
+ */
+ private static TreePath getSearchRoot(TreeViewer viewer, TreePath rootPath) {
+ if (rootPath != null) {
+ if (!hasChildren(rootPath, viewer)) {
+ rootPath = rootPath.getParentPath();
+ }
+ if (rootPath.getSegmentCount() == 0) {
+ return new TreePath(new Object[] { viewer.getInput() });
+ }
+ return rootPath;
+ }
+ return new TreePath(new Object[] { viewer.getInput() });
+ }
+
/**
* Test if the root for the tree viewer is eligible as a root path
* of a quick filter.
@@ -157,19 +171,27 @@ public class TreeViewerUtil { */
private static boolean isEligibleRoot(TreePath root, TreeViewer viewer) {
if (viewer.getExpandedState(root)) {
- ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
- Object rootElement = root.getLastSegment();
- Object[] children = contentProvider.getChildren(rootElement);
- if (children != null && children.length > 0) {
- ViewerFilter[] filters = viewer.getFilters();
- if (filters != null && filters.length > 0) {
- for (ViewerFilter filter : filters) {
- children = filter.filter(viewer, rootElement, children);
- if (children == null || children.length == 0) break;
- }
+ return hasChildren(root, viewer);
+ }
+ return false;
+ }
+
+ /**
+ * Judges if the specified root has children nodes.
+ */
+ private static boolean hasChildren(TreePath root, TreeViewer viewer) {
+ ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
+ Object rootElement = root.getLastSegment();
+ Object[] children = contentProvider.getChildren(rootElement);
+ if (children != null && children.length > 0) {
+ ViewerFilter[] filters = viewer.getFilters();
+ if (filters != null && filters.length > 0) {
+ for (ViewerFilter filter : filters) {
+ children = filter.filter(viewer, rootElement, children);
+ if (children == null || children.length == 0) break;
}
- return children != null && children.length > 0;
}
+ return children != null && children.length > 0;
}
return false;
}
|