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

(-)Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredPreferenceDialog.java (-4 / +15 lines)
Lines 45-50 Link Here
45
import org.eclipse.ui.internal.WorkbenchMessages;
45
import org.eclipse.ui.internal.WorkbenchMessages;
46
import org.eclipse.ui.internal.WorkbenchPlugin;
46
import org.eclipse.ui.internal.WorkbenchPlugin;
47
import org.eclipse.ui.internal.preferences.WorkingCopyManager;
47
import org.eclipse.ui.internal.preferences.WorkingCopyManager;
48
import org.eclipse.ui.internal.wizards.preferences.PreferencesMessages;
48
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
49
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
49
import org.eclipse.ui.preferences.IWorkingCopyManager;
50
import org.eclipse.ui.preferences.IWorkingCopyManager;
50
import org.osgi.service.prefs.BackingStoreException;
51
import org.osgi.service.prefs.BackingStoreException;
Lines 65-72 Link Here
65
	
66
	
66
	private Collection updateJobs = new ArrayList();
67
	private Collection updateJobs = new ArrayList();
67
	
68
	
68
	//Composite toolBarComposite;
69
	//A key which is paired with a search history string as part of dialog settings
69
70
	private static final String SEARCHHISTORY = PreferencesMessages.SearchKey; //$NON-NLS-1$
70
	
71
	
71
	/**
72
	/**
72
	 * The preference page history.
73
	 * The preference page history.
Lines 110-116 Link Here
110
	protected TreeViewer createTreeViewer(Composite parent) {
111
	protected TreeViewer createTreeViewer(Composite parent) {
111
		PatternItemFilter filter = new PatternItemFilter(true); 
112
		PatternItemFilter filter = new PatternItemFilter(true); 
112
		int styleBits = SWT.SINGLE | SWT.H_SCROLL;
113
		int styleBits = SWT.SINGLE | SWT.H_SCROLL;
113
		filteredTree = new FilteredTextTree(parent, styleBits, filter);
114
		filteredTree = new FilteredTextTree(parent, styleBits, filter,SEARCHHISTORY);
114
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
115
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
115
		gd.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
116
		gd.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
116
		filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
117
		filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
Lines 354-366 Link Here
354
					null));
355
					null));
355
		}
356
		}
356
		return success;
357
		return success;
357
	}
358
	}	
358
359
359
	/* (non-Javadoc)
360
	/* (non-Javadoc)
361
	 * @see org.eclipse.jface.window.Window#open()
362
	 */
363
	public int open() {
364
		int code = super.open();
365
		filteredTree.setPreferenceSearchHistory(filteredTree.getDialogSettings(),SEARCHHISTORY);
366
		return code;
367
	}
368
	 
369
	/* (non-Javadoc)
360
	 * @see org.eclipse.jface.window.Window#close()
370
	 * @see org.eclipse.jface.window.Window#close()
361
	 */
371
	 */
362
	public boolean close() {
372
	public boolean close() {
363
		history.dispose();
373
		history.dispose();
374
		filteredTree.saveDialogSettings(filteredTree.getDialogSettings(),SEARCHHISTORY);
364
		return super.close();
375
		return super.close();
365
	}
376
	}
366
	
377
	
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTextTree.java (-58 / +101 lines)
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
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/FilteredTree.java (-33 lines)
Lines 26-32 Link Here
26
import org.eclipse.swt.accessibility.AccessibleEvent;
26
import org.eclipse.swt.accessibility.AccessibleEvent;
27
import org.eclipse.swt.events.DisposeEvent;
27
import org.eclipse.swt.events.DisposeEvent;
28
import org.eclipse.swt.events.DisposeListener;
28
import org.eclipse.swt.events.DisposeListener;
29
import org.eclipse.swt.events.FocusEvent;
30
import org.eclipse.swt.events.FocusListener;
29
import org.eclipse.swt.events.FocusListener;
31
import org.eclipse.swt.events.KeyAdapter;
30
import org.eclipse.swt.events.KeyAdapter;
32
import org.eclipse.swt.events.KeyEvent;
31
import org.eclipse.swt.events.KeyEvent;
Lines 358-377 Link Here
358
    	setFilterText(initialText);
357
    	setFilterText(initialText);
359
    	
358
    	
360
        textChanged();
359
        textChanged();
361
        listener = new FocusListener() {
362
            public void focusGained(FocusEvent event) {
363
                filterFocusGained();
364
            }
365
366
            /*
367
             * (non-Javadoc)
368
             * 
369
             * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
370
             */
371
            public void focusLost(FocusEvent e) {
372
            }
373
        };
374
        getFilterControl().addFocusListener(listener);
375
    }
360
    }
376
361
377
	
362
	
Lines 409-430 Link Here
409
				cachedTitle));
394
				cachedTitle));
410
		
395
		
411
	}
396
	}
412
413
	/**
414
	 * Focus has been gained on the filter control.
415
	 *
416
	 */
417
	protected void filterFocusGained() {
418
		selectAll();
419
		getFilterControl().removeFocusListener(listener);
420
	}
421
422
	/**
423
	 * Focus has been lost on the filter control.
424
	 *
425
	 */
426
	protected void filterFocusLost() {
427
		
428
	}
429
	
430
}
397
}
(-)Eclipse UI/org/eclipse/ui/internal/wizards/preferences/PreferencesMessages.java (+1 lines)
Lines 24-29 Link Here
24
	public static String WizardPreferences_description;
24
	public static String WizardPreferences_description;
25
	public static String WizardPreferencesPage_noOptionsSelected;
25
	public static String WizardPreferencesPage_noOptionsSelected;
26
	public static String WizardPreferences_noSpecificPreferenceDescription;
26
	public static String WizardPreferences_noSpecificPreferenceDescription;
27
	public static String SearchKey;
27
	 
28
	 
28
	public static String PreferencesExportWizard_export;
29
	public static String PreferencesExportWizard_export;
29
	public static String WizardPreferencesExportPage1_exportTitle;
30
	public static String WizardPreferencesExportPage1_exportTitle;
(-)Eclipse UI/org/eclipse/ui/internal/wizards/preferences/messages.properties (+1 lines)
Lines 15-20 Link Here
15
PreferencesExportWizard_export=Export Preferences
15
PreferencesExportWizard_export=Export Preferences
16
WizardPreferencesExportPage1_exportTitle=Export Preferences
16
WizardPreferencesExportPage1_exportTitle=Export Preferences
17
WizardPreferencesExportPage1_exportDescription=Export preferences to the local file system.
17
WizardPreferencesExportPage1_exportDescription=Export preferences to the local file system.
18
SearchKey = SearchHistory
18
19
19
WizardPreferencesExportPage1_preferences=Preferences
20
WizardPreferencesExportPage1_preferences=Preferences
20
WizardPreferencesExportPage1_noPrefFile=Preference file not set, or is not a normal file.
21
WizardPreferencesExportPage1_noPrefFile=Preference file not set, or is not a normal file.

Return to bug 102081