Skip to main content
summaryrefslogtreecommitdiffstats
blob: a7c98b24a9783e50ae3303a9b03df31b209b02cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*******************************************************************************
 * 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.mylyn.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.mylyn.internal.bugzilla.ui.search.BugzillaSearchEngine;
import org.eclipse.mylyn.internal.bugzilla.ui.search.BugzillaSearchResultCollector;
import org.eclipse.mylyn.internal.bugzilla.ui.search.IBugzillaSearchOperation;
import org.eclipse.mylyn.internal.tasks.ui.search.AbstractRepositorySearchQuery;
import org.eclipse.mylyn.tasks.core.QueryHitCollector;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.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(QueryHitCollector collector);
	}

	/** The bugzilla collector for the search */
	private QueryHitCollector 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,
			QueryHitCollector 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 QueryHitCollector with the search results
	 */
	private QueryHitCollector 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.mylyn.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;
	}
}

Back to the top