Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 102081 | Differences between
and this patch

Collapse All | Expand All

(-)FilteredTextTree.java (-42 / +94 lines)
Lines 19-30 Link Here
19
import org.eclipse.swt.events.ControlEvent;
19
import org.eclipse.swt.events.ControlEvent;
20
import org.eclipse.swt.events.DisposeEvent;
20
import org.eclipse.swt.events.DisposeEvent;
21
import org.eclipse.swt.events.DisposeListener;
21
import org.eclipse.swt.events.DisposeListener;
22
import org.eclipse.swt.events.FocusAdapter;
23
import org.eclipse.swt.events.FocusEvent;
22
import org.eclipse.swt.events.KeyAdapter;
24
import org.eclipse.swt.events.KeyAdapter;
23
import org.eclipse.swt.events.KeyEvent;
25
import org.eclipse.swt.events.KeyEvent;
24
import org.eclipse.swt.events.SelectionAdapter;
26
import org.eclipse.swt.events.SelectionAdapter;
25
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.events.TraverseEvent;
28
import org.eclipse.swt.events.TraverseEvent;
27
import org.eclipse.swt.events.TraverseListener;
29
import org.eclipse.swt.events.TraverseListener;
30
import org.eclipse.swt.graphics.Font;
28
import org.eclipse.swt.graphics.Point;
31
import org.eclipse.swt.graphics.Point;
29
import org.eclipse.swt.graphics.Rectangle;
32
import org.eclipse.swt.graphics.Rectangle;
30
import org.eclipse.swt.layout.GridData;
33
import org.eclipse.swt.layout.GridData;
Lines 45-51 Link Here
45
public class FilteredTextTree extends FilteredTree {
48
public class FilteredTextTree extends FilteredTree {
46
	// A list contains all strings in search history
49
	// A list contains all strings in search history
47
	private List searchHistory;
50
	private List searchHistory;
51
	
52
	//A popup shell to hold the currentSeachTable 
53
	private Shell shell;
48
54
55
	//A key which is paired with a search history string as part of dialog settings
49
	private static final String SEARCHHISTORY = "search"; //$NON-NLS-1$
56
	private static final String SEARCHHISTORY = "search"; //$NON-NLS-1$
50
57
51
	// A table which contains only strings begin with typed strings
58
	// A table which contains only strings begin with typed strings
Lines 71-76 Link Here
71
	public FilteredTextTree(Composite parent, int treeStyle,
78
	public FilteredTextTree(Composite parent, int treeStyle,
72
			PatternItemFilter filter) {
79
			PatternItemFilter filter) {
73
		super(parent, treeStyle, filter);
80
		super(parent, treeStyle, filter);
81
		treeViewer.getControl().addFocusListener(new FocusAdapter(){
82
			/* 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)
84
			 */
85
			public void focusGained(FocusEvent e) {
86
				String newText = filterText.getText();				
87
				Object[] textValues = searchHistory.toArray();
88
				
89
				if((newText.equals(""))||(newText.equals(initialText)))//$NON-NLS-1$
90
					return;
91
		
92
				for (int i = 0; i < textValues.length; i++) {
93
					if(((String)textValues[i]).equals(newText))
94
						return;					
95
				}	
96
				searchHistory.add(newText);
97
			}
98
		});
99
74
	}
100
	}
75
101
76
	/*
102
	/*
Lines 83-89 Link Here
83
		filterText.setFont(parent.getFont());
109
		filterText.setFont(parent.getFont());
84
		searchHistory = getPreferenceSearchHistory();
110
		searchHistory = getPreferenceSearchHistory();
85
111
86
		final Shell shell = new Shell(parent.getShell(), SWT.NO_TRIM);
112
		shell = new Shell(parent.getShell(), SWT.NO_TRIM);
87
		shell
113
		shell
88
				.setBackground(parent.getDisplay().getSystemColor(
114
				.setBackground(parent.getDisplay().getSystemColor(
89
						SWT.COLOR_WHITE));
115
						SWT.COLOR_WHITE));
Lines 97-103 Link Here
97
		currentSeachTable = new Table(shell, SWT.SINGLE | SWT.BORDER);
123
		currentSeachTable = new Table(shell, SWT.SINGLE | SWT.BORDER);
98
		currentSeachTable.setLayoutData(new GridData(
124
		currentSeachTable.setLayoutData(new GridData(
99
				(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL)));
125
				(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL)));
100
126
		Font font = parent.getFont();	
127
		
128
		//Make sure the popup shell show whole words without scrollable horizontally
129
		currentSeachTable.setFont(new Font
130
						(parent.getDisplay(),font.getFontData()[0].getName(),
131
						 font.getFontData()[0].getHeight()-1,font.getFontData()[0].getStyle()));
132
		
101
		filterText.addTraverseListener(new TraverseListener() {
133
		filterText.addTraverseListener(new TraverseListener() {
102
			public void keyTraversed(TraverseEvent e) {
134
			public void keyTraversed(TraverseEvent e) {
103
				if (e.detail == SWT.TRAVERSE_RETURN) {
135
				if (e.detail == SWT.TRAVERSE_RETURN) {
Lines 131-154 Link Here
131
						// Make selection be on the left tree
163
						// Make selection be on the left tree
132
						treeViewer.getTree().setFocus();
164
						treeViewer.getTree().setFocus();
133
				} else {
165
				} else {
134
					if (e.character == SWT.CR)
166
					if (e.character == SWT.CR){						
167
						int index =currentSeachTable.getSelectionIndex();
168
						setFilterText(currentSeachTable.getItem(index).getText());
169
						textChanged();						
170
						shell.setVisible(false);
135
						return;
171
						return;
136
172
					}						
137
					textChanged();
173
					textChanged();
138
					List result = new ArrayList();
174
					List result = new ArrayList();
139
					result = reduceSearch(searchHistory, filterText.getText());
175
					result = reduceSearch(searchHistory, filterText.getText());
140
					upDateTable(currentSeachTable, result);
176
					updateTable(currentSeachTable, result);
141
177
142
					if (currentSeachTable.getItemCount() > 0) {
178
					if (currentSeachTable.getItemCount() > 0) {
143
						Rectangle textBounds = filterText.getBounds();
179
						Rectangle textBounds = filterText.getBounds();
144
						Point point = getDisplay().map(parent, null,
180
												
145
								textBounds.x, textBounds.y);
181
						setShellLocationAndSize(parent,textBounds);
146
						int space = currentSeachTable.getItemHeight();
147
						shell.setBounds(point.x, point.y + textBounds.height,
148
								textBounds.width, currentSeachTable
149
										.getItemHeight()
150
										* currentSeachTable.getItemCount()
151
										+ space);
152
182
153
						if (shell.isDisposed())
183
						if (shell.isDisposed())
154
							shell.open();
184
							shell.open();
Lines 231-248 Link Here
231
	 *            String
261
	 *            String
232
	 * @return a list in which all strings start from the typed letter(s)
262
	 * @return a list in which all strings start from the typed letter(s)
233
	 */
263
	 */
234
	public List reduceSearch(List list, String wordsEntered) {
264
	private List reduceSearch(List list, String wordsEntered) {
235
		List result = new ArrayList();
265
		List result = new ArrayList();
236
		if (list == null)
266
		if (list == null)
237
			return result;
267
			return result;
238
		for (int i = 0; i < list.size(); i++) {
268
		for (int i = 0; i < list.size(); i++) {
239
			if (filterText.getText() == "") //$NON-NLS-1$
269
			if (filterText.getText() == "") //$NON-NLS-1$
270
						return result;
271
		            String historyString = (String) list.get(i);
272
				    String typedString = wordsEntered;
273
				    if (historyString.toLowerCase().startsWith(typedString.toLowerCase()))
274
					    result.add(historyString);
275
				}
276
		
240
				return result;
277
				return result;
241
			else if (((String) list.get(i)).startsWith(wordsEntered))
278
		 	}
242
				result.add(list.get(i));
279
     /**
243
		}
280
	 * Caculate and set the position and size of the popup shell
244
281
	 * @param parent
245
		return result;
282
	 * @param textBounds
283
	 */
284
	private void setShellLocationAndSize(Composite parent, Rectangle  textBounds){
285
		
286
		//Caculate size of the popup shell
287
		int space = currentSeachTable.getItemHeight();
288
		int tableHeight = currentSeachTable
289
			    .getItemHeight()* currentSeachTable.getItemCount() + space;
290
		int tableWidth = textBounds.width;	
291
		shell.setSize(tableWidth,tableHeight);
292
		
293
		//Caculate x,y coordinator of the popup shell
294
		Point point = getDisplay().map(parent, null,
295
				textBounds.x, textBounds.y);	
296
		final int xCoord = point.x;
297
		final int yCoord = point.y + textBounds.height;
298
		
299
		final Point location = new Point(xCoord, yCoord);
300
		
301
		//Try to show whole popup shell through relocating its x and y coordinator
302
		final Display display = shell.getDisplay();		
303
		final Rectangle displayBounds = display.getClientArea();
304
		final int displayRightEdge = displayBounds.x + displayBounds.width;
305
		
306
		if (location.x <0) 
307
			location.x = 0;
308
		if ((location.x + tableWidth) > displayRightEdge) 
309
			location.x = displayRightEdge - tableWidth;
310
		
311
		final int displayBottomEdge = displayBounds.y + displayBounds.height;	
312
		if ((location.y + tableHeight) > displayBottomEdge)
313
			location.y = displayBottomEdge - tableHeight;
314
		
315
		// Set the location.
316
		shell.setLocation(location);		
246
	}
317
	}
247
318
248
	/**
319
	/**
Lines 251-257 Link Here
251
	 * @param table
322
	 * @param table
252
	 * @param list
323
	 * @param list
253
	 */
324
	 */
254
	public void upDateTable(Table table, List list) {
325
	private void updateTable(Table table, List list) {
255
		table.removeAll();
326
		table.removeAll();
256
		if (list.size() > 0) {
327
		if (list.size() > 0) {
257
			TableItem newItem;
328
			TableItem newItem;
Lines 269-275 Link Here
269
	 * 
340
	 * 
270
	 * @return IDialogSettings
341
	 * @return IDialogSettings
271
	 */
342
	 */
272
	private IDialogSettings getDialogSettings() {
343
	private IDialogSettings getDialogSettings(){
273
		IDialogSettings settings = WorkbenchPlugin.getDefault()
344
		IDialogSettings settings = WorkbenchPlugin.getDefault()
274
				.getDialogSettings();
345
				.getDialogSettings();
275
		IDialogSettings thisSettings = settings
346
		IDialogSettings thisSettings = settings
Lines 286-292 Link Here
286
	 * 
357
	 * 
287
	 * @return a list
358
	 * @return a list
288
	 */
359
	 */
289
	public List getPreferenceSearchHistory() {
360
	private List getPreferenceSearchHistory() {
290
361
291
		List searchList = new ArrayList();
362
		List searchList = new ArrayList();
292
		IDialogSettings settings = getDialogSettings();
363
		IDialogSettings settings = getDialogSettings();
Lines 303-309 Link Here
303
	/**
374
	/**
304
	 * Saves the search history.
375
	 * Saves the search history.
305
	 */
376
	 */
306
	private void saveDialogSettings() {
377
	private void saveDialogSettings(){
307
		IDialogSettings settings = getDialogSettings();
378
		IDialogSettings settings = getDialogSettings();
308
379
309
		// If the settings contains the same key, the previous value will be
380
		// If the settings contains the same key, the previous value will be
Lines 320-342 Link Here
320
			string[i] = (String) list.get(i);
391
			string[i] = (String) list.get(i);
321
	}
392
	}
322
393
323
	/*
324
	 * (non-Javadoc)
325
	 * 
326
	 * @see org.eclipse.ui.internal.dialogs.FilteredTree#filterFocusLost()
327
	 */
328
	protected void filterFocusLost() {
329
		String newText = filterText.getText();
330
		Object[] textValues = searchHistory.toArray();
331
332
		if ((newText.equals("")) || (newText.equals(initialText)))//$NON-NLS-1$
333
			return;
334
335
		for (int i = 0; i < textValues.length; i++) {
336
			if (((String) textValues[i]).equals(newText))
337
				return;
338
		}
339
		searchHistory.add(newText);
340
	}
341
342
}
394
}
(-)FilteredTree.java (-9 / +1 lines)
Lines 241-247 Link Here
241
			 * @see org.eclipse.swt.accessibility.AccessibleListener#getName(org.eclipse.swt.accessibility.AccessibleEvent)
241
			 * @see org.eclipse.swt.accessibility.AccessibleListener#getName(org.eclipse.swt.accessibility.AccessibleEvent)
242
			 */
242
			 */
243
			public void getName(AccessibleEvent e) {
243
			public void getName(AccessibleEvent e) {
244
				String filterTextString = getFilterText();
244
				String filterTextString = getFilterControlText();
245
				if(filterTextString.length() == 0){
245
				if(filterTextString.length() == 0){
246
					e.result = initialText;
246
					e.result = initialText;
247
				}
247
				}
Lines 253-265 Link Here
253
	}
253
	}
254
254
255
	/**
255
	/**
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
256
     * update the receiver after the text has changed
264
     */
257
     */
265
    protected void textChanged() {
258
    protected void textChanged() {
Lines 376-382 Link Here
376
             * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
369
             * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
377
             */
370
             */
378
            public void focusLost(FocusEvent e) {
371
            public void focusLost(FocusEvent e) {
379
            	filterFocusLost();
380
            }
372
            }
381
        };
373
        };
382
        getFilterControl().addFocusListener(listener);
374
        getFilterControl().addFocusListener(listener);

Return to bug 102081