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 (-57 / +95 lines)
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
(-)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