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