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.ArrayList;
|
|
21 |
import java.util.Collection;
|
|
22 |
import java.util.HashMap;
|
|
23 |
import java.util.Map;
|
|
24 |
|
|
25 |
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
|
26 |
import org.eclipse.jface.viewers.TableViewer;
|
|
27 |
import org.eclipse.jface.viewers.Viewer;
|
|
28 |
import org.eclipse.swt.SWT;
|
|
29 |
import org.eclipse.swt.browser.Browser;
|
|
30 |
import org.eclipse.swt.browser.LocationEvent;
|
|
31 |
import org.eclipse.swt.browser.LocationListener;
|
|
32 |
import org.eclipse.swt.custom.BusyIndicator;
|
|
33 |
import org.eclipse.swt.events.SelectionEvent;
|
|
34 |
import org.eclipse.swt.events.SelectionListener;
|
|
35 |
import org.eclipse.swt.layout.FillLayout;
|
|
36 |
import org.eclipse.swt.layout.GridData;
|
|
37 |
import org.eclipse.swt.layout.GridLayout;
|
|
38 |
import org.eclipse.swt.widgets.Button;
|
|
39 |
import org.eclipse.swt.widgets.Composite;
|
|
40 |
import org.eclipse.swt.widgets.Display;
|
|
41 |
import org.eclipse.swt.widgets.Event;
|
|
42 |
import org.eclipse.swt.widgets.Label;
|
|
43 |
import org.eclipse.swt.widgets.Layout;
|
|
44 |
import org.eclipse.swt.widgets.Listener;
|
|
45 |
import org.eclipse.swt.widgets.Table;
|
|
46 |
import org.eclipse.swt.widgets.TableColumn;
|
|
47 |
import org.eclipse.swt.widgets.TableItem;
|
|
48 |
import org.eclipse.ui.PlatformUI;
|
|
49 |
|
|
50 |
import com.nokia.s60tools.apiquery.APIQueryHelpContextIDs;
|
|
51 |
import com.nokia.s60tools.apiquery.settings.UserSettings;
|
|
52 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIDetailField;
|
|
53 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIDetails;
|
|
54 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIQueryParameters;
|
|
55 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIShortDescription;
|
|
56 |
import com.nokia.s60tools.apiquery.shared.datatypes.QueryErrorInfo;
|
|
57 |
import com.nokia.s60tools.apiquery.shared.exceptions.QueryOperationFailedException;
|
|
58 |
import com.nokia.s60tools.apiquery.shared.plugin.APIQueryPlugin;
|
|
59 |
import com.nokia.s60tools.apiquery.shared.preferences.APIQueryPreferences;
|
|
60 |
import com.nokia.s60tools.apiquery.shared.resources.Messages;
|
|
61 |
import com.nokia.s60tools.apiquery.shared.searchmethod.ISearchMethodExtension;
|
|
62 |
import com.nokia.s60tools.apiquery.shared.searchmethod.ui.AbstractUiFractionComposite;
|
|
63 |
import com.nokia.s60tools.apiquery.shared.ui.dialogs.APIQueryMessageBox;
|
|
64 |
import com.nokia.s60tools.apiquery.shared.util.console.APIQueryConsole;
|
|
65 |
import com.nokia.s60tools.util.debug.DbgUtility;
|
|
66 |
|
|
67 |
|
|
68 |
/**
|
|
69 |
* UI composite containing controls that show the query results.
|
|
70 |
*/
|
|
71 |
class QueryResultsComposite extends AbstractUiFractionComposite {
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Amount of columns in the used grid layout.
|
|
75 |
*/
|
|
76 |
private final int COLUMN_COUNT = 1;
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Search results label text to be shown for user.
|
|
80 |
*/
|
|
81 |
private static final String SEARCH_RESULTS_LABEL_TEXT = Messages
|
|
82 |
.getString("QueryResultsComposite.SearchResults_Msg"); //$NON-NLS-1$
|
|
83 |
|
|
84 |
private static final String SEARCH_RESULTS_LABEL_API_TEXT = Messages
|
|
85 |
.getString("QueryResultsComposite.APIs_Msg"); //$NON-NLS-1$
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Preferred size for the search result list control. Targeted currently to
|
|
89 |
* show 10 items without need for scrolling.
|
|
90 |
*/
|
|
91 |
private final int SEARCH_RESULT_FIELD_HEIGHT = 150;
|
|
92 |
|
|
93 |
private TableViewer tableViewer;
|
|
94 |
|
|
95 |
private APIDataTaskList taskList = null;
|
|
96 |
|
|
97 |
// private APIShortDescription shortDescription = null;
|
|
98 |
|
|
99 |
//
|
|
100 |
// Setting static data section for HTML data shown in the browser component
|
|
101 |
//
|
|
102 |
private final String HTML_DATA_BODY_STYLE = "body {margin-left: 0px;margin-right: 0px;margin-top: 0px;margin-bottom: 0px;}"; //$NON-NLS-1$
|
|
103 |
|
|
104 |
private final String HTML_DATA_TABLE_STYLE = "table{border-collapse: collapse; font-family: Tahoma; font-size: 11px}"; //$NON-NLS-1$
|
|
105 |
|
|
106 |
private final String HTML_DATA_STYLE = "<style>" + HTML_DATA_BODY_STYLE + HTML_DATA_TABLE_STYLE + "</style>"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
107 |
|
|
108 |
private final String HTML_DATA_HEAD = "<head>" + HTML_DATA_STYLE + "</head>"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
109 |
|
|
110 |
private final String HTML_DATA_HEADER = "<html>" + HTML_DATA_HEAD + "<body>"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
111 |
|
|
112 |
private final String HTML_DATA_FOOTER = "</body></html>"; //$NON-NLS-1$
|
|
113 |
|
|
114 |
private final String HTML_DATA_TABLE_START = "<table border=1 width=\"100%\" ><colgroup span=\"2\"><col width=\"30%\"></col><col width=\"70%\"></col></colgroup>"; //$NON-NLS-1$
|
|
115 |
|
|
116 |
private final String HTML_DATA_TABLE_END = "</table>"; //$NON-NLS-1$
|
|
117 |
|
|
118 |
private final String EMPTY_HTML_DOC = HTML_DATA_HEADER + HTML_DATA_FOOTER;
|
|
119 |
|
|
120 |
private static final String COMMA = ",";//$NON-NLS-1$
|
|
121 |
|
|
122 |
// boolean sourceNeeded = false;
|
|
123 |
// boolean onlyAPIInfo = false;
|
|
124 |
// int columns = 0;
|
|
125 |
|
|
126 |
int apiIndex = -1;
|
|
127 |
|
|
128 |
int otherFiledIndex = -1;
|
|
129 |
|
|
130 |
int sourceIndex = -1;
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Listener for changing how the results is shown
|
|
134 |
*/
|
|
135 |
private IResultSettingsListener resultSettingsListener;
|
|
136 |
|
|
137 |
/**
|
|
138 |
* List item for showing list of APIs
|
|
139 |
*/
|
|
140 |
// private List searchResultList;
|
|
141 |
/**
|
|
142 |
* Button to change how results are shown
|
|
143 |
*/
|
|
144 |
private Button showOnlyAPINamesBtn;
|
|
145 |
|
|
146 |
/**
|
|
147 |
* Map that stores indexes for searchResults data by searchResultList name
|
|
148 |
* (matches UI text to {@link APIShortDescription} id).
|
|
149 |
*/
|
|
150 |
private Map<String, Integer> searchResultIndexes;
|
|
151 |
|
|
152 |
/**
|
|
153 |
* Label item to be updated with API count.
|
|
154 |
*/
|
|
155 |
Label searchResultsLabel;
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Summary data to be shown in the API list.
|
|
159 |
*/
|
|
160 |
private APIShortDescription[] searchResultData;
|
|
161 |
|
|
162 |
/**
|
|
163 |
* Details data to be shown in browser control.
|
|
164 |
*/
|
|
165 |
private APIDetails details;
|
|
166 |
|
|
167 |
static int TABLE_STYLE_BITS = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL
|
|
168 |
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.RESIZE;
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Browser control for showing API details data.
|
|
172 |
*/
|
|
173 |
private Browser browserControl;
|
|
174 |
|
|
175 |
private APIQueryParameters params;
|
|
176 |
|
|
177 |
private Table table;
|
|
178 |
|
|
179 |
|
|
180 |
String[] src = { "API NAME", "SUBSYSTEM NAME", " DLL NAME", "LIB NAME",
|
|
181 |
"HEADER NAME", "CRPS KEY NAME", " ", "SOURCE" };
|
|
182 |
|
|
183 |
/**
|
|
184 |
* Constructor.
|
|
185 |
*
|
|
186 |
* @param parentComposite
|
|
187 |
* Parent composite for the created composite.
|
|
188 |
*/
|
|
189 |
public QueryResultsComposite(Composite parentComposite) {
|
|
190 |
super(parentComposite);
|
|
191 |
}
|
|
192 |
|
|
193 |
/*
|
|
194 |
* (non-Javadoc)
|
|
195 |
*
|
|
196 |
* @see com.nokia.s60tools.apiquery.ui.views.main.AbstractTabComposite#createLayout()
|
|
197 |
*/
|
|
198 |
protected Layout createLayout() {
|
|
199 |
return new GridLayout(COLUMN_COUNT, false);
|
|
200 |
}
|
|
201 |
|
|
202 |
/*
|
|
203 |
* (non-Javadoc)
|
|
204 |
*
|
|
205 |
* @see com.nokia.s60tools.apiquery.ui.views.main.AbstractTabComposite#createLayoutData()
|
|
206 |
*/
|
|
207 |
protected Object createLayoutData() {
|
|
208 |
return new GridData(GridData.FILL_BOTH);
|
|
209 |
}
|
|
210 |
|
|
211 |
/**
|
|
212 |
* Set context sensitive help ids to components that can have focus
|
|
213 |
*
|
|
214 |
*/
|
|
215 |
private void setContextSensitiveHelpIds() {
|
|
216 |
|
|
217 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(showOnlyAPINamesBtn,
|
|
218 |
APIQueryHelpContextIDs.API_QUERY_HELP_SEARCH_TAB);
|
|
219 |
}
|
|
220 |
|
|
221 |
private void createTableViewer() {
|
|
222 |
|
|
223 |
tableViewer = new TableViewer(table);
|
|
224 |
tableViewer.setUseHashlookup(true);
|
|
225 |
|
|
226 |
}
|
|
227 |
|
|
228 |
private void createTable(Composite parent, int numberOfColumns,
|
|
229 |
String[] columnNames) {
|
|
230 |
|
|
231 |
table = new Table(parent, TABLE_STYLE_BITS);
|
|
232 |
|
|
233 |
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
|
234 |
gridData.heightHint = SEARCH_RESULT_FIELD_HEIGHT;
|
|
235 |
table.setLayoutData(gridData);
|
|
236 |
table.setLinesVisible(true);
|
|
237 |
table.setHeaderVisible(true);
|
|
238 |
|
|
239 |
table.addSelectionListener(new SelectionListener() {
|
|
240 |
|
|
241 |
public void widgetDefaultSelected(SelectionEvent arg0) {
|
|
242 |
}
|
|
243 |
|
|
244 |
public void widgetSelected(SelectionEvent arg0) {
|
|
245 |
getAPIDetailsData();
|
|
246 |
}
|
|
247 |
|
|
248 |
});
|
|
249 |
|
|
250 |
int size = 150;
|
|
251 |
for (int i = 0; i < numberOfColumns; i++) {
|
|
252 |
TableColumn column = new TableColumn(table, SWT.LEFT, i);
|
|
253 |
column.setText(columnNames[i]);
|
|
254 |
column.setWidth(size);
|
|
255 |
size = size - 50;
|
|
256 |
final int j = i;
|
|
257 |
column.addListener(SWT.Selection, new Listener() {
|
|
258 |
public void handleEvent(Event event) {
|
|
259 |
TableColumn sortedColumn = table.getSortColumn();
|
|
260 |
TableColumn currentSelected = (TableColumn)event.widget;
|
|
261 |
|
|
262 |
int dir = table.getSortDirection();
|
|
263 |
if(sortedColumn == currentSelected){
|
|
264 |
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
|
|
265 |
}
|
|
266 |
else{
|
|
267 |
table.setSortColumn(currentSelected);
|
|
268 |
dir = SWT.UP;
|
|
269 |
}
|
|
270 |
|
|
271 |
if(currentSelected == table.getColumn(j))
|
|
272 |
{
|
|
273 |
tableViewer.setSorter(new DataSorter(dir, j));
|
|
274 |
}
|
|
275 |
|
|
276 |
table.setSortDirection(dir);
|
|
277 |
|
|
278 |
}
|
|
279 |
});
|
|
280 |
|
|
281 |
}
|
|
282 |
|
|
283 |
}
|
|
284 |
|
|
285 |
/*
|
|
286 |
* (non-Javadoc)
|
|
287 |
*
|
|
288 |
* @see com.nokia.s60tools.apiquery.ui.views.main.AbstractTabComposite#createControls()
|
|
289 |
*/
|
|
290 |
protected void createControls() {
|
|
291 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION,
|
|
292 |
"-- createControls() --> " + getClass().getName()); //$NON-NLS-1$
|
|
293 |
//
|
|
294 |
// Creating label and list for showing APIs found based on the query.
|
|
295 |
//
|
|
296 |
searchResultsLabel = new Label(this, SWT.HORIZONTAL | SWT.LEFT);
|
|
297 |
searchResultsLabel.setText(SEARCH_RESULTS_LABEL_TEXT + ":"); //$NON-NLS-1$
|
|
298 |
|
|
299 |
// final int listBoxStyleBits = SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL;
|
|
300 |
// searchResultList = new List(this, listBoxStyleBits);
|
|
301 |
createTable(this, 3, new String[] { " ", " ", " " });
|
|
302 |
createTableViewer();
|
|
303 |
|
|
304 |
searchResultIndexes = new HashMap<String, Integer>();
|
|
305 |
GridData listData1 = new GridData(GridData.FILL_HORIZONTAL);
|
|
306 |
listData1.heightHint = SEARCH_RESULT_FIELD_HEIGHT;
|
|
307 |
|
|
308 |
//
|
|
309 |
// Creating button to change how the results are shown
|
|
310 |
//
|
|
311 |
String desc = Messages
|
|
312 |
.getString("QueryResultsComposite.ShowOnlyAPINames_MSg"); //$NON-NLS-1$ "Show only API names";
|
|
313 |
showOnlyAPINamesBtn = new Button(this, SWT.CHECK);
|
|
314 |
showOnlyAPINamesBtn.setText(desc);
|
|
315 |
|
|
316 |
showOnlyAPINamesBtn.setSelection(APIQueryPreferences
|
|
317 |
.getShowOnlyAPINames());
|
|
318 |
showOnlyAPINamesBtn
|
|
319 |
.addSelectionListener(new ShowOnlyAPINamesSelectionListener());
|
|
320 |
|
|
321 |
//
|
|
322 |
// Creating label and browser control for showing API details for the
|
|
323 |
// selected API.
|
|
324 |
//
|
|
325 |
Label apiDetailsLabel = new Label(this, SWT.HORIZONTAL | SWT.LEFT);
|
|
326 |
apiDetailsLabel.setText(Messages
|
|
327 |
.getString("QueryResultsComposite.APIDetails_MSg")); //$NON-NLS-1$
|
|
328 |
|
|
329 |
// Browser control does not seem to support SWT.BORDER style bit.
|
|
330 |
// Therefore need to add separate border component.
|
|
331 |
Composite browserBorder = new Composite(this, SWT.BORDER);
|
|
332 |
FillLayout borderLayout = new FillLayout(SWT.VERTICAL | SWT.HORIZONTAL);
|
|
333 |
browserBorder.setLayout(borderLayout);
|
|
334 |
browserBorder.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
335 |
|
|
336 |
// Adding browser control
|
|
337 |
browserControl = new Browser(browserBorder, SWT.NONE);
|
|
338 |
|
|
339 |
browserControl.addLocationListener(new LocationListener() {
|
|
340 |
|
|
341 |
public void changed(LocationEvent arg0) {
|
|
342 |
|
|
343 |
}
|
|
344 |
|
|
345 |
public void changing(LocationEvent arg0) {
|
|
346 |
|
|
347 |
// //get the setting
|
|
348 |
final ISearchMethodExtension serachMethod = UserSettings
|
|
349 |
.getInstance().getCurrentlySelectedSearchMethod();
|
|
350 |
|
|
351 |
if (!arg0.location.contains("about:blank")) {
|
|
352 |
|
|
353 |
arg0.doit = false;
|
|
354 |
final String headerName = arg0.location.substring(2,
|
|
355 |
arg0.location.length()).trim();
|
|
356 |
String apidetailsName = "Name";
|
|
357 |
if (serachMethod.isAsyncQueryPreferred())
|
|
358 |
apidetailsName = "API Name";
|
|
359 |
APIDetailField det = details.getDetail(apidetailsName);
|
|
360 |
|
|
361 |
serachMethod.openHeaderFile(headerName, det.getValue()
|
|
362 |
.trim());
|
|
363 |
|
|
364 |
}
|
|
365 |
}
|
|
366 |
});
|
|
367 |
|
|
368 |
setContextSensitiveHelpIds();
|
|
369 |
}
|
|
370 |
|
|
371 |
/**
|
|
372 |
* Class that listens button state changes and updates preferences and
|
|
373 |
* results composite
|
|
374 |
*/
|
|
375 |
private class ShowOnlyAPINamesSelectionListener implements
|
|
376 |
SelectionListener {
|
|
377 |
|
|
378 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
379 |
}
|
|
380 |
|
|
381 |
public void widgetSelected(SelectionEvent e) {
|
|
382 |
|
|
383 |
// Setting selection preferences
|
|
384 |
// APIQueryPreferences.setShowOnlyAPINames(showOnlyAPINamesBtn.getSelection());
|
|
385 |
// Update view, do not get information again from data source, but
|
|
386 |
// just update data
|
|
387 |
resultSettingsListener.resultSettingsChanged();
|
|
388 |
|
|
389 |
}
|
|
390 |
|
|
391 |
}
|
|
392 |
|
|
393 |
/**
|
|
394 |
* Converts API details into html-data.
|
|
395 |
*
|
|
396 |
* @param details
|
|
397 |
* API details object to be converted.
|
|
398 |
* @return
|
|
399 |
*/
|
|
400 |
private String buildHtmlDataFromDetails(APIDetails details) {
|
|
401 |
StringBuffer htmlTextBuf = new StringBuffer();
|
|
402 |
|
|
403 |
htmlTextBuf.append(HTML_DATA_HEADER);
|
|
404 |
|
|
405 |
// Appending table start
|
|
406 |
htmlTextBuf.append(HTML_DATA_TABLE_START);
|
|
407 |
|
|
408 |
// Converting API details into html data
|
|
409 |
for (APIDetailField detailField : details) {
|
|
410 |
// System.out.println("datailValue" + detailField.getValue() + "
|
|
411 |
// getdesc" + detailField.getDescription());
|
|
412 |
convertSingleDetailField(detailField, htmlTextBuf);
|
|
413 |
}
|
|
414 |
|
|
415 |
// Appending table end
|
|
416 |
htmlTextBuf.append(HTML_DATA_TABLE_END);
|
|
417 |
htmlTextBuf.append(HTML_DATA_FOOTER);
|
|
418 |
|
|
419 |
|
|
420 |
return htmlTextBuf.toString();
|
|
421 |
}
|
|
422 |
|
|
423 |
/**
|
|
424 |
* @param field
|
|
425 |
* @param htmlTextBuf
|
|
426 |
*/
|
|
427 |
private void convertSingleDetailField(APIDetailField field,
|
|
428 |
StringBuffer htmlTextBuf) {
|
|
429 |
String desc = field.getDescription();
|
|
430 |
String val = field.getValue();
|
|
431 |
// System.out.println("values" +val);
|
|
432 |
|
|
433 |
htmlTextBuf.append("<tr><td><b>"); //$NON-NLS-1$
|
|
434 |
htmlTextBuf.append(desc);
|
|
435 |
htmlTextBuf.append(":</b></td><td>"); //$NON-NLS-1$
|
|
436 |
|
|
437 |
boolean isSelectedSearchType = getIsSelectedSearchType(desc);
|
|
438 |
// String what user was set to be searched
|
|
439 |
String[] serachStrings = params.getSearchString().split(";");
|
|
440 |
String searchString = params.getSearchString();
|
|
441 |
// Checking if empty string was searched (empty search lists all)
|
|
442 |
boolean isEmptySearchString = false;
|
|
443 |
if (searchString == null || searchString.trim().equals("")) {//$NON-NLS-1$
|
|
444 |
isEmptySearchString = true;
|
|
445 |
}
|
|
446 |
boolean isValueContainingSearchString = false;
|
|
447 |
|
|
448 |
for (int i = 0; i < serachStrings.length; i++) {
|
|
449 |
String temp = serachStrings[i].trim();
|
|
450 |
isValueContainingSearchString = isValueContainingSearchString(val,
|
|
451 |
temp);
|
|
452 |
if (isValueContainingSearchString) {
|
|
453 |
searchString = temp;
|
|
454 |
break;
|
|
455 |
}
|
|
456 |
}
|
|
457 |
|
|
458 |
// get the setting
|
|
459 |
ISearchMethodExtension serachMethod = UserSettings.getInstance()
|
|
460 |
.getCurrentlySelectedSearchMethod();
|
|
461 |
|
|
462 |
// Checking search criteria and set matching search string as red when
|
|
463 |
// found
|
|
464 |
if (!isEmptySearchString && isSelectedSearchType
|
|
465 |
&& isValueContainingSearchString) {
|
|
466 |
String[] vals = val.split(COMMA);
|
|
467 |
for (int i = 0; i < vals.length; i++) {
|
|
468 |
|
|
469 |
if (vals[i].toLowerCase().indexOf(searchString.toLowerCase()) != -1) {
|
|
470 |
String s = "<font color=\"red\">" + vals[i] + "</font>";
|
|
471 |
if (params.getQueryType() == APIQueryParameters.QUERY_BY_HEADER_NAME
|
|
472 |
&& serachMethod.serachHeaderLinkEnable())
|
|
473 |
s = "<a href=\"file://" + vals[i] + "\">" + s + "</a>";
|
|
474 |
//System.out.println("link" + s);
|
|
475 |
htmlTextBuf.append(s);//$NON-NLS-1$ //$NON-NLS-2$
|
|
476 |
} else {
|
|
477 |
htmlTextBuf.append(vals[i]);
|
|
478 |
}
|
|
479 |
if (i < (vals.length - 1)) {
|
|
480 |
htmlTextBuf.append(COMMA);
|
|
481 |
}
|
|
482 |
}
|
|
483 |
} else {
|
|
484 |
htmlTextBuf.append(val);
|
|
485 |
}
|
|
486 |
|
|
487 |
htmlTextBuf.append("</td></tr>"); //$NON-NLS-1$
|
|
488 |
|
|
489 |
}
|
|
490 |
|
|
491 |
/**
|
|
492 |
* Check if value contains search string (case in sensitive)
|
|
493 |
*
|
|
494 |
* @param val
|
|
495 |
* @param searchString
|
|
496 |
* @return <code>true</code> if val contains searchString, false
|
|
497 |
* othrewise.
|
|
498 |
*/
|
|
499 |
private boolean isValueContainingSearchString(String val,
|
|
500 |
String searchString) {
|
|
501 |
return val != null
|
|
502 |
&& val.toLowerCase().contains(searchString.toLowerCase());
|
|
503 |
}
|
|
504 |
|
|
505 |
/**
|
|
506 |
* Check if given string is same as selected search type
|
|
507 |
*
|
|
508 |
* @param desc
|
|
509 |
* @return <code>true</code> if is, <code>false</code> otherwise.
|
|
510 |
*/
|
|
511 |
private boolean getIsSelectedSearchType(String desc) {
|
|
512 |
// UI name in API Details for selected search type
|
|
513 |
String searchTypeInReport = UserSettings.getInstance()
|
|
514 |
.getCurrentlySelectedSearchMethod()
|
|
515 |
.getAPIDetailNameInDetailsByQueryType(params.getQueryType());
|
|
516 |
// Check if this value is same type as users search criteria
|
|
517 |
boolean isSelectedSearchType = searchTypeInReport
|
|
518 |
.equalsIgnoreCase(desc);
|
|
519 |
return isSelectedSearchType;
|
|
520 |
}
|
|
521 |
|
|
522 |
/**
|
|
523 |
* Updates summary field with the queried data. If only one result was
|
|
524 |
* found, API Details for that API is shown.
|
|
525 |
*
|
|
526 |
* @param summaryDataColl
|
|
527 |
* API summary data to be shown.
|
|
528 |
*/
|
|
529 |
public void updateAPIShortDescriptionData(
|
|
530 |
Collection<APIShortDescription> summaryDataColl,
|
|
531 |
APIQueryParameters params) {
|
|
532 |
|
|
533 |
|
|
534 |
// boolean sourceNeeded = false;
|
|
535 |
boolean onlyAPIInfo = false;
|
|
536 |
|
|
537 |
apiIndex = -1;
|
|
538 |
otherFiledIndex = -1;
|
|
539 |
sourceIndex = -1;
|
|
540 |
|
|
541 |
if (!params.isDetailsMentToAddToDescriptions()
|
|
542 |
|| params.getQueryType() == APIQueryParameters.QUERY_BY_API_NAME) {
|
|
543 |
onlyAPIInfo = true;
|
|
544 |
}
|
|
545 |
|
|
546 |
int columns = 1;
|
|
547 |
|
|
548 |
if (!onlyAPIInfo)
|
|
549 |
++columns;
|
|
550 |
|
|
551 |
if (APIQueryPreferences.getShowDataSourceInResults())
|
|
552 |
columns++;
|
|
553 |
|
|
554 |
int[] indicies = new int[3];
|
|
555 |
|
|
556 |
indicies[2] = src.length - 2;
|
|
557 |
|
|
558 |
if (columns == 3) {
|
|
559 |
indicies[0] = (params.getQueryType() - 1);
|
|
560 |
indicies[1] = 0;
|
|
561 |
indicies[2] = src.length - 1;
|
|
562 |
otherFiledIndex = 0;
|
|
563 |
apiIndex = 1;
|
|
564 |
sourceIndex = 2;
|
|
565 |
|
|
566 |
} else if (columns == 2) {
|
|
567 |
if (APIQueryPreferences.getShowDataSourceInResults() && onlyAPIInfo) {
|
|
568 |
|
|
569 |
indicies[0] = 0;
|
|
570 |
indicies[1] = src.length - 1;
|
|
571 |
|
|
572 |
apiIndex = 0;
|
|
573 |
sourceIndex = 1;
|
|
574 |
} else {
|
|
575 |
indicies[0] = params.getQueryType() - 1;
|
|
576 |
indicies[1] = 0;
|
|
577 |
otherFiledIndex = 0;
|
|
578 |
apiIndex = 1;
|
|
579 |
}
|
|
580 |
|
|
581 |
}
|
|
582 |
|
|
583 |
else {
|
|
584 |
indicies[0] = 0;
|
|
585 |
indicies[1] = src.length - 2;
|
|
586 |
apiIndex = 0;
|
|
587 |
}
|
|
588 |
|
|
589 |
|
|
590 |
TableColumn[] tableColumns = table.getColumns();
|
|
591 |
for (int i = 0; i < tableColumns.length; i++) {
|
|
592 |
tableColumns[i].setText(src[indicies[i]]);
|
|
593 |
|
|
594 |
}
|
|
595 |
|
|
596 |
// add the contents to table
|
|
597 |
|
|
598 |
this.params = params;
|
|
599 |
// Clearing...
|
|
600 |
// searchResultList.removeAll();
|
|
601 |
searchResultIndexes.clear();
|
|
602 |
|
|
603 |
// Storing the data
|
|
604 |
searchResultData = summaryDataColl.toArray(new APIShortDescription[0]);
|
|
605 |
taskList = new APIDataTaskList();
|
|
606 |
|
|
607 |
// Populating the list
|
|
608 |
for (int i = 0; i < searchResultData.length; i++) {
|
|
609 |
|
|
610 |
APIShortDescription summary = searchResultData[i];
|
|
611 |
String shortUIText = summary.getName();
|
|
612 |
|
|
613 |
// Checking if Data source should add to item
|
|
614 |
if (APIQueryPreferences.getShowDataSourceInResults()) {
|
|
615 |
|
|
616 |
shortUIText += " [" + summary.getSourceDescription() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
617 |
}
|
|
618 |
|
|
619 |
// Checking from preferences should we show only API Names or also
|
|
620 |
// queried items
|
|
621 |
// if we want only API Names, just adding text to list. When API
|
|
622 |
// Name is search criteria, only API Names will be added anyway.
|
|
623 |
if (!params.isDetailsMentToAddToDescriptions()
|
|
624 |
|| params.getQueryType() == APIQueryParameters.QUERY_BY_API_NAME) {
|
|
625 |
|
|
626 |
taskList
|
|
627 |
.addTask(new APITask(
|
|
628 |
new String[] {
|
|
629 |
summary.getName(),
|
|
630 |
(APIQueryPreferences
|
|
631 |
.getShowDataSourceInResults()) ? summary
|
|
632 |
.getSourceDescription()
|
|
633 |
: " ", " " }));
|
|
634 |
|
|
635 |
// searchResultList.add(shortUIText); //$NON-NLS-1$
|
|
636 |
// //$NON-NLS-2$
|
|
637 |
searchResultIndexes.put(shortUIText, new Integer(i));
|
|
638 |
}
|
|
639 |
// If details for query type is ment to add for list, getting items
|
|
640 |
// that match for query
|
|
641 |
else {
|
|
642 |
String[] queriedMatchingItems = getQueriedMatchingItemNames(
|
|
643 |
summary, params.getSearchString());
|
|
644 |
if (queriedMatchingItems != null) {
|
|
645 |
for (int j = 0; j < queriedMatchingItems.length; j++) {
|
|
646 |
taskList
|
|
647 |
.addTask(new APITask(
|
|
648 |
new String[] {
|
|
649 |
queriedMatchingItems[j],
|
|
650 |
summary.getName(),
|
|
651 |
(APIQueryPreferences
|
|
652 |
.getShowDataSourceInResults()) ? summary
|
|
653 |
.getSourceDescription()
|
|
654 |
: " " }));
|
|
655 |
String longUIText = "[" + queriedMatchingItems[j] + "] in " + shortUIText; //$NON-NLS-1$ //$NON-NLS-2$
|
|
656 |
// searchResultList.add(longUIText);
|
|
657 |
searchResultIndexes.put(longUIText, new Integer(i));
|
|
658 |
|
|
659 |
}
|
|
660 |
}
|
|
661 |
}// else
|
|
662 |
} // if
|
|
663 |
|
|
664 |
tableViewer.setContentProvider(new APIContentProvider());
|
|
665 |
tableViewer.setLabelProvider(new DataLabelProvider());
|
|
666 |
|
|
667 |
// The input for the table viewer is the instance of ExampleTaskList
|
|
668 |
|
|
669 |
tableViewer.setInput(taskList);
|
|
670 |
|
|
671 |
searchResultsLabel.setText(SEARCH_RESULTS_LABEL_TEXT
|
|
672 |
+ " (" + Messages.getString("QueryResultsComposite.Found_Msg") //$NON-NLS-1$ //$NON-NLS-2$
|
|
673 |
+ table.getItemCount() + " " //$NON-NLS-1$
|
|
674 |
+ SEARCH_RESULTS_LABEL_API_TEXT + "):"); //$NON-NLS-1$
|
|
675 |
searchResultsLabel.pack(); // Adjusting the label size to match new
|
|
676 |
|
|
677 |
// If we have only one result, that will be selected automatically
|
|
678 |
if (table.getItemCount() == 1) {
|
|
679 |
table.setSelection(0);
|
|
680 |
getAPIDetailsData();
|
|
681 |
}
|
|
682 |
|
|
683 |
// update the serachstring for the serached query
|
|
684 |
|
|
685 |
}
|
|
686 |
|
|
687 |
/**
|
|
688 |
* @param summary
|
|
689 |
* @param searchString
|
|
690 |
* @return list of
|
|
691 |
*/
|
|
692 |
private String[] getQueriedMatchingItemNames(APIShortDescription summary,
|
|
693 |
String searchString) {
|
|
694 |
|
|
695 |
String[] ars = searchString.split(";");
|
|
696 |
|
|
697 |
ArrayList<String> results = new ArrayList<String>();
|
|
698 |
if (UserSettings.getInstance().getCurrentlySelectedSearchMethod()
|
|
699 |
.isAsyncQueryPreferred()) {
|
|
700 |
|
|
701 |
ArrayList<String> data = summary.getSearchedData();
|
|
702 |
for (int i = 0; i < data.size(); i++) {
|
|
703 |
for (int j = 0; j < ars.length; j++) {
|
|
704 |
if (data.get(i).toLowerCase().contains(
|
|
705 |
ars[j].trim().toLowerCase()))
|
|
706 |
results.add(data.get(i).trim());
|
|
707 |
}
|
|
708 |
|
|
709 |
}
|
|
710 |
return (String[]) results.toArray(new String[0]);
|
|
711 |
}
|
|
712 |
|
|
713 |
// Details can be allreay stored to summary, if so, we don't need to get
|
|
714 |
// details again
|
|
715 |
APIDetails det = null;
|
|
716 |
if (summary.hasAPIDetails()) {
|
|
717 |
det = summary.getAPIDetails();
|
|
718 |
} else {
|
|
719 |
try {
|
|
720 |
// Get currenty selected search method extension
|
|
721 |
// get api details
|
|
722 |
det = UserSettings.getInstance()
|
|
723 |
.getCurrentlySelectedSearchMethod().getAPIDetails(
|
|
724 |
summary);
|
|
725 |
} catch (QueryOperationFailedException e) {
|
|
726 |
APIQueryConsole
|
|
727 |
.getInstance()
|
|
728 |
.println(
|
|
729 |
Messages
|
|
730 |
.getString("QueryResultsComposite.UnableToGetAPIDetails_ErrMsg_Part1") + summary.getName() + Messages.getString("QueryResultsComposite.UnableToGetAPIDetails_ErrMsg_Part2") + e, APIQueryConsole.MSG_ERROR); //$NON-NLS-1$ //$NON-NLS-2$
|
|
731 |
return null;
|
|
732 |
}
|
|
733 |
}
|
|
734 |
|
|
735 |
// ArrayList<String> results = new ArrayList<String>();
|
|
736 |
|
|
737 |
// Converting API details into fields and checking matching items by API
|
|
738 |
// Query params
|
|
739 |
for (APIDetailField field : det) {
|
|
740 |
// Checking if there matching items
|
|
741 |
String desc = field.getDescription();
|
|
742 |
String val = field.getValue();
|
|
743 |
boolean isSelectedSearchType = getIsSelectedSearchType(desc);
|
|
744 |
if (isSelectedSearchType) {
|
|
745 |
String[] vals = val.split(COMMA);
|
|
746 |
for (int i = 0; i < vals.length; i++) {
|
|
747 |
for (int j = 0; j < ars.length; j++) {
|
|
748 |
boolean isValueContainingSearchString = isValueContainingSearchString(
|
|
749 |
vals[i], ars[j].trim());
|
|
750 |
// Add matching item to results
|
|
751 |
if (isValueContainingSearchString) {
|
|
752 |
// System.out.println("values : "+ vals[i]);
|
|
753 |
results.add(vals[i].trim());
|
|
754 |
}
|
|
755 |
}
|
|
756 |
}
|
|
757 |
}
|
|
758 |
|
|
759 |
}
|
|
760 |
return (String[]) results.toArray(new String[0]);
|
|
761 |
|
|
762 |
}
|
|
763 |
|
|
764 |
/**
|
|
765 |
* Gets API details for the API selected from the API list. Shows busy
|
|
766 |
* cursor to user during the operation.
|
|
767 |
*/
|
|
768 |
private void getAPIDetailsData() {
|
|
769 |
|
|
770 |
final QueryErrorInfo errInfo = new QueryErrorInfo();
|
|
771 |
|
|
772 |
Runnable performAPIDetailsQueryRunnable = new Runnable() {
|
|
773 |
public void run() {
|
|
774 |
performAPIDetailsQuery(errInfo);
|
|
775 |
}
|
|
776 |
};
|
|
777 |
|
|
778 |
// Showing busy cursor during operation
|
|
779 |
Display d = APIQueryPlugin.getCurrentlyActiveWbWindowShell()
|
|
780 |
.getDisplay();
|
|
781 |
BusyIndicator.showWhile(d, performAPIDetailsQueryRunnable);
|
|
782 |
|
|
783 |
// Did we succeed?
|
|
784 |
if (details != null) {
|
|
785 |
// Populating browser control with the HTML formatted data.
|
|
786 |
browserControl.setText(buildHtmlDataFromDetails(details));
|
|
787 |
} else {
|
|
788 |
// Something failed
|
|
789 |
String errMsg = Messages
|
|
790 |
.getString("QueryResultsComposite.APIDetailsQueryFailde_ErrMsg") + errInfo.getErrorDescription(); //$NON-NLS-1$
|
|
791 |
APIQueryConsole.getInstance().println(errMsg,
|
|
792 |
APIQueryConsole.MSG_ERROR);
|
|
793 |
APIQueryMessageBox mbox = new APIQueryMessageBox(errMsg,
|
|
794 |
SWT.ICON_ERROR | SWT.OK);
|
|
795 |
mbox.open();
|
|
796 |
}
|
|
797 |
}
|
|
798 |
|
|
799 |
/**
|
|
800 |
* Performs the actual API details query.
|
|
801 |
*
|
|
802 |
* @param errInfo
|
|
803 |
* Error info to be filled in error situation.
|
|
804 |
*/
|
|
805 |
private void performAPIDetailsQuery(QueryErrorInfo errInfo) {
|
|
806 |
|
|
807 |
// details = null; // Resetting previous searches
|
|
808 |
// check if the details already in localstorage
|
|
809 |
// int currSelIndex = searchResultList.getSelectionIndex();
|
|
810 |
|
|
811 |
// details=(APIDetails)apiDetailsStorage.elementAt(currSelIndex);
|
|
812 |
// if(details!=null)return;
|
|
813 |
|
|
814 |
// Table data
|
|
815 |
|
|
816 |
TableItem[] ar = table.getSelection();
|
|
817 |
String shortUIText = ar[0].getText(apiIndex).trim();
|
|
818 |
if (sourceIndex != -1)
|
|
819 |
shortUIText += " [" + ar[0].getText(sourceIndex).trim() + "]";
|
|
820 |
if (otherFiledIndex != -1)
|
|
821 |
shortUIText = "[" + ar[0].getText(0).trim() + "] in " + shortUIText;
|
|
822 |
|
|
823 |
// //////
|
|
824 |
|
|
825 |
// String s = searchResultList.getItems()[currSelIndex];
|
|
826 |
// System.out.println("Text in secrh res infices : " + s);
|
|
827 |
// Not getting ID from list directly, because same API can be there
|
|
828 |
// multiple times, ID is taken from indexes list
|
|
829 |
// int currShortDescIndex = searchResultIndexes.get(searchResultList
|
|
830 |
// .getItems()[currSelIndex]);
|
|
831 |
|
|
832 |
int currShortDescIndex = searchResultIndexes.get(shortUIText);
|
|
833 |
|
|
834 |
APIShortDescription summary = searchResultData[currShortDescIndex];
|
|
835 |
// shortDescription = summary;
|
|
836 |
|
|
837 |
// API Details can be already stored in summary, if so, we don't need
|
|
838 |
// get details again
|
|
839 |
if (summary.hasAPIDetails()) {
|
|
840 |
details = summary.getAPIDetails();
|
|
841 |
}
|
|
842 |
// Else get api details by using selected search method extension
|
|
843 |
else {
|
|
844 |
ISearchMethodExtension currSelExt = UserSettings.getInstance()
|
|
845 |
.getCurrentlySelectedSearchMethod();
|
|
846 |
try {
|
|
847 |
details = currSelExt.getAPIDetails(summary);
|
|
848 |
summary.setAPIDetails(details);
|
|
849 |
} catch (QueryOperationFailedException e) {
|
|
850 |
errInfo.setErrorDescription(e.getMessage());
|
|
851 |
}
|
|
852 |
}
|
|
853 |
|
|
854 |
}
|
|
855 |
|
|
856 |
/**
|
|
857 |
* Clears all the previously shown data.
|
|
858 |
*/
|
|
859 |
public void clear() {
|
|
860 |
// Clearing summary data
|
|
861 |
// searchResultList.removeAll();
|
|
862 |
table.removeAll();
|
|
863 |
// taskList.removeTaksList();
|
|
864 |
// tableViewer.setInput(taskList);
|
|
865 |
// Clearing found APIs count
|
|
866 |
searchResultsLabel.setText(SEARCH_RESULTS_LABEL_TEXT + ":"); //$NON-NLS-1$
|
|
867 |
// Clearing details data
|
|
868 |
browserControl.setText(EMPTY_HTML_DOC);
|
|
869 |
}
|
|
870 |
|
|
871 |
/*
|
|
872 |
* (non-Javadoc)
|
|
873 |
*
|
|
874 |
* @see org.eclipse.swt.widgets.Widget#dispose()
|
|
875 |
*/
|
|
876 |
public void dispose() {
|
|
877 |
super.dispose();
|
|
878 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION,
|
|
879 |
"-- Dispose() --> " + getClass().getName()); //$NON-NLS-1$
|
|
880 |
}
|
|
881 |
|
|
882 |
/**
|
|
883 |
* Check if show only api names is selected
|
|
884 |
*
|
|
885 |
* @return <code>true</code> if Show only API names is selected
|
|
886 |
* <code>false</code> otherwise.
|
|
887 |
*/
|
|
888 |
public boolean isShowOnlyAPINamesSelected() {
|
|
889 |
return showOnlyAPINamesBtn.getSelection();
|
|
890 |
}
|
|
891 |
|
|
892 |
/**
|
|
893 |
* Adds listener that listens for result setting changes.
|
|
894 |
*
|
|
895 |
* @param searchTabUIFieldsMediator
|
|
896 |
* Result settings changes listener
|
|
897 |
*/
|
|
898 |
public void setResultSettingsListener(
|
|
899 |
IResultSettingsListener resultSettingsListener) {
|
|
900 |
this.resultSettingsListener = resultSettingsListener;
|
|
901 |
}
|
|
902 |
|
|
903 |
/**
|
|
904 |
* InnerClass that acts as a proxy for the ExampleTaskList providing content
|
|
905 |
* for the Table. It implements the ITaskListViewer interface since it must
|
|
906 |
* register changeListeners with the ExampleTaskList
|
|
907 |
*/
|
|
908 |
class APIContentProvider implements IStructuredContentProvider {
|
|
909 |
|
|
910 |
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
|
911 |
|
|
912 |
}
|
|
913 |
|
|
914 |
public void dispose() {
|
|
915 |
|
|
916 |
}
|
|
917 |
|
|
918 |
// Return the tasks as an array of Objects
|
|
919 |
public Object[] getElements(Object parent) {
|
|
920 |
return taskList.getTasks().toArray();
|
|
921 |
}
|
|
922 |
|
|
923 |
}
|
|
924 |
|
|
925 |
}
|