diff options
author | relves | 2006-09-11 00:22:30 +0000 |
---|---|---|
committer | relves | 2006-09-11 00:22:30 +0000 |
commit | 580e36be035f63f453c1772044ae7a3b75030226 (patch) | |
tree | ace35e7361db03b75e7507b85f1535f192cc4093 | |
parent | 9b46ff0d517c0c8e053c06fd707fb11e30569a7b (diff) | |
download | org.eclipse.mylyn.tasks-580e36be035f63f453c1772044ae7a3b75030226.tar.gz org.eclipse.mylyn.tasks-580e36be035f63f453c1772044ae7a3b75030226.tar.xz org.eclipse.mylyn.tasks-580e36be035f63f453c1772044ae7a3b75030226.zip |
Progress on: 155279: Split search into headless and ui
https://bugs.eclipse.org/bugs/show_bug.cgi?id=155279
31 files changed, 252 insertions, 970 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java index 0a9f1ba6c..8de4b7062 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.mylar.tasks.core.AbstractAttributeFactory; import org.eclipse.mylar.tasks.core.AbstractQueryHit; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.IOfflineTaskHandler; import org.eclipse.mylar.tasks.core.ITask; import org.eclipse.mylar.tasks.core.RepositoryTaskData; @@ -178,7 +179,7 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { private void queryForChanged(TaskRepository repository, Set<AbstractRepositoryTask> changedTasks, String urlQueryString, Proxy proxySettings) throws UnsupportedEncodingException, CoreException { RepositoryQueryResultsFactory queryFactory = new RepositoryQueryResultsFactory(); - BugzillaResultCollector collector = new BugzillaResultCollector(taskList); + QueryHitCollector collector = new QueryHitCollector(taskList); if (repository.hasCredentials()) { urlQueryString = BugzillaServerFacade.addCredentials(urlQueryString, repository.getUserName(), repository .getPassword()); @@ -190,7 +191,7 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, "failed to perform query", e)); } - for (AbstractQueryHit hit : collector.getResults()) { + for (AbstractQueryHit hit : collector.getHits()) { String handle = AbstractRepositoryTask.getHandle(repository.getUrl(), hit.getId()); ITask correspondingTask = taskList.getTask(handle); if (correspondingTask != null && correspondingTask instanceof AbstractRepositoryTask) { diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java index 291eb7f90..7b8372923 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java @@ -28,8 +28,8 @@ import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; import org.eclipse.mylar.tasks.core.IAttachmentHandler; import org.eclipse.mylar.tasks.core.IOfflineTaskHandler; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; import org.eclipse.mylar.tasks.core.ITask; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.RepositoryTaskData; import org.eclipse.mylar.tasks.core.TaskList; import org.eclipse.mylar.tasks.core.TaskRepository; @@ -132,17 +132,10 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { @Override public IStatus performQuery(final AbstractRepositoryQuery query, TaskRepository repository, Proxy proxySettings, - IProgressMonitor monitor, IQueryHitCollector resultCollector) { + IProgressMonitor monitor, QueryHitCollector resultCollector) { IStatus queryStatus = Status.OK_STATUS; - - // Note need for ctype=rdf in query url - // String urlString = - // "http://mylar.eclipse.org/bugs222/buglist.cgi?ctype=rdf&query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0="; RepositoryQueryResultsFactory queryFactory = new RepositoryQueryResultsFactory(); - - // Tasklist can be null but calls to hit.getOrCreateCorrespondingTask() - // will return null. try { String queryUrl = query.getUrl(); queryUrl = queryUrl.concat(IBugzillaConstants.CONTENT_TYPE_RDF); @@ -157,49 +150,20 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { queryFactory.performQuery(taskList, repository.getUrl(), resultCollector, queryUrl, proxySettings, query .getMaxHits(), repository.getCharacterEncoding()); } catch (IOException e) { - // MylarStatusHandler.fail(e, "I/O error occurred during query of - // repository: " + repository.getUrl(), true); - queryStatus = new Status(Status.OK, BugzillaCorePlugin.PLUGIN_ID, Status.ERROR, + queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, Status.ERROR, "Check repository credentials and connectivity.", e); } catch (BugzillaException e) { if (e instanceof UnrecognizedReponseException) { - // MylarStatusHandler.fail(e, "Bugzilla error occurred for - // repository: " + repository.getUrl(), true); - queryStatus = new Status(Status.OK, BugzillaCorePlugin.PLUGIN_ID, Status.INFO, + queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, Status.INFO, "Unrecognized response from server", e); } else { - // MylarStatusHandler.fail(e, "Bugzilla error occurred for - // repository: " + repository.getUrl(), true); - queryStatus = new Status(IStatus.OK, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, + queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, "Unable to perform query due to Bugzilla error", e); } } catch (GeneralSecurityException e) { - // MylarStatusHandler.fail(e, "unable to perform query due to - // repository configuration error: " - // + repository.getUrl(), true); - queryStatus = new Status(IStatus.OK, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, + queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, "Unable to perform query due to repository configuration error", e); } - - // TaskRepository repository = - // TasksUiPlugin.getRepositoryManager().getRepository(query.getRepositoryKind(), - // query.getRepositoryUrl()); - - // final BugzillaCategorySearchOperation categorySearch = new - // BugzillaCategorySearchOperation(repository, query - // .getUrl(), query.getMaxHits(), resultCollector); - // - // categorySearch.execute(monitor); - // try { - // queryStatus = categorySearch.getStatus(); - // } catch (LoginException e) { - // // TODO: Set some form of disconnect status on Query? - // MylarStatusHandler.fail(e, "login failure for repository url: " + - // repository, false); - // queryStatus = new Status(IStatus.OK, BugzillaCorePlugin.PLUGIN_ID, - // IStatus.OK, "Could not log in", e); - // } - // return queryStatus; } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaResultCollector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaResultCollector.java deleted file mode 100644 index aae00a417..000000000 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaResultCollector.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.internal.bugzilla.core; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractQueryHitCollector; -import org.eclipse.mylar.tasks.core.TaskList; - -/** - * Collector for the Bugzilla query results - * - * TODO: unify BugzillaSearchResultCollector and BugzillaResultCollector - * - * @author Shawn Minto - * @author Rob Elves - */ -public class BugzillaResultCollector extends AbstractQueryHitCollector { - - public BugzillaResultCollector(TaskList tasklist) { - super(tasklist); - } - - private List<AbstractQueryHit> results = new ArrayList<AbstractQueryHit>(); - - @Override - public void addMatch(AbstractQueryHit hit) { - String description = hit.getId() + ": " + hit.getDescription(); - hit.setDescription(description); - results.add(hit); - } - - public List<AbstractQueryHit> getResults() { - return results; - } - -} - -///** -//* Get the string specifying the number of matches found -//* -//* @param count -//* The number of matches found -//* @return The <code>String</code> specifying the number of matches found -//*/ -//private String getFormattedMatchesString(int count) { -// // if only 1 match, return the singular match string -// String name = ""; -// if (operation != null && operation.getName() != null) -// name = " - " + operation.getName(); -// if (count == 1) -// return MATCH + name; -// -// // format the matches string and return it -// Object[] messageFormatArgs = { new Integer(count) }; -// return MessageFormat.format(MATCHES + name, messageFormatArgs); -//} diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java index 9b137e2dc..b3015a601 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java @@ -16,7 +16,7 @@ import java.net.Proxy; import java.net.URL; import java.security.GeneralSecurityException; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.TaskList; @@ -27,7 +27,7 @@ public class RepositoryQueryResultsFactory extends AbstractReportFactory { /** expects rdf returned from repository (ctype=rdf in url) * @throws GeneralSecurityException */ - public void performQuery(TaskList taskList, String repositoryUrl, IQueryHitCollector collector, String queryUrlString, + public void performQuery(TaskList taskList, String repositoryUrl, QueryHitCollector collector, String queryUrlString, Proxy proxySettings, int maxHits, String characterEncoding) throws IOException, BugzillaException, GeneralSecurityException { SaxBugzillaQueryContentHandler contentHandler = new SaxBugzillaQueryContentHandler(taskList, repositoryUrl, diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugzillaQueryContentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugzillaQueryContentHandler.java index 7424cd539..fe70f764b 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugzillaQueryContentHandler.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugzillaQueryContentHandler.java @@ -14,7 +14,7 @@ package org.eclipse.mylar.internal.bugzilla.core; import org.eclipse.core.runtime.CoreException; import org.eclipse.mylar.context.core.MylarStatusHandler; import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.TaskList; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -41,7 +41,7 @@ public class SaxBugzillaQueryContentHandler extends DefaultHandler { private StringBuffer characters; - private IQueryHitCollector collector; + private QueryHitCollector collector; private String repositoryUrl; @@ -53,7 +53,7 @@ public class SaxBugzillaQueryContentHandler extends DefaultHandler { private int numCollected = 0; - public SaxBugzillaQueryContentHandler(TaskList tasklist, String repositoryUrl, IQueryHitCollector col, int maxHits) { + public SaxBugzillaQueryContentHandler(TaskList tasklist, String repositoryUrl, QueryHitCollector col, int maxHits) { this.taskList = tasklist; this.repositoryUrl = repositoryUrl; collector = col; diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java index 2d16455e6..0fb5b1401 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java @@ -35,15 +35,14 @@ import org.eclipse.mylar.internal.bugzilla.core.BugzillaException; import org.eclipse.mylar.internal.bugzilla.core.BugzillaQueryHit; import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement; import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm; +import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery; import org.eclipse.mylar.internal.bugzilla.core.BugzillaTask; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylar.internal.bugzilla.core.PossibleBugzillaFailureException; import org.eclipse.mylar.internal.bugzilla.core.RepositoryConfiguration; import org.eclipse.mylar.internal.bugzilla.ui.editor.BugSubmissionHandler; -import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchOperation; -import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchQuery; -import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchResultCollector; import org.eclipse.mylar.internal.tasks.core.SslProtocolSocketFactory; +import org.eclipse.mylar.internal.tasks.ui.search.SearchHitCollector; import org.eclipse.mylar.tasks.core.AbstractQueryHit; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; import org.eclipse.mylar.tasks.core.ITask; @@ -90,20 +89,31 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest { BugzillaTask task = this.generateLocalTaskAndDownload("2"); assertNotNull(task); - // test anonymous query (note that this demonstrates query via eclipse search (ui) - BugzillaSearchResultCollector collector = new BugzillaSearchResultCollector(taskList); - collector.setProgressMonitor(new NullProgressMonitor()); - BugzillaSearchOperation operation = new BugzillaSearchOperation( - repository, - "http://mylar.eclipse.org/bugs218/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=", - null, collector, "-1"); +// // test anonymous query (note that this demonstrates query via eclipse search (ui) +// SearchHitCollector collector = new SearchHitCollector(taskList); +// collector.setProgressMonitor(new NullProgressMonitor()); +// BugzillaSearchOperation operation = new BugzillaSearchOperation( +// repository, +// "http://mylar.eclipse.org/bugs218/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=", +// null, collector, "-1"); +// + String queryUrl = "http://mylar.eclipse.org/bugs218/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0="; + BugzillaRepositoryQuery bugzillaQuery = new BugzillaRepositoryQuery(repository.getUrl(), queryUrl, "search", "-1", taskList); + + + + + SearchHitCollector collector = new SearchHitCollector(TasksUiPlugin.getTaskListManager() + .getTaskList(), repository, bugzillaQuery, null); + + //operation.run(new NullProgressMonitor()); - BugzillaSearchQuery searchQuery = new BugzillaSearchQuery(operation); - searchQuery.run(new NullProgressMonitor()); - assertEquals(2, collector.getResults().size()); + //BugzillaSearchQuery searchQuery = new BugzillaSearchQuery(collector); + collector.run(new NullProgressMonitor()); + assertEquals(2, collector.getHits().size()); - for (AbstractQueryHit hit : collector.getResults()) { + for (AbstractQueryHit hit : collector.getHits()) { assertTrue(hit.getDescription().contains("search-match-test")); } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchEngineTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchEngineTest.java index 3eddb2f28..651419792 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchEngineTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchEngineTest.java @@ -11,7 +11,6 @@ package org.eclipse.mylar.bugzilla.tests; -import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; @@ -21,8 +20,8 @@ import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractQueryHitCollector; import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.TaskRepository; import org.eclipse.mylar.tasks.ui.TasksUiPlugin; @@ -86,8 +85,7 @@ public class BugzillaSearchEngineTest extends TestCase { assertEquals(NUM_EXPECTED_HITS, hits.size()); } - private List<AbstractQueryHit> runQuery(String repositoryURL, String SearchString) throws Exception { - final ArrayList<AbstractQueryHit> results = new ArrayList<AbstractQueryHit>(); + private List<AbstractQueryHit> runQuery(String repositoryURL, String SearchString) throws Exception { TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(BugzillaCorePlugin.REPOSITORY_KIND, repositoryURL); assertNotNull(repository); @@ -99,19 +97,12 @@ public class BugzillaSearchEngineTest extends TestCase { AbstractRepositoryConnector connector = (AbstractRepositoryConnector) TasksUiPlugin.getRepositoryManager().getRepositoryConnector(BugzillaCorePlugin.REPOSITORY_KIND); - AbstractQueryHitCollector collector = new AbstractQueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) { - - @Override - public void addMatch(AbstractQueryHit hit) { - results.add(hit); - } - - }; + QueryHitCollector collector = new QueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()); connector.performQuery(repositoryQuery, repository, TasksUiPlugin.getDefault().getProxySettings(), new NullProgressMonitor(), collector); //results.addAll(connector.performQuery(repositoryQuery, new NullProgressMonitor(), new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null))); - return results; + return collector.getHits(); } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java index ced7e1296..a47cc7289 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java @@ -23,11 +23,11 @@ import org.eclipse.mylar.context.tests.support.MylarTestUtils.Credentials; import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylar.internal.bugzilla.core.BugzillaException; import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement; -import org.eclipse.mylar.internal.bugzilla.core.BugzillaResultCollector; import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylar.internal.bugzilla.core.RepositoryQueryResultsFactory; import org.eclipse.mylar.tasks.core.AbstractQueryHit; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.RepositoryTaskData; import org.eclipse.mylar.tasks.core.TaskList; import org.eclipse.mylar.tasks.core.TaskRepository; @@ -104,7 +104,7 @@ public class BugzillaQueryTest extends TestCase { public void testQueryBugs() throws Exception { - BugzillaResultCollector collector = new BugzillaResultCollector(new TaskList()); + QueryHitCollector collector = new QueryHitCollector(new TaskList()); // Note need for ctype=rdf in query url String urlString = "http://mylar.eclipse.org/bugs222/buglist.cgi?ctype=rdf&query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0="; @@ -114,8 +114,8 @@ public class BugzillaQueryTest extends TestCase { queryFactory.performQuery(null, repository.getUrl(), collector, urlString, null, -1, repository .getCharacterEncoding()); - assertEquals(2, collector.getResults().size()); - for (AbstractQueryHit hit : collector.getResults()) { + assertEquals(2, collector.getHits().size()); + for (AbstractQueryHit hit : collector.getHits()) { assertTrue(hit.getDescription().contains("search-match-test")); } } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugEditor.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugEditor.java index 0f9273328..c7f7ad434 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugEditor.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugEditor.java @@ -27,16 +27,13 @@ import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm; +import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants; -import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchOperation; -import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchQuery; -import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchResultCollector; -import org.eclipse.mylar.internal.bugzilla.ui.search.IBugzillaSearchOperation; import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil; import org.eclipse.mylar.internal.tasks.ui.editors.AbstractRepositoryTaskEditor; import org.eclipse.mylar.internal.tasks.ui.editors.RepositoryTaskOutlineNode; import org.eclipse.mylar.internal.tasks.ui.editors.RepositoryTaskSelection; -import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery; +import org.eclipse.mylar.internal.tasks.ui.search.SearchHitCollector; import org.eclipse.mylar.internal.tasks.ui.util.WebBrowserDialog; import org.eclipse.mylar.internal.tasks.ui.views.TaskListView; import org.eclipse.mylar.internal.tasks.ui.views.TaskRepositoriesView; @@ -219,12 +216,14 @@ public class NewBugEditor extends AbstractRepositoryTaskEditor { queryUrl += "&product=" + getRepositoryTaskData().getProduct(); - BugzillaSearchResultCollector resultCollector = new BugzillaSearchResultCollector(TasksUiPlugin.getTaskListManager().getTaskList()); - IBugzillaSearchOperation operation = new BugzillaSearchOperation(repository, queryUrl, TasksUiPlugin - .getDefault().getProxySettings(), resultCollector, "100"); - AbstractRepositorySearchQuery query = new BugzillaSearchQuery(operation); + BugzillaRepositoryQuery bugzillaQuery = new BugzillaRepositoryQuery(repository.getUrl(), queryUrl, "search", "100", TasksUiPlugin.getTaskListManager() + .getTaskList()); + Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings(); + SearchHitCollector collector = new SearchHitCollector(TasksUiPlugin.getTaskListManager() + .getTaskList(), repository, bugzillaQuery, proxySettings); + - NewSearchUI.runQueryInBackground(query); + NewSearchUI.runQueryInBackground(collector); return true; } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchEngine.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchEngine.java index 30e9d15c6..27cafb525 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchEngine.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchEngine.java @@ -34,7 +34,7 @@ import org.eclipse.mylar.internal.bugzilla.core.UnrecognizedReponseException; import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin; import org.eclipse.mylar.internal.tasks.ui.util.WebBrowserDialog; import org.eclipse.mylar.internal.tasks.ui.views.TaskRepositoriesView; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.TaskRepository; import org.eclipse.mylar.tasks.ui.TasksUiPlugin; import org.eclipse.ui.PlatformUI; @@ -44,7 +44,7 @@ import org.eclipse.ui.PlatformUI; * * @author Mik Kersten (hardening of initial prototype) */ - +// TODO: Delete once not needed by sandbox public class BugzillaSearchEngine { protected static final String QUERYING_SERVER = "Querying Bugzilla Server..."; @@ -91,7 +91,7 @@ public class BugzillaSearchEngine { * @param collector - * The collector for the results to go into */ - public IStatus search(IQueryHitCollector collector) throws LoginException { + public IStatus search(QueryHitCollector collector) throws LoginException { return this.search(collector, 0, IBugzillaConstants.RETURN_ALL_HITS); } @@ -103,7 +103,7 @@ public class BugzillaSearchEngine { * @param startMatches - * The number of matches to start with for the progress monitor */ - public IStatus search(IQueryHitCollector collector, int startMatches) throws LoginException { + public IStatus search(QueryHitCollector collector, int startMatches) throws LoginException { return this.search(collector, startMatches, BugzillaUiPlugin.getDefault().getMaxResults()); } @@ -119,7 +119,7 @@ public class BugzillaSearchEngine { * the maximum number of matches to return or * IBugzillaConstants.RETURN_ALL_HITS for unlimited */ - public IStatus search(IQueryHitCollector collector, int startMatches, int maxHits) + public IStatus search(QueryHitCollector collector, int startMatches, int maxHits) throws LoginException { IProgressMonitor monitor = collector.getProgressMonitor(); IStatus status = null; diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchOperation.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchOperation.java deleted file mode 100644 index 005eef078..000000000 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchOperation.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ -package org.eclipse.mylar.internal.bugzilla.ui.search; - -import java.net.Proxy; - -import javax.security.auth.login.LoginException; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.mylar.internal.bugzilla.core.BugzillaResultCollector; -import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery; -import org.eclipse.mylar.tasks.core.TaskRepository; - -/** - * An operation to perform Bugzilla search query. - * - * @author Mik Kersten (hardening of prototype) - */ -public class BugzillaSearchOperation implements IBugzillaSearchOperation { - private String queryUrl; - - private BugzillaResultCollector collector; - - private AbstractRepositorySearchQuery query; - - /** The status of the search operation */ - private IStatus status; - - /** The LoginException that was thrown when trying to do the search */ - private LoginException loginException = null; - - private int maxHits; - - private TaskRepository repository; - - private Proxy proxySettings; - - public BugzillaSearchOperation(TaskRepository repository, String queryUrl, Proxy proxySettings, - BugzillaSearchResultCollector collector, String maxHits) { - this.repository = repository; - this.queryUrl = queryUrl; - this.collector = collector; - this.proxySettings = proxySettings; - collector.setOperation(this); - - try { - this.maxHits = Integer.parseInt(maxHits); - } catch (Exception e) { - this.maxHits = -1; - } - } - - public void run(IProgressMonitor monitor) { - // set the progress monitor for the search collector and start the - // search - collector.setProgressMonitor(monitor); - BugzillaSearchEngine engine = new BugzillaSearchEngine(repository, queryUrl, proxySettings); - try { - status = engine.search(collector, 0, maxHits); - } catch (LoginException e) { - // save this exception to throw later - this.loginException = e; - } - } - - /** - * @see org.eclipse.mylar.internal.bugzilla.ui.search.IBugzillaSearchOperation#getStatus() - */ - public IStatus getStatus() throws LoginException { - // if a LoginException was thrown while trying to search, throw this - if (loginException == null) - return status; - else - throw loginException; - } - - /** - * @see org.eclipse.mylar.internal.bugzilla.core.search.IBugzillaSearchOperation#getQuery() - */ - public AbstractRepositorySearchQuery getQuery() { - return query; - } - - /** - * @see org.eclipse.mylar.internal.bugzilla.core.search.IBugzillaSearchOperation#setQuery(org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery) - */ - public void setQuery(AbstractRepositorySearchQuery newQuery) { - this.query = newQuery; - } - - public String getName() { - return null; - } -} diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java index 8a71eb951..f76ba397f 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java @@ -32,7 +32,7 @@ import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin; import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositoryQueryPage; -import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery; +import org.eclipse.mylar.internal.tasks.ui.search.SearchHitCollector; import org.eclipse.mylar.internal.tasks.ui.views.TaskRepositoriesView; import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylar.tasks.core.TaskRepository; @@ -889,28 +889,6 @@ public class BugzillaSearchPage extends AbstractRepositoryQueryPage implements L getPatternData(commentPattern, commentOperation, previousCommentPatterns); getPatternData(this.emailPattern, emailOperation, previousEmailPatterns); - String summaryText; - String queryUrl; - // if (rememberedQuery == true) { - // queryUrl = getQueryURL(repository, new - // StringBuffer(input.getQueryParameters(selIndex))); - // summaryText = input.getSummaryText(selIndex); - // } else { - try { - StringBuffer params = getQueryParameters(); - queryUrl = getQueryURL(repository, params); - summaryText = summaryPattern.getText(); - } catch (UnsupportedEncodingException e) { - /* - * These statements should never be executed. Every implementation - * of the Java platform is required to support the standard charset - * "UTF-8" - */ - queryUrl = ""; - summaryText = ""; - } - // } - // try { // // if the summary contains a single bug id, open the bug directly // int id = Integer.parseInt(summaryText); @@ -924,17 +902,13 @@ public class BugzillaSearchPage extends AbstractRepositoryQueryPage implements L // the view if no searching is going to take place. NewSearchUI.activateSearchResultView(); + String summaryText = summaryPattern.getText(); BugzillaUiPlugin.getDefault().getPreferenceStore().setValue(IBugzillaConstants.MOST_RECENT_QUERY, summaryText); - BugzillaSearchResultCollector collector = new BugzillaSearchResultCollector(TasksUiPlugin.getTaskListManager() - .getTaskList()); - Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings(); - IBugzillaSearchOperation op = new BugzillaSearchOperation(repository, queryUrl, proxySettings, collector, - getMaxHits()); - - AbstractRepositorySearchQuery searchQuery = new BugzillaSearchQuery(op); - NewSearchUI.runQueryInBackground(searchQuery); + SearchHitCollector collector = new SearchHitCollector(TasksUiPlugin.getTaskListManager().getTaskList(), + repository, getQuery(), proxySettings); + NewSearchUI.runQueryInBackground(collector); return true; } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchQuery.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchQuery.java deleted file mode 100644 index 56a488b58..000000000 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchQuery.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.internal.bugzilla.ui.search; - -import java.lang.reflect.InvocationTargetException; - -import javax.security.auth.login.LoginException; - -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.jface.dialogs.MessageDialog; -import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin; -import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin; -import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery; -import org.eclipse.search.ui.text.AbstractTextSearchResult; -import org.eclipse.ui.PlatformUI; - -/** - * This class performs a search query on Bugzilla bug reports. - * - * @author Rob Elves (modifications) - */ -public class BugzillaSearchQuery extends AbstractRepositorySearchQuery { - - private static final String MESSAGE_LOGIN_FAILURE = "Could not log you in to get the information you requested since login name or password is incorrect.\nPlease check settings."; - - /** The operation that performs the Bugzilla search query. */ - private IBugzillaSearchOperation operation; - - public BugzillaSearchQuery(IBugzillaSearchOperation operation) { - this.operation = operation; - operation.setQuery(this); - } - - public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { - final IStatus[] status = new IStatus[1]; - final AbstractTextSearchResult textResult = (AbstractTextSearchResult) getSearchResult(); - textResult.removeAll(); - - try { - operation.run(monitor); - - status[0] = operation.getStatus(); - - if (status[0].getCode() == IStatus.CANCEL) { - status[0] = Status.OK_STATUS; - } else if (!status[0].isOK()) { - PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, "Repository Search Error", status[0].getMessage()); - } - }); - status[0] = Status.OK_STATUS; - } - } catch (InvocationTargetException e) { - PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { - public void run() { - MessageDialog.openInformation(null, "Bugzilla Login Error", MESSAGE_LOGIN_FAILURE); - } - }); - } catch (InterruptedException e) { - // ignore - } catch (final LoginException e) { - PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { - public void run() { - MessageDialog.openInformation(null, "Bugzilla Login Error", MESSAGE_LOGIN_FAILURE); - BugzillaCorePlugin.log(new Status(IStatus.ERROR, BugzillaUiPlugin.PLUGIN_ID, IStatus.OK, "", e)); - } - }); - } - - return status[0]; - } -} diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchResultCollector.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchResultCollector.java deleted file mode 100644 index 6661bb4f4..000000000 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchResultCollector.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ -package org.eclipse.mylar.internal.bugzilla.ui.search; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.mylar.internal.bugzilla.core.BugzillaResultCollector; -import org.eclipse.mylar.internal.tasks.ui.search.RepositorySearchResult; -import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.TaskList; -import org.eclipse.search.ui.NewSearchUI; -import org.eclipse.search.ui.text.Match; - -/** - * Used for returning results from Eclipse Search view. Collects results of a - * Bugzilla search and inserts them into the search results view. - * - * TODO: unify BugzillaSearchResultCollector and BugzillaResultCollector - * - * @author Rob Elves (modifications) - */ -public class BugzillaSearchResultCollector extends BugzillaResultCollector { - - private IBugzillaSearchOperation operation; - - public BugzillaSearchResultCollector(TaskList tasklist) { - super(tasklist); - } - - private RepositorySearchResult searchResult; - - public void aboutToStart(int startMatchCount) throws CoreException { - super.aboutToStart(startMatchCount); - NewSearchUI.activateSearchResultView(); - searchResult = (RepositorySearchResult) getOperation().getQuery().getSearchResult(); - } - - public void done() { - super.done(); - searchResult = null; - } - - @Override - public void addMatch(AbstractQueryHit hit) { - super.addMatch(hit); - searchResult.addMatch(new Match(hit, 0, 0)); - } - - public void setOperation(IBugzillaSearchOperation operation) { - this.operation = operation; - } - - public IBugzillaSearchOperation getOperation() { - return operation; - } - -} - -// /** Array of severities for a bug */ -// private static final String[] severity = { "blo", "cri", "maj", "nor", "min", -// "tri", "enh" }; -// -// /** Array of priorities for a bug */ -// private static final String[] priority = { "P1", "P2", "P3", "P4", "P5", "--" -// }; -// -// /** Array of possible states of a bug */ -// private static final String[] state = { "UNCO", "NEW", "ASSI", "REOP", -// "RESO", "VERI", "CLOS" }; -// -// /** Array of the possible resolutions of the bug */ -// private static final String[] result = { "", "FIXE", "INVA", "WONT", "LATE", -// "REMI", "DUPL", "WORK" }; - -// /** -// * Returns a map where BugReport's attributes are entered into a Map using -// * the same key/value pairs as those created on a search hit marker. -// */ -// public static Map<String, Object> getAttributeMap(RepositoryTaskData bug) { -// HashMap<String, Object> map = new HashMap<String, Object>(); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_ID, new Integer(bug.getId())); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_REPOSITORY, bug.getRepositoryUrl()); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_DESC, bug.getDescription()); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_SEVERITY, mapValue(bug.getAttribute( -// BugzillaReportElement.BUG_SEVERITY.getKeyString()).getValue(), severity)); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_PRIORITY, -// mapValue(bug.getAttribute(BugzillaReportElement.PRIORITY.getKeyString()) -// .getValue(), priority)); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_PLATFORM, -// bug.getAttribute("Hardware").getValue()); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_STATE, mapValue(bug.getStatus(), -// state)); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_RESULT, -// mapValue(bug.getResolution(), result)); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_OWNER, bug.getAssignedTo()); -// map.put(BugzillaUiPlugin.HIT_MARKER_ATTR_QUERY, ""); -// return map; -// } -// -// /** -// * Get the map value for the given <code>String</code> value -// * -// * @param value -// * The value that we are trying to map -// * @param map -// * The map that we are using -// * @return The map value -// */ -// private static Integer mapValue(String value, String[] map) { -// // go through each element in the map -// for (int i = 0; i < map.length; i++) { -// // if we found the value, return the position in the map -// if (map[i].equals(value)) { -// return new Integer(i); -// } -// } -// -// // return null if we didn't find anything -// return null; -// } - -// /** -// * @see -// org.eclipse.mylar.internal.bugzilla.ui.search.IBugzillaSearchResultCollector#accept(org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchHit) -// */ -// public void accept(BugzillaQueryHit queryHit) throws CoreException { -// // String description = hit.getId() + ": " + hit.getDescription(); -// // -// // BugzillaQueryHit queryHit = new BugzillaQueryHit(description, -// hit.getPriority(), hit.getRepositoryUrl(), ""+hit -// // .getId(), null, hit.getState()); -// -// ITask correspondingTask = -// TasksUiPlugin.getTaskListManager().getTaskList().getTask( -// queryHit.getHandleIdentifier()); -// if (correspondingTask instanceof AbstractRepositoryTask) { -// queryHit.setCorrespondingTask((AbstractRepositoryTask) correspondingTask); -// } -// -// // searchResult.addMatch(new Match(queryHit, 0, 0)); -// -// // increment the match count -// // matchCount++; -// // -// // if (!getProgressMonitor().isCanceled()) { -// // // if the operation is cancelled finish with whatever data was -// // // already found -// // getProgressMonitor().subTask(getFormattedMatchesString(matchCount)); -// // getProgressMonitor().worked(1); -// // } -// } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/IBugzillaSearchOperation.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/IBugzillaSearchOperation.java index f8ef58ef6..b56177f48 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/IBugzillaSearchOperation.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/IBugzillaSearchOperation.java @@ -21,6 +21,8 @@ import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery; * Interface for the bugzilla search operation * * @author Shawn Minto + * + * TODO: Delete once not requred by sandbox */ public interface IBugzillaSearchOperation extends IRunnableWithProgress { diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaCategorySearchOperation.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaCategorySearchOperation.java deleted file mode 100644 index 85000b776..000000000 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaCategorySearchOperation.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ -/* - * Created on Oct 14, 2004 - */ -package org.eclipse.mylar.internal.bugzilla.ui.tasklist; - -import java.net.Proxy; -import java.util.ArrayList; -import java.util.List; - -import javax.security.auth.login.LoginException; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchEngine; -import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchResultCollector; -import org.eclipse.mylar.internal.bugzilla.ui.search.IBugzillaSearchOperation; -import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; -import org.eclipse.mylar.tasks.core.TaskRepository; -import org.eclipse.mylar.tasks.ui.TasksUiPlugin; -import org.eclipse.ui.actions.WorkspaceModifyOperation; - -/** - * TODO: delete? - * - * @author Shawn Minto - */ -public class BugzillaCategorySearchOperation extends WorkspaceModifyOperation implements IBugzillaSearchOperation { - /** The IMember we are doing the search for */ - - public interface ICategorySearchListener { - public void searchCompleted(IQueryHitCollector collector); - } - - /** The bugzilla collector for the search */ - private IQueryHitCollector collector = null; - - /** The status of the search operation */ - private IStatus status; - - /** The LoginException that was thrown when trying to do the search */ - private LoginException loginException = null; - - private String queryUrl; - - private TaskRepository repository; - - private int maxHits; - - private boolean isMaxReached; - - /** - * Constructor - * - * @param m - * The member that we are doing the search for - */ - public BugzillaCategorySearchOperation(TaskRepository repository, String queryUrl, int maxHits, - IQueryHitCollector collector) { - this.queryUrl = queryUrl; - this.maxHits = maxHits; - this.repository = repository; - this.collector = collector; - } - - @Override - public void execute(IProgressMonitor monitor) { - // XXX: Hack - if (collector instanceof BugzillaSearchResultCollector) { - ((BugzillaSearchResultCollector) collector).setOperation(this); - } - collector.setProgressMonitor(monitor); - Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings(); - search(queryUrl, proxySettings, monitor); - for (ICategorySearchListener listener : listeners) - listener.searchCompleted(collector); - } - - /** - * Perform the actual search on the Bugzilla server - * - * @param queryUrl - * The queryUrl to use for the search - * @param searchCollector - * The collector to put the search results into - * @param monitor - * The progress monitor to use for the search - * @return The BugzillaResultCollector with the search results - */ - private IQueryHitCollector search(String queryUrl, Proxy proxySettings, IProgressMonitor monitor) { - - // set the initial number of matches to 0 - int matches = 0; - // setup the progress monitor and start the search - collector.setProgressMonitor(monitor); - BugzillaSearchEngine engine = new BugzillaSearchEngine(repository, queryUrl, proxySettings); - try { - // perform the search - status = engine.search(collector, matches, maxHits); - - // check the status so that we don't keep searching if there - // is a problem - if (status.getCode() == IStatus.CANCEL) { - return null; - } else if (!status.isOK()) { - return null; - } - isMaxReached = engine.isMaxReached(); - return collector; - } catch (LoginException e) { - // save this exception to throw later - this.loginException = e; - } - return null; - } - - /** - * @see org.eclipse.mylar.internal.bugzilla.ui.search.IBugzillaSearchOperation#getStatus() - */ - public IStatus getStatus() throws LoginException { - // if a LoginException was thrown while trying to search, throw this - if (loginException == null) - return status; - else - throw loginException; - } - - public ImageDescriptor getImageDescriptor() { - return null; - } - - public AbstractRepositorySearchQuery getQuery() { - return null; - } - - public void setQuery(AbstractRepositorySearchQuery newQuery) { - } - - private List<ICategorySearchListener> listeners = new ArrayList<ICategorySearchListener>(); - - public void addResultsListener(ICategorySearchListener listener) { - listeners.add(listener); - } - - public String getName() { - return null; - } - - public boolean isMaxReached() { - return isMaxReached; - } -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java index 7dcccaeac..65663bcdd 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java @@ -99,7 +99,7 @@ public abstract class AbstractRepositoryConnector { * IQueryHitCollector that collects the hits found */ public abstract IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository, - Proxy proxySettings, IProgressMonitor monitor, IQueryHitCollector resultCollector); + Proxy proxySettings, IProgressMonitor monitor, QueryHitCollector resultCollector); public abstract String getLabel(); diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IQueryHitCollector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IQueryHitCollector.java deleted file mode 100644 index 80c54f2c5..000000000 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IQueryHitCollector.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.tasks.core; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * Interface for the Mylar search result collector. - * - * @author Shawn Minto - */ -public interface IQueryHitCollector { - - /** - * Called before the actual search starts. - * - * @param startCount - - * The starting count for the number of matches - * @throws CoreException - */ - public void aboutToStart(int startCount) throws CoreException; - - /** - * Accept a search hit and add it as a match and set the markers. - * - * @param hit - * The search hit that was a match - * @throws CoreException - */ - public void accept(AbstractQueryHit hit) throws CoreException; - - /** - * Called when the search has ended. - */ - public void done(); - - /** - * Get the progress monitor for the search. - * - * @return The progress monitor - */ - public IProgressMonitor getProgressMonitor(); - - /** - * Set the progress monitor. - * - * @param monitor - * The progress monitor the search should use - */ - public void setProgressMonitor(IProgressMonitor monitor); - -} diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractQueryHitCollector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/QueryHitCollector.java index 82864ab6d..ad315abb5 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractQueryHitCollector.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/QueryHitCollector.java @@ -11,17 +11,22 @@ package org.eclipse.mylar.tasks.core; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; /** - * Collects results of a search. + * Collects QueryHits resulting from repository search * + * @author Shawn Minto * @author Rob Elves (generalized from bugzilla) */ -public abstract class AbstractQueryHitCollector implements IQueryHitCollector { +public class QueryHitCollector { + + private List<AbstractQueryHit> results = new ArrayList<AbstractQueryHit>(); /** The progress monitor for the search operation */ private IProgressMonitor monitor = new NullProgressMonitor(); @@ -43,13 +48,12 @@ public abstract class AbstractQueryHitCollector implements IQueryHitCollector { private TaskList taskList; - public abstract void addMatch(AbstractQueryHit hit); - - public AbstractQueryHitCollector(TaskList tasklist) { + public QueryHitCollector(TaskList tasklist) { this.taskList = tasklist; } public void aboutToStart(int startMatchCount) throws CoreException { + results.clear(); matchCount = startMatchCount; monitor.setTaskName(STARTING); } @@ -65,7 +69,7 @@ public abstract class AbstractQueryHitCollector implements IQueryHitCollector { matchCount++; if (!getProgressMonitor().isCanceled()) { - // if the operation is cancelled finish with whatever data was + // if the operation is canceled finish with whatever data was // already found getProgressMonitor().subTask(getFormattedMatchesString(matchCount)); getProgressMonitor().worked(1); @@ -73,30 +77,22 @@ public abstract class AbstractQueryHitCollector implements IQueryHitCollector { } public void done() { - if (!monitor.isCanceled()) { + if (monitor != null && !monitor.isCanceled()) { // if the operation is cancelled, finish with the data that we // already have String matchesString = getFormattedMatchesString(matchCount); monitor.setTaskName(MessageFormat.format(DONE, new Object[] { matchesString })); + monitor.done(); } // Cut no longer used references because the collector might be re-used monitor = null; } - /** - * Get the string specifying the number of matches found - * - * @param count - * The number of matches found - * @return The <code>String</code> specifying the number of matches found - */ protected String getFormattedMatchesString(int count) { - // if only 1 match, return the singular match string - if (count == 1) + if (count == 1) { return MATCH; - - // format the matches string and return it + } Object[] messageFormatArgs = { new Integer(count) }; return MessageFormat.format(MATCHES, messageFormatArgs); } @@ -109,4 +105,14 @@ public abstract class AbstractQueryHitCollector implements IQueryHitCollector { this.monitor = monitor; } + public void addMatch(AbstractQueryHit hit) { + String description = hit.getId() + ": " + hit.getDescription(); + hit.setDescription(description); + results.add(hit); + } + + public List<AbstractQueryHit> getHits() { + return results; + } + } diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java index 40b54413c..8e04d95a4 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java @@ -22,8 +22,8 @@ import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; import org.eclipse.mylar.tasks.core.IAttachmentHandler; import org.eclipse.mylar.tasks.core.IOfflineTaskHandler; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; import org.eclipse.mylar.tasks.core.ITask; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.TaskRepository; /** @@ -97,7 +97,7 @@ public class MockRepositoryConnector extends AbstractRepositoryConnector { } @Override - public IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor, IQueryHitCollector resultCollector) { + public IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor, QueryHitCollector resultCollector) { return null; } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/AbstractRepositoryQueryPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/AbstractRepositoryQueryPage.java index b2c6e4707..3e7e9ce18 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/AbstractRepositoryQueryPage.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/AbstractRepositoryQueryPage.java @@ -106,7 +106,7 @@ public abstract class AbstractRepositoryQueryPage extends WizardPage implements } public String getQueryTitle() { - return title.getText(); + return title != null ? title.getText() : ""; } public abstract AbstractRepositoryQuery getQuery(); diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResult.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResult.java index c65b4d797..110fdc3ad 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResult.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/RepositorySearchResult.java @@ -29,7 +29,7 @@ public class RepositorySearchResult extends AbstractTextSearchResult { /** * The query producing this result. */ - private AbstractRepositorySearchQuery repositoryQuery; + private ISearchQuery repositoryQuery; /** * Constructor for <code>RepositorySearchResult</code> class. @@ -38,7 +38,7 @@ public class RepositorySearchResult extends AbstractTextSearchResult { * <code>AbstractRepositorySearchQuery</code> that is producing * this result. */ - public RepositorySearchResult(AbstractRepositorySearchQuery query) { + public RepositorySearchResult(ISearchQuery query) { super(); repositoryQuery = query; } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchHitCollector.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchHitCollector.java new file mode 100644 index 000000000..d6629c166 --- /dev/null +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/search/SearchHitCollector.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2003 - 2006 University Of British Columbia 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: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ +package org.eclipse.mylar.internal.tasks.ui.search; + +import java.net.Proxy; + +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.mylar.context.core.MylarStatusHandler; +import org.eclipse.mylar.tasks.core.AbstractQueryHit; +import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; +import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; +import org.eclipse.mylar.tasks.core.QueryHitCollector; +import org.eclipse.mylar.tasks.core.TaskList; +import org.eclipse.mylar.tasks.core.TaskRepository; +import org.eclipse.mylar.tasks.ui.TasksUiPlugin; +import org.eclipse.search.ui.ISearchQuery; +import org.eclipse.search.ui.ISearchResult; +import org.eclipse.search.ui.NewSearchUI; +import org.eclipse.search.ui.text.Match; + +/** + * Used for returning results from Eclipse Search view. Collects results of a + * repository search + * + * @author Rob Elves + */ +public class SearchHitCollector extends QueryHitCollector implements ISearchQuery { + + private static final String QUERYING_REPOSITORY = "Querying Repository..."; + + private Proxy proxySettings; + + private TaskRepository repository; + + private AbstractRepositoryQuery repositoryQuery; + + private RepositorySearchResult searchResult; + + public SearchHitCollector(TaskList tasklist, TaskRepository repository, AbstractRepositoryQuery repositoryQuery, + Proxy proxySettings) { + super(tasklist); + this.repository = repository; + this.repositoryQuery = repositoryQuery; + this.proxySettings = proxySettings; + this.searchResult = new RepositorySearchResult(this); + } + + public void aboutToStart(int startMatchCount) throws CoreException { + super.aboutToStart(startMatchCount); + searchResult.removeAll(); + NewSearchUI.activateSearchResultView(); + } + + public void done() { + super.done(); + } + + @Override + public void addMatch(AbstractQueryHit hit) { + super.addMatch(hit); + this.searchResult.addMatch(new Match(hit, 0, 0)); + } + + public String getLabel() { + return QUERYING_REPOSITORY; + } + + public boolean canRerun() { + return true; + } + + public boolean canRunInBackground() { + return true; + } + + public ISearchResult getSearchResult() { + return searchResult; + } + + public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { + this.setProgressMonitor(monitor); + IStatus status = Status.OK_STATUS; + try { + aboutToStart(0); + monitor.beginTask(QUERYING_REPOSITORY, IProgressMonitor.UNKNOWN); + + if (monitor.isCanceled()) { + throw new OperationCanceledException("Search cancelled"); + } + AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( + repositoryQuery.getRepositoryKind()); + if (connector != null) { + status = connector.performQuery(repositoryQuery, repository, proxySettings, monitor, this); + } else { + return new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.OK, + "repository connector could not be found", null); + } + + if (!status.isOK()) { + MylarStatusHandler.fail(status.getException(), "Search failed. Please see details below.", true); + status = Status.OK_STATUS; + } + + } catch (CoreException e) { + MylarStatusHandler.fail(e, "Search failed.", true); + status = new Status(IStatus.OK, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR, + "Core Exception occurred while querying Bugzilla Server " + repository.getUrl() + ".\n" + + "\nClick Details for more information.", e); + + } finally { + // deals with monitor + done(); + } + return status; + } + +}
\ No newline at end of file diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeQueryJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeQueryJob.java index 6fd6d18fd..5e9d2790e 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeQueryJob.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeQueryJob.java @@ -13,9 +13,7 @@ package org.eclipse.mylar.tasks.ui; import java.io.FileNotFoundException; import java.io.IOException; -import java.util.ArrayList; import java.util.Date; -import java.util.List; import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; @@ -26,10 +24,9 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.mylar.context.core.MylarStatusHandler; import org.eclipse.mylar.internal.context.core.util.DateUtil; import org.eclipse.mylar.internal.tasks.ui.TaskListImages; -import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractQueryHitCollector; import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.TaskList; import org.eclipse.mylar.tasks.core.TaskRepository; import org.eclipse.swt.widgets.Display; @@ -47,8 +44,6 @@ class SynchronizeQueryJob extends Job { private Set<AbstractRepositoryQuery> queries; - private List<AbstractQueryHit> newHits = new ArrayList<AbstractQueryHit>(); - private boolean synchTasks; private TaskList taskList; @@ -83,29 +78,12 @@ class SynchronizeQueryJob extends Job { }); } - // MultiStatus queryStatus = new - // MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", - // null); - - newHits.clear(); - AbstractQueryHitCollector collector = new AbstractQueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) { - - @Override - public void addMatch(AbstractQueryHit hit) { - // TODO: do hit -> task matching here rather than in - // abstract? - newHits.add(hit); - - } - - }; - - IStatus resultingStatus = connector.performQuery(repositoryQuery, repository, TasksUiPlugin.getDefault().getProxySettings(), monitor, collector); - // connector.performQuery(repositoryQuery, new - // NullProgressMonitor(), queryStatus); + QueryHitCollector collector = new QueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()); + IStatus resultingStatus = connector.performQuery(repositoryQuery, repository, TasksUiPlugin.getDefault() + .getProxySettings(), monitor, collector); if (resultingStatus.getException() == null) { - repositoryQuery.updateHits(newHits, taskList); + repositoryQuery.updateHits(collector.getHits(), taskList); if (synchTasks) { // TODO: Should sync changed per repository not per // query @@ -125,24 +103,6 @@ class SynchronizeQueryJob extends Job { // assume working offline return Status.OK_STATUS; } - - - - // if (queryStatus.getChildren() != null && - // queryStatus.getChildren().length > 0) { - // if (queryStatus.getChildren()[0].getException() == null) { - // repositoryQuery.updateHits(newHits, taskList); - // if (synchTasks) { - // // TODO: Should sync changed per repository not per query - // TasksUiPlugin.getSynchronizationManager().synchronizeChanged(connector, - // repository); - // } - // - // } else { - // repositoryQuery.setCurrentlySynchronizing(false); - // return queryStatus.getChildren()[0]; - // } - // } repositoryQuery.setCurrentlySynchronizing(false); repositoryQuery.setLastRefreshTimeStamp(DateUtil.getFormattedDate(new Date(), "MMM d, H:mm:ss")); diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java index 6ab5b82ef..c6ade79f6 100644 --- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java +++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java @@ -30,8 +30,8 @@ import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; import org.eclipse.mylar.tasks.core.IAttachmentHandler; import org.eclipse.mylar.tasks.core.IOfflineTaskHandler; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; import org.eclipse.mylar.tasks.core.ITask; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.TaskRepository; /** @@ -110,7 +110,7 @@ public class TracRepositoryConnector extends AbstractRepositoryConnector { @Override public IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository, - Proxy proxySettings, IProgressMonitor monitor, IQueryHitCollector resultCollector) { + Proxy proxySettings, IProgressMonitor monitor, QueryHitCollector resultCollector) { final List<TracTicket> tickets = new ArrayList<TracTicket>(); diff --git a/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF index 2fcd0e50e..9d869a7d4 100644 --- a/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF @@ -12,7 +12,8 @@ Require-Bundle: org.junit, org.eclipse.mylar.tasks.core, org.eclipse.mylar.core.tests, org.eclipse.mylar.trac.ui, - org.eclipse.mylar.trac.core + org.eclipse.mylar.trac.core, + org.eclipse.search Export-Package: org.eclipse.mylar.trac.tests Bundle-Activator: org.eclipse.mylar.trac.tests.TracTestPlugin Eclipse-LazyStart: true diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/RepositorySearchQueryTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/RepositorySearchQueryTest.java index a228046f6..7feac3b10 100644 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/RepositorySearchQueryTest.java +++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/RepositorySearchQueryTest.java @@ -13,19 +13,17 @@ package org.eclipse.mylar.trac.tests; import junit.framework.TestCase; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.mylar.context.tests.support.MylarTestUtils; import org.eclipse.mylar.context.tests.support.MylarTestUtils.Credentials; import org.eclipse.mylar.context.tests.support.MylarTestUtils.PrivilegeLevel; +import org.eclipse.mylar.internal.tasks.ui.search.SearchHitCollector; import org.eclipse.mylar.internal.trac.core.ITracClient; import org.eclipse.mylar.internal.trac.core.TracCorePlugin; import org.eclipse.mylar.internal.trac.core.TracRepositoryQuery; import org.eclipse.mylar.internal.trac.core.ITracClient.Version; import org.eclipse.mylar.internal.trac.core.model.TracSearch; -import org.eclipse.mylar.internal.trac.ui.search.RepositorySearchQuery; import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractQueryHitCollector; import org.eclipse.mylar.tasks.core.TaskRepository; import org.eclipse.mylar.tasks.core.TaskRepositoryManager; import org.eclipse.mylar.tasks.ui.TasksUiPlugin; @@ -78,18 +76,16 @@ public class RepositorySearchQueryTest extends TestCase { String queryUrl = repository.getUrl() + ITracClient.QUERY_URL + search.toUrl(); TracRepositoryQuery query = new TracRepositoryQuery(repository.getUrl(), queryUrl, "description", null); - final int count[] = new int[1]; - RepositorySearchQuery searchQuery = new RepositorySearchQuery(repository, query); - searchQuery.setCollector(new AbstractQueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) { + SearchHitCollector collector = new SearchHitCollector(TasksUiPlugin.getTaskListManager() + .getTaskList(), repository, query, null) { @Override public void addMatch(AbstractQueryHit hit) { - assertEquals(Constants.TEST_TRAC_096_URL, hit.getRepositoryUrl()); - count[0]++; + super.addMatch(hit); + assertEquals(Constants.TEST_TRAC_096_URL, hit.getRepositoryUrl()); } - }); - IStatus status = searchQuery.run(new NullProgressMonitor()); - assertTrue(status.isOK()); - assertEquals(data.tickets.size(), count[0]); + }; + collector.run(new NullProgressMonitor()); + assertEquals(data.tickets.size(), collector.getHits().size()); } } diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java index f78bce72d..087a9fb21 100644 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java +++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java @@ -42,7 +42,7 @@ import org.eclipse.mylar.internal.trac.core.model.TracVersion; import org.eclipse.mylar.internal.trac.core.model.TracTicket.Key; import org.eclipse.mylar.internal.trac.ui.wizard.TracRepositorySettingsPage; import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractQueryHitCollector; +import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; import org.eclipse.mylar.tasks.core.ITask; @@ -193,7 +193,7 @@ public class TracRepositoryConnectorTest extends TestCase { //MultiStatus queryStatus = new MultiStatus(TracUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null); final List<AbstractQueryHit> result = new ArrayList<AbstractQueryHit>(); - AbstractQueryHitCollector hitCollector = new AbstractQueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) { + QueryHitCollector hitCollector = new QueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) { @Override public void addMatch(AbstractQueryHit hit) { diff --git a/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF index 08e39a837..5aa9c1f1b 100644 --- a/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF @@ -17,5 +17,4 @@ Require-Bundle: org.eclipse.ui, Eclipse-LazyStart: true Export-Package: org.eclipse.mylar.internal.trac.ui, org.eclipse.mylar.internal.trac.ui.editor, - org.eclipse.mylar.internal.trac.ui.search, org.eclipse.mylar.internal.trac.ui.wizard diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/search/RepositorySearchQuery.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/search/RepositorySearchQuery.java deleted file mode 100644 index 6888745f3..000000000 --- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/search/RepositorySearchQuery.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 - 2006 University Of British Columbia 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: - * University Of British Columbia - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylar.internal.trac.ui.search; - -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.jface.dialogs.ErrorDialog; -import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositorySearchQuery; -import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; -import org.eclipse.mylar.tasks.core.TaskRepository; -import org.eclipse.mylar.tasks.ui.TasksUiPlugin; -import org.eclipse.ui.PlatformUI; - -/** - * This class performs a search query. - * - * @author Steffen Pingel - */ -public class RepositorySearchQuery extends AbstractRepositorySearchQuery { - - private IQueryHitCollector collector; - - private TaskRepository repository; - - private AbstractRepositoryQuery query; - - public RepositorySearchQuery(TaskRepository repository, AbstractRepositoryQuery query) { - this.repository = repository; - this.query = query; - } - - public IQueryHitCollector getCollector() { - return collector; - } - - public void setCollector(IQueryHitCollector collector) { - this.collector = collector; - } - - public IStatus run(IProgressMonitor monitor) throws OperationCanceledException { - //MultiStatus queryStatus = new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null); - IStatus queryStatus = Status.OK_STATUS; - try { - collector.setProgressMonitor(monitor); - collector.aboutToStart(0); - - AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( - repository.getKind()); - - queryStatus = connector.performQuery(query, repository, TasksUiPlugin.getDefault().getProxySettings(), monitor, collector); - collector.done(); - } catch (final CoreException e) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - ErrorDialog.openError(null, "Repository Search Error", null, e.getStatus()); - } - }); - return Status.OK_STATUS; - } - - final IStatus status = queryStatus; - if (status.getCode() == IStatus.CANCEL) { - return Status.OK_STATUS; - } else if (!status.isOK()) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - ErrorDialog.openError(null, "Repository Search Error", null, status); - } - }); - return Status.OK_STATUS; - } - return status; - } -} diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/wizard/TracCustomQueryPage.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/wizard/TracCustomQueryPage.java index 97b4efb50..1285cb808 100644 --- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/wizard/TracCustomQueryPage.java +++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/wizard/TracCustomQueryPage.java @@ -12,16 +12,16 @@ package org.eclipse.mylar.internal.trac.ui.wizard; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; +import java.net.Proxy; import java.util.HashMap; import java.util.Map; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.mylar.context.core.MylarStatusHandler; import org.eclipse.mylar.internal.tasks.ui.search.AbstractRepositoryQueryPage; -import org.eclipse.mylar.internal.tasks.ui.search.RepositorySearchResult; +import org.eclipse.mylar.internal.tasks.ui.search.SearchHitCollector; import org.eclipse.mylar.internal.trac.core.ITracClient; import org.eclipse.mylar.internal.trac.core.TracCorePlugin; import org.eclipse.mylar.internal.trac.core.TracException; @@ -31,16 +31,11 @@ import org.eclipse.mylar.internal.trac.core.model.TracSearch; import org.eclipse.mylar.internal.trac.core.model.TracSearchFilter; import org.eclipse.mylar.internal.trac.core.model.TracSearchFilter.CompareOperator; import org.eclipse.mylar.internal.trac.ui.TracUiPlugin; -import org.eclipse.mylar.internal.trac.ui.search.RepositorySearchQuery; -import org.eclipse.mylar.tasks.core.AbstractQueryHit; -import org.eclipse.mylar.tasks.core.AbstractQueryHitCollector; import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; -import org.eclipse.mylar.tasks.core.IQueryHitCollector; import org.eclipse.mylar.tasks.core.TaskRepository; import org.eclipse.mylar.tasks.core.TaskRepositoryManager; import org.eclipse.mylar.tasks.ui.TasksUiPlugin; import org.eclipse.search.ui.NewSearchUI; -import org.eclipse.search.ui.text.Match; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; @@ -429,29 +424,11 @@ public class TracCustomQueryPage extends AbstractRepositoryQueryPage { TaskRepositoryManager.MESSAGE_NO_REPOSITORY); return false; } - - final RepositorySearchQuery searchQuery = new RepositorySearchQuery(repository, getQuery()); - IQueryHitCollector collector = new AbstractQueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) { - - private RepositorySearchResult searchResult; - - @Override - public void aboutToStart(int startMatchCount) throws CoreException { - super.aboutToStart(startMatchCount); - - NewSearchUI.activateSearchResultView(); - searchResult = (RepositorySearchResult) searchQuery.getSearchResult(); - searchResult.removeAll(); - } - - @Override - public void addMatch(AbstractQueryHit hit) { - searchResult.addMatch(new Match(hit, 0, 0)); - } - - }; - searchQuery.setCollector(collector); - NewSearchUI.runQueryInBackground(searchQuery); + + Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings(); + SearchHitCollector collector = new SearchHitCollector(TasksUiPlugin.getTaskListManager() + .getTaskList(), repository, getQuery(), proxySettings); + NewSearchUI.runQueryInBackground(collector); return true; } |