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 293230 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/dialogs/FilteredTree.java (-134 / +30 lines)
Lines 26-35 Link Here
26
import org.eclipse.jface.viewers.TreeViewer;
26
import org.eclipse.jface.viewers.TreeViewer;
27
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.osgi.util.NLS;
28
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.accessibility.ACC;
30
import org.eclipse.swt.accessibility.AccessibleAdapter;
29
import org.eclipse.swt.accessibility.AccessibleAdapter;
31
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
32
import org.eclipse.swt.accessibility.AccessibleControlEvent;
33
import org.eclipse.swt.accessibility.AccessibleEvent;
30
import org.eclipse.swt.accessibility.AccessibleEvent;
34
import org.eclipse.swt.events.DisposeEvent;
31
import org.eclipse.swt.events.DisposeEvent;
35
import org.eclipse.swt.events.DisposeListener;
32
import org.eclipse.swt.events.DisposeListener;
Lines 41-62 Link Here
41
import org.eclipse.swt.events.ModifyListener;
38
import org.eclipse.swt.events.ModifyListener;
42
import org.eclipse.swt.events.MouseAdapter;
39
import org.eclipse.swt.events.MouseAdapter;
43
import org.eclipse.swt.events.MouseEvent;
40
import org.eclipse.swt.events.MouseEvent;
44
import org.eclipse.swt.events.MouseMoveListener;
45
import org.eclipse.swt.events.MouseTrackListener;
46
import org.eclipse.swt.events.SelectionAdapter;
41
import org.eclipse.swt.events.SelectionAdapter;
47
import org.eclipse.swt.events.SelectionEvent;
42
import org.eclipse.swt.events.SelectionEvent;
48
import org.eclipse.swt.events.TraverseEvent;
43
import org.eclipse.swt.events.TraverseEvent;
49
import org.eclipse.swt.events.TraverseListener;
44
import org.eclipse.swt.events.TraverseListener;
50
import org.eclipse.swt.graphics.Color;
45
import org.eclipse.swt.graphics.Color;
51
import org.eclipse.swt.graphics.Font;
46
import org.eclipse.swt.graphics.Font;
52
import org.eclipse.swt.graphics.Image;
53
import org.eclipse.swt.graphics.Point;
54
import org.eclipse.swt.layout.GridData;
47
import org.eclipse.swt.layout.GridData;
55
import org.eclipse.swt.layout.GridLayout;
48
import org.eclipse.swt.layout.GridLayout;
56
import org.eclipse.swt.widgets.Composite;
49
import org.eclipse.swt.widgets.Composite;
57
import org.eclipse.swt.widgets.Control;
50
import org.eclipse.swt.widgets.Control;
58
import org.eclipse.swt.widgets.Display;
51
import org.eclipse.swt.widgets.Display;
59
import org.eclipse.swt.widgets.Label;
60
import org.eclipse.swt.widgets.Text;
52
import org.eclipse.swt.widgets.Text;
61
import org.eclipse.swt.widgets.Tree;
53
import org.eclipse.swt.widgets.Tree;
62
import org.eclipse.swt.widgets.TreeItem;
54
import org.eclipse.swt.widgets.TreeItem;
Lines 163-168 Link Here
163
	private boolean useNewLook = false;
155
	private boolean useNewLook = false;
164
156
165
	/**
157
	/**
158
	 * A class that encapsulates the entire search control behavior so that it can be reused.
159
	 * This is either the native or an emulated control depending on the windowing system used.
160
	 * 
161
	 * @since 3.6
162
	 */
163
	private TextSearchControl searchControl;
164
165
	/**
166
	 * Image descriptor for enabled clear button.
166
	 * Image descriptor for enabled clear button.
167
	 */
167
	 */
168
	private static final String CLEAR_ICON = "org.eclipse.ui.internal.dialogs.CLEAR_ICON"; //$NON-NLS-1$
168
	private static final String CLEAR_ICON = "org.eclipse.ui.internal.dialogs.CLEAR_ICON"; //$NON-NLS-1$
Lines 310-324 Link Here
310
		setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
310
		setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
311
311
312
		if (showFilterControls) {
312
		if (showFilterControls) {
313
			if (!useNewLook || useNativeSearchField(parent)) {
313
			filterComposite = new Composite(this, SWT.NONE);
314
				filterComposite= new Composite(this, SWT.NONE);
314
			GridLayout filterLayout = new GridLayout(2, false);
315
			} else {
315
			filterLayout.marginHeight = 0;
316
				filterComposite= new Composite(this, SWT.BORDER);
316
			filterLayout.marginWidth = 0;
317
				filterComposite.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
318
			}
319
			GridLayout filterLayout= new GridLayout(2, false);
320
			filterLayout.marginHeight= 0;
321
			filterLayout.marginWidth= 0;
322
			filterComposite.setLayout(filterLayout);
317
			filterComposite.setLayout(filterLayout);
323
			filterComposite.setFont(parent.getFont());
318
			filterComposite.setFont(parent.getFont());
324
319
Lines 337-361 Link Here
337
		createTreeControl(treeComposite, treeStyle);
332
		createTreeControl(treeComposite, treeStyle);
338
	}
333
	}
339
	
334
	
340
	private static Boolean useNativeSearchField;
341
	
342
	private static boolean useNativeSearchField(Composite composite) {
343
		if (useNativeSearchField == null) {
344
			useNativeSearchField = Boolean.FALSE;
345
			Text testText = null;
346
			try {
347
				testText = new Text(composite, SWT.SEARCH | SWT.ICON_CANCEL);
348
				useNativeSearchField = new Boolean((testText.getStyle() & SWT.ICON_CANCEL) != 0);
349
			} finally {
350
				if (testText != null) {
351
					testText.dispose();
352
				}
353
			}
354
				
355
		}
356
		return useNativeSearchField.booleanValue();
357
	}
358
	
359
335
360
	/**
336
	/**
361
	 * Create the filter controls. By default, a text and corresponding tool bar
337
	 * Create the filter controls. By default, a text and corresponding tool bar
Lines 368-376 Link Here
368
	 */
344
	 */
369
	protected Composite createFilterControls(Composite parent) {
345
	protected Composite createFilterControls(Composite parent) {
370
		createFilterText(parent);
346
		createFilterText(parent);
371
		if (useNewLook)
347
		if (!useNewLook)
372
			createClearTextNew(parent);
373
		else
374
			createClearTextOld(parent);
348
			createClearTextOld(parent);
375
		if (clearButtonControl != null) {
349
		if (clearButtonControl != null) {
376
			// initially there is no text to clear
350
			// initially there is no text to clear
Lines 793-800 Link Here
793
		// if we're using a field with built in cancel we need to listen for
767
		// if we're using a field with built in cancel we need to listen for
794
		// default selection changes (which tell us the cancel button has been
768
		// default selection changes (which tell us the cancel button has been
795
		// pressed)
769
		// pressed)
796
		if ((filterText.getStyle() & SWT.ICON_CANCEL) != 0) {
770
		if (searchControl != null) {
797
			filterText.addSelectionListener(new SelectionAdapter() {
771
			searchControl.addSelectionListener(new SelectionAdapter() {
798
				/*
772
				/*
799
				 * (non-Javadoc)
773
				 * (non-Javadoc)
800
				 * 
774
				 * 
Lines 803-808 Link Here
803
				public void widgetDefaultSelected(SelectionEvent e) {
777
				public void widgetDefaultSelected(SelectionEvent e) {
804
					if (e.detail == SWT.ICON_CANCEL)
778
					if (e.detail == SWT.ICON_CANCEL)
805
						clearText();
779
						clearText();
780
					if (e.detail == SWT.ICON_SEARCH)
781
						textChanged();
806
				}
782
				}
807
			});
783
			});
808
		}
784
		}
Lines 826-836 Link Here
826
	 * @since 3.3
802
	 * @since 3.3
827
	 */
803
	 */
828
	protected Text doCreateFilterText(Composite parent) {
804
	protected Text doCreateFilterText(Composite parent) {
829
		if (!useNewLook || useNativeSearchField(parent)) {
805
		if (!useNewLook) {
830
			return new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.SEARCH
806
			return new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.SEARCH
831
					| SWT.ICON_CANCEL);
807
					| SWT.ICON_CANCEL);
832
		}
808
		}
833
		return new Text(parent, SWT.SINGLE);
809
		searchControl = new TextSearchControl(parent, true);
810
		if (filterComposite == parent && filterComposite.getChildren().length == 1) {
811
			// remove the extra composite that was created if nothing has been added to it
812
			// needed for backwards compatibility
813
			searchControl.getComposite().setParent(this);
814
			filterComposite.dispose();
815
			filterComposite = searchControl.getComposite();
816
		}
817
		return searchControl.getTextControl();
834
	}
818
	}
835
819
836
	private String previousFilterText;
820
	private String previousFilterText;
Lines 871-878 Link Here
871
	 */
855
	 */
872
	public void setBackground(Color background) {
856
	public void setBackground(Color background) {
873
		super.setBackground(background);
857
		super.setBackground(background);
874
		if (filterComposite != null && (!useNewLook || useNativeSearchField(filterComposite))) {
858
		if (filterComposite != null && !useNewLook) {
875
			filterComposite.setBackground(background);
859
			filterComposite.setBackground(background);
860
		} else if(searchControl != null) {
861
			searchControl.setBackground(background);
876
		}
862
		}
877
		if (filterToolBar != null && filterToolBar.getControl() != null) {
863
		if (filterToolBar != null && filterToolBar.getControl() != null) {
878
			filterToolBar.getControl().setBackground(background);
864
			filterToolBar.getControl().setBackground(background);
Lines 915-1010 Link Here
915
	}
901
	}
916
902
917
	/**
903
	/**
918
	 * Create the button that clears the text.
919
	 * 
920
	 * @param parent parent <code>Composite</code> of toolbar button
921
	 */
922
	private void createClearTextNew(Composite parent) {
923
		// only create the button if the text widget doesn't support one
924
		// natively
925
		if ((filterText.getStyle() & SWT.ICON_CANCEL) == 0) {
926
			final Image inactiveImage= JFaceResources.getImageRegistry().getDescriptor(DISABLED_CLEAR_ICON).createImage();
927
			final Image activeImage= JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON).createImage();
928
			final Image pressedImage= new Image(getDisplay(), activeImage, SWT.IMAGE_GRAY);
929
			
930
			final Label clearButton= new Label(parent, SWT.NONE);
931
			clearButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
932
			clearButton.setImage(inactiveImage);
933
			clearButton.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
934
			clearButton.setToolTipText(WorkbenchMessages.FilteredTree_ClearToolTip);
935
			clearButton.addMouseListener(new MouseAdapter() {
936
				private MouseMoveListener fMoveListener;
937
938
				public void mouseDown(MouseEvent e) {
939
					clearButton.setImage(pressedImage);
940
					fMoveListener= new MouseMoveListener() {
941
						private boolean fMouseInButton= true;
942
943
						public void mouseMove(MouseEvent e) {
944
							boolean mouseInButton= isMouseInButton(e);
945
							if (mouseInButton != fMouseInButton) {
946
								fMouseInButton= mouseInButton;
947
								clearButton.setImage(mouseInButton ? pressedImage : inactiveImage);
948
							}
949
						}
950
					};
951
					clearButton.addMouseMoveListener(fMoveListener);
952
				}
953
954
				public void mouseUp(MouseEvent e) {
955
					if (fMoveListener != null) {
956
						clearButton.removeMouseMoveListener(fMoveListener);
957
						fMoveListener= null;
958
						boolean mouseInButton= isMouseInButton(e);
959
						clearButton.setImage(mouseInButton ? activeImage : inactiveImage);
960
						if (mouseInButton) {
961
							clearText();
962
							filterText.setFocus();
963
						}
964
					}
965
				}
966
				
967
				private boolean isMouseInButton(MouseEvent e) {
968
					Point buttonSize = clearButton.getSize();
969
					return 0 <= e.x && e.x < buttonSize.x && 0 <= e.y && e.y < buttonSize.y;
970
				}
971
			});
972
			clearButton.addMouseTrackListener(new MouseTrackListener() {
973
				public void mouseEnter(MouseEvent e) {
974
					clearButton.setImage(activeImage);
975
				}
976
977
				public void mouseExit(MouseEvent e) {
978
					clearButton.setImage(inactiveImage);
979
				}
980
981
				public void mouseHover(MouseEvent e) {
982
				}
983
			});
984
			clearButton.addDisposeListener(new DisposeListener() {
985
				public void widgetDisposed(DisposeEvent e) {
986
					inactiveImage.dispose();
987
					activeImage.dispose();
988
					pressedImage.dispose();
989
				}
990
			});
991
			clearButton.getAccessible().addAccessibleListener(
992
				new AccessibleAdapter() {
993
					public void getName(AccessibleEvent e) {
994
						e.result= WorkbenchMessages.FilteredTree_AccessibleListenerClearButton;
995
					}
996
			});
997
			clearButton.getAccessible().addAccessibleControlListener(
998
				new AccessibleControlAdapter() {
999
					public void getRole(AccessibleControlEvent e) {
1000
						e.detail= ACC.ROLE_PUSHBUTTON;
1001
					}
1002
			});
1003
			this.clearButtonControl= clearButton;
1004
		}
1005
	}
1006
1007
	/**
1008
	 * Clears the text in the filter text widget.
904
	 * Clears the text in the filter text widget.
1009
	 */
905
	 */
1010
	protected void clearText() {
906
	protected void clearText() {
(-)Eclipse (+336 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.dialogs;
13
14
import java.util.HashSet;
15
import java.util.Iterator;
16
import java.util.Set;
17
import org.eclipse.jface.layout.GridLayoutFactory;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.JFaceResources;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.accessibility.ACC;
22
import org.eclipse.swt.accessibility.AccessibleAdapter;
23
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
24
import org.eclipse.swt.accessibility.AccessibleControlEvent;
25
import org.eclipse.swt.accessibility.AccessibleEvent;
26
import org.eclipse.swt.events.ModifyEvent;
27
import org.eclipse.swt.events.ModifyListener;
28
import org.eclipse.swt.events.MouseAdapter;
29
import org.eclipse.swt.events.MouseEvent;
30
import org.eclipse.swt.events.MouseMoveListener;
31
import org.eclipse.swt.events.MouseTrackListener;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.events.SelectionListener;
34
import org.eclipse.swt.graphics.Color;
35
import org.eclipse.swt.graphics.Image;
36
import org.eclipse.swt.graphics.Point;
37
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Control;
40
import org.eclipse.swt.widgets.Event;
41
import org.eclipse.swt.widgets.Label;
42
import org.eclipse.swt.widgets.Text;
43
import org.eclipse.ui.PlatformUI;
44
import org.eclipse.ui.internal.WorkbenchMessages;
45
import org.eclipse.ui.plugin.AbstractUIPlugin;
46
47
public class TextSearchControl {
48
49
	/**
50
	 * Image descriptor for enabled clear button.
51
	 */
52
	private static final String CLEAR_ICON = "org.eclipse.ui.internal.dialogs.CLEAR_ICON"; //$NON-NLS-1$
53
54
	/**
55
	 * Image descriptor for enabled clear button.
56
	 */
57
	private static final String FIND_ICON = "org.eclipse.ui.internal.dialogs.FIND_ICON"; //$NON-NLS-1$
58
59
	/**
60
	 * Get image descriptors for the clear button.
61
	 */
62
	static {
63
		ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PlatformUI.PLUGIN_ID,
64
				"$nl$/icons/full/etool16/clear_co.gif"); //$NON-NLS-1$
65
		if (descriptor != null) {
66
			JFaceResources.getImageRegistry().put(CLEAR_ICON, descriptor);
67
		}
68
69
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PlatformUI.PLUGIN_ID,
70
		"$nl$/icons/full/etool16/find.png"); //$NON-NLS-1$
71
		if (descriptor != null) {
72
			JFaceResources.getImageRegistry().put(FIND_ICON, descriptor);
73
		}
74
	}
75
76
	private final Text textControl;
77
78
	private Control clearControl;
79
80
	private Control findControl;
81
82
	private final boolean automaticFind;
83
84
	private final Set selectionListeners = new HashSet();
85
86
	private Boolean useNativeSearchField;
87
88
	private Composite composite;
89
90
	public TextSearchControl(Composite parent, boolean automaticFind) {
91
		this.automaticFind = automaticFind;
92
		this.composite = parent;
93
94
		int textStyle = SWT.SINGLE;
95
		int numColumns = 1;
96
		if (useNativeSearchField(automaticFind)) {
97
			if (automaticFind) {
98
				textStyle |= SWT.SEARCH | SWT.ICON_CANCEL;
99
			} else {
100
				textStyle |= SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL;
101
			}
102
			composite = new Composite(parent, SWT.NONE);
103
		} else {
104
			this.composite = new Composite(parent, SWT.BORDER);
105
			composite.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
106
			composite.setFont(parent.getFont());
107
			numColumns = 2;
108
			if (!automaticFind) {
109
				numColumns += 1;
110
			}
111
		}
112
		GridLayoutFactory.swtDefaults().margins(0, 0).extendedMargins(0, 0, 0, 0).numColumns(numColumns).applyTo(
113
				composite);
114
115
		textControl = new Text(composite, textStyle);
116
117
		GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
118
		textControl.setLayoutData(gridData);
119
120
		if (!useNativeSearchField(automaticFind)) {
121
			findControl = createLabelButtonControl(composite, textControl, JFaceResources
122
					.getImageRegistry().getDescriptor(FIND_ICON),
123
					WorkbenchMessages.FilteredTree_AccessibleListenerFindButton,
124
					WorkbenchMessages.FilteredTree_FindToolTip, SWT.ICON_SEARCH);
125
			clearControl = createLabelButtonControl(composite, textControl, JFaceResources.getImageRegistry()
126
					.getDescriptor(CLEAR_ICON), WorkbenchMessages.FilteredTree_AccessibleListenerClearButton,
127
					WorkbenchMessages.FilteredTree_ClearToolTip, SWT.ICON_CANCEL);
128
			addModifyListener(new ModifyListener() {
129
130
				public void modifyText(ModifyEvent e) {
131
					updateButtonVisibilityAndEnablement();
132
133
				}
134
			});
135
			updateButtonVisibilityAndEnablement();
136
		}
137
	}
138
139
	private boolean useNativeSearchField(boolean automaticFind) {
140
		if (composite != null) {
141
			if (useNativeSearchField == null) {
142
				useNativeSearchField = Boolean.FALSE;
143
				Text testText = null;
144
				try {
145
					int style = SWT.SEARCH | SWT.ICON_CANCEL;
146
					if (automaticFind) {
147
						style |= SWT.ICON_SEARCH;
148
					}
149
					testText = new Text(composite, style);
150
					useNativeSearchField = new Boolean((testText.getStyle() & SWT.ICON_CANCEL) != 0
151
							&& (!automaticFind || (testText.getStyle() & SWT.ICON_SEARCH) != 0));
152
				} finally {
153
					if (testText != null) {
154
						testText.dispose();
155
					}
156
				}
157
158
			}
159
		} else {
160
			useNativeSearchField = Boolean.FALSE;
161
		}
162
		return useNativeSearchField.booleanValue();
163
	}
164
165
	private Control createLabelButtonControl(Composite parent, final Text textControl,
166
			ImageDescriptor activeImageDescriptor, final String accessibilityText, String toolTipText, final int detail) {
167
		final Image activeImage = activeImageDescriptor.createImage();
168
		final Image inactiveImage = new Image(parent.getDisplay(), activeImage, SWT.IMAGE_GRAY);
169
		final Image pressedImage = inactiveImage;
170
171
		final Label labelButton = new Label(parent, SWT.NONE);
172
		labelButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
173
		labelButton.setImage(inactiveImage);
174
		labelButton.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
175
		labelButton.setToolTipText(toolTipText);
176
		labelButton.addMouseListener(new MouseAdapter() {
177
			private MouseMoveListener fMoveListener;
178
179
			public void mouseDown(MouseEvent e) {
180
				labelButton.setImage(pressedImage);
181
				fMoveListener = new MouseMoveListener() {
182
					private boolean fMouseInButton = true;
183
184
					public void mouseMove(MouseEvent e) {
185
						boolean mouseInButton = isMouseInButton(e);
186
						if (mouseInButton != fMouseInButton) {
187
							fMouseInButton = mouseInButton;
188
							labelButton.setImage(mouseInButton ? pressedImage : inactiveImage);
189
						}
190
					}
191
				};
192
				labelButton.addMouseMoveListener(fMoveListener);
193
			}
194
195
			public void mouseUp(MouseEvent e) {
196
				if (fMoveListener != null) {
197
					labelButton.removeMouseMoveListener(fMoveListener);
198
					fMoveListener = null;
199
					boolean mouseInButton = isMouseInButton(e);
200
					labelButton.setImage(mouseInButton ? activeImage : inactiveImage);
201
					if (mouseInButton) {
202
						if (textControl.isEnabled() && textControl.getText().length() > 0) {
203
							notifySelectionChanged(detail);
204
						}
205
					}
206
				}
207
			}
208
209
			private boolean isMouseInButton(MouseEvent e) {
210
				Point buttonSize = labelButton.getSize();
211
				return 0 <= e.x && e.x < buttonSize.x && 0 <= e.y && e.y < buttonSize.y;
212
			}
213
		});
214
215
		labelButton.addMouseTrackListener(new MouseTrackListener() {
216
			public void mouseEnter(MouseEvent e) {
217
				if (labelButton.getImage() != activeImage) {
218
					labelButton.setImage(activeImage);
219
				}
220
			}
221
222
			public void mouseExit(MouseEvent e) {
223
				if (labelButton.getImage() != inactiveImage) {
224
					labelButton.setImage(inactiveImage);
225
				}
226
			}
227
228
			public void mouseHover(MouseEvent e) {
229
			}
230
		});
231
232
		labelButton.getAccessible().addAccessibleListener(new AccessibleAdapter() {
233
			public void getName(AccessibleEvent e) {
234
				e.result = accessibilityText;
235
			}
236
		});
237
		labelButton.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
238
			public void getRole(AccessibleControlEvent e) {
239
				e.detail = ACC.ROLE_PUSHBUTTON;
240
			}
241
		});
242
		return labelButton;
243
	}
244
245
	public void addSelectionListener(SelectionListener listener) {
246
		textControl.addSelectionListener(listener);
247
		selectionListeners.add(listener);
248
	}
249
250
	public void removeSelectionListener(SelectionListener listener) {
251
		textControl.removeSelectionListener(listener);
252
		selectionListeners.remove(listener);
253
	}
254
255
	public void addModifyListener(ModifyListener listener) {
256
		textControl.addModifyListener(listener);
257
	}
258
259
	public void removeModifyListener(ModifyListener listener) {
260
		textControl.removeModifyListener(listener);
261
	}
262
263
	private void notifySelectionChanged(int detail) {
264
		if (useNativeSearchField(automaticFind)) {
265
			// notification should happen via the widgets selection listener
266
			return;
267
		}
268
		Event event = new Event();
269
		event.detail = detail;
270
		event.widget = textControl;
271
		event.display = textControl.getDisplay();
272
273
		SelectionEvent e = new SelectionEvent(event);
274
		for (Iterator itr = selectionListeners.iterator(); itr.hasNext();) {
275
			((SelectionListener) itr.next()).widgetDefaultSelected(e);
276
		}
277
	}
278
279
	private void updateButtonVisibilityAndEnablement() {
280
		if (textControl != null && !textControl.isDisposed()) {
281
			boolean hasText = textControl.getText().length() > 0;
282
283
			setFindButtonVisibility(!(hasText && automaticFind));
284
			setFindButtonEnablement(hasText);
285
286
			setClearButtonVisibility(hasText);
287
			setClearButtonEnablement(hasText);
288
		}
289
	}
290
291
	private void setFindButtonVisibility(boolean visible) {
292
		if (findControl != null && !findControl.isDisposed()) {
293
			findControl.setVisible(visible);
294
			if (findControl.getLayoutData() instanceof GridData) {
295
				((GridData) findControl.getLayoutData()).exclude = !visible;
296
				findControl.getParent().layout();
297
			}
298
		}
299
	}
300
301
	private void setClearButtonVisibility(boolean visible) {
302
		if (clearControl != null && !clearControl.isDisposed()) {
303
			clearControl.setVisible(visible);
304
			if (clearControl.getLayoutData() instanceof GridData) {
305
				((GridData) clearControl.getLayoutData()).exclude = !visible;
306
				clearControl.getParent().layout();
307
			}
308
		}
309
	}
310
311
	private void setClearButtonEnablement(boolean enabled) {
312
		if (clearControl != null && !clearControl.isDisposed()) {
313
			clearControl.setEnabled(enabled);
314
		}
315
	}
316
317
	private void setFindButtonEnablement(boolean enabled) {
318
		if (findControl != null && !findControl.isDisposed()) {
319
			findControl.setEnabled(enabled);
320
		}
321
	}
322
323
	public Text getTextControl() {
324
		return textControl;
325
	}
326
327
	public Composite getComposite() {
328
		return composite;
329
	}
330
331
	public void setBackground(Color color) {
332
		if (useNativeSearchField(automaticFind)) {
333
			composite.setBackground(color);
334
		}
335
	}
336
}

Return to bug 293230