Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgreen2011-06-15 01:29:48 +0000
committerdgreen2011-06-15 01:29:48 +0000
commita4c3459521e497ecaccdde329d8926c918569e41 (patch)
treea56198c16b81b7227e2e186b0fc41ce7ea4f6cbb /org.eclipse.mylyn.sandbox.search.ui
parentbbf199f32d91ab65caa101a366dabd98bf1dd13d (diff)
downloadorg.eclipse.mylyn.incubator-a4c3459521e497ecaccdde329d8926c918569e41.tar.gz
org.eclipse.mylyn.incubator-a4c3459521e497ecaccdde329d8926c918569e41.tar.xz
org.eclipse.mylyn.incubator-a4c3459521e497ecaccdde329d8926c918569e41.zip
349351: [search] enhance Eclipse search capabilities to include desktop resources
https://bugs.eclipse.org/bugs/show_bug.cgi?id=349351 initial contribution
Diffstat (limited to 'org.eclipse.mylyn.sandbox.search.ui')
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/.classpath7
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/.project28
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/META-INF/MANIFEST.MF14
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/about.html27
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/build.properties16
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/icons/full/elcl16/tsearch_obj.gifbin0 -> 592 bytes
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/plugin.xml80
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/ContentProvider.java94
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearch.java58
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchAdapterFactory.java40
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchPage.java274
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchQuery.java88
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResult.java96
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResultEvent.java43
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResultPage.java143
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchWorkbenchAdapter.java60
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/MockSearchProvider.java51
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/OpenDesktopSearchActionDelegate.java42
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/OpenDesktopSearchHandler.java54
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchCallback.java25
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchCriteria.java122
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchPlugin.java60
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchProvider.java34
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchResultItem.java38
-rw-r--r--org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/Windows7SearchProvider.java43
26 files changed, 1549 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.sandbox.search.ui/.classpath b/org.eclipse.mylyn.sandbox.search.ui/.classpath
new file mode 100644
index 00000000..ad32c83a
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.mylyn.sandbox.search.ui/.project b/org.eclipse.mylyn.sandbox.search.ui/.project
new file mode 100644
index 00000000..dbbff14d
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.mylyn.sandbox.search.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.mylyn.sandbox.search.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.mylyn.sandbox.search.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..09f7f942
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Mon Jun 13 21:26:11 PDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/org.eclipse.mylyn.sandbox.search.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.sandbox.search.ui/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..8e85a993
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Mylyn Sandbox Search UI
+Bundle-SymbolicName: org.eclipse.mylyn.sandbox.search.ui;singleton:=true
+Bundle-Version: 0.1.0.qualifier
+Bundle-Vendor: Tasktop Technologies Inc.
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0",
+ org.eclipse.search,
+ org.eclipse.ui;bundle-version="3.5.0",
+ org.eclipse.jface.text;bundle-version="3.5.0"
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.mylyn.internal.sandbox.search.ui.SearchPlugin
+Eclipse-PlatformFilter: (&(osgi.os=win32) (osgi.arch=x86))
diff --git a/org.eclipse.mylyn.sandbox.search.ui/about.html b/org.eclipse.mylyn.sandbox.search.ui/about.html
new file mode 100644
index 00000000..c426db22
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/about.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html>
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 14, 2011</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.mylyn.sandbox.search.ui/build.properties b/org.eclipse.mylyn.sandbox.search.ui/build.properties
new file mode 100644
index 00000000..2325c4d7
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/build.properties
@@ -0,0 +1,16 @@
+###############################################################################
+# Copyright (c) 2011 Tasktop Technologies 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:
+# Tasktop Technologies - initial API and implementation
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ icons/
diff --git a/org.eclipse.mylyn.sandbox.search.ui/icons/full/elcl16/tsearch_obj.gif b/org.eclipse.mylyn.sandbox.search.ui/icons/full/elcl16/tsearch_obj.gif
new file mode 100644
index 00000000..a0ccf660
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/icons/full/elcl16/tsearch_obj.gif
Binary files differ
diff --git a/org.eclipse.mylyn.sandbox.search.ui/plugin.xml b/org.eclipse.mylyn.sandbox.search.ui/plugin.xml
new file mode 100644
index 00000000..96ad7c6f
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/plugin.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2011 Tasktop Technologies 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:
+ Tasktop Technologies - initial API and implementation
+-->
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.search.searchPages">
+ <page
+ class="org.eclipse.mylyn.internal.sandbox.search.ui.DesktopSearchPage"
+ id="org.eclipse.mylyn.internal.sandbox.search.ui.desktopSearchPage"
+ icon="$nl$/icons/full/elcl16/tsearch_obj.gif"
+ label="Desktop Search">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.search.ui.category.search"
+ defaultHandler="org.eclipse.mylyn.internal.sandbox.search.ui.OpenDesktopSearchHandler"
+ description="Open the Search dialog&apos;s desktop search page"
+ id="org.eclipse.mylyn.internal.sandbox.search.ui.openDesktopSearchCommand"
+ name="Desktop Search">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ commandId="org.eclipse.mylyn.internal.sandbox.search.ui.openDesktopSearchCommand"
+ class="org.eclipse.mylyn.internal.sandbox.search.ui.OpenDesktopSearchHandler">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.actionSets">
+
+ <!-- bug 213385 -->
+ <actionSet
+ id="org.eclipse.mylyn.internal.sandbox.search.ui.actionSet2"
+ label="Search Actions"
+ visible="true">
+ <action
+ class="org.eclipse.mylyn.internal.sandbox.search.ui.OpenDesktopSearchActionDelegate"
+ definitionId="org.eclipse.mylyn.internal.sandbox.search.ui.openDesktopSearchCommand"
+ icon="$nl$/icons/full/elcl16/tsearch_obj.gif"
+ id="org.eclipse.mylyn.internal.sandbox.search.ui.action2"
+ label="Desktop Search..."
+ menubarPath="org.eclipse.search.menu/dialogGroup"
+ style="push">
+ </action>
+ </actionSet>
+ </extension>
+ <extension
+ point="org.eclipse.search.searchResultViewPages">
+ <viewPage
+ class="org.eclipse.mylyn.internal.sandbox.search.ui.DesktopSearchResultPage"
+ icon="icons/full/elcl16/tsearch_obj.gif"
+ id="org.eclipse.mylyn.internal.sandbox.search.ui.DesktopSearchResultViewPage"
+ label="Desktop Search"
+ searchResultClass="org.eclipse.mylyn.internal.sandbox.search.ui.DesktopSearchResult">
+ </viewPage>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.mylyn.internal.sandbox.search.ui.SearchResultItem"
+ class="org.eclipse.mylyn.internal.sandbox.search.ui.DesktopSearchAdapterFactory">
+ <adapter
+ type="org.eclipse.ui.model.IWorkbenchAdapter">
+ </adapter>
+ </factory>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/ContentProvider.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/ContentProvider.java
new file mode 100644
index 00000000..3ebe43ff
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/ContentProvider.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.search.ui.ISearchResultListener;
+import org.eclipse.search.ui.SearchResultEvent;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ *
+ * @author David Green
+ */
+class ContentProvider implements ITreeContentProvider, ISearchResultListener {
+
+ private DesktopSearchResult searchResult;
+ private TreeViewer viewer;
+
+ public void dispose() {
+ if (searchResult != null) {
+ searchResult.removeListener(this);
+ }
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ this.viewer = (TreeViewer) viewer;
+ if (searchResult != null) {
+ searchResult.removeListener(this);
+ }
+ searchResult = (DesktopSearchResult) newInput;
+ if (searchResult != null) {
+ searchResult.addListener(this);
+ }
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (searchResult == inputElement) {
+ List<SearchResultItem> items = searchResult.getItems();
+ return items.toArray(new Object[items.size()]);
+ }
+ return new Object[0];
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return getElements(parentElement);
+ }
+
+ public Object getParent(Object element) {
+ if (element != searchResult) {
+ return searchResult;
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element == searchResult) {
+ return true;
+ }
+ return false;
+ }
+
+ public void searchResultChanged(SearchResultEvent e) {
+ final DesktopSearchResultEvent event = (DesktopSearchResultEvent) e;
+ final Control control = viewer.getControl();
+ if (!control.isDisposed()) {
+ control.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (!control.isDisposed() && viewer.getInput() == event.getSearchResult()) {
+ switch (event.getKind()) {
+ case ADDED:
+ viewer.add(searchResult, event.getItems());
+ break;
+ case CLEARED:
+ viewer.refresh();
+ break;
+ }
+ }
+ }
+ });
+ }
+ }
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearch.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearch.java
new file mode 100644
index 00000000..a4fb4450
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearch.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.text.FileTextSearchScope;
+import org.eclipse.search.ui.text.TextSearchQueryProvider;
+import org.eclipse.search.ui.text.TextSearchQueryProvider.TextSearchInput;
+
+/**
+ *
+ * @author David Green
+ */
+public class DesktopSearch {
+
+ private static DesktopSearch instance = new DesktopSearch();
+
+ public static DesktopSearch getInstance() {
+ return instance;
+ }
+
+ public ISearchQuery createQuery(final SearchCriteria item) throws CoreException {
+ // FIXME: this is for testing
+ TextSearchInput textSearchInput = new TextSearchInput() {
+
+ @Override
+ public boolean isRegExSearch() {
+ return false;
+ }
+
+ @Override
+ public boolean isCaseSensitiveSearch() {
+ return item.isCaseSensitive();
+ }
+
+ @Override
+ public String getSearchText() {
+ return item.getText();
+ }
+
+ @Override
+ public FileTextSearchScope getScope() {
+ return FileTextSearchScope.newWorkspaceScope(item.getFilenamePatterns(), false);
+ }
+ };
+ return TextSearchQueryProvider.getPreferred().createQuery(textSearchInput);
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchAdapterFactory.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchAdapterFactory.java
new file mode 100644
index 00000000..1a5b190d
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchAdapterFactory.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+/**
+ *
+ * @author David Green
+ */
+public class DesktopSearchAdapterFactory implements IAdapterFactory {
+
+ @SuppressWarnings("rawtypes")
+ private static Class[] ADAPTER_LIST = new Class[] {
+ IWorkbenchAdapter.class
+ };
+
+ @SuppressWarnings("rawtypes")
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adapterType == IWorkbenchAdapter.class && adaptableObject instanceof SearchResultItem) {
+ return DesktopSearchWorkbenchAdapter.instance();
+ }
+ return null;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public Class[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchPage.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchPage.java
new file mode 100644
index 00000000..31e8f629
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchPage.java
@@ -0,0 +1,274 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.search.ui.ISearchPage;
+import org.eclipse.search.ui.ISearchPageContainer;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.swt.SWT;
+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.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * A search page for desktop search
+ *
+ * @author David Green
+ */
+public class DesktopSearchPage extends DialogPage implements ISearchPage {
+
+ private static final String PAGE_NAME = "DesktopSearch";
+ public static final String PAGE_ID = "org.eclipse.mylyn.internal.sandbox.search.ui.desktopSearchPage";
+
+ private static final int MAX_HISTORY = 20;
+
+
+ private ISearchPageContainer container;
+ private Combo searchText;
+ private boolean initialized;
+ private List<SearchCriteria> searchHistory;
+
+
+
+ private Combo filenamePatternText;
+
+
+ private Button caseSensitive;
+
+
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).applyTo(container);
+
+ addTextControls(container);
+ addFileNamePatternControls(container);
+
+ Dialog.applyDialogFont(container);
+ setControl(container);
+ }
+
+ private void addTextControls(Composite container) {
+ Label searchLabel = new Label(container,SWT.LEAD);
+ searchLabel.setText("Containing text:");
+ GridDataFactory.swtDefaults().span(2, 1).applyTo(searchLabel);
+
+ searchText = new Combo(container, SWT.SINGLE| SWT.BORDER);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(searchText);
+ searchText.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ searchTextSelected();
+ updateStatus();
+ }
+ });
+ searchText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateStatus();
+ }
+ });
+
+ caseSensitive = new Button(container,SWT.CHECK);
+ caseSensitive.setText("Case sensitive");
+ GridDataFactory.swtDefaults().applyTo(caseSensitive);
+ }
+
+ private void addFileNamePatternControls(Composite container) {
+ Label searchLabel = new Label(container,SWT.LEAD);
+ searchLabel.setText("File name patterns:");
+ GridDataFactory.swtDefaults().span(2, 1).applyTo(searchLabel);
+
+ filenamePatternText = new Combo(container, SWT.SINGLE| SWT.BORDER);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(filenamePatternText);
+ filenamePatternText.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateStatus();
+ }
+ });
+ filenamePatternText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateStatus();
+ }
+ });
+ }
+
+
+ private void searchTextSelected() {
+ int index = searchText.getSelectionIndex();
+ if (index >= 0 && index < getSearchHistory().size()) {
+ SearchCriteria item = getSearchHistory().get(index);
+ if (!searchText.getText().equals(item.getText())) {
+ return;
+ }
+ filenamePatternText.setText(item.getFilenamePatternsAsText());
+ }
+ }
+
+ public boolean performAction() {
+ SearchCriteria criteria = computeSearchCriteria();
+ getSearchHistory().remove(criteria);
+ getSearchHistory().add(0,criteria);
+ saveSearchHistory();
+ NewSearchUI.runQueryInBackground(new DesktopSearchQuery(SearchProvider.instance(), criteria));
+ return true;
+ }
+
+ public void setContainer(ISearchPageContainer container) {
+ this.container = container;
+ }
+
+ public ISearchPageContainer getContainer() {
+ return container;
+ }
+ @Override
+ public void setVisible(boolean visible) {
+ if (!initialized) {
+ initialized = true;
+ String[] previousSearchItems = getPreviousSearchItems();
+ searchText.setItems(previousSearchItems);
+ if (!initializeSearchSettings()) {
+ if (!getSearchHistory().isEmpty()) {
+ initializeSearchSettings(getSearchHistory().get(0));
+ }
+ }
+ if (filenamePatternText.getText().isEmpty()) {
+ filenamePatternText.setText("*");
+ }
+ updateStatus();
+ }
+ super.setVisible(visible);
+ }
+
+ private String[] getPreviousSearchItems() {
+ List<SearchCriteria> searchHistory = getSearchHistory();
+ List<String> items = new ArrayList<String>();
+ for (SearchCriteria item: searchHistory) {
+ items.add(item.getText());
+ }
+ return items.toArray(new String[items.size()]);
+ }
+
+ private SearchCriteria computeSearchCriteria() {
+ SearchCriteria item = new SearchCriteria();
+ item.setText(searchText.getText());
+ item.setFilenamePatternsAsText(filenamePatternText.getText());
+ item.setCaseSensitive(caseSensitive.getSelection());
+ return item;
+ }
+
+ private IDialogSettings getDialogSettings() {
+ return SearchPlugin.getDefault().getDialogSettings(PAGE_NAME);
+ }
+
+ public List<SearchCriteria> getSearchHistory() {
+ if (searchHistory == null) {
+ loadSearchHistory();
+ }
+ return searchHistory;
+ }
+ private void loadSearchHistory() {
+ List<SearchCriteria> newSearchHistory = new ArrayList<SearchCriteria>();
+
+ IDialogSettings settings = getDialogSettings();
+ final String historyPrefix = "history";
+ for (int x = 0;x<MAX_HISTORY;++x) {
+ IDialogSettings historySection = settings.getSection(historyPrefix+x);
+ if (historySection == null) {
+ break;
+ }
+ SearchCriteria item = new SearchCriteria();
+ item.load(historySection);
+ newSearchHistory.add(item);
+ }
+ this.searchHistory = newSearchHistory;
+ }
+
+ private void saveSearchHistory() {
+ IDialogSettings settings = getDialogSettings();
+ final String historyPrefix = "history";
+ for (int x = 0;x<MAX_HISTORY;++x) {
+ String itemName = historyPrefix+x;
+ IDialogSettings historySection = settings.getSection(itemName);
+ if (historySection == null) {
+ if (x >= searchHistory.size()) {
+ break;
+ }
+ historySection = settings.addNewSection(itemName);
+ }
+ searchHistory.get(x).save(historySection);
+ }
+ }
+
+
+ private void updateStatus() {
+ boolean ok = true;
+ SearchCriteria item = computeSearchCriteria();
+ if (item.getText() == null || item.getText().trim().isEmpty()) {
+ ok = false;
+ setMessage("Please specify the text to match", ERROR);
+ }
+ if (ok && item.getFilenamePatterns().length == 0) {
+ ok = false;
+ setMessage("Please specify the file patterns to match, or '*' for all files", ERROR);
+ }
+ if (ok) {
+ setMessage(null);
+ }
+ getContainer().setPerformActionEnabled(ok);
+ }
+
+ private boolean initializeSearchSettings() {
+ ISelection selection = getContainer().getSelection();
+ if (selection instanceof ITextSelection && !selection.isEmpty()) {
+ String text = ((ITextSelection)selection).getText();
+ if (text != null && text.trim().length() > 0) {
+ SearchCriteria item = computeSearchHistoryItem(text);
+ initializeSearchSettings(item);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void initializeSearchSettings(SearchCriteria item) {
+ searchText.setText(item.getText());
+ filenamePatternText.setText(item.getFilenamePatternsAsText());
+ caseSensitive.setSelection(item.isCaseSensitive());
+ }
+
+ private SearchCriteria computeSearchHistoryItem(String text) {
+ for (SearchCriteria historyItem: getSearchHistory()) {
+ if (historyItem.getText().equals(text)) {
+ return historyItem;
+ }
+ }
+ // default
+ SearchCriteria historyItem = new SearchCriteria();
+ historyItem.setText(text);
+ historyItem.setFilenamePatternsAsText("*");
+ historyItem.setCaseSensitive(false);
+ return historyItem;
+ }
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchQuery.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchQuery.java
new file mode 100644
index 00000000..4f423f8f
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchQuery.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResult;
+
+/**
+ *
+ * @author David Green
+ */
+public class DesktopSearchQuery implements ISearchQuery {
+
+ private final SearchProvider provider;
+ private final SearchCriteria criteria;
+ private DesktopSearchResult searchResult;
+
+ public DesktopSearchQuery(SearchProvider provider,SearchCriteria criteria) {
+ this.provider = provider;
+ this.criteria = criteria;
+ searchResult = new DesktopSearchResult(this);
+ }
+
+ public IStatus run(IProgressMonitor monitor)
+ throws OperationCanceledException {
+ searchResult.clear();
+
+ SearchCallback callback = new SearchCallback() {
+ public void searchResult(SearchResultItem item) {
+ searchResult.add(item);
+ }
+
+ public void searchInitiated() {
+ }
+
+ public void searchCompleted() {
+ }
+ };
+ try {
+ provider.performSearch(criteria, callback, monitor);
+ } catch (CoreException e) {
+ return e.getStatus();
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ public String getLabel() {
+ return "Desktop Search";
+ }
+
+ public boolean canRerun() {
+ return true;
+ }
+
+ public boolean canRunInBackground() {
+ return true;
+ }
+
+ public ISearchResult getSearchResult() {
+ return searchResult;
+ }
+
+ public String getResultLabel(int size) {
+ if (size == 0) {
+ return NLS.bind("No files matching \"{0}\"",criteria.getText());
+ } else if (size == 1) {
+ return NLS.bind("1 file matches \"{0}\"",criteria.getText());
+ } else {
+ return NLS.bind("{1} files matching \"{0}\"",criteria.getText(),Integer.valueOf(size));
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResult.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResult.java
new file mode 100644
index 00000000..54fbc642
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResult.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylyn.internal.sandbox.search.ui.DesktopSearchResultEvent.Kind;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.ISearchResultListener;
+
+/**
+ *
+ * @author David Green
+ */
+public class DesktopSearchResult implements ISearchResult {
+
+ private List<ISearchResultListener> listeners = new CopyOnWriteArrayList<ISearchResultListener>();
+
+ private List<SearchResultItem> items = new ArrayList<SearchResultItem>();
+ private final DesktopSearchQuery searchQuery;
+
+ public DesktopSearchResult(DesktopSearchQuery searchQuery) {
+ this.searchQuery = searchQuery;
+ }
+
+ public int getSize() {
+ synchronized (items) {
+ return items.size();
+ }
+ }
+
+ public void clear() {
+ synchronized (items) {
+ items.clear();
+ }
+ fire(Kind.CLEARED);
+ }
+
+ public List<SearchResultItem> getItems() {
+ synchronized (items) {
+ return new ArrayList<SearchResultItem>(items);
+ }
+ }
+
+ private void fire(Kind eventKind,SearchResultItem... items) {
+ DesktopSearchResultEvent event = new DesktopSearchResultEvent(this,eventKind,items);
+ for (ISearchResultListener listener: listeners) {
+ listener.searchResultChanged(event);
+ }
+ }
+
+ public void add(SearchResultItem item) {
+ synchronized (items) {
+ items.add(item);
+ }
+ fire(Kind.ADDED,item);
+ }
+
+ public void addListener(ISearchResultListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(ISearchResultListener listener) {
+ listeners.remove(listener);
+ }
+
+ public String getLabel() {
+ return searchQuery.getResultLabel(getSize());
+ }
+
+ public String getTooltip() {
+ return getLabel();
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return SearchPlugin.getDefault().getImageRegistry().getDescriptor(SearchPlugin.IMAGE_SEARCH);
+ }
+
+ public ISearchQuery getQuery() {
+ return searchQuery;
+ }
+
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResultEvent.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResultEvent.java
new file mode 100644
index 00000000..7806f286
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResultEvent.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.SearchResultEvent;
+
+/**
+ *
+ * @author David Green
+ */
+@SuppressWarnings("serial")
+public class DesktopSearchResultEvent extends SearchResultEvent {
+
+ private final Kind kind;
+ private final SearchResultItem[] items;
+
+ public enum Kind {
+ ADDED, CLEARED
+ }
+
+ public DesktopSearchResultEvent(ISearchResult searchResult,Kind kind, SearchResultItem... items) {
+ super(searchResult);
+ this.kind = kind;
+ this.items = items;
+ }
+
+ public Kind getKind() {
+ return kind;
+ }
+
+ public SearchResultItem[] getItems() {
+ return items;
+ }
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResultPage.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResultPage.java
new file mode 100644
index 00000000..5fa272ad
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchResultPage.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.ISearchResultListener;
+import org.eclipse.search.ui.ISearchResultPage;
+import org.eclipse.search.ui.ISearchResultViewPart;
+import org.eclipse.search.ui.SearchResultEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.part.Page;
+
+/**
+ *
+ * @author David Green
+ */
+public class DesktopSearchResultPage extends Page implements ISearchResultPage {
+
+ private String id;
+ private DesktopSearchResult searchResult;
+ private TreeViewer viewer;
+ private ISearchResultViewPart viewPart;
+ private Control control;
+ private ISearchResultListener listener;
+
+ public Object getUIState() {
+ return viewer==null?null:viewer.getSelection();
+ }
+
+ public void setInput(ISearchResult search, Object uiState) {
+ if (listener == null) {
+ listener = new ISearchResultListener() {
+ public void searchResultChanged(SearchResultEvent e) {
+ DesktopSearchResultEvent event = (DesktopSearchResultEvent) e;
+ changed(event);
+ }
+ };
+ }
+ if (searchResult != null) {
+ searchResult.removeListener(listener);
+ }
+ searchResult = (DesktopSearchResult) search;
+ if (searchResult != null) {
+ searchResult.addListener(listener);
+ }
+ viewer.setInput(searchResult);
+ if (uiState instanceof ISelection) {
+ viewer.setSelection((ISelection) uiState);
+ }
+
+ getViewPart().updateLabel();
+ }
+
+
+ private void changed(DesktopSearchResultEvent event) {
+ final Control control = getControl();
+ if (!control.isDisposed()) {
+ control.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (!control.isDisposed()) {
+ getViewPart().updateLabel();
+ }
+ }
+ });
+ }
+ }
+
+ public void setViewPart(ISearchResultViewPart part) {
+ this.viewPart = part;
+ }
+
+ public ISearchResultViewPart getViewPart() {
+ return viewPart;
+ }
+
+ public void restoreState(IMemento memento) {
+ // no state
+ }
+
+ public void saveState(IMemento memento) {
+ // no state
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ container.setLayout(new FillLayout());
+
+ viewer = new TreeViewer(container,SWT.MULTI| SWT.H_SCROLL | SWT.V_SCROLL);
+
+ viewer.setContentProvider(new ContentProvider());
+ viewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
+
+ getSite().setSelectionProvider(viewer);
+
+ // FIXME: actions, context menu
+
+ control = container;
+
+ getViewPart().updateLabel();
+ }
+
+ @Override
+ public Control getControl() {
+ return control;
+ }
+
+ @Override
+ public void setFocus() {
+ getControl().setFocus();
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ public String getID() {
+ return id;
+ }
+
+ public String getLabel() {
+ if (searchResult != null) {
+ return searchResult.getLabel();
+ }
+ return "";
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchWorkbenchAdapter.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchWorkbenchAdapter.java
new file mode 100644
index 00000000..8788c629
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/DesktopSearchWorkbenchAdapter.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+/**
+ *
+ * @author David Green
+ */
+public class DesktopSearchWorkbenchAdapter implements IWorkbenchAdapter {
+
+ private static DesktopSearchWorkbenchAdapter instance = new DesktopSearchWorkbenchAdapter();
+
+
+ public ImageDescriptor getImageDescriptor(Object o) {
+ if (o instanceof SearchResultItem) {
+ SearchResultItem item = (SearchResultItem) o;
+
+ ImageDescriptor image = PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(item.getFile().getName(), null);
+ if (image == null) {
+ image = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
+ }
+ return image;
+ }
+ return null;
+ }
+
+ public String getLabel(Object o) {
+ if (o instanceof SearchResultItem) {
+ SearchResultItem item = (SearchResultItem) o;
+ return item.getFile().getName();
+ }
+ return null;
+ }
+
+ public Object[] getChildren(Object o) {
+ return new Object[0];
+ }
+
+ public Object getParent(Object o) {
+ return null;
+ }
+
+ public static DesktopSearchWorkbenchAdapter instance() {
+ return instance;
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/MockSearchProvider.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/MockSearchProvider.java
new file mode 100644
index 00000000..393baf2e
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/MockSearchProvider.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * Temporary, for testing purposes a {@link SearchProvider} that provides some search results
+ *
+ * @author David Green
+ */
+public class MockSearchProvider extends SearchProvider {
+
+ @Override
+ public void performSearch(SearchCriteria searchSpecification,
+ SearchCallback callback, IProgressMonitor monitor)
+ throws CoreException {
+ callback.searchInitiated();
+ try {
+ int count = 0;
+ File[] roots = File.listRoots();
+ for (File root: roots) {
+ File[] files = root.listFiles();
+ if (files != null) {
+ for (File file: files) {
+ if (file.isFile()) {
+ callback.searchResult(new SearchResultItem(file));
+ if (++count > 20) {
+ return;
+ }
+ }
+ }
+ }
+ }
+ } finally {
+ callback.searchCompleted();
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/OpenDesktopSearchActionDelegate.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/OpenDesktopSearchActionDelegate.java
new file mode 100644
index 00000000..61530702
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/OpenDesktopSearchActionDelegate.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+
+/**
+ *
+ * @author David Green
+ */
+public class OpenDesktopSearchActionDelegate implements
+ IWorkbenchWindowActionDelegate {
+
+ private IWorkbenchWindow window;
+
+ public void run(IAction action) {
+ NewSearchUI.openSearchDialog(window, DesktopSearchPage.PAGE_ID);
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ this.window = window;
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/OpenDesktopSearchHandler.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/OpenDesktopSearchHandler.java
new file mode 100644
index 00000000..b6e62634
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/OpenDesktopSearchHandler.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ *
+ * @author David Green
+ */
+public class OpenDesktopSearchHandler extends AbstractHandler implements
+ IHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Display display = null;
+ final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
+ if (workbenchWindow != null) {
+ display = workbenchWindow.getShell().getDisplay();
+ }
+ if (display == null) {
+ display = Display.getDefault();
+ }
+ display.asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = workbenchWindow;
+ if (window == null) {
+ window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null) {
+ window = PlatformUI.getWorkbench().getWorkbenchWindows()[0];
+ }
+ }
+ NewSearchUI.openSearchDialog(window, DesktopSearchPage.PAGE_ID);
+ }
+ });
+ return null;
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchCallback.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchCallback.java
new file mode 100644
index 00000000..6303595b
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchCallback.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+
+/**
+ *
+ * @author David Green
+ */
+public interface SearchCallback {
+
+ public void searchInitiated();
+
+ public void searchResult(SearchResultItem item);
+
+ public void searchCompleted();
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchCriteria.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchCriteria.java
new file mode 100644
index 00000000..515c8f36
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchCriteria.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import java.util.Arrays;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+
+/**
+ * a search specification that defines criteria for a search
+ *
+ * @author David Green
+ */
+public class SearchCriteria {
+
+ private static final String KEY_FILE_NAME_PATTERNS = "filenamePatterns";
+ private static final String KEY_TEXT = "text";
+ private static final String KEY_CASE_SENSITIVE = "caseSensitive";
+ private String text;
+ private boolean caseSensitive;
+ private String[] filenamePatterns;
+
+
+ public SearchCriteria() {
+ }
+ public SearchCriteria(String text, String[] filenamePatterns) {
+ this.text = text;
+ this.filenamePatterns = filenamePatterns;
+ }
+
+ public String getText() {
+ return text;
+ }
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public boolean isCaseSensitive() {
+ return caseSensitive;
+ }
+ public void setCaseSensitive(boolean caseSensitive) {
+ this.caseSensitive = caseSensitive;
+ }
+ public String[] getFilenamePatterns() {
+ return filenamePatterns;
+ }
+ public void setFilenamePatterns(String[] filenamePatterns) {
+ this.filenamePatterns = filenamePatterns;
+ }
+
+ public String getFilenamePatternsAsText() {
+ String[] patterns = getFilenamePatterns();
+ String text = "";
+ for (String pattern: patterns) {
+ pattern = pattern.trim();
+ if (!pattern.isEmpty()) {
+ if (text.length() > 0) {
+ text += ", ";
+ }
+ text += pattern;
+ }
+ }
+ return text;
+ }
+
+ public void setFilenamePatternsAsText(String text) {
+ filenamePatterns = text==null||text.trim().isEmpty()?new String[0]:text.trim().split("(\\s*,\\s*)|(\\s+)");
+ }
+
+ public void load(IDialogSettings settings) {
+ text = settings.get(KEY_TEXT);
+ filenamePatterns = settings.getArray(KEY_FILE_NAME_PATTERNS);
+ caseSensitive = settings.getBoolean(KEY_CASE_SENSITIVE);
+ }
+
+ public void save(IDialogSettings settings) {
+ settings.put(KEY_TEXT, text);
+ settings.put(KEY_FILE_NAME_PATTERNS, filenamePatterns);
+ settings.put(KEY_CASE_SENSITIVE, caseSensitive);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((text == null) ? 0 : text.hashCode());
+ return result;
+ }
+ /**
+ * equality based on text only
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SearchCriteria other = (SearchCriteria) obj;
+ if (text == null) {
+ if (other.text != null)
+ return false;
+ } else if (!text.equals(other.text))
+ return false;
+ return true;
+ }
+ @Override
+ public String toString() {
+ return "SearchCriteria [text=" + text + ", filenamePatterns="
+ + Arrays.toString(filenamePatterns) + "]";
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchPlugin.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchPlugin.java
new file mode 100644
index 00000000..1a66b947
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchPlugin.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ *
+ * @author David Green
+ */
+public class SearchPlugin extends AbstractUIPlugin {
+
+ private static final String ENABLED_16 = "elcl16/";
+
+ private static final String ICONS_FULL = "icons/full/";
+
+ public static final String IMAGE_SEARCH = ICONS_FULL+ENABLED_16+"tsearch_obj.gif";
+
+ private static SearchPlugin instance;
+
+ public SearchPlugin() {
+ instance = this;
+ }
+
+ public static SearchPlugin getDefault() {
+ return instance;
+ }
+
+ @Override
+ protected void initializeImageRegistry(ImageRegistry reg) {
+ registerImage(reg,IMAGE_SEARCH);
+ }
+
+ private void registerImage(ImageRegistry reg, String image) {
+ reg.put(image, ImageDescriptor.createFromURL(FileLocator.find(getBundle(),new Path(image),null)));
+ }
+
+ public IDialogSettings getDialogSettings(String sectionName) {
+ IDialogSettings settings = super.getDialogSettings();
+ IDialogSettings section = settings.getSection(sectionName);
+ if (section == null) {
+ section = settings.addNewSection(sectionName);
+ }
+ return section;
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchProvider.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchProvider.java
new file mode 100644
index 00000000..915d8a46
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchProvider.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ *
+ * @author David Green
+ */
+public abstract class SearchProvider {
+
+ public static SearchProvider instance() {
+ return new MockSearchProvider(); //new Windows7SearchProvider();
+ }
+
+ /**
+ * perform the search
+ * @param searchSpecification
+ * @param callback
+ * @param monitor the progress monitor, can be null
+ * @throws CoreException
+ */
+ public abstract void performSearch(SearchCriteria searchSpecification,SearchCallback callback,IProgressMonitor monitor) throws CoreException;
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchResultItem.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchResultItem.java
new file mode 100644
index 00000000..b0b4be36
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/SearchResultItem.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.PlatformObject;
+
+/**
+ *
+ * @author David Green
+ */
+public class SearchResultItem extends PlatformObject {
+
+ private File file;
+
+ public SearchResultItem(File file) {
+ this.file = file;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ @Override
+ public String toString() {
+ return file.toString();
+ }
+
+}
diff --git a/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/Windows7SearchProvider.java b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/Windows7SearchProvider.java
new file mode 100644
index 00000000..d70341db
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.search.ui/src/org/eclipse/mylyn/internal/sandbox/search/ui/Windows7SearchProvider.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.sandbox.search.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+
+/**
+ *
+ * @author David Green
+ */
+public class Windows7SearchProvider extends SearchProvider {
+
+ @Override
+ public void performSearch(SearchCriteria searchSpecification,
+ SearchCallback callback, IProgressMonitor m)
+ throws CoreException {
+ SubMonitor monitor = SubMonitor.convert(m);
+ monitor.beginTask("TEST", 10000);
+ callback.searchInitiated();
+ try {
+ // monitor.worked(1);
+ // monitor.newChild(100);
+
+ // FIXME: implement
+
+ } finally {
+ callback.searchCompleted();
+ monitor.done();
+ }
+
+ }
+
+}

Back to the top