Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Chen2012-05-20 13:41:07 +0000
committerWilliam Chen2012-05-20 13:41:07 +0000
commit0758aa9ac3e6ec6b1e92a699d3c2ba5de45cf5a9 (patch)
tree68b8c83f5733c2b7a507d2661a61d069b0b8a9f2 /target_explorer/plugins/org.eclipse.tcf.te.ui
parent85aa44b17ef1745b10bb24517882aebc7005d25a (diff)
downloadorg.eclipse.tcf-0758aa9ac3e6ec6b1e92a699d3c2ba5de45cf5a9.tar.gz
org.eclipse.tcf-0758aa9ac3e6ec6b1e92a699d3c2ba5de45cf5a9.tar.xz
org.eclipse.tcf-0758aa9ac3e6ec6b1e92a699d3c2ba5de45cf5a9.zip
Target Explorer: More code about searching action.
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/activator/UIPlugin.java56
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/DelegateProgressMonitor.java129
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerSearchDialog.java367
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/TreeViewerUtil.java19
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/interfaces/ISearchMatcher.java3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/AbstractSearcher.java186
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/DepthTreeSearcher.java57
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ISearchCallback.java32
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ITreeSearcher.java21
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/WidthTreeSearcher.java31
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.java7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/nls/Messages.properties7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/Pending.java62
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerComparator.java17
14 files changed, 545 insertions, 449 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/activator/UIPlugin.java
index 4a0ea24a5..65ad07cfa 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/activator/UIPlugin.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/activator/UIPlugin.java
@@ -9,16 +9,22 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.activator;
+import java.io.InputStream;
import java.net.URL;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageLoader;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.tcf.te.runtime.tracing.TraceHandler;
import org.eclipse.tcf.te.ui.interfaces.ImageConsts;
import org.eclipse.tcf.te.ui.jface.images.AbstractImageDescriptor;
-import org.eclipse.tcf.te.ui.trees.Pending;
import org.eclipse.tcf.te.ui.trees.ViewerStateManager;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -30,6 +36,8 @@ public class UIPlugin extends AbstractUIPlugin {
private static UIPlugin plugin;
// The trace handler instance
private static volatile TraceHandler traceHandler;
+ // The pending images used to display the animation.
+ Image[] pendingImages;
/**
* The constructor
@@ -38,6 +46,40 @@ public class UIPlugin extends AbstractUIPlugin {
}
/**
+ * Load the pending images used to animate.
+ */
+ private void loadPendingImages() {
+ SafeRunner.run(new ISafeRunnable() {
+ @Override
+ public void handleException(Throwable exception) {
+ // Ignore it.
+ }
+
+ @Override
+ public void run() throws Exception {
+ InputStream is = null;
+ try {
+ URL url = UIPlugin.getDefault().getBundle().getEntry(ImageConsts.IMAGE_DIR_ROOT + ImageConsts.IMAGE_DIR_ELCL + "pending.gif"); //$NON-NLS-1$
+ if (url != null) {
+ is = url.openStream();
+ ImageData[] imageDatas = new ImageLoader().load(is);
+ pendingImages = new Image[imageDatas.length];
+ Display display = PlatformUI.getWorkbench().getDisplay();
+ for (int i = 0; i < imageDatas.length; i++) {
+ pendingImages[i] = new Image(display, imageDatas[i]);
+ }
+ }
+ }
+ finally {
+ if (is != null) {
+ try { is.close(); } catch (Exception e) {}
+ }
+ }
+ }
+ });
+ }
+
+ /**
* Returns the shared instance
*
* @return the shared instance
@@ -75,6 +117,7 @@ public class UIPlugin extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ loadPendingImages();
// Load the tree viewer's state.
ViewerStateManager.getInstance().loadViewerStates();
}
@@ -86,11 +129,20 @@ public class UIPlugin extends AbstractUIPlugin {
public void stop(BundleContext context) throws Exception {
// Save the tree viewer's state.
ViewerStateManager.getInstance().storeViewerStates();
- Pending.dispose();
+ if (pendingImages != null && pendingImages.length > 0) {
+ for (Image img : pendingImages) {
+ img.dispose();
+ }
+ }
+ pendingImages = null;
plugin = null;
traceHandler = null;
super.stop(context);
}
+
+ public Image[] getPendingImages() {
+ return pendingImages;
+ }
/* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
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
new file mode 100644
index 000000000..63c35339c
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/DelegateProgressMonitor.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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.dialogs;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.ProgressMonitorWrapper;
+import org.eclipse.jface.wizard.ProgressMonitorPart;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+
+class DelegateProgressMonitor extends ProgressMonitorWrapper {
+ ProgressMonitorPart fProgressMonitor;
+ public DelegateProgressMonitor(IProgressMonitor monitor, ProgressMonitorPart monitorPart) {
+ super(monitor);
+ fProgressMonitor = monitorPart;
+ safeRun(new Runnable() {
+ @Override
+ public void run() {
+ if (!fProgressMonitor.isDisposed()) {
+ fProgressMonitor.attachToCancelComponent(null);
+ fProgressMonitor.setCanceled(false);
+ fProgressMonitor.setVisible(true);
+ }
+ }
+ });
+ }
+
+ @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);
+ }
+ }
+ });
+ }
+
+ @Override
+ public boolean isCanceled() {
+ boolean cancel = fProgressMonitor.isCanceled();
+ return cancel || super.isCanceled();
+ }
+
+ @Override
+ public void subTask(final String name) {
+ super.subTask(name);
+ safeRun(new Runnable() {
+ @Override
+ public void run() {
+ if (!fProgressMonitor.isDisposed()) {
+ fProgressMonitor.subTask(name);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void done() {
+ super.done();
+ safeRun(new Runnable() {
+ @Override
+ public void run() {
+ if (!fProgressMonitor.isDisposed()) {
+ fProgressMonitor.done();
+ fProgressMonitor.setVisible(false);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void setTaskName(final String name) {
+ super.setTaskName(name);
+ safeRun(new Runnable() {
+ @Override
+ public void run() {
+ if (!fProgressMonitor.isDisposed()) {
+ fProgressMonitor.setTaskName(name);
+ }
+ }
+ });
+
+ }
+
+ @Override
+ public void setCanceled(final boolean b) {
+ super.setCanceled(b);
+ safeRun(new Runnable() {
+ @Override
+ public void run() {
+ if (!fProgressMonitor.isDisposed()) {
+ fProgressMonitor.setCanceled(b);
+ }
+ }
+ });
+ }
+
+ @Override
+ public void worked(final int work) {
+ super.worked(work);
+ safeRun(new Runnable() {
+ @Override
+ public void run() {
+ if (!fProgressMonitor.isDisposed()) {
+ fProgressMonitor.worked(work);
+ }
+ }
+ });
+ }
+
+ void safeRun(Runnable runnable) {
+ if(Display.getCurrent() != null) {
+ runnable.run();
+ }
+ else {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(runnable);
+ }
+ }
+}
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 22f0654a7..a37c08777 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
@@ -9,19 +9,27 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.dialogs;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.dialogs.Dialog;
+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.dialogs.ProgressIndicator;
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;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.wizard.ProgressMonitorPart;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
@@ -33,81 +41,79 @@ 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.DepthTreeSearcher;
-import org.eclipse.tcf.te.ui.internal.ISearchCallback;
-import org.eclipse.tcf.te.ui.internal.ITreeSearcher;
import org.eclipse.tcf.te.ui.internal.WidthTreeSearcher;
+import org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog;
import org.eclipse.tcf.te.ui.nls.Messages;
/**
* The searching dialog used to get the searching input.
*/
-public class TreeViewerSearchDialog extends Dialog implements
- SelectionListener, ISearchMatcher {
+public class TreeViewerSearchDialog extends CustomTitleAreaDialog implements SelectionListener, ISearchMatcher {
- //A new search button's ID.
+ // A new search button's ID.
private static final int SEARCH_ID = 31;
- //The viewer being searched.
+ // The viewer being searched.
private TreeViewer fViewer;
- //The progress indicator on the bottom to report searching progress.
- private ProgressIndicator fProgress;
- //The starting path.
- private TreePath fStart;
- //If the starting path has been set.
- private boolean fSet;
- //The input field for searching conditions.
+ // The input field for searching conditions.
private Text fSearchField;
- //The text to be searched.
+ // The text to be searched.
private String fSearchTarget;
- //The case sensitive check box.
+ private Button fBtnDeep;
+ // The case sensitive check box.
+ private Button fBtnWidth;
private Button fBtnCase;
- //The wrap search check box.
+ // The wrap search check box.
private Button fBtnWrap;
- //The matching rule check box.
+ // The matching rule check box.
private Button fBtnMatch;
- //The searching orientation check box.
+ // The searching orientation check box.
private Button fBtnBackward;
- //Whether it is case sensitive
+ ProgressMonitorPart fPmPart;
+ // Whether it is case sensitive
private boolean fCaseSensitive;
- //Whether it is wrap search.
+ // Whether it is wrap search.
private boolean fWrap;
- //Whether it is precise matching.
+ // Whether it is precise matching.
private boolean fMatch;
- //Whether it is backward searching.
- private boolean fBackward;
- //The last result being searched.
- private TreePath lastResult;
- //The message label using to show "no records found".
- private Label fMessage;
+ // The last result being searched.
+ private TreePath fLastResult;
// The search engine used search the tree
- private ITreeSearcher fSearcher;
- // The search matcher
- private ISearchMatcher matcher;
+ AbstractSearcher fSearcher;
// If the search algorithm is depth preferable
private boolean fDeep;
-
+ // The searching job.
+ protected Job fSearchJob;
+ private ISearchMatcher fMatcher;
+ TreePath fStartPath;
+
/**
* Create a searching dialog using the specified parent and viewer.
+ *
* @param parent The parent shell.
* @param viewer The execution context viewer.
*/
public TreeViewerSearchDialog(TreeViewer viewer) {
this(viewer, false);
}
-
+
/**
- * Create a searching dialog using the specified parent and viewer.
+ * ow Create a searching dialog using the specified parent and viewer.
+ *
* @param parent The parent shell.
* @param viewer The execution context viewer.
*/
public TreeViewerSearchDialog(TreeViewer viewer, boolean deep) {
this(viewer, deep, null);
}
-
+
/**
* Create a searching dialog using the specified parent and viewer.
+ *
* @param parent The parent shell.
* @param viewer The execution context viewer.
*/
@@ -117,15 +123,21 @@ public class TreeViewerSearchDialog extends Dialog implements
fViewer = viewer;
fViewer.getTree().addSelectionListener(this);
setShellStyle(SWT.DIALOG_TRIM | SWT.MODELESS);
- fSearcher = deep ? new DepthTreeSearcher(fViewer) : new WidthTreeSearcher(fViewer);
- if (matcher == null) this.matcher = this;
- else this.matcher = matcher;
+ if (matcher == null) matcher = this;
+ fMatcher = matcher;
+ fSearcher = fDeep ? new DepthTreeSearcher(fViewer, fMatcher) : new WidthTreeSearcher(fViewer, fMatcher);
+ this.setTitle(Messages.TreeViewerSearchDialog_DialogTitleMessage);
}
public void setStartPath(TreePath path) {
- fStart = path;
+ fStartPath = path;
+ fSearcher.setStartPath(path);
+ if(fSearcher != null) {
+ String text = fSearcher.getElementText(path.getLastSegment());
+ this.setDefaultMessage(NLS.bind(Messages.TreeViewerSearchDialog_DialogPromptMessage, text), NONE);
+ }
}
-
+
/*
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#close()
@@ -157,63 +169,77 @@ public class TreeViewerSearchDialog extends Dialog implements
*/
@Override
protected void cancelPressed() {
- fProgress.done();
- fProgress.setVisible(false);
- fSearcher.endSearch();
+ if (fSearchJob != null) {
+ fSearchJob.cancel();
+ fSearchJob = null;
+ }
super.cancelPressed();
}
private void searchNext() {
- if (!fSet) {
- fSearcher.startSearch(fStart);
- lastResult = null;
- fSet = true;
- }
fSearchTarget = fSearchField.getText().trim();
getButton(SEARCH_ID).setEnabled(false);
- fSearcher.searchNext(!fBackward, matcher, new ISearchCallback() {
+ final TreePath[] result = new TreePath[1];
+ fSearchJob = new Job(Messages.TreeViewerSearchDialog_JobName) {
@Override
- public void callback(IStatus status, TreePath path) {
- safeSearchDone(status, path);
+ 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(IJobChangeEvent event) {
+ safeSearchDone(event.getResult(), result[0]);
}
});
- fProgress.setVisible(true);
- fProgress.beginAnimatedTask();
+ fSearchJob.schedule();
}
/*
* (non-Javadoc)
- * @see com.windriver.scopetools.common.ui.phoenix.interfaces.ISearchMatcher#match(com.windriver.scopetools.common.core.phoenix.interfaces.IExecutionContext)
+ * @see
+ * com.windriver.scopetools.common.ui.phoenix.interfaces.ISearchMatcher#match(com.windriver.
+ * scopetools.common.core.phoenix.interfaces.IExecutionContext)
*/
@Override
- public boolean match(Object context) {
- if (context == null)
- return false;
+ public boolean match(Object context) {
+ if (context == null) return false;
String text = getTreeColumnText(context);
- if (text == null)
- return false;
+ if (text == null) return false;
String target = fSearchTarget;
if (!fCaseSensitive) {
text = text.toLowerCase();
target = fSearchTarget.toLowerCase();
}
- if (fMatch)
- return text.equals(target);
+ if (fMatch) return text.equals(target);
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();
+ 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() {
+ public void run() {
result[0] = getTreeColumnText(context);
}
});
@@ -221,47 +247,45 @@ public class TreeViewerSearchDialog extends Dialog implements
}
void searchDone(IStatus status, TreePath path) {
+ Button btn = getButton(SEARCH_ID);
+ if (btn != null && !btn.isDisposed()) {
+ btn.setEnabled(true);
+ btn.setFocus();
+ }
if (status.isOK()) {
if (path == null) {
if (fWrap) {
- if (lastResult == null) {
- getButton(SEARCH_ID).setEnabled(true);
- fMessage.setText(Messages.TreeViewerSearchDialog_NoSuchNode);
- } else {
- fSearcher.endSearch();
- fSearcher.startSearch(null);
- lastResult = null;
- getButton(SEARCH_ID).setEnabled(true);
+ if (fLastResult == null) {
+ setErrorMessage(Messages.TreeViewerSearchDialog_NoSuchNode);
+ }
+ else {
+ setStartPath(fLastResult);
+ fLastResult = null;
buttonPressed(SEARCH_ID);
return;
}
- } else {
- getButton(SEARCH_ID).setEnabled(true);
- fMessage.setText(Messages.TreeViewerSearchDialog_NoSuchNode1);
}
- } else {
- fMessage.setText(""); //$NON-NLS-1$
- lastResult = path;
+ else {
+ setErrorMessage(Messages.TreeViewerSearchDialog_NoSuchNode1);
+ }
+ }
+ else {
+ setMessage(null);
+ fLastResult = path;
fViewer.expandToLevel(path, 0);
- fViewer.setSelection(new StructuredSelection(
- new Object[] { path }), true);
- getButton(SEARCH_ID).setEnabled(true);
- getButton(SEARCH_ID).setFocus();
+ fViewer.setSelection(new StructuredSelection(new Object[] { path }), true);
}
- } else {
- if (getButton(SEARCH_ID) != null)
- getButton(SEARCH_ID).setEnabled(true);
}
- if (!fProgress.isDisposed()) {
- fProgress.done();
- fProgress.setVisible(false);
+ else {
+ setMessage(null);
}
+ fSearchJob = null;
}
void safeSearchDone(final IStatus status, final TreePath path) {
fViewer.getTree().getDisplay().asyncExec(new Runnable() {
@Override
- public void run() {
+ public void run() {
searchDone(status, path);
}
});
@@ -279,16 +303,11 @@ public class TreeViewerSearchDialog extends Dialog implements
/*
* (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) {
- ((GridLayout) parent.getLayout()).numColumns++;
- fMessage = new Label(parent, SWT.NONE);
- fMessage.setText(""); //$NON-NLS-1$
- GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
- data.widthHint = 50;
- fMessage.setLayoutData(data);
createButton(parent, SEARCH_ID, Messages.TreeViewerSearchDialog_BtnSearchText, true);
createButton(parent, IDialogConstants.CANCEL_ID, Messages.TreeViewerSearchDialog_BtnCancelText, false);
getButton(SEARCH_ID).setEnabled(false);
@@ -300,35 +319,59 @@ public class TreeViewerSearchDialog extends Dialog implements
*/
@Override
protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite) super.createDialogArea(parent);
+ // set margins of dialog and apply dialog font
+ Composite container = (Composite) super.createDialogArea(parent);
+ Composite composite = new Composite(container, 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);
label.setText(Messages.TreeViewerSearchDialog_LblCancelText);
fSearchField = new Text(composite, SWT.SINGLE | SWT.BORDER);
- fSearchField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
- false));
- fSearchField.addKeyListener(new KeyListener() {
+ fSearchField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ fSearchField.addModifyListener(new ModifyListener() {
@Override
- public void keyPressed(KeyEvent e) {
+ public void modifyText(ModifyEvent e) {
updateButton();
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
+ setStartPath(fStartPath);
}
});
Group group = new Group(composite, SWT.SHADOW_ETCHED_IN);
- group.setText(Messages.TreeViewerSearchDialog_GrpOptionsText);
+ group.setText(Messages.TreeViewerSearchDialog_SearchAlgorithm);
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
data.horizontalSpan = 2;
group.setLayoutData(data);
group.setLayout(new GridLayout(2, false));
- OptionsListener l = new OptionsListener();
+
+ SelectionListener l = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ optionChecked(e);
+ }
+ };
+
+ fBtnWidth = new Button(group, SWT.RADIO);
+ fBtnWidth.setText(Messages.TreeViewerSearchDialog_BreadthFirst);
+ fBtnWidth.setSelection(true);
+ fBtnWidth.addSelectionListener(l);
+ fBtnWidth.setLayoutData(new GridData());
+
+ fBtnDeep = new Button(group, SWT.RADIO);
+ fBtnDeep.setText(Messages.TreeViewerSearchDialog_DepthFirst);
+ fBtnDeep.addSelectionListener(l);
+ fBtnDeep.setLayoutData(new GridData());
+
+ group = new Group(composite, 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));
+
fBtnCase = new Button(group, SWT.CHECK);
fBtnCase.setText(Messages.TreeViewerSearchDialog_BtnCaseText);
fBtnCase.addSelectionListener(l);
@@ -338,46 +381,61 @@ public class TreeViewerSearchDialog extends Dialog implements
fBtnWrap = new Button(group, SWT.CHECK);
fBtnWrap.setText(Messages.TreeViewerSearchDialog_BtnWrapText);
fBtnWrap.addSelectionListener(l);
- if (fDeep) {
- fBtnBackward = new Button(group, SWT.CHECK);
- fBtnBackward.setText(Messages.TreeViewerSearchDialog_BtnBackText);
- fBtnBackward.addSelectionListener(l);
- }
- fProgress = new ProgressIndicator(composite);
- data = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ fBtnBackward = new Button(group, SWT.CHECK);
+ fBtnBackward.setText(Messages.TreeViewerSearchDialog_BtnBackText);
+ fBtnBackward.addSelectionListener(l);
+ fBtnBackward.setVisible(fDeep);
+ fPmPart = new ProgressMonitorPart(composite, null, true);
+ data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
data.horizontalSpan = 2;
- data.heightHint = 15;
- fProgress.setLayoutData(data);
- fProgress.setVisible(false);
- return composite;
+ fPmPart.setLayoutData(data);
+ fPmPart.setVisible(false);
+ return container;
}
void optionChecked(SelectionEvent e) {
Object src = e.getSource();
if (src == fBtnCase) {
fCaseSensitive = fBtnCase.getSelection();
- } else if (src == fBtnWrap) {
+ }
+ else if (src == fBtnWrap) {
fWrap = fBtnWrap.getSelection();
- } else if (src == fBtnMatch) {
+ }
+ else if (src == fBtnMatch) {
fMatch = fBtnMatch.getSelection();
- } else if (src == fBtnBackward) {
- fSearcher.endSearch();
- fSearcher.startSearch(lastResult);
- fBackward = fBtnBackward.getSelection();
}
- }
-
- class OptionsListener implements SelectionListener {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- optionChecked(e);
+ else if (src == fBtnBackward) {
+ endSearch();
+ setStartPath(fLastResult);
+ if(fDeep) {
+ ((DepthTreeSearcher) fSearcher).setForeward(!fBtnBackward.getSelection());
+ }
}
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
+ else if (src == fBtnDeep || src == fBtnWidth) {
+ if (src == fBtnDeep) {
+ fBtnDeep.setSelection(true);
+ fBtnWidth.setSelection(false);
+ }
+ else if (src == fBtnWidth) {
+ fBtnWidth.setSelection(true);
+ fBtnDeep.setSelection(false);
+ }
+ endSearch();
+ fDeep = fBtnDeep.getSelection();
+ fBtnBackward.setVisible(fDeep);
+ fSearcher = fDeep ? new DepthTreeSearcher(fViewer, fMatcher) : new WidthTreeSearcher(fViewer, fMatcher);
+ setStartPath(fStartPath);
+ if (fDeep) {
+ ((DepthTreeSearcher) fSearcher).setForeward(!fBtnBackward.getSelection());
+ }
}
+ }
+ void endSearch() {
+ if (fSearchJob != null) {
+ fSearchJob.cancel();
+ fSearchJob = null;
+ }
}
void updateButton() {
@@ -392,31 +450,36 @@ public class TreeViewerSearchDialog extends Dialog implements
/*
* (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) {
+ public void widgetSelected(SelectionEvent e) {
+ endSearch();
ISelection sel = fViewer.getSelection();
- fSearcher.endSearch();
if (sel == null || sel.isEmpty()) {
- fStart = null;
- } else {
+ setStartPath(fStartPath);
+ }
+ else {
TreeSelection iss = (TreeSelection) sel;
TreePath[] paths = iss.getPaths();
if (paths == null || paths.length == 0) {
- fStart = null;
- } else {
- fStart = paths[0];
+ setStartPath(fStartPath);
+ }
+ else {
+ setStartPath(paths[0]);
}
}
- fSet = false;
+ fLastResult = null;
}
/*
* (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) {
+ public void widgetDefaultSelected(SelectionEvent e) {
}
}
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/dialogs/TreeViewerUtil.java
index 0cff8ce66..99dce32b0 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/dialogs/TreeViewerUtil.java
@@ -67,20 +67,13 @@ public class TreeViewerUtil {
*/
public static void doSearch(TreeViewer viewer) {
TreePath rootPath = getSelectedPath(viewer);
- Object root = getFilterRoot(viewer, rootPath);
- if(root == viewer.getInput() || viewer.getExpandedState(root)) {
- TreePath path;
- if(root == viewer.getInput()) {
- path = new TreePath(new Object[]{root});
- }
- else {
- path = (TreePath) root;
- }
- TreeViewerSearchDialog dialog = new TreeViewerSearchDialog(viewer);
- dialog.setStartPath(path);
- dialog.open();
+ if (rootPath == null) {
+ rootPath = new TreePath(new Object[] { viewer.getInput() });
}
- }
+ TreeViewerSearchDialog dialog = new TreeViewerSearchDialog(viewer);
+ dialog.setStartPath(rootPath);
+ dialog.open();
+ }
/**
* Get the filter root for the viewer based on the root path.
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 e02332eab..845225de1 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
@@ -6,7 +6,6 @@
*/
package org.eclipse.tcf.te.ui.interfaces;
-import org.eclipse.tcf.te.ui.internal.ISearchCallback;
/**
@@ -27,5 +26,5 @@ public interface ISearchMatcher {
* The execution context node to be examined.
* @return true if it matches or else false.
*/
- boolean match(Object context);
+ public boolean match(Object context);
}
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 be25f7ec9..a89abe571 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
@@ -9,122 +9,104 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.internal;
-import java.lang.reflect.InvocationTargetException;
-import java.util.concurrent.atomic.AtomicReference;
+import java.lang.reflect.Method;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
-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.AbstractTreeViewer;
import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.jface.viewers.ViewerFilter;
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.trees.Pending;
+import org.eclipse.ui.PlatformUI;
public abstract class AbstractSearcher implements ITreeSearcher {
+ private static Method methodGetSortedChildren;
+ static {
+ try {
+ methodGetSortedChildren = AbstractTreeViewer.class.getDeclaredMethod("getSortedChildren", new Class[]{Object.class}); //$NON-NLS-1$
+ methodGetSortedChildren.setAccessible(true);
+ }
+ catch (Exception e) {
+ }
+ }
protected TreeViewer fViewer;
+ // The label provider of the tree viewer.
private ILabelProvider fLabelProvider;
- // The searching job.
- protected Job fSearchJob;
- public AbstractSearcher(TreeViewer viewer) {
+ protected ISearchMatcher fMatcher;
+ public AbstractSearcher(TreeViewer viewer, ISearchMatcher matcher) {
fViewer = viewer;
fLabelProvider = (ILabelProvider) fViewer.getLabelProvider();
+ fMatcher = matcher;
}
-
- abstract protected TreePath searchNode(boolean forward, ISearchMatcher matcher, IProgressMonitor monitor);
-
- protected void reportProgress(final Object element, final IProgressMonitor monitor) {
+
+ abstract public void setStartPath(TreePath path);
+
+ public 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();
+ elementText = element == null ? "" : element.toString(); //$NON-NLS-1$
}
- monitor.subTask("Try to matching \"" + elementText + "\""); //$NON-NLS-1$ //$NON-NLS-2$
- }
- else {
- fViewer.getTree().getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- reportProgress(element, monitor);
- }
- });
+ return elementText;
}
+ final String[] result = new String[1];
+ fViewer.getTree().getDisplay().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ result[0] = getElementText(element);
+ }
+ });
+ return result[0];
}
+ protected void advance(String msg, IProgressMonitor monitor) {
+ monitor.subTask(msg);
+ }
+
protected Object[] getUpdatedChildren(final Object parent, final IProgressMonitor monitor) {
- if (Display.getCurrent() != null) {
- if (parent instanceof Pending) return new Object[0];
- ILazyLoader lazyLoader = getLazyLoader(parent);
- if (lazyLoader != null) {
- if (!lazyLoader.isDataLoaded()) {
- try {
- lazyLoader.loadData(monitor);
- }
- catch (InvocationTargetException e) {
- return new Object[0];
- }
- catch (InterruptedException e) {
- monitor.setCanceled(true);
- return new Object[0];
- }
+ if (parent instanceof Pending) return new Object[0];
+ final ILazyLoader lazyLoader = getLazyLoader(parent);
+ if (lazyLoader != null) {
+ if (!lazyLoader.isDataLoaded()) {
+ try{
+ lazyLoader.loadData(monitor);
+ }catch(Exception e) {
+ return new Object[0];
}
}
- Object[] children = getSortedChildren(parent);
- return children;
}
- final AtomicReference<Object[]> ref = new AtomicReference<Object[]>();
- fViewer.getTree().getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- ref.set(getUpdatedChildren(parent, monitor));
- }
- });
- return ref.get();
+ Object[] children = getSortedChildren(parent);
+ return children;
}
- private Object[] getSortedChildren(Object parentElementOrTreePath) {
- Object[] result = getFilteredChildren(parentElementOrTreePath);
- ViewerComparator comparator = fViewer.getComparator();
- if (comparator != null) {
- // be sure we're not modifying the original array from the model
- result = (Object[]) result.clone();
- comparator.sort(fViewer, result);
- }
- return result;
- }
-
- private Object[] getFilteredChildren(Object parent) {
- Object[] result = getRawChildren(parent);
- ViewerFilter[] filters = fViewer.getFilters();
- if (filters != null) {
- for (ViewerFilter f : filters) {
- result = f.filter(fViewer, parent, result);
+ Object[] getSortedChildren(final Object parentElementOrTreePath) {
+ if(Display.getCurrent() != null) {
+ try {
+ if (methodGetSortedChildren != null) {
+ return (Object[]) methodGetSortedChildren.invoke(fViewer, parentElementOrTreePath);
}
}
- return result;
- }
-
- private Object[] getRawChildren(Object parent) {
- Object[] result = null;
- if (parent != null) {
- ITreeContentProvider tcp = (ITreeContentProvider) fViewer.getContentProvider();
- result = tcp.getChildren(parent);
+ catch (Exception e) {
}
- return (result != null) ? result : new Object[0];
- }
+ return new Object[0];
+ }
+ final Object[][]result = new Object[1][];
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable(){
+ @Override
+ public void run() {
+ result[0] = getSortedChildren(parentElementOrTreePath);
+ }});
+ return result[0];
+ }
private ILazyLoader getLazyLoader(Object parent) {
ILazyLoader loader = null;
@@ -139,50 +121,4 @@ public abstract class AbstractSearcher implements ITreeSearcher {
}
return loader;
}
-
- /**
- * 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 void searchNext(final boolean foreward, final ISearchMatcher matcher, final ISearchCallback callback) {
- final TreePath[]result = new TreePath[1];
- fSearchJob = new Job("Searching ...") { //$NON-NLS-1$
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask("Searching ...", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
- result[0] = searchNode(foreward, matcher, monitor);
- monitor.done();
- return monitor.isCanceled()?Status.CANCEL_STATUS:Status.OK_STATUS;
- }
- };
- fSearchJob.addJobChangeListener(new JobChangeAdapter() {
- @Override
- public void done(IJobChangeEvent event) {
- callback.callback(event.getResult(), result[0]);
- }
- });
- fSearchJob.schedule();
- }
-
- /**
- * End the search process. This method is called to clear the searching
- * context when the search process is ended. Callers must call this method
- * to clean up the state data left by the search process.
- */
- public void endSearch() {
- if (fSearchJob != null) {
- fSearchJob.cancel();
- fSearchJob = null;
- }
- }
-
}
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/DepthTreeSearcher.java
index c508c2f1a..0b4cc3761 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/DepthTreeSearcher.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.internal;
+import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -47,6 +48,7 @@ public class DepthTreeSearcher extends AbstractSearcher {
}
// The searching stack in which searching contexts are stored.
private LinkedList<StackElement> fSearchStack;
+ private boolean fForeward;
/**
* Create an execution context searcher with the specified viewer and its
@@ -57,26 +59,22 @@ public class DepthTreeSearcher extends AbstractSearcher {
* @param controller
* The controller of the execution context viewer.
*/
- public DepthTreeSearcher(TreeViewer viewer) {
- super(viewer);
+ public DepthTreeSearcher(TreeViewer viewer, ISearchMatcher matcher) {
+ super(viewer, matcher);
}
-
- /**
- * Start the search process. This method is called to clear the searching
- * context. Each search process is stateful process. Callers must call this
- * method to reset the search state before each searching process starts.
- *
- * @param start
- * The beginning path from which the seach process starts.
- */
+
@Override
- public void startSearch(TreePath start) {
+ public void setStartPath(TreePath path) {
fSearchStack = new LinkedList<StackElement>();
- if (start == null) {
+ if (path == null) {
Object obj = fViewer.getInput();
- start = new TreePath(new Object[] { obj });
+ path = new TreePath(new Object[] { obj });
}
- initSearchContext(start);
+ initSearchContext(path);
+ }
+
+ public void setForeward(boolean foreward) {
+ fForeward = foreward;
}
/**
@@ -93,7 +91,7 @@ public class DepthTreeSearcher extends AbstractSearcher {
if (i > 0) {
IProgressMonitor monitor = new NullProgressMonitor();
Object parent = start.getSegment(i-1);
- Object[] children = getUpdatedChildren(parent, monitor);
+ Object[] children = getUpdatedChildren(parent, monitor);
for (int j = 0; j < children.length; j++) {
if (children[j] == element) {
StackElement parentStack = fSearchStack.get(i - 1);
@@ -114,29 +112,30 @@ public class DepthTreeSearcher extends AbstractSearcher {
* @param monitor The monitor reporting the progress.
* @return The tree path whose leaf node statisfies the searching rule.
*/
- @SuppressWarnings("synthetic-access")
- protected TreePath searchNode(boolean forward, ISearchMatcher matcher, IProgressMonitor monitor) {
+ @Override
+ public TreePath searchNext(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
TreePath result = null;
while (!fSearchStack.isEmpty() && result == null && !monitor.isCanceled()) { //Search util the stack is empty or the result is found.
StackElement top = fSearchStack.getLast(); //Get the top stack element.
- if(!forward && top.index == END_INDEX || forward && top.index == START_INDEX){
- reportProgress(top.node, monitor);
- result = matchContext(matcher, top.node);
+ if(!fForeward && top.index == END_INDEX || fForeward && top.index == START_INDEX){
+ String elementText = getElementText(top.node);
+ advance(elementText, monitor);
+ 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.
fSearchStack.removeLast(); //Then discard it.
} else {
Object[] children = getUpdatedChildren(top.node, monitor);//Get current node's children.
if (children != null && children.length > 0) {//If there are some children.
- if(forward && top.index == children.length-1 || !forward && top.index == 0){
+ if(fForeward && top.index == children.length-1 || !fForeward && top.index == 0){
//If this is the last index
top.index = END_INDEX;
}else{
//Increase or decrease the index according to the direction.
if(top.index == START_INDEX)
- top.index = forward ? 0 : children.length - 1;
+ top.index = fForeward ? 0 : children.length - 1;
else
- top.index = forward ? top.index + 1 : top.index - 1;
+ top.index = fForeward ? top.index + 1 : top.index - 1;
//Push the child at the index with START_INDEX into the stack.
fSearchStack.addLast(new StackElement(children[top.index], START_INDEX));
}
@@ -145,14 +144,12 @@ public class DepthTreeSearcher extends AbstractSearcher {
}
}
}
- return result;
- }
- private TreePath matchContext(ISearchMatcher matcher, Object context){
- if (matcher.match(context)) {//Match the context using the matcher.
- return createContextPath();//If the matching is successful, assign the result with the current path.
+ if(monitor.isCanceled()) {
+ throw new InterruptedException();
}
- return null;
+ return result;
}
+
/**
* Create a path using the current elements of the stack.
*
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ISearchCallback.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ISearchCallback.java
deleted file mode 100644
index ddbce087a..000000000
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/ISearchCallback.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * ISearchCallback.java
- * Created on Feb 15, 2011
- *
- * Copyright 2008 Wind River Systems Inc. All rights reserved.
- */
-package org.eclipse.tcf.te.ui.internal;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.viewers.TreePath;
-
-/**
- * This is callback handler invoked search processes to report searching results
- * or progress, including methods like @link ExecutionContextViewer#searchNext},
- * {@link ExecutionContextViewer#getExpensivePath},and {@link
- * ExecutionContextViewer#getCheapPath}.
- *
- * @author william.chen@windriver.com
- *
- */
-public interface ISearchCallback {
- /**
- * Callback handler method called when a search target found or a progress is
- * made in the searching process.
- *
- * @param status
- * The resulting status of the searching.
- * @param path
- * The searching result or current searching position.
- */
- void callback(IStatus status, TreePath path);
-}
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
index ae0c90b5e..d1c20dd08 100644
--- 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
@@ -9,6 +9,9 @@
*******************************************************************************/
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;
@@ -28,15 +31,6 @@ import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
* @see ISearchCallback
*/
public interface ITreeSearcher {
-
- /**
- * Start the search process. This method is called to clear the searching context. Each search
- * process is stateful process. Callers must call this method to reset the search state before
- * each searching process starts.
- *
- * @param start The beginning path from which the seach process starts.
- */
- public void startSearch(TreePath start);
/**
* Search the viewer for the next target which matches the condition defined by the matcher. The
@@ -46,12 +40,5 @@ public interface ITreeSearcher {
* @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 void searchNext(boolean foreward, ISearchMatcher matcher, ISearchCallback callback);
-
- /**
- * End the search process. This method is called to clear the searching context when the search
- * process is ended. Callers must call this method to clean up the state data left by the search
- * process.
- */
- public void endSearch();
+ 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/WidthTreeSearcher.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/internal/WidthTreeSearcher.java
index 73de12b8a..ec57e0d89 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/WidthTreeSearcher.java
@@ -9,34 +9,29 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.internal;
+import java.lang.reflect.InvocationTargetException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
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.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
public class WidthTreeSearcher extends AbstractSearcher{
private Queue<TreePath> queue;
- // The searching job.
- private Job fSearchJob;
- public WidthTreeSearcher(TreeViewer viewer){
- super(viewer);
- this.queue = new ConcurrentLinkedQueue<TreePath>();
+ public WidthTreeSearcher(TreeViewer viewer, ISearchMatcher matcher){
+ super(viewer, matcher);
}
+
@Override
- public void startSearch(TreePath start) {
- queue.offer(start);
+ public void setStartPath(TreePath path) {
+ this.queue = new ConcurrentLinkedQueue<TreePath>();
+ this.queue.offer(path);
}
-
+
@Override
- protected TreePath searchNode(boolean forward, ISearchMatcher matcher, IProgressMonitor monitor) {
+ public TreePath searchNext(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException{
TreePath result = null;
while(!queue.isEmpty() && result == null && !monitor.isCanceled()) {
TreePath path = queue.poll();
@@ -48,11 +43,15 @@ public class WidthTreeSearcher extends AbstractSearcher{
queue.offer(childPath);
}
}
- reportProgress(element, monitor);
- if(matcher.match(element)) {
+ String elementText = getElementText(element);
+ advance(elementText, monitor);
+ if(fMatcher.match(element)) {
result = path;
}
}
+ if(monitor.isCanceled()) {
+ throw new InterruptedException();
+ }
return result;
}
}
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 03605e1eb..1ab403c73 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
@@ -75,10 +75,17 @@ public class Messages extends NLS {
public static String TreeViewerSearchDialog_BtnPreciseText;
public static String TreeViewerSearchDialog_BtnSearchText;
public static String TreeViewerSearchDialog_BtnWrapText;
+ public static String TreeViewerSearchDialog_DepthFirst;
+ public static String TreeViewerSearchDialog_DialogPromptMessage;
public static String TreeViewerSearchDialog_DialogTitle;
+ public static String TreeViewerSearchDialog_DialogTitleMessage;
public static String TreeViewerSearchDialog_GrpOptionsText;
+ public static String TreeViewerSearchDialog_JobName;
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 92981f75f..3836041e8 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
@@ -67,9 +67,16 @@ TreeViewerSearchDialog_BtnCaseText=Case sensitive
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_DialogTitle=Search Element Dialog
+TreeViewerSearchDialog_DialogTitleMessage=Search Elements
TreeViewerSearchDialog_GrpOptionsText=Options
+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\!
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/Pending.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/Pending.java
index 6a0535027..39adf21d8 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/Pending.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/Pending.java
@@ -9,18 +9,10 @@
*******************************************************************************/
package org.eclipse.tcf.te.ui.trees;
-import java.io.InputStream;
-import java.net.URL;
-
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tcf.te.ui.activator.UIPlugin;
-import org.eclipse.tcf.te.ui.interfaces.ImageConsts;
import org.eclipse.tcf.te.ui.nls.Messages;
/**
@@ -28,8 +20,6 @@ import org.eclipse.tcf.te.ui.nls.Messages;
* displays an animated GIF image read from "pending.gif".
*/
public class Pending {
- // The pending images used to display the animation.
- static Image[] pendingImages;
// The interval between two frames.
private static final int FRAME_INTERVAL = 100;
// Reference to the parent tree viewer
@@ -40,7 +30,8 @@ public class Pending {
boolean animating;
// The current frame index of the image list.
int frame;
-
+ // The pending images used.
+ Image[] images;
/**
* Create a pending node for the specified tree viewer.
*
@@ -51,42 +42,6 @@ public class Pending {
this.display = viewer.getTree().getDisplay();
this.animating = true;
this.frame = 0;
- if(pendingImages == null) {
- loadPendingImages(display);
- }
- }
-
- /**
- * Load the pending images used to animate.
- */
- private static void loadPendingImages(final Display display) {
- SafeRunner.run(new ISafeRunnable() {
- @Override
- public void handleException(Throwable exception) {
- // Ignore it.
- }
-
- @Override
- public void run() throws Exception {
- InputStream is = null;
- try {
- URL url = UIPlugin.getDefault().getBundle().getEntry(ImageConsts.IMAGE_DIR_ROOT + ImageConsts.IMAGE_DIR_ELCL + "pending.gif"); //$NON-NLS-1$
- if (url != null) {
- is = url.openStream();
- ImageData[] imageDatas = new ImageLoader().load(is);
- pendingImages = new Image[imageDatas.length];
- for (int i = 0; i < imageDatas.length; i++) {
- pendingImages[i] = new Image(display, imageDatas[i]);
- }
- }
- }
- finally {
- if (is != null) {
- try { is.close(); } catch (Exception e) {}
- }
- }
- }
- });
}
/**
@@ -129,24 +84,13 @@ public class Pending {
*/
public Image getImage() {
Image img = null;
+ Image[] pendingImages = UIPlugin.getDefault().getPendingImages();
if (pendingImages != null && pendingImages.length > 0) {
img = pendingImages[frame++];
frame = frame % pendingImages.length;
}
return img;
}
-
- /**
- * Dispose the pending images used.
- */
- public static void dispose() {
- if (pendingImages != null && pendingImages.length > 0) {
- for (Image img : pendingImages) {
- img.dispose();
- }
- }
- pendingImages = null;
- }
/**
* Stop the animation.
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 e87d8386e..d64000bd4 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
@@ -15,6 +15,7 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
@@ -44,7 +45,7 @@ public class TreeViewerComparator extends ViewerComparator {
return (e1 instanceof Pending) ? (e2 instanceof Pending ? 0 : 1) : -1;
}
Tree tree = ((TreeViewer) viewer).getTree();
- int inverter = tree.getSortDirection() == SWT.DOWN ? -1 : 1;
+ int inverter = getSortDirection(tree) == SWT.DOWN ? -1 : 1;
TreeColumn treeColumn = tree.getSortColumn();
if(treeColumn == null) {
// If the sort column is not set, then use the first column.
@@ -61,4 +62,18 @@ public class TreeViewerComparator extends ViewerComparator {
}
return inverter * super.compare(viewer, e1, e2);
}
+
+ int getSortDirection(final Tree tree) {
+ if(Display.getCurrent() != null) {
+ return tree.getSortDirection();
+ }
+ final int[] result = new int[1];
+ tree.getDisplay().syncExec(new Runnable(){
+
+ @Override
+ public void run() {
+ result[0] = getSortDirection(tree);
+ }});
+ return result[0];
+ }
}

Back to the top