Class XFilteredTree
- java.lang.Object
-
- org.eclipse.swt.widgets.Widget
-
- org.eclipse.swt.widgets.Control
-
- org.eclipse.swt.widgets.Scrollable
-
- org.eclipse.swt.widgets.Composite
-
- org.eclipse.nebula.widgets.xviewer.util.internal.dialog.XFilteredTree
-
- All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable
- Direct Known Subclasses:
XCheckedFilteredTree
public class XFilteredTree extends org.eclipse.swt.widgets.Composite
A simple control that provides a text widget and a tree viewer. The contents of the text widget are used to drive a PatternFilter that is on the viewer.- Since:
- 3.2
- See Also:
PatternFilter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
XFilteredTree.NotifyingTreeViewer
Custom tree viewer subclass that clears the caches in patternFilter on any change to the tree.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CLEAR_ICON
Image descriptor for enabled clear button.protected org.eclipse.swt.widgets.Control
clearButtonControl
The control representing the clear button for the filter text entry.private static java.lang.String
DISABLED_CLEAR_ICON
Image descriptor for disabled clear button.protected org.eclipse.swt.widgets.Composite
filterComposite
The Composite on which the filter controls are created.protected org.eclipse.swt.widgets.Text
filterText
The filter text widget to be used by this tree.protected org.eclipse.jface.action.ToolBarManager
filterToolBar
The control representing the clear button for the filter text entry.protected java.lang.String
initialText
The text to initially show in the filter text control.private boolean
narrowingDown
protected org.eclipse.swt.widgets.Composite
parent
The parent composite of the filtered tree.private PatternFilter
patternFilter
The pattern filter for the tree.private java.lang.String
previousFilterText
private org.eclipse.core.runtime.jobs.Job
refreshJob
The job used to refresh the tree.protected boolean
showFilterControls
Whether or not to show the filter controls (text and clear button).private static long
SOFT_MAX_EXPAND_TIME
Maximum time spent expanding the tree after the filter text has been updated (this is only used if we were able to at least expand the visible nodes)protected org.eclipse.swt.widgets.Composite
treeComposite
protected org.eclipse.jface.viewers.TreeViewer
treeViewer
The viewer for the filtered tree.private static java.lang.Boolean
useNativeSearchField
private boolean
useNewLook
Tells whether to use the pre 3.5 or the new look.
-
Constructor Summary
Constructors Modifier Constructor Description protected
XFilteredTree(org.eclipse.swt.widgets.Composite parent)
Deprecated.As of 3.5, replaced by#FilteredTree(Composite, boolean)
where using the look is encouragedprotected
XFilteredTree(org.eclipse.swt.widgets.Composite parent, boolean useNewLook)
Create a new instance of the receiver.XFilteredTree(org.eclipse.swt.widgets.Composite parent, int treeStyle, PatternFilter filter)
Deprecated.As of 3.5, replaced by#FilteredTree(Composite, int, PatternFilter, boolean)
where using the new look is encouragedXFilteredTree(org.eclipse.swt.widgets.Composite parent, int treeStyle, PatternFilter filter, boolean useNewLook)
Create a new instance of the receiver.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
clearText()
Clears the text in the filter text widget.private void
createClearTextNew(org.eclipse.swt.widgets.Composite parent)
Create the button that clears the text.private void
createClearTextOld(org.eclipse.swt.widgets.Composite parent)
Create the button that clears the text.protected void
createControl(org.eclipse.swt.widgets.Composite parent, int treeStyle)
Create the filtered tree's controls.protected org.eclipse.swt.widgets.Composite
createFilterControls(org.eclipse.swt.widgets.Composite parent)
Create the filter controls.protected void
createFilterText(org.eclipse.swt.widgets.Composite parent)
Creates the filter text and adds listeners.private void
createRefreshJob()
Create the refresh job for the receiver.protected org.eclipse.swt.widgets.Control
createTreeControl(org.eclipse.swt.widgets.Composite parent, int style)
Creates and set up the tree and tree viewer.protected org.eclipse.swt.widgets.Text
doCreateFilterText(org.eclipse.swt.widgets.Composite parent)
Creates the text control for entering the filter text.protected org.eclipse.ui.progress.WorkbenchJob
doCreateRefreshJob()
Creates a workbench job that will refresh the tree based on the current filter text.protected org.eclipse.jface.viewers.TreeViewer
doCreateTreeViewer(org.eclipse.swt.widgets.Composite parent, int style)
Creates the tree viewer.static org.eclipse.swt.graphics.Font
getBoldFont(java.lang.Object element, XFilteredTree tree, PatternFilter filter)
Return a bold font if the given element matches the given pattern.org.eclipse.swt.widgets.Text
getFilterControl()
Get the filter text for the receiver, if it was created.protected java.lang.String
getFilterString()
Convenience method to return the text of the filter control.private org.eclipse.swt.widgets.TreeItem
getFirstMatchingItem(org.eclipse.swt.widgets.TreeItem[] items)
Return the first item in the tree that matches the filter pattern.protected java.lang.String
getInitialText()
Get the initial text for the receiver.PatternFilter
getPatternFilter()
Returns the pattern filter used by this tree.protected long
getRefreshJobDelay()
Return the time delay that should be used when scheduling the filter refresh job.org.eclipse.jface.viewers.TreeViewer
getViewer()
Get the tree viewer of the receiver.protected void
init(int treeStyle, PatternFilter filter)
Create the filtered tree.protected void
selectAll()
Select all text in the filter text field.void
setBackground(org.eclipse.swt.graphics.Color background)
Set the background for the widgets that support the filter text area.protected void
setFilterText(java.lang.String string)
Set the text in the filter control.void
setInitialText(java.lang.String text)
Set the text that will be shown until the first focus.protected void
textChanged()
Update the receiver after the text has changed.protected void
updateToolbar(boolean visible)
private static boolean
useNativeSearchField(org.eclipse.swt.widgets.Composite composite)
-
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
-
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
-
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
-
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
-
-
-
-
Field Detail
-
filterText
protected org.eclipse.swt.widgets.Text filterText
The filter text widget to be used by this tree. This value may benull
if there is no filter widget, or if the controls have not yet been created.
-
filterToolBar
protected org.eclipse.jface.action.ToolBarManager filterToolBar
The control representing the clear button for the filter text entry. This value may benull
if no such button exists, or if the controls have not yet been created.Note: As of 3.5, this is not used if the new look is chosen.
-
clearButtonControl
protected org.eclipse.swt.widgets.Control clearButtonControl
The control representing the clear button for the filter text entry. This value may benull
if no such button exists, or if the controls have not yet been created.Note: This is only used if the new look is chosen.
- Since:
- 3.5
-
treeViewer
protected org.eclipse.jface.viewers.TreeViewer treeViewer
The viewer for the filtered tree. This value should never benull
after the widget creation methods are complete.
-
filterComposite
protected org.eclipse.swt.widgets.Composite filterComposite
The Composite on which the filter controls are created. This is used to set the background color of the filter controls to match the surrounding controls.
-
patternFilter
private PatternFilter patternFilter
The pattern filter for the tree. This value must not benull
.
-
initialText
protected java.lang.String initialText
The text to initially show in the filter text control.
-
refreshJob
private org.eclipse.core.runtime.jobs.Job refreshJob
The job used to refresh the tree.
-
parent
protected org.eclipse.swt.widgets.Composite parent
The parent composite of the filtered tree.- Since:
- 3.3
-
showFilterControls
protected boolean showFilterControls
Whether or not to show the filter controls (text and clear button). The default is to show these controls. This can be overridden by providing a setting in the product configuration file. The setting to add to not show these controls is: org.eclipse.ui/SHOW_FILTERED_TEXTS=false
-
treeComposite
protected org.eclipse.swt.widgets.Composite treeComposite
- Since:
- 3.3
-
useNewLook
private boolean useNewLook
Tells whether to use the pre 3.5 or the new look.- Since:
- 3.5
-
CLEAR_ICON
private static final java.lang.String CLEAR_ICON
Image descriptor for enabled clear button.- See Also:
- Constant Field Values
-
DISABLED_CLEAR_ICON
private static final java.lang.String DISABLED_CLEAR_ICON
Image descriptor for disabled clear button.- See Also:
- Constant Field Values
-
SOFT_MAX_EXPAND_TIME
private static final long SOFT_MAX_EXPAND_TIME
Maximum time spent expanding the tree after the filter text has been updated (this is only used if we were able to at least expand the visible nodes)- See Also:
- Constant Field Values
-
useNativeSearchField
private static java.lang.Boolean useNativeSearchField
-
previousFilterText
private java.lang.String previousFilterText
-
narrowingDown
private boolean narrowingDown
-
-
Constructor Detail
-
XFilteredTree
@Deprecated public XFilteredTree(org.eclipse.swt.widgets.Composite parent, int treeStyle, PatternFilter filter)
Deprecated.As of 3.5, replaced by#FilteredTree(Composite, int, PatternFilter, boolean)
where using the new look is encouragedCreate a new instance of the receiver.- Parameters:
parent
- the parentComposite
treeStyle
- the style bits for theTree
filter
- the filter to be used
-
XFilteredTree
public XFilteredTree(org.eclipse.swt.widgets.Composite parent, int treeStyle, PatternFilter filter, boolean useNewLook)
Create a new instance of the receiver.- Parameters:
parent
- the parentComposite
treeStyle
- the style bits for theTree
filter
- the filter to be useduseNewLook
-true
if the new 3.5 look should be used- Since:
- 3.5
-
XFilteredTree
@Deprecated protected XFilteredTree(org.eclipse.swt.widgets.Composite parent)
Deprecated.As of 3.5, replaced by#FilteredTree(Composite, boolean)
where using the look is encouragedCreate a new instance of the receiver. Subclasses that wish to override the default creation behavior may use this constructor, but must ensure that theinit(composite, int, PatternFilter)
method is called in the overriding constructor.- Parameters:
parent
- the parentComposite
- Since:
- 3.3
- See Also:
init(int, PatternFilter)
-
XFilteredTree
protected XFilteredTree(org.eclipse.swt.widgets.Composite parent, boolean useNewLook)
Create a new instance of the receiver. Subclasses that wish to override the default creation behavior may use this constructor, but must ensure that theinit(composite, int, PatternFilter)
method is called in the overriding constructor.- Parameters:
parent
- the parentComposite
useNewLook
-true
if the new 3.5 look should be used- Since:
- 3.5
- See Also:
init(int, PatternFilter)
-
-
Method Detail
-
init
protected void init(int treeStyle, PatternFilter filter)
Create the filtered tree.- Parameters:
treeStyle
- the style bits for theTree
filter
- the filter to be used- Since:
- 3.3
-
createControl
protected void createControl(org.eclipse.swt.widgets.Composite parent, int treeStyle)
Create the filtered tree's controls. Subclasses should override.- Parameters:
parent
-treeStyle
-
-
useNativeSearchField
private static boolean useNativeSearchField(org.eclipse.swt.widgets.Composite composite)
-
createFilterControls
protected org.eclipse.swt.widgets.Composite createFilterControls(org.eclipse.swt.widgets.Composite parent)
Create the filter controls. By default, a text and corresponding tool bar button that clears the contents of the text is created. Subclasses may override.- Parameters:
parent
- parentComposite
of the filter controls- Returns:
- the
Composite
that contains the filter controls
-
createTreeControl
protected org.eclipse.swt.widgets.Control createTreeControl(org.eclipse.swt.widgets.Composite parent, int style)
Creates and set up the tree and tree viewer. This method callsdoCreateTreeViewer(Composite, int)
to create the tree viewer. Subclasses should overridedoCreateTreeViewer(Composite, int)
instead of overriding this method.- Parameters:
parent
- parentComposite
style
- SWT style bits used to create the tree- Returns:
- the tree
-
doCreateTreeViewer
protected org.eclipse.jface.viewers.TreeViewer doCreateTreeViewer(org.eclipse.swt.widgets.Composite parent, int style)
Creates the tree viewer. Subclasses may override.- Parameters:
parent
- the parent compositestyle
- SWT style bits used to create the tree viewer- Returns:
- the tree viewer
- Since:
- 3.3
-
getFirstMatchingItem
private org.eclipse.swt.widgets.TreeItem getFirstMatchingItem(org.eclipse.swt.widgets.TreeItem[] items)
Return the first item in the tree that matches the filter pattern.- Parameters:
items
-- Returns:
- the first matching TreeItem
-
createRefreshJob
private void createRefreshJob()
Create the refresh job for the receiver.
-
doCreateRefreshJob
protected org.eclipse.ui.progress.WorkbenchJob doCreateRefreshJob()
Creates a workbench job that will refresh the tree based on the current filter text. Subclasses may override.- Returns:
- a workbench job that can be scheduled to refresh the tree
- Since:
- 3.4
-
updateToolbar
protected void updateToolbar(boolean visible)
-
createFilterText
protected void createFilterText(org.eclipse.swt.widgets.Composite parent)
Creates the filter text and adds listeners. This method callsdoCreateFilterText(Composite)
to create the text control. Subclasses should overridedoCreateFilterText(Composite)
instead of overriding this method.- Parameters:
parent
-Composite
of the filter text
-
doCreateFilterText
protected org.eclipse.swt.widgets.Text doCreateFilterText(org.eclipse.swt.widgets.Composite parent)
Creates the text control for entering the filter text. Subclasses may override.- Parameters:
parent
- the parent composite- Returns:
- the text widget
- Since:
- 3.3
-
textChanged
protected void textChanged()
Update the receiver after the text has changed.
-
getRefreshJobDelay
protected long getRefreshJobDelay()
Return the time delay that should be used when scheduling the filter refresh job. Subclasses may override.- Returns:
- a time delay in milliseconds before the job should run
- Since:
- 3.5
-
setBackground
public void setBackground(org.eclipse.swt.graphics.Color background)
Set the background for the widgets that support the filter text area.- Overrides:
setBackground
in classorg.eclipse.swt.widgets.Control
- Parameters:
background
- backgroundColor
to set
-
createClearTextOld
private void createClearTextOld(org.eclipse.swt.widgets.Composite parent)
Create the button that clears the text.- Parameters:
parent
- parentComposite
of toolbar button
-
createClearTextNew
private void createClearTextNew(org.eclipse.swt.widgets.Composite parent)
Create the button that clears the text.- Parameters:
parent
- parentComposite
of toolbar button
-
clearText
protected void clearText()
Clears the text in the filter text widget.
-
setFilterText
protected void setFilterText(java.lang.String string)
Set the text in the filter control.- Parameters:
string
-
-
getPatternFilter
public final PatternFilter getPatternFilter()
Returns the pattern filter used by this tree.- Returns:
- The pattern filter; never
null
.
-
getViewer
public org.eclipse.jface.viewers.TreeViewer getViewer()
Get the tree viewer of the receiver.- Returns:
- the tree viewer
-
getFilterControl
public org.eclipse.swt.widgets.Text getFilterControl()
Get the filter text for the receiver, if it was created. Otherwise returnnull
.- Returns:
- the filter Text, or null if it was not created
-
getFilterString
protected java.lang.String getFilterString()
Convenience method to return the text of the filter control. If the text widget is not created, then null is returned.- Returns:
- String in the text, or null if the text does not exist
-
setInitialText
public void setInitialText(java.lang.String text)
Set the text that will be shown until the first focus. A default value is provided, so this method only need be called if overriding the default initial text is desired.- Parameters:
text
- initial text to appear in text field
-
selectAll
protected void selectAll()
Select all text in the filter text field.
-
getInitialText
protected java.lang.String getInitialText()
Get the initial text for the receiver.- Returns:
- String
-
getBoldFont
public static org.eclipse.swt.graphics.Font getBoldFont(java.lang.Object element, XFilteredTree tree, PatternFilter filter)
Return a bold font if the given element matches the given pattern. Clients can opt to call this method from a Viewer's label provider to get a bold font for which to highlight the given element in the tree.- Parameters:
element
- element for which a match should be determinedtree
- FilteredTree in which the element residesfilter
- PatternFilter which determines a match- Returns:
- bold font
-
-