|
Lines 10-15
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.internal.dialogs; |
11 |
package org.eclipse.ui.internal.dialogs; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.ArrayList; |
| 14 |
import java.util.List; |
| 15 |
|
| 13 |
import org.eclipse.core.runtime.IProgressMonitor; |
16 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 14 |
import org.eclipse.core.runtime.IStatus; |
17 |
import org.eclipse.core.runtime.IStatus; |
| 15 |
import org.eclipse.core.runtime.Status; |
18 |
import org.eclipse.core.runtime.Status; |
|
Lines 17-22
Link Here
|
| 17 |
import org.eclipse.jface.action.Action; |
20 |
import org.eclipse.jface.action.Action; |
| 18 |
import org.eclipse.jface.action.IAction; |
21 |
import org.eclipse.jface.action.IAction; |
| 19 |
import org.eclipse.jface.action.ToolBarManager; |
22 |
import org.eclipse.jface.action.ToolBarManager; |
|
|
23 |
import org.eclipse.jface.dialogs.IDialogSettings; |
| 20 |
import org.eclipse.jface.resource.ImageDescriptor; |
24 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 21 |
import org.eclipse.jface.resource.JFaceResources; |
25 |
import org.eclipse.jface.resource.JFaceResources; |
| 22 |
import org.eclipse.jface.viewers.TreeViewer; |
26 |
import org.eclipse.jface.viewers.TreeViewer; |
|
Lines 24-43
Link Here
|
| 24 |
import org.eclipse.swt.SWT; |
28 |
import org.eclipse.swt.SWT; |
| 25 |
import org.eclipse.swt.accessibility.AccessibleAdapter; |
29 |
import org.eclipse.swt.accessibility.AccessibleAdapter; |
| 26 |
import org.eclipse.swt.accessibility.AccessibleEvent; |
30 |
import org.eclipse.swt.accessibility.AccessibleEvent; |
|
|
31 |
import org.eclipse.swt.events.ControlAdapter; |
| 32 |
import org.eclipse.swt.events.ControlEvent; |
| 27 |
import org.eclipse.swt.events.DisposeEvent; |
33 |
import org.eclipse.swt.events.DisposeEvent; |
| 28 |
import org.eclipse.swt.events.DisposeListener; |
34 |
import org.eclipse.swt.events.DisposeListener; |
|
|
35 |
import org.eclipse.swt.events.FocusAdapter; |
| 29 |
import org.eclipse.swt.events.FocusEvent; |
36 |
import org.eclipse.swt.events.FocusEvent; |
| 30 |
import org.eclipse.swt.events.FocusListener; |
37 |
import org.eclipse.swt.events.FocusListener; |
| 31 |
import org.eclipse.swt.events.KeyAdapter; |
38 |
import org.eclipse.swt.events.KeyAdapter; |
| 32 |
import org.eclipse.swt.events.KeyEvent; |
39 |
import org.eclipse.swt.events.KeyEvent; |
|
|
40 |
import org.eclipse.swt.events.SelectionAdapter; |
| 41 |
import org.eclipse.swt.events.SelectionEvent; |
| 42 |
import org.eclipse.swt.events.TraverseEvent; |
| 43 |
import org.eclipse.swt.events.TraverseListener; |
| 33 |
import org.eclipse.swt.graphics.Color; |
44 |
import org.eclipse.swt.graphics.Color; |
|
|
45 |
import org.eclipse.swt.graphics.Font; |
| 46 |
import org.eclipse.swt.graphics.Point; |
| 47 |
import org.eclipse.swt.graphics.Rectangle; |
| 34 |
import org.eclipse.swt.layout.GridData; |
48 |
import org.eclipse.swt.layout.GridData; |
| 35 |
import org.eclipse.swt.layout.GridLayout; |
49 |
import org.eclipse.swt.layout.GridLayout; |
| 36 |
import org.eclipse.swt.widgets.Composite; |
50 |
import org.eclipse.swt.widgets.Composite; |
|
|
51 |
import org.eclipse.swt.widgets.Display; |
| 52 |
import org.eclipse.swt.widgets.Event; |
| 53 |
import org.eclipse.swt.widgets.Listener; |
| 54 |
import org.eclipse.swt.widgets.Shell; |
| 55 |
import org.eclipse.swt.widgets.Table; |
| 56 |
import org.eclipse.swt.widgets.TableItem; |
| 37 |
import org.eclipse.swt.widgets.Text; |
57 |
import org.eclipse.swt.widgets.Text; |
| 38 |
import org.eclipse.swt.widgets.ToolBar; |
58 |
import org.eclipse.swt.widgets.ToolBar; |
| 39 |
import org.eclipse.ui.PlatformUI; |
59 |
import org.eclipse.ui.PlatformUI; |
| 40 |
import org.eclipse.ui.internal.WorkbenchMessages; |
60 |
import org.eclipse.ui.internal.WorkbenchMessages; |
|
|
61 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
| 41 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
62 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
| 42 |
import org.eclipse.ui.progress.WorkbenchJob; |
63 |
import org.eclipse.ui.progress.WorkbenchJob; |
| 43 |
|
64 |
|
|
Lines 52-57
Link Here
|
| 52 |
|
73 |
|
| 53 |
protected Text filterText; |
74 |
protected Text filterText; |
| 54 |
|
75 |
|
|
|
76 |
//A list contains all strings in search history |
| 77 |
protected List searchHistory; |
| 78 |
|
| 79 |
//A key to match dialogsetting value |
| 80 |
protected static final String SEARCHHISTORY = "search"; //$NON-NLS-1$ |
| 81 |
|
| 82 |
//A table which contains only strings begin with typed string(s) |
| 83 |
private Table currentSeachTable; |
| 84 |
|
| 85 |
private Shell shell; |
| 86 |
|
| 55 |
private ToolBarManager filterToolBar; |
87 |
private ToolBarManager filterToolBar; |
| 56 |
|
88 |
|
| 57 |
protected TreeViewer treeViewer; |
89 |
protected TreeViewer treeViewer; |
|
Lines 148-153
Link Here
|
| 148 |
treeViewer = new TreeViewer(this, treeStyle); |
180 |
treeViewer = new TreeViewer(this, treeStyle); |
| 149 |
data = new GridData(GridData.FILL_BOTH); |
181 |
data = new GridData(GridData.FILL_BOTH); |
| 150 |
treeViewer.getControl().setLayoutData(data); |
182 |
treeViewer.getControl().setLayoutData(data); |
|
|
183 |
treeViewer.getControl().addFocusListener(new FocusAdapter(){ |
| 184 |
/* Each time the tree gains focus, the current text in filterText is saved as search history |
| 185 |
* @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent) |
| 186 |
*/ |
| 187 |
public void focusGained(FocusEvent e) { |
| 188 |
String newText = filterText.getText(); |
| 189 |
Object[] textValues = searchHistory.toArray(); |
| 190 |
|
| 191 |
if((newText.equals(""))||(newText.equals(initialText)))//$NON-NLS-1$ |
| 192 |
return; |
| 193 |
|
| 194 |
for (int i = 0; i < textValues.length; i++) { |
| 195 |
if(((String)textValues[i]).equals(newText)) |
| 196 |
return; |
| 197 |
} |
| 198 |
searchHistory.add(newText); |
| 199 |
} |
| 200 |
}); |
| 201 |
|
| 151 |
treeViewer.getControl().addDisposeListener(new DisposeListener(){ |
202 |
treeViewer.getControl().addDisposeListener(new DisposeListener(){ |
| 152 |
/* (non-Javadoc) |
203 |
/* (non-Javadoc) |
| 153 |
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) |
204 |
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) |
|
Lines 206-238
Link Here
|
| 206 |
/** |
257 |
/** |
| 207 |
* Create the filter control. |
258 |
* Create the filter control. |
| 208 |
*/ |
259 |
*/ |
| 209 |
protected void createFilterControl(Composite parent) { |
260 |
protected void createFilterControl(final Composite parent) { |
| 210 |
filterText = new Text(parent, SWT.SINGLE | SWT.BORDER); |
261 |
|
| 211 |
filterText.getAccessible().addAccessibleListener(getAccessibleListener()); |
262 |
filterText = new Text(parent, SWT.BORDER); |
| 212 |
getFilterControl().addKeyListener(getKeyListener()); |
263 |
searchHistory = getPreferenceSearchHistory(); |
| 213 |
|
264 |
|
| 214 |
} |
265 |
shell = new Shell(parent.getShell(), SWT.NO_TRIM); |
|
|
266 |
shell.setBackground(parent.getDisplay().getSystemColor( |
| 267 |
SWT.COLOR_WHITE)); |
| 268 |
GridLayout shellGL = new GridLayout(); |
| 269 |
shellGL.marginHeight = 0; |
| 270 |
shellGL.marginWidth = 0; |
| 271 |
shell.setLayout(shellGL); |
| 272 |
shell.setLayoutData(new GridData( |
| 273 |
(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL))); |
| 274 |
|
| 275 |
currentSeachTable = new Table(shell, SWT.SINGLE | SWT.BORDER); |
| 276 |
currentSeachTable.setLayoutData(new GridData( |
| 277 |
(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL))); |
| 278 |
|
| 279 |
//Make sure show all text in the horizonal space through Changing the font size of table |
| 280 |
Font font = parent.getFont(); |
| 281 |
currentSeachTable.setFont(new Font |
| 282 |
(parent.getDisplay(),font.getFontData()[0].getName(), |
| 283 |
font.getFontData()[0].getHeight()-1,font.getFontData()[0].getStyle())); |
| 284 |
|
| 285 |
filterText.addTraverseListener(new TraverseListener() { |
| 286 |
public void keyTraversed(TraverseEvent e) { |
| 287 |
if (e.detail == SWT.TRAVERSE_RETURN) { |
| 288 |
e.doit = false; |
| 289 |
shell.setVisible(false); |
| 290 |
if (getViewer().getTree().getItemCount() == 0) { |
| 291 |
Display.getCurrent().beep(); |
| 292 |
setFilterText(""); //$NON-NLS-1$ |
| 293 |
} else { |
| 294 |
getViewer().getTree().setFocus(); |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
}); |
| 299 |
|
| 300 |
/*filterText.addFocusListener(new FocusAdapter(){ |
| 301 |
Focus has been gained on the filter control. |
| 302 |
* @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent) |
| 303 |
|
| 304 |
public void focusGained(FocusEvent event) { |
| 305 |
selectAll(); |
| 306 |
|
| 307 |
} |
| 308 |
|
| 309 |
});*/ |
| 310 |
|
| 311 |
filterText.addKeyListener(new KeyAdapter() { |
| 312 |
/* |
| 313 |
* (non-Javadoc) |
| 314 |
* |
| 315 |
* @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) |
| 316 |
*/ |
| 317 |
public void keyReleased(KeyEvent e) { |
| 318 |
|
| 319 |
if (e.keyCode == SWT.ARROW_DOWN) { |
| 320 |
if (currentSeachTable.isVisible()) { |
| 321 |
// Set focus on the popup table |
| 322 |
currentSeachTable.setFocus(); |
| 323 |
currentSeachTable.setSelection(0); |
| 324 |
} else |
| 325 |
// Set focus on the left tree |
| 326 |
treeViewer.getTree().setFocus(); |
| 327 |
} else { |
| 328 |
if (e.character == SWT.CR){ |
| 329 |
int index =currentSeachTable.getSelectionIndex(); |
| 330 |
setFilterText(currentSeachTable.getItem(index).getText()); |
| 331 |
textChanged(); |
| 332 |
shell.setVisible(false); |
| 333 |
return; |
| 334 |
} |
| 335 |
textChanged(); |
| 336 |
List result = new ArrayList(); |
| 337 |
result = reduceSearch(searchHistory, filterText.getText()); |
| 338 |
updateTable(currentSeachTable, result); |
| 339 |
|
| 340 |
if (currentSeachTable.getItemCount() > 0) { |
| 341 |
Rectangle textBounds = filterText.getBounds(); |
| 342 |
|
| 343 |
setShellLocationAndSize(parent,textBounds); |
| 344 |
|
| 345 |
if (shell.isDisposed()) |
| 346 |
shell.open(); |
| 347 |
|
| 348 |
if (!shell.getVisible()) { |
| 349 |
shell.setVisible(true); |
| 350 |
filterText.setFocus(); |
| 351 |
} |
| 352 |
|
| 353 |
} else |
| 354 |
shell.setVisible(false); |
| 355 |
} |
| 356 |
|
| 357 |
} |
| 358 |
}); |
| 359 |
|
| 360 |
parent.getDisplay().addFilter(SWT.MouseDown, new Listener() { |
| 361 |
/* |
| 362 |
* Anytime the parent composit detects a mouse down event, the eventhandler will set the shell unvisible |
| 363 |
* |
| 364 |
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Events) |
| 365 |
*/ |
| 366 |
public void handleEvent(Event event) { |
| 367 |
if (!shell.isDisposed()) |
| 368 |
shell.setVisible(false); |
| 369 |
} |
| 370 |
}); |
| 371 |
|
| 372 |
getShell().addControlListener(new ControlAdapter() { |
| 373 |
/* |
| 374 |
* Move dialog also make the popup shell not visible |
| 375 |
* |
| 376 |
* @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent) |
| 377 |
*/ |
| 378 |
public void controlMoved(ControlEvent e) { |
| 379 |
shell.setVisible(false); |
| 380 |
} |
| 381 |
}); |
| 382 |
|
| 383 |
currentSeachTable.addSelectionListener(new SelectionAdapter() { |
| 384 |
/* |
| 385 |
* (non-Javadoc) |
| 386 |
* |
| 387 |
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 388 |
*/ |
| 389 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 390 |
shell.setVisible(false); |
| 391 |
} |
| 392 |
}); |
| 393 |
|
| 394 |
filterText.addDisposeListener(new DisposeListener() { |
| 395 |
/* |
| 396 |
* (non-Javadoc) |
| 397 |
* |
| 398 |
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) |
| 399 |
*/ |
| 400 |
public void widgetDisposed(DisposeEvent e) { |
| 401 |
saveDialogSettings(); |
| 402 |
} |
| 403 |
}); |
| 404 |
|
| 405 |
filterText.getAccessible().addAccessibleListener( |
| 406 |
getAccessibleListener()); |
| 215 |
|
407 |
|
| 216 |
/** |
|
|
| 217 |
* Get the key listener used for the receiver. |
| 218 |
* @return KeyListener |
| 219 |
*/ |
| 220 |
protected KeyAdapter getKeyListener() { |
| 221 |
return new KeyAdapter() { |
| 222 |
|
| 223 |
/* |
| 224 |
* (non-Javadoc) |
| 225 |
* |
| 226 |
* @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent) |
| 227 |
*/ |
| 228 |
public void keyReleased(KeyEvent e) { |
| 229 |
// on a CR we want to transfer focus to the list |
| 230 |
if(e.keyCode == SWT.ARROW_DOWN) |
| 231 |
treeViewer.getTree().setFocus(); |
| 232 |
else |
| 233 |
textChanged(); |
| 234 |
} |
| 235 |
}; |
| 236 |
} |
408 |
} |
| 237 |
|
409 |
|
| 238 |
protected AccessibleAdapter getAccessibleListener() { |
410 |
protected AccessibleAdapter getAccessibleListener() { |
|
Lines 241-247
Link Here
|
| 241 |
* @see org.eclipse.swt.accessibility.AccessibleListener#getName(org.eclipse.swt.accessibility.AccessibleEvent) |
413 |
* @see org.eclipse.swt.accessibility.AccessibleListener#getName(org.eclipse.swt.accessibility.AccessibleEvent) |
| 242 |
*/ |
414 |
*/ |
| 243 |
public void getName(AccessibleEvent e) { |
415 |
public void getName(AccessibleEvent e) { |
| 244 |
String filterTextString = getFilterText(); |
416 |
String filterTextString = getFilterControlText(); |
| 245 |
if(filterTextString.length() == 0){ |
417 |
if(filterTextString.length() == 0){ |
| 246 |
e.result = initialText; |
418 |
e.result = initialText; |
| 247 |
} |
419 |
} |
|
Lines 253-265
Link Here
|
| 253 |
} |
425 |
} |
| 254 |
|
426 |
|
| 255 |
/** |
427 |
/** |
| 256 |
* Get the text from the filter widget. |
|
|
| 257 |
* @return String |
| 258 |
*/ |
| 259 |
protected String getFilterText() { |
| 260 |
return filterText.getText(); |
| 261 |
} |
| 262 |
/** |
| 263 |
* update the receiver after the text has changed |
428 |
* update the receiver after the text has changed |
| 264 |
*/ |
429 |
*/ |
| 265 |
protected void textChanged() { |
430 |
protected void textChanged() { |
|
Lines 362-389
Link Here
|
| 362 |
*/ |
527 |
*/ |
| 363 |
public void setInitialText(String text) { |
528 |
public void setInitialText(String text) { |
| 364 |
initialText = text; |
529 |
initialText = text; |
| 365 |
setFilterText(initialText); |
530 |
setFilterText(initialText); |
| 366 |
|
531 |
textChanged(); |
| 367 |
textChanged(); |
|
|
| 368 |
listener = new FocusListener() { |
| 369 |
public void focusGained(FocusEvent event) { |
| 370 |
filterFocusGained(); |
| 371 |
} |
| 372 |
|
| 373 |
/* |
| 374 |
* (non-Javadoc) |
| 375 |
* |
| 376 |
* @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) |
| 377 |
*/ |
| 378 |
public void focusLost(FocusEvent e) { |
| 379 |
filterFocusLost(); |
| 380 |
} |
| 381 |
}; |
| 382 |
getFilterControl().addFocusListener(listener); |
| 383 |
} |
532 |
} |
| 384 |
|
533 |
|
| 385 |
|
|
|
| 386 |
|
| 387 |
protected void selectAll() { |
534 |
protected void selectAll() { |
| 388 |
filterText.selectAll(); |
535 |
filterText.selectAll(); |
| 389 |
} |
536 |
} |
|
Lines 419-438
Link Here
|
| 419 |
} |
566 |
} |
| 420 |
|
567 |
|
| 421 |
/** |
568 |
/** |
| 422 |
* Focus has been gained on the filter control. |
569 |
* Find all items which start with typed words list the list contains all |
| 423 |
* |
570 |
* strings of the search history |
|
|
571 |
* |
| 572 |
* @param list |
| 573 |
* the list to search |
| 574 |
* @param wordsEntered |
| 575 |
* String |
| 576 |
* @return a list in which all strings start from the typed letter(s) |
| 424 |
*/ |
577 |
*/ |
| 425 |
protected void filterFocusGained() { |
578 |
protected List reduceSearch(List list, String wordsEntered) { |
| 426 |
selectAll(); |
579 |
List result = new ArrayList(); |
| 427 |
getFilterControl().removeFocusListener(listener); |
580 |
if (list == null) |
|
|
581 |
return result; |
| 582 |
for (int i = 0; i < list.size(); i++) { |
| 583 |
if (filterText.getText() == "") //$NON-NLS-1$ |
| 584 |
return result; |
| 585 |
String historyString = (String) list.get(i); |
| 586 |
String typedString = wordsEntered; |
| 587 |
if (historyString.toLowerCase().startsWith(typedString.toLowerCase())) |
| 588 |
result.add(historyString); |
| 589 |
} |
| 590 |
|
| 591 |
return result; |
| 428 |
} |
592 |
} |
| 429 |
|
593 |
|
| 430 |
/** |
594 |
/** |
| 431 |
* Focus has been lost on the filter control. |
595 |
* Copy all elements from a list to a table |
| 432 |
* |
596 |
* |
|
|
597 |
* @param table |
| 598 |
* @param list |
| 433 |
*/ |
599 |
*/ |
| 434 |
protected void filterFocusLost() { |
600 |
protected void updateTable(Table table, List list) { |
|
|
601 |
table.removeAll(); |
| 602 |
if (list.size() > 0) { |
| 603 |
TableItem newItem; |
| 604 |
for (int i = 0; i < list.size(); i++) { |
| 605 |
newItem = new TableItem(table, SWT.NULL, i); |
| 606 |
newItem.setText((String) list.get(i)); |
| 607 |
|
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
} |
| 612 |
|
| 613 |
/** |
| 614 |
* Caculate and set the position and size of the popup shell |
| 615 |
* @param parent |
| 616 |
* @param textBounds |
| 617 |
*/ |
| 618 |
public void setShellLocationAndSize(Composite parent, Rectangle textBounds){ |
| 619 |
|
| 620 |
//Caculate size of the popup shell |
| 621 |
int space = currentSeachTable.getItemHeight(); |
| 622 |
int tableHeight = currentSeachTable |
| 623 |
.getItemHeight()* currentSeachTable.getItemCount() + space; |
| 624 |
int tableWidth = textBounds.width; |
| 625 |
shell.setSize(tableWidth,tableHeight); |
| 626 |
|
| 627 |
//Caculate x,y coordinator of the popup shell |
| 628 |
Point point = getDisplay().map(parent, null, |
| 629 |
textBounds.x, textBounds.y); |
| 630 |
final int xCoord = point.x; |
| 631 |
final int yCoord = point.y + textBounds.height; |
| 632 |
|
| 633 |
final Point location = new Point(xCoord, yCoord); |
| 634 |
|
| 635 |
//Try to show whole popup shell through relocating its x and y coordinator |
| 636 |
final Display display = shell.getDisplay(); |
| 637 |
final Rectangle displayBounds = display.getClientArea(); |
| 638 |
final int displayRightEdge = displayBounds.x + displayBounds.width; |
| 435 |
|
639 |
|
|
|
640 |
if (location.x <0) |
| 641 |
location.x = 0; |
| 642 |
if ((location.x + tableWidth) > displayRightEdge) |
| 643 |
location.x = displayRightEdge - tableWidth; |
| 644 |
|
| 645 |
final int displayBottomEdge = displayBounds.y + displayBounds.height; |
| 646 |
if ((location.y + tableHeight) > displayBottomEdge) |
| 647 |
location.y = displayBottomEdge - tableHeight; |
| 648 |
|
| 649 |
// Set the location. |
| 650 |
shell.setLocation(location); |
| 651 |
} |
| 652 |
/** |
| 653 |
* Return a dialog setting section for this dialog |
| 654 |
* |
| 655 |
* @return IDialogSettings |
| 656 |
*/ |
| 657 |
|
| 658 |
|
| 659 |
private IDialogSettings getDialogSettings() { |
| 660 |
IDialogSettings settings = WorkbenchPlugin.getDefault() |
| 661 |
.getDialogSettings(); |
| 662 |
IDialogSettings thisSettings = settings |
| 663 |
.getSection(getClass().getName()); |
| 664 |
if (thisSettings == null) |
| 665 |
thisSettings = settings.addNewSection(getClass().getName()); |
| 666 |
|
| 667 |
return thisSettings; |
| 668 |
} |
| 669 |
|
| 670 |
/** |
| 671 |
* Get the preferences search history for this eclipse's start, Note that |
| 672 |
* this history will not be cleared until this eclipse closes |
| 673 |
* |
| 674 |
* @return a list |
| 675 |
*/ |
| 676 |
public List getPreferenceSearchHistory() { |
| 677 |
|
| 678 |
List searchList = new ArrayList(); |
| 679 |
IDialogSettings settings = getDialogSettings(); |
| 680 |
String[] search = settings.getArray(SEARCHHISTORY); //$NON-NLS-1$ |
| 681 |
|
| 682 |
if (search != null) { |
| 683 |
for (int i = 0; i < search.length; i++) |
| 684 |
searchList.add(search[i]); |
| 685 |
} |
| 686 |
return searchList; |
| 687 |
|
| 436 |
} |
688 |
} |
|
|
689 |
|
| 690 |
/** |
| 691 |
* Saves the search history. |
| 692 |
*/ |
| 693 |
private void saveDialogSettings() { |
| 694 |
IDialogSettings settings = getDialogSettings(); |
| 695 |
|
| 696 |
// If the settings contains the same key, the previous value will be |
| 697 |
// replaced by new one |
| 698 |
String[] result = new String[searchHistory.size()]; |
| 699 |
listToArray(searchHistory, result); |
| 700 |
settings.put(SEARCHHISTORY, result); |
| 701 |
|
| 702 |
} |
| 703 |
|
| 704 |
private void listToArray(List list, String[] string) { |
| 705 |
int size = list.size(); |
| 706 |
for (int i = 0; i < size; i++) |
| 707 |
string[i] = (String) list.get(i); |
| 708 |
} |
| 437 |
|
709 |
|
| 438 |
} |
710 |
} |