|
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() { |