|
Lines 17-24
Link Here
|
| 17 |
import org.eclipse.swt.SWT; |
17 |
import org.eclipse.swt.SWT; |
| 18 |
import org.eclipse.swt.events.ControlAdapter; |
18 |
import org.eclipse.swt.events.ControlAdapter; |
| 19 |
import org.eclipse.swt.events.ControlEvent; |
19 |
import org.eclipse.swt.events.ControlEvent; |
| 20 |
import org.eclipse.swt.events.DisposeEvent; |
|
|
| 21 |
import org.eclipse.swt.events.DisposeListener; |
| 22 |
import org.eclipse.swt.events.FocusAdapter; |
20 |
import org.eclipse.swt.events.FocusAdapter; |
| 23 |
import org.eclipse.swt.events.FocusEvent; |
21 |
import org.eclipse.swt.events.FocusEvent; |
| 24 |
import org.eclipse.swt.events.KeyAdapter; |
22 |
import org.eclipse.swt.events.KeyAdapter; |
|
Lines 52-63
Link Here
|
| 52 |
//A popup shell to hold the currentSeachTable |
50 |
//A popup shell to hold the currentSeachTable |
| 53 |
private Shell popupShell; |
51 |
private Shell popupShell; |
| 54 |
|
52 |
|
| 55 |
//A key which is paired with a search history string as part of dialog settings |
|
|
| 56 |
private static final String SEARCHHISTORY = "search"; //$NON-NLS-1$ |
| 57 |
|
| 58 |
// A table which contains only strings begin with typed strings |
53 |
// A table which contains only strings begin with typed strings |
| 59 |
private Table currentSeachTable; |
54 |
private Table currentSeachTable; |
| 60 |
|
55 |
|
|
|
56 |
//Set a minimum width for popupShell to make sure to show all |
| 57 |
//text in the horizonal space |
| 58 |
private int minPopupShellWidth; |
| 59 |
|
| 60 |
//Identify wether the text area was resized. |
| 61 |
private boolean resizedFlag; |
| 61 |
/** |
62 |
/** |
| 62 |
* Create a new instance of the receiver. |
63 |
* Create a new instance of the receiver. |
| 63 |
* |
64 |
* |
|
Lines 74-84
Link Here
|
| 74 |
* @param parent |
75 |
* @param parent |
| 75 |
* @param treeStyle |
76 |
* @param treeStyle |
| 76 |
* @param filter |
77 |
* @param filter |
|
|
78 |
* @param searchKey |
| 77 |
*/ |
79 |
*/ |
| 78 |
public FilteredTextTree(Composite parent, int treeStyle, |
80 |
public FilteredTextTree(Composite parent, int treeStyle, |
| 79 |
PatternItemFilter filter) { |
81 |
PatternItemFilter filter, String searchKey) { |
| 80 |
super(parent, treeStyle, filter); |
82 |
super(parent, treeStyle, filter); |
| 81 |
treeViewer.getControl().addFocusListener(new FocusAdapter(){ |
83 |
searchHistory = getPreferenceSearchHistory(searchKey); |
|
|
84 |
resizedFlag = false; |
| 85 |
treeViewer.getControl().addFocusListener(new FocusAdapter(){ |
| 82 |
/* Each time the tree gains focus, the current text in text area is saved as search history |
86 |
/* Each time the tree gains focus, the current text in text area is saved as search history |
| 83 |
* @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent) |
87 |
* @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent) |
| 84 |
*/ |
88 |
*/ |
|
Lines 105-114
Link Here
|
| 105 |
* @see org.eclipse.ui.internal.dialogs.FilteredTree#createFilterControl(org.eclipse.swt.widgets.Composite) |
109 |
* @see org.eclipse.ui.internal.dialogs.FilteredTree#createFilterControl(org.eclipse.swt.widgets.Composite) |
| 106 |
*/ |
110 |
*/ |
| 107 |
protected void createFilterControl(final Composite parent) { |
111 |
protected void createFilterControl(final Composite parent) { |
| 108 |
filterText = new Text(parent, SWT.DROP_DOWN | SWT.BORDER); |
112 |
filterText = new Text(parent, SWT.BORDER | SWT.MULTI); |
| 109 |
filterText.setFont(parent.getFont()); |
113 |
filterText.setFont(parent.getFont()); |
| 110 |
searchHistory = getPreferenceSearchHistory(); |
114 |
|
| 111 |
|
|
|
| 112 |
popupShell = new Shell(parent.getShell(), SWT.NO_TRIM); |
115 |
popupShell = new Shell(parent.getShell(), SWT.NO_TRIM); |
| 113 |
popupShell |
116 |
popupShell |
| 114 |
.setBackground(parent.getDisplay().getSystemColor( |
117 |
.setBackground(parent.getDisplay().getSystemColor( |
|
Lines 123-131
Link Here
|
| 123 |
currentSeachTable = new Table(popupShell, SWT.SINGLE | SWT.BORDER); |
126 |
currentSeachTable = new Table(popupShell, SWT.SINGLE | SWT.BORDER); |
| 124 |
currentSeachTable.setLayoutData(new GridData( |
127 |
currentSeachTable.setLayoutData(new GridData( |
| 125 |
(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL))); |
128 |
(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL))); |
| 126 |
Font font = parent.getFont(); |
|
|
| 127 |
|
129 |
|
| 128 |
//Make sure the popup shell show whole words without scrollable horizontally |
130 |
//Make sure the popup shell show whole words without scrollable horizontally |
|
|
131 |
Font font = parent.getFont(); |
| 129 |
currentSeachTable.setFont(new Font |
132 |
currentSeachTable.setFont(new Font |
| 130 |
(parent.getDisplay(),font.getFontData()[0].getName(), |
133 |
(parent.getDisplay(),font.getFontData()[0].getName(), |
| 131 |
font.getFontData()[0].getHeight()-1,font.getFontData()[0].getStyle())); |
134 |
font.getFontData()[0].getHeight()-1,font.getFontData()[0].getStyle())); |
|
Lines 144-150
Link Here
|
| 144 |
} |
147 |
} |
| 145 |
} |
148 |
} |
| 146 |
}); |
149 |
}); |
|
|
150 |
|
| 151 |
|
| 152 |
filterText.addFocusListener(new FocusAdapter(){ |
| 153 |
public void focusGained(FocusEvent e) { |
| 154 |
//filterText.setText("Focus gained!!"); //$NON-NLS-1$ |
| 155 |
filterText.selectAll(); |
| 156 |
} |
| 157 |
|
| 158 |
public void focusLost(FocusEvent e) { |
| 159 |
filterText.setSelection(0,0); |
| 160 |
} |
| 161 |
}); |
| 162 |
|
| 163 |
|
| 164 |
popupShell.addTraverseListener(new TraverseListener() { |
| 165 |
public void keyTraversed(TraverseEvent e) { |
| 166 |
if ((e.detail == SWT.TRAVERSE_RETURN)||(e.detail == SWT.TRAVERSE_ESCAPE)) { |
| 167 |
e.doit = false; |
| 168 |
if(e.detail == SWT.TRAVERSE_RETURN){ |
| 169 |
setFilterText(currentSeachTable.getSelection()[0].getText()); |
| 170 |
textChanged(); |
| 171 |
} |
| 172 |
popupShell.setVisible(false); |
| 173 |
getViewer().getTree().setFocus(); |
| 174 |
} |
| 175 |
} |
| 176 |
}); |
| 147 |
|
177 |
|
|
|
178 |
currentSeachTable.addSelectionListener(new SelectionAdapter(){ |
| 179 |
public void widgetSelected(SelectionEvent e) { |
| 180 |
setFilterText(currentSeachTable.getSelection()[0].getText()); //$NON-NLS-1$ |
| 181 |
textChanged(); |
| 182 |
} |
| 183 |
}); |
| 148 |
filterText.addKeyListener(new KeyAdapter() { |
184 |
filterText.addKeyListener(new KeyAdapter() { |
| 149 |
/* |
185 |
/* |
| 150 |
* (non-Javadoc) |
186 |
* (non-Javadoc) |
|
Lines 156-175
Link Here
|
| 156 |
if (e.keyCode == SWT.ARROW_DOWN) { |
192 |
if (e.keyCode == SWT.ARROW_DOWN) { |
| 157 |
if (currentSeachTable.isVisible()) { |
193 |
if (currentSeachTable.isVisible()) { |
| 158 |
// Make selection at popup table |
194 |
// Make selection at popup table |
| 159 |
if (currentSeachTable.getSelectionCount() < 1) |
195 |
if (currentSeachTable.getSelectionCount() < 1){ |
| 160 |
currentSeachTable.setSelection(0); |
196 |
currentSeachTable.setSelection(0); |
|
|
197 |
setFilterText(currentSeachTable.getSelection()[0].getText()); //$NON-NLS-1$ |
| 198 |
textChanged(); |
| 199 |
} |
| 161 |
currentSeachTable.setFocus(); |
200 |
currentSeachTable.setFocus(); |
| 162 |
} else |
201 |
} else if(getViewer().getTree().getItemCount() > 0) |
| 163 |
// Make selection be on the left tree |
202 |
//Make selection be on the left tree |
| 164 |
treeViewer.getTree().setFocus(); |
203 |
treeViewer.getTree().setFocus(); |
| 165 |
} else { |
204 |
} else { |
| 166 |
if (e.character == SWT.CR){ |
|
|
| 167 |
int index =currentSeachTable.getSelectionIndex(); |
| 168 |
setFilterText(currentSeachTable.getItem(index).getText()); |
| 169 |
textChanged(); |
| 170 |
popupShell.setVisible(false); |
| 171 |
return; |
| 172 |
} |
| 173 |
textChanged(); |
205 |
textChanged(); |
| 174 |
List result = new ArrayList(); |
206 |
List result = new ArrayList(); |
| 175 |
result = reduceSearch(searchHistory, filterText.getText()); |
207 |
result = reduceSearch(searchHistory, filterText.getText()); |
|
Lines 217-251
Link Here
|
| 217 |
popupShell.setVisible(false); |
249 |
popupShell.setVisible(false); |
| 218 |
} |
250 |
} |
| 219 |
}); |
251 |
}); |
| 220 |
|
252 |
|
| 221 |
currentSeachTable.addSelectionListener(new SelectionAdapter() { |
253 |
filterText.addControlListener(new ControlAdapter() { |
| 222 |
/* |
|
|
| 223 |
* (non-Javadoc) |
| 224 |
* |
| 225 |
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 226 |
*/ |
| 227 |
public void widgetSelected(SelectionEvent e) { |
| 228 |
|
| 229 |
setFilterText(currentSeachTable.getSelection()[0].getText()); |
| 230 |
textChanged(); |
| 231 |
} |
| 232 |
|
| 233 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 234 |
popupShell.setVisible(false); |
| 235 |
} |
| 236 |
}); |
| 237 |
|
| 238 |
filterText.addDisposeListener(new DisposeListener() { |
| 239 |
/* |
254 |
/* |
| 240 |
* (non-Javadoc) |
255 |
* (non-Javadoc) |
| 241 |
* |
256 |
* |
| 242 |
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) |
257 |
* @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent) |
| 243 |
*/ |
258 |
*/ |
| 244 |
public void widgetDisposed(DisposeEvent e) { |
259 |
public void controlResized(ControlEvent e) { |
| 245 |
saveDialogSettings(); |
260 |
int initialTextWidth = filterText.getBounds().width; |
|
|
261 |
if((initialTextWidth >0)&& (resizedFlag ==false)){ |
| 262 |
minPopupShellWidth=initialTextWidth; |
| 263 |
resizedFlag = true; |
| 264 |
} |
| 246 |
} |
265 |
} |
| 247 |
}); |
266 |
}); |
| 248 |
|
267 |
|
| 249 |
filterText.getAccessible().addAccessibleListener( |
268 |
filterText.getAccessible().addAccessibleListener( |
| 250 |
getAccessibleListener()); |
269 |
getAccessibleListener()); |
| 251 |
|
270 |
|
|
Lines 288-295
Link Here
|
| 288 |
int tableHeight = currentSeachTable |
307 |
int tableHeight = currentSeachTable |
| 289 |
.getItemHeight()* currentSeachTable.getItemCount() + space; |
308 |
.getItemHeight()* currentSeachTable.getItemCount() + space; |
| 290 |
int tableWidth = textBounds.width; |
309 |
int tableWidth = textBounds.width; |
| 291 |
popupShell.setSize(tableWidth,tableHeight); |
|
|
| 292 |
|
310 |
|
|
|
311 |
//Make sure the width of popupShell be at least minPopupShellWidth |
| 312 |
if(tableWidth <= minPopupShellWidth) |
| 313 |
popupShell.setSize(minPopupShellWidth,tableHeight); |
| 314 |
else |
| 315 |
popupShell.setSize(tableWidth,tableHeight); |
| 316 |
|
| 293 |
//Caculate x,y coordinator of the popup shell |
317 |
//Caculate x,y coordinator of the popup shell |
| 294 |
Point point = getDisplay().map(parent, null, |
318 |
Point point = getDisplay().map(parent, null, |
| 295 |
textBounds.x, textBounds.y); |
319 |
textBounds.x, textBounds.y); |
|
Lines 301-312
Link Here
|
| 301 |
//Try to show whole popup shell through relocating its x and y coordinator |
325 |
//Try to show whole popup shell through relocating its x and y coordinator |
| 302 |
final Display display = popupShell.getDisplay(); |
326 |
final Display display = popupShell.getDisplay(); |
| 303 |
final Rectangle displayBounds = display.getClientArea(); |
327 |
final Rectangle displayBounds = display.getClientArea(); |
|
|
328 |
Rectangle popupShellBounds = popupShell.getBounds(); |
| 304 |
final int displayRightEdge = displayBounds.x + displayBounds.width; |
329 |
final int displayRightEdge = displayBounds.x + displayBounds.width; |
| 305 |
|
330 |
|
| 306 |
if (location.x <0) |
331 |
if (location.x <0) |
| 307 |
location.x = 0; |
332 |
location.x = 0; |
| 308 |
if ((location.x + tableWidth) > displayRightEdge) |
333 |
if ((location.x + popupShellBounds.width) > displayRightEdge) |
| 309 |
location.x = displayRightEdge - tableWidth; |
334 |
location.x = displayRightEdge - popupShellBounds.width; |
| 310 |
|
335 |
|
| 311 |
final int displayBottomEdge = displayBounds.y + displayBounds.height; |
336 |
final int displayBottomEdge = displayBounds.y + displayBounds.height; |
| 312 |
if ((location.y + tableHeight) > displayBottomEdge) |
337 |
if ((location.y + tableHeight) > displayBottomEdge) |
|
Lines 340-346
Link Here
|
| 340 |
* |
365 |
* |
| 341 |
* @return IDialogSettings |
366 |
* @return IDialogSettings |
| 342 |
*/ |
367 |
*/ |
| 343 |
private IDialogSettings getDialogSettings(){ |
368 |
public IDialogSettings getDialogSettings(){ |
| 344 |
IDialogSettings settings = WorkbenchPlugin.getDefault() |
369 |
IDialogSettings settings = WorkbenchPlugin.getDefault() |
| 345 |
.getDialogSettings(); |
370 |
.getDialogSettings(); |
| 346 |
IDialogSettings thisSettings = settings |
371 |
IDialogSettings thisSettings = settings |
|
Lines 357-367
Link Here
|
| 357 |
* |
382 |
* |
| 358 |
* @return a list |
383 |
* @return a list |
| 359 |
*/ |
384 |
*/ |
| 360 |
private List getPreferenceSearchHistory() { |
385 |
private List getPreferenceSearchHistory(String key) { |
| 361 |
|
386 |
|
| 362 |
List searchList = new ArrayList(); |
387 |
List searchList = new ArrayList(); |
| 363 |
IDialogSettings settings = getDialogSettings(); |
388 |
IDialogSettings settings = getDialogSettings(); |
| 364 |
String[] search = settings.getArray(SEARCHHISTORY); |
389 |
String[] search = settings.getArray(key); |
| 365 |
|
390 |
|
| 366 |
if (search != null) { |
391 |
if (search != null) { |
| 367 |
for (int i = 0; i < search.length; i++) |
392 |
for (int i = 0; i < search.length; i++) |
|
Lines 370-387
Link Here
|
| 370 |
return searchList; |
395 |
return searchList; |
| 371 |
|
396 |
|
| 372 |
} |
397 |
} |
|
|
398 |
|
| 399 |
/**Set the preference value matching searchkey |
| 400 |
* @param settings |
| 401 |
* @param searchKey |
| 402 |
*/ |
| 403 |
public void setPreferenceSearchHistory(IDialogSettings settings, String searchKey) { |
| 404 |
String[] search = settings.getArray(searchKey); //$NON-NLS-1$ |
| 405 |
if (search != null) { |
| 406 |
for (int i = 0; i < search.length; i++) |
| 407 |
searchHistory.add(search[i]); |
| 408 |
} |
| 409 |
} |
| 373 |
|
410 |
|
| 374 |
/** |
411 |
/** |
| 375 |
* Saves the search history. |
412 |
* Saves the search history. |
|
|
413 |
* @param settings |
| 414 |
* @param key |
| 376 |
*/ |
415 |
*/ |
| 377 |
private void saveDialogSettings(){ |
416 |
public void saveDialogSettings(IDialogSettings settings,String key){ |
| 378 |
IDialogSettings settings = getDialogSettings(); |
417 |
|
| 379 |
|
|
|
| 380 |
// If the settings contains the same key, the previous value will be |
418 |
// If the settings contains the same key, the previous value will be |
| 381 |
// replaced by new one |
419 |
// replaced by new one |
| 382 |
String[] result = new String[searchHistory.size()]; |
420 |
String[] result = new String[searchHistory.size()]; |
| 383 |
listToArray(searchHistory, result); |
421 |
listToArray(searchHistory, result); |
| 384 |
settings.put(SEARCHHISTORY, result); |
422 |
settings.put(key, result); |
| 385 |
|
423 |
|
| 386 |
} |
424 |
} |
| 387 |
|
425 |
|