0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.apiquery.ui.views.main.search;
|
|
19 |
|
|
20 |
import java.util.Collection;
|
|
21 |
|
|
22 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
23 |
import org.eclipse.core.runtime.IStatus;
|
|
24 |
import org.eclipse.core.runtime.Status;
|
|
25 |
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
|
|
26 |
import org.eclipse.core.runtime.jobs.Job;
|
|
27 |
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
|
|
28 |
import org.eclipse.jface.dialogs.MessageDialog;
|
|
29 |
import org.eclipse.swt.SWT;
|
|
30 |
import org.eclipse.swt.custom.BusyIndicator;
|
|
31 |
import org.eclipse.swt.widgets.Display;
|
|
32 |
|
|
33 |
import com.nokia.s60tools.apiquery.settings.IUserSettingsListener;
|
|
34 |
import com.nokia.s60tools.apiquery.settings.UserSettings;
|
|
35 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIQueryParameters;
|
|
36 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIShortDescription;
|
|
37 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIShortDescriptionSearchResults;
|
|
38 |
import com.nokia.s60tools.apiquery.shared.job.JobCancelledByUserException;
|
|
39 |
import com.nokia.s60tools.apiquery.shared.plugin.APIQueryPlugin;
|
|
40 |
import com.nokia.s60tools.apiquery.shared.resources.Messages;
|
|
41 |
import com.nokia.s60tools.apiquery.shared.searchmethod.AbstractSearchMethodExtension;
|
|
42 |
import com.nokia.s60tools.apiquery.shared.searchmethod.ISearchMethodExtension;
|
|
43 |
import com.nokia.s60tools.apiquery.shared.ui.dialogs.APIQueryMessageBox;
|
|
44 |
import com.nokia.s60tools.apiquery.shared.util.console.APIQueryConsole;
|
|
45 |
import com.nokia.s60tools.apiquery.ui.views.main.MainView;
|
|
46 |
import com.nokia.s60tools.util.debug.DbgUtility;
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Mediator class between the search tab's UI fields.
|
|
50 |
* Listens the actions and creates the query object,
|
|
51 |
* performs the query, and controls the population
|
|
52 |
* of the fields used to query results.
|
|
53 |
*/
|
|
54 |
class SearchTabUIFieldsMediator implements IQueryDefCompositeListener,
|
|
55 |
IUserSettingsListener, IResultSettingsListener {
|
|
56 |
|
|
57 |
/**
|
|
58 |
* UI control used to set the query type.
|
|
59 |
*/
|
|
60 |
private final QueryTypeSelectionComposite queryTypeControl;
|
|
61 |
|
|
62 |
private final QueryResultsComposite queryResultsControl;
|
|
63 |
|
|
64 |
private final QueryDefComposite queryDefControl;
|
|
65 |
|
|
66 |
/**
|
|
67 |
* Collection to store returned API summary data and errors.
|
|
68 |
*/
|
|
69 |
APIShortDescriptionSearchResults resultColl = null;
|
|
70 |
|
|
71 |
private APIQueryParameters params;
|
|
72 |
|
|
73 |
static Job prevWebSerachJob = null;
|
|
74 |
|
|
75 |
static Object prevQueryJobObjLock = new Object();
|
|
76 |
|
|
77 |
static String prevQueryString = null;
|
|
78 |
|
|
79 |
static public IProgressMonitor progressMonitor;
|
|
80 |
|
|
81 |
// Web query job
|
|
82 |
class WebQueryJob extends Job {
|
|
83 |
private String searchString = null;
|
|
84 |
|
|
85 |
public WebQueryJob(String jobDescription, String searchString) {
|
|
86 |
super(jobDescription);
|
|
87 |
this.searchString = searchString;
|
|
88 |
}
|
|
89 |
|
|
90 |
protected IStatus run(IProgressMonitor monitor) {
|
|
91 |
try {
|
|
92 |
progressMonitor = monitor;
|
|
93 |
prevQueryString = searchString;
|
|
94 |
//start the progress operation
|
|
95 |
progressMonitor.beginTask("Web Query in progress... ",
|
|
96 |
IProgressMonitor.UNKNOWN);
|
|
97 |
|
|
98 |
performQuery(params,monitor);
|
|
99 |
|
|
100 |
if (monitor.isCanceled()) {
|
|
101 |
|
|
102 |
return Status.CANCEL_STATUS;
|
|
103 |
}
|
|
104 |
|
|
105 |
return Status.OK_STATUS;
|
|
106 |
|
|
107 |
}
|
|
108 |
catch (JobCancelledByUserException e)
|
|
109 |
{
|
|
110 |
//System.out.println("Job cancelled");
|
|
111 |
return Status.CANCEL_STATUS;
|
|
112 |
|
|
113 |
}
|
|
114 |
|
|
115 |
catch (Exception e) {
|
|
116 |
|
|
117 |
APIQueryMessageBox msgBox = new APIQueryMessageBox(
|
|
118 |
Messages
|
|
119 |
.getString("SearchTabComposite.API_Query_ErrMsg") + e.getMessage() //$NON-NLS-1$
|
|
120 |
, SWT.ICON_ERROR | SWT.OK);
|
|
121 |
msgBox.open();
|
|
122 |
} finally {
|
|
123 |
monitor.done();
|
|
124 |
}
|
|
125 |
return Status.CANCEL_STATUS;
|
|
126 |
}
|
|
127 |
|
|
128 |
}
|
|
129 |
|
|
130 |
class WebQueryJobListener extends JobChangeAdapter {
|
|
131 |
|
|
132 |
Display d = null;
|
|
133 |
|
|
134 |
String searchString = null;
|
|
135 |
|
|
136 |
WebQueryJobListener(Display d, String searchString) {
|
|
137 |
this.d = d;
|
|
138 |
this.searchString = searchString;
|
|
139 |
}
|
|
140 |
|
|
141 |
public void done(IJobChangeEvent event) {
|
|
142 |
|
|
143 |
synchronized (prevQueryJobObjLock) {
|
|
144 |
|
|
145 |
try {
|
|
146 |
// if job done ,update the display with results
|
|
147 |
if (event.getResult().isOK()) {
|
|
148 |
updateResults(true, d, searchString);
|
|
149 |
|
|
150 |
}
|
|
151 |
|
|
152 |
} catch (Exception e) {
|
|
153 |
|
|
154 |
e.printStackTrace();
|
|
155 |
|
|
156 |
} finally {
|
|
157 |
// finally release
|
|
158 |
if (event.getJob() == prevWebSerachJob) {
|
|
159 |
prevWebSerachJob = null;
|
|
160 |
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
}
|
|
165 |
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
public SearchTabUIFieldsMediator(
|
|
170 |
QueryTypeSelectionComposite queryTypeControl,
|
|
171 |
QueryDefComposite queryDefControl,
|
|
172 |
QueryResultsComposite queryResultsControl) {
|
|
173 |
this.queryTypeControl = queryTypeControl;
|
|
174 |
this.queryDefControl = queryDefControl;
|
|
175 |
this.queryResultsControl = queryResultsControl;
|
|
176 |
// Registering to listen for query start actions
|
|
177 |
this.queryDefControl.setCompositeListener(this);
|
|
178 |
// Registering to listen for result view setting changes
|
|
179 |
this.queryResultsControl.setResultSettingsListener(this);
|
|
180 |
// Starting to listen user settings change events
|
|
181 |
UserSettings.getInstance().addUserSettingListener(this);
|
|
182 |
}
|
|
183 |
|
|
184 |
/**
|
|
185 |
* Performs the according the given parameters and
|
|
186 |
* updates the UI components after the query.
|
|
187 |
* @param params Parameters for the query.
|
|
188 |
* @param errInfo Error info class for returning
|
|
189 |
* error description in case if an error.
|
|
190 |
*/
|
|
191 |
private void performQuery(APIQueryParameters params) {
|
|
192 |
try { // disable datasource selection option from properites page
|
|
193 |
MainView.enablePropTabcontents(false);
|
|
194 |
resultColl = null; // Resetting previous searches.
|
|
195 |
ISearchMethodExtension currSelExt = UserSettings.getInstance()
|
|
196 |
.getCurrentlySelectedSearchMethod();
|
|
197 |
resultColl = currSelExt.runAPIQuery(params);
|
|
198 |
} finally {
|
|
199 |
|
|
200 |
MainView.enablePropTabcontents(true);
|
|
201 |
}
|
|
202 |
}
|
|
203 |
|
|
204 |
/**
|
|
205 |
* Runs <code>this.queryStarted(searchString)</code> and returns APIShortDescriptions
|
|
206 |
* @param searchString semi-colon separated search criterias
|
|
207 |
* @return all API Summarys matching semi-colon separated search criterias
|
|
208 |
* @see com.nokia.s60tools.apiquery.ui.views.main.search.IQueryDefCompositeListener#queryStarted(java.lang.String)
|
|
209 |
*/
|
|
210 |
public Collection<APIShortDescription> activeProjectQueryStarted(
|
|
211 |
String searchString) {
|
|
212 |
queryStarted(searchString, false);
|
|
213 |
return resultColl.getSearchResults();
|
|
214 |
}
|
|
215 |
|
|
216 |
/**
|
|
217 |
* update the results page
|
|
218 |
*
|
|
219 |
* @param syncDisp :
|
|
220 |
* for webquery jobs
|
|
221 |
* @param d
|
|
222 |
* @param queryString
|
|
223 |
* :Search string to be shown in the query serach string text box
|
|
224 |
*/
|
|
225 |
private void updateResults(boolean syncDisp, final Display d,
|
|
226 |
final String queryString) {
|
|
227 |
|
|
228 |
|
|
229 |
// Did we succeed?
|
|
230 |
if (resultColl != null) {
|
|
231 |
|
|
232 |
if (syncDisp) {// for non UI thread
|
|
233 |
Runnable updateCompositeThread = new Runnable() {
|
|
234 |
public void run() {
|
|
235 |
// Setting queried data into UI control.
|
|
236 |
updateResultComposite();
|
|
237 |
// update the search string text box for this search
|
|
238 |
//queryDefControl.setQueryString(queryString);
|
|
239 |
|
|
240 |
}
|
|
241 |
};
|
|
242 |
|
|
243 |
// update the result composite page
|
|
244 |
d.syncExec(updateCompositeThread);
|
|
245 |
|
|
246 |
} else {
|
|
247 |
// Setting queried data into UI control.
|
|
248 |
updateResultComposite();
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
|
252 |
if (resultColl.hasErrors()) {
|
|
253 |
|
|
254 |
// Something failed
|
|
255 |
// If there was some errors, but after all, there was also some
|
|
256 |
// results, giving warning dialog
|
|
257 |
// but if everything failed, then gbvgiving error dialog. So
|
|
258 |
// then is easier to make different if e.g. only one server was
|
|
259 |
// down but others works OK.
|
|
260 |
int messageType = resultColl.getSearchResults().isEmpty() ? APIQueryConsole.MSG_ERROR
|
|
261 |
: APIQueryConsole.MSG_WARNING;
|
|
262 |
int messageTypeIcon = resultColl.getSearchResults().isEmpty() ? SWT.ICON_ERROR
|
|
263 |
: SWT.ICON_WARNING;
|
|
264 |
|
|
265 |
final String errMsg = Messages
|
|
266 |
.getString("SearchTabUIFieldsMediator.APIListQueryFailed_ErrMsg") + "\n" + resultColl.getErrorMessages(); //$NON-NLS-1$ //$NON-NLS-2$
|
|
267 |
APIQueryConsole.getInstance().println(errMsg, messageType);
|
|
268 |
if (d == null) {
|
|
269 |
APIQueryMessageBox mbox = new APIQueryMessageBox(errMsg,
|
|
270 |
messageTypeIcon | SWT.OK);
|
|
271 |
mbox.open();
|
|
272 |
} else {
|
|
273 |
Runnable errormsg = new Runnable() {
|
|
274 |
public void run() {
|
|
275 |
MessageDialog.openError(d.getActiveShell(),
|
|
276 |
"API query", errMsg);
|
|
277 |
}
|
|
278 |
};
|
|
279 |
|
|
280 |
// update the result composite page
|
|
281 |
d.syncExec(errormsg);
|
|
282 |
|
|
283 |
}
|
|
284 |
|
|
285 |
}
|
|
286 |
|
|
287 |
}
|
|
288 |
|
|
289 |
/* (non-Javadoc)
|
|
290 |
* @see com.nokia.s60tools.apiquery.ui.views.main.search.IQueryDefCompositeListener#queryStarted(java.lang.String)
|
|
291 |
*/
|
|
292 |
public void queryStarted(String searchString, boolean useExactMatch) {
|
|
293 |
|
|
294 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION,
|
|
295 |
"* Search started: " + searchString); //$NON-NLS-1$
|
|
296 |
int queryType = queryTypeControl.getSelectedQueryType();
|
|
297 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION,
|
|
298 |
"** Query type as int: " + queryType); //$NON-NLS-1$
|
|
299 |
DbgUtility
|
|
300 |
.println(
|
|
301 |
DbgUtility.PRIORITY_OPERATION,
|
|
302 |
"** Query type descr: " + APIQueryParameters.getDescriptionForQueryType(queryType)); //$NON-NLS-1$
|
|
303 |
|
|
304 |
params = new APIQueryParameters(queryType, searchString);
|
|
305 |
params.setDetailsMentToAddToDescriptions(!queryResultsControl
|
|
306 |
.isShowOnlyAPINamesSelected());
|
|
307 |
params.setExactMatchInUse(useExactMatch);
|
|
308 |
|
|
309 |
ISearchMethodExtension currSelExt = UserSettings.getInstance()
|
|
310 |
.getCurrentlySelectedSearchMethod();
|
|
311 |
|
|
312 |
// Showing busy cursor during operation
|
|
313 |
Display d = APIQueryPlugin.getCurrentlyActiveWbWindowShell()
|
|
314 |
.getDisplay();
|
|
315 |
if (currSelExt.isAsyncQueryPreferred()) {
|
|
316 |
// run as the back ground job only if it's a webquery
|
|
317 |
|
|
318 |
synchronized (prevQueryJobObjLock) {
|
|
319 |
//any query running
|
|
320 |
if (prevWebSerachJob != null) {
|
|
321 |
boolean cancel = true;
|
|
322 |
if (!progressMonitor.isCanceled()) {
|
|
323 |
//if job not cancelled yet,check if user wants to continue with new query
|
|
324 |
cancel = MessageDialog.openQuestion(APIQueryPlugin
|
|
325 |
.getCurrentlyActiveWbWindowShell(),
|
|
326 |
"Query Cancel",
|
|
327 |
"Do you want to cancel pervious apiquery for :"
|
|
328 |
+ prevQueryString
|
|
329 |
+ " and continue with new search?");
|
|
330 |
}
|
|
331 |
|
|
332 |
if (cancel) {
|
|
333 |
|
|
334 |
//already cancelled?
|
|
335 |
if (!progressMonitor.isCanceled()) {
|
|
336 |
if (progressMonitor != null)
|
|
337 |
progressMonitor
|
|
338 |
.setTaskName("In cancellation...........");
|
|
339 |
if (prevWebSerachJob != null)
|
|
340 |
prevWebSerachJob.cancel();
|
|
341 |
}
|
|
342 |
//set the job to null
|
|
343 |
prevWebSerachJob = null;
|
|
344 |
|
|
345 |
MainView.enablePropTabcontents(true);
|
|
346 |
}
|
|
347 |
|
|
348 |
else {
|
|
349 |
// end the new search
|
|
350 |
return;
|
|
351 |
}
|
|
352 |
|
|
353 |
}
|
|
354 |
}
|
|
355 |
|
|
356 |
prevWebSerachJob = new WebQueryJob("Web Query for search string: "
|
|
357 |
+ searchString, searchString);
|
|
358 |
|
|
359 |
prevWebSerachJob.addJobChangeListener(new WebQueryJobListener(d,
|
|
360 |
searchString));
|
|
361 |
|
|
362 |
prevWebSerachJob.setPriority(Job.SHORT);
|
|
363 |
prevWebSerachJob.setUser(true);
|
|
364 |
prevWebSerachJob.schedule(); // start as soon as possible
|
|
365 |
|
|
366 |
}
|
|
367 |
|
|
368 |
else {
|
|
369 |
Runnable performAPIDetailsQueryRunnable = new Runnable() {
|
|
370 |
public void run() {
|
|
371 |
performQuery(params);
|
|
372 |
}
|
|
373 |
};
|
|
374 |
// run with a busy indicator
|
|
375 |
BusyIndicator.showWhile(d, performAPIDetailsQueryRunnable);
|
|
376 |
updateResults(false, d, null);
|
|
377 |
}
|
|
378 |
}
|
|
379 |
|
|
380 |
/* (non-Javadoc)
|
|
381 |
* @see com.nokia.s60tools.apiquery.ui.views.main.search.IQueryActionListener#queryModified(java.lang.String)
|
|
382 |
*/
|
|
383 |
public void queryModified(String searchString) {
|
|
384 |
// Currently we do not do anything when query string is modified.
|
|
385 |
}
|
|
386 |
|
|
387 |
/* (non-Javadoc)
|
|
388 |
* @see com.nokia.s60tools.apiquery.settings.IUserSettingsListener#userSettingsChanged()
|
|
389 |
*/
|
|
390 |
public void userSettingsChanged() {
|
|
391 |
// Settings have changed which might mean that
|
|
392 |
// the user has changed the currently used query type.
|
|
393 |
// => Therefore resetting previous query results
|
|
394 |
queryResultsControl.clear();
|
|
395 |
}
|
|
396 |
|
|
397 |
/**
|
|
398 |
* Releases all the listeners. Called when parent UI composite
|
|
399 |
* is disposed. If we have listeners in action after UI components
|
|
400 |
* are disposed we will get "Widget is disposed" error.
|
|
401 |
*/
|
|
402 |
public void releaseListeners() {
|
|
403 |
UserSettings.getInstance().removeUserSettingListener(this);
|
|
404 |
queryDefControl.setCompositeListener(null);
|
|
405 |
queryResultsControl.setResultSettingsListener(null);
|
|
406 |
}
|
|
407 |
|
|
408 |
/**
|
|
409 |
* Updates results composite
|
|
410 |
*/
|
|
411 |
private void updateResultComposite() {
|
|
412 |
// Clearing old results
|
|
413 |
queryResultsControl.clear();
|
|
414 |
|
|
415 |
//Updating results composite
|
|
416 |
queryResultsControl.updateAPIShortDescriptionData(resultColl
|
|
417 |
.getSearchResults(), params);
|
|
418 |
|
|
419 |
}
|
|
420 |
|
|
421 |
/* (non-Javadoc)
|
|
422 |
* @see com.nokia.s60tools.apiquery.ui.views.main.search.IResultSettingsListener#resultSettingsChanged()
|
|
423 |
*/
|
|
424 |
public void resultSettingsChanged() {
|
|
425 |
//When request comes outside of this class, show only API names selection must be updated
|
|
426 |
params.setDetailsMentToAddToDescriptions(!queryResultsControl
|
|
427 |
.isShowOnlyAPINamesSelected());
|
|
428 |
updateResultComposite();
|
|
429 |
}
|
|
430 |
|
|
431 |
/**
|
|
432 |
* Performs the according the given parameters and updates the UI components
|
|
433 |
* after the query.
|
|
434 |
*
|
|
435 |
* @param params
|
|
436 |
* Parameters for the query.
|
|
437 |
* @param errInfo
|
|
438 |
* Error info class for returning error description in case if an
|
|
439 |
* error.
|
|
440 |
*/
|
|
441 |
private void performQuery(APIQueryParameters params,IProgressMonitor progressmonitor) throws JobCancelledByUserException{
|
|
442 |
try { // disable datasource selection option from properites page
|
|
443 |
MainView.enablePropTabcontents(false);
|
|
444 |
resultColl = null; // Resetting previous searches.
|
|
445 |
|
|
446 |
ISearchMethodExtension currSelExt = UserSettings.getInstance()
|
|
447 |
.getCurrentlySelectedSearchMethod();
|
|
448 |
if ( currSelExt.isAsyncQueryPreferred())
|
|
449 |
{
|
|
450 |
|
|
451 |
Object obj = UserSettings.getInstance()
|
|
452 |
.getCurrentlySelectedSearchMethod();
|
|
453 |
|
|
454 |
resultColl = ((AbstractSearchMethodExtension)obj).runAPIQuery(params, progressMonitor);
|
|
455 |
|
|
456 |
|
|
457 |
|
|
458 |
}
|
|
459 |
else
|
|
460 |
{
|
|
461 |
|
|
462 |
resultColl = currSelExt.runAPIQuery(params);
|
|
463 |
}
|
|
464 |
|
|
465 |
// enable dataSelection source feature
|
|
466 |
} finally {
|
|
467 |
|
|
468 |
MainView.enablePropTabcontents(true);
|
|
469 |
}
|
|
470 |
}
|
|
471 |
|
|
472 |
|
|
473 |
|
|
474 |
}
|