Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/search/BugzillaMylarSearch.java')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/search/BugzillaMylarSearch.java174
1 files changed, 174 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/search/BugzillaMylarSearch.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/search/BugzillaMylarSearch.java
new file mode 100644
index 000000000..f167a9b1b
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/search/BugzillaMylarSearch.java
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2005 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 13, 2004
+ */
+package org.eclipse.mylar.bugs.search;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.mylar.bugs.BugzillaMylarBridge;
+import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaReportNode;
+import org.eclipse.mylar.core.InterestComparator;
+import org.eclipse.mylar.core.search.IActiveSearchListener;
+import org.eclipse.mylar.core.search.IMylarSearchOperation;
+
+
+/**
+ * Used to facilitate bugzilla searches based on IJavaElements
+ *
+ * @author Shawn Minto
+ */
+public class BugzillaMylarSearch implements IMylarSearchOperation {
+
+ // scope identifiers
+ public static final int LOCAL_QUAL = 1; // local implies a bugzilla task, not just an offline report
+ public static final int LOCAL_UNQUAL = 2;
+ public static final int FULLY_QUAL = 3;
+ public static final int UNQUAL = 4;
+
+ private int scope;
+
+ private IJavaElement element;
+
+ private String handle = "";
+
+ /**
+ * Constructor
+ * @param scope The scope of this search
+ */
+ public BugzillaMylarSearch(int scope, IJavaElement element) {
+ this.scope = scope;
+ this.element = element;
+ }
+
+ public IStatus run(IProgressMonitor monitor) {
+ handle = element.getHandleIdentifier() + " " + scope;
+ List<IJavaElement> landmarks = new ArrayList<IJavaElement>();
+ landmarks.add(element);
+
+ if (!BugzillaMylarBridge.doesJobExist(handle)) {
+
+ // perform the bugzilla search
+ // get only the useful landmarks (IMember)
+ List<IMember> members = getMemberLandmarks(landmarks);
+
+ // go through all of the landmarks that we are given and perform a
+ // search on them
+ for(IMember m : members){
+
+ // FIXME: decide whether to do leave the caching of searches in for now or not
+ // check if we have the info cached
+// List<BugzillaReportNode> landmarkDoi = MylarTasklistPlugin.getBridge()
+// .getFromLandmarksHash(m, scope);
+
+// if (landmarkDoi != null) {
+// //TODO decide when to queue up and do a refresh search
+// notifySearchCompleted(landmarkDoi);
+// continue;
+// }
+
+ // create a search operation so that we can search
+ BugzillaMylarSearchOperation op = new BugzillaMylarSearchOperation(
+ this, m, scope);
+
+ // create a new search job so that it can be scheduled and
+ // run as a background thread
+ Job searchJob = new BugzillaMylarSearchJob(
+ "Querying Bugzilla Server - Mylar - "
+ + op.getSearchMemberName(), op);
+
+ // schedule the new search job
+ searchJob.schedule();
+
+ // save this searchJobs handle so that we can cancel it if need be
+ BugzillaMylarBridge.addJob(handle, searchJob);
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ /** List of listeners wanting to know about the searches */
+ private List<IActiveSearchListener> listeners = new ArrayList<IActiveSearchListener>();
+
+ /**
+ * Add a listener for when the bugzilla search is completed
+ *
+ * @param l
+ * The listener to add
+ */
+ public void addListener(IActiveSearchListener l) {
+ // add the listener to the list
+ listeners.add(l);
+ }
+
+ /**
+ * Remove a listener for when the bugzilla search is completed
+ *
+ * @param l
+ * The listener to remove
+ */
+ public void removeListener(IActiveSearchListener l) {
+ // remove the listener from the list
+ listeners.remove(l);
+ }
+
+ /**
+ * Notify all of the listeners that the bugzilla search is completed
+ *
+ * @param doiList
+ * A list of BugzillaSearchHitDoiInfo
+ * @param member
+ * The IMember that the search was performed on
+ */
+ public void notifySearchCompleted(List<BugzillaReportNode> doiList) {
+ // go through all of the listeners and call searchCompleted(colelctor,
+ // member)
+ BugzillaMylarBridge.removeSearchJob(handle);
+ for (IActiveSearchListener listener : listeners) {
+ listener.searchCompleted(doiList);
+ }
+ }
+
+ /**
+ * Get only the landmarks that are IMember and sort them according to their
+ * DOI value (highest to lowest)
+ *
+ * @param landmarks
+ * The landmarks to check
+ * @return List of IMember landmarks sorted by DOI value
+ */
+ public static List<IMember> getMemberLandmarks(List<IJavaElement> landmarks) {
+ List<IMember> memberLandmarks = new ArrayList<IMember>();
+
+ for(IJavaElement je : landmarks) {
+
+ // keep only the IMember landmarks
+ if (je instanceof IMember) {
+ memberLandmarks.add((IMember)je);
+ }
+ }
+
+ // sort the landmarks
+ Collections.sort(memberLandmarks, new InterestComparator<IMember>());
+
+ return memberLandmarks;
+ }
+
+} \ No newline at end of file

Back to the top