Class GTableFilterPanel<ROW_OBJECT>
- Type Parameters:
ROW_OBJECT
- the row object type for this given table and model
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
- Direct Known Subclasses:
GhidraTableFilterPanel
This class also handles restoring selection for the client when the table has been filtered. See below for a caveat.
Filter Reminder
The filter text will flash as the table (by default) gains focus. This is done to remind the
user that the data has been filtered. To change the component that triggers the flashing use
setFocusComponent(Component)
, where the Component
parameter is the
component that will trigger focus flashing when it gains focus. To disable focus flashing,
pass in null to setFocusComponent(Component)
.
Filtering
The filtering behavior is controlled by the filter button displayed to the right of this
panel's text field.
Important Usage Notes
- You must translate row values retrieved from the table using this panel.
Since this class wraps the given table with a new model, you must use this class to translate row number values. For example, when getting the selected row, the normal Java code snippet below will give the incorrect value:
JTable table = ...
int selectedRowNumber = table.getSelectedRow();
Instead, you must translate the returned value from above, as in the following snippet:
JTable table = ...
int selectedRowNumber = table.getSelectedRow();
int modelRowNumber = tableFilterPanel.getModelRow( selectedRowNumber ); // see getModelRow(int)
If JTable.getAutoCreateColumnsFromModel()
returns true, then the columns will
be recreated and resized when this class is constructed.
TableFilter
used by this class will be passed the empty string ("") when
TableFilter.acceptsRow(Object)
is called.JTable.getRowCount()
to access all of the table data,
since the data may be filtered.
To get a row count that is always all of the model's data, call
getUnfilteredRowCount()
.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorDescriptionGTableFilterPanel
(JTable table, RowObjectTableModel<ROW_OBJECT> tableModel) Creates a table filter panel that filters the contents of the given table.GTableFilterPanel
(JTable table, RowObjectTableModel<ROW_OBJECT> tableModel, String filterLabel) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEnterListener
(Callback callback) Adds a listener to this widget that is called when the user presses enter in the filtering area.void
Adds a listener that gets notified when the filter is changedprotected RowObjectFilterModel
<ROW_OBJECT> Generates a key used to store user filter configuration state.void
dispose()
Returns the ColumnTableFilter that has been set on this GTableFilterPanel or null if there is none.protected TableFilter
<ROW_OBJECT> getCombinedTableFilter
(TableFilter<ROW_OBJECT> filter1, TableFilter<ROW_OBJECT> filter2, TableFilter<ROW_OBJECT> filter3) Gets the contents of the filter's text field.int
getModelRow
(int viewRow) Returns a row number for this panel's underlying table model that is tied to the given row number that represents a row in a table's display.Return a unique key that can be used to store preferences for this table.int
getRowObject
(int viewRow) Returns the row object for the given view row index.Returns the currently selected row object or null if there is no table selection.Returns the currently selected row objects or an empty list if there is no selection.protected JTable
getTable()
int
int
getViewRow
(int modelRow) Returns a row number in the table (the view) for the given table model row number (the model).protected RowObjectFilterModel
<ROW_OBJECT> installTableModel
(RowObjectTableModel<ROW_OBJECT> currentModel) boolean
boolean
Returns true if the given row object is currently in the view of the table; false implies the object has been filtered out of view.void
Overridden to focus the text field if requestFocus() is called on this panelvoid
Scrolls the view to the currently selected item.void
setAccessibleNamePrefix
(String namePrefix) Sets an accessible name on the filter component.void
setColumnTableFilter
(ColumnBasedTableFilter<ROW_OBJECT> newFilter) Sets a ColumnTableFilter on this panel.void
setFilterOptions
(FilterOptions filterOptions) Sets the filter options used by the filter factory.void
setFilterRowTransformer
(RowFilterTransformer<ROW_OBJECT> transformer) Sets a custom RowFilterTransformer.void
setFilterText
(String text) Sets the contents of the filter's text field to the given text.void
setFocusComponent
(Component component) Setting this component will trigger the filter field to flash when the component gains focus.void
setSecondaryFilter
(TableFilter<ROW_OBJECT> tableFilter) Sets a secondary filter that users can use to filter table rows by other criteria other than the text typed in at the bottom of a table.void
Select the given row object.void
setSelectedItems
(List<ROW_OBJECT> items) Select the given row objects.void
setToolTipText
(String text) Allows the caller to set tooltip text on the filter's search label.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
FILTER_TEXTFIELD_NAME
- See Also:
-
-
Constructor Details
-
GTableFilterPanel
Creates a table filter panel that filters the contents of the given table.- Parameters:
table
- The table whose contents will be filtered.tableModel
- The table model used by the table--passed in by the type that we require
-
GTableFilterPanel
public GTableFilterPanel(JTable table, RowObjectTableModel<ROW_OBJECT> tableModel, String filterLabel)
-
-
Method Details
-
setAccessibleNamePrefix
Sets an accessible name on the filter component. This prefix will be used to assign meaningful accessible names to the filter text field and the filter options button such that screen readers will properly describe them.This prefix should be the base name that describes the type of items in the table. For example if the table contains fruits, then "Fruits" would be an appropriate prefix name. This method will then append the necessary information to name the text field and the button.
- Parameters:
namePrefix
- the accessible name prefix to assign to the filter component.
-
getCombinedTableFilter
protected TableFilter<ROW_OBJECT> getCombinedTableFilter(TableFilter<ROW_OBJECT> filter1, TableFilter<ROW_OBJECT> filter2, TableFilter<ROW_OBJECT> filter3) -
addFilterChagnedListener
Adds a listener that gets notified when the filter is changedNote: this listener cannot be anonymous, as the underlying storage mechanism may be using a weak data structure. This means that you will need to store the listener in a field inside of your class.
- Parameters:
l
- the listener
-
addEnterListener
Adds a listener to this widget that is called when the user presses enter in the filtering area.Note: this listener cannot be anonymous, as the underlying storage mechanism may be using a weak data structure. This means that you will need to store the listener in a field inside of your class.
- Parameters:
callback
- the listener
-
setColumnTableFilter
Sets a ColumnTableFilter on this panel.- Parameters:
newFilter
- the ColumnTableFilter to use for filtering this table.
-
setFilterRowTransformer
Sets a custom RowFilterTransformer. The default row transformer will gather strings for each column in the table and use those strings for filtering. This method allows the user to have complete control on generating the strings used to filter a table row; for example, to only filter on some columns but not others.- Parameters:
transformer
- the custom row to string transformer used to generate strings from a row to be used for filtering.
-
setSecondaryFilter
Sets a secondary filter that users can use to filter table rows by other criteria other than the text typed in at the bottom of a table. This filter is an additional filter that will be applied with the typed text filter.- Parameters:
tableFilter
- the additional filter to use for the table.
-
setFilterOptions
Sets the filter options used by the filter factory. The options are items like "starts with", "contains", "regex", etc.- Parameters:
filterOptions
- the filter options to be used by the filter factory.
-
installTableModel
protected RowObjectFilterModel<ROW_OBJECT> installTableModel(RowObjectTableModel<ROW_OBJECT> currentModel) -
createTextFilterModel
protected RowObjectFilterModel<ROW_OBJECT> createTextFilterModel(RowObjectTableModel<ROW_OBJECT> model) -
getTable
-
getTableFilterModel
-
dispose
public void dispose() -
setFocusComponent
Setting this component will trigger the filter field to flash when the component gains focus. If you do not want the filter field to flash as focus returns to the client, then pass in null.- Parameters:
component
- The component that will trigger the filter field to flash when it gains focus.
-
requestFocus
public void requestFocus()Overridden to focus the text field if requestFocus() is called on this panel- Overrides:
requestFocus
in classJComponent
-
setToolTipText
Allows the caller to set tooltip text on the filter's search label. This can be used to provide an indication as to exactly how the filter text field will filter the table.- Overrides:
setToolTipText
in classJComponent
- Parameters:
text
- The tooltip text.
-
setFilterText
Sets the contents of the filter's text field to the given text.- Parameters:
text
- The text to set.
-
getFilterText
Gets the contents of the filter's text field.- Returns:
- The filter text field text.
-
getModelRow
public int getModelRow(int viewRow) Returns a row number for this panel's underlying table model that is tied to the given row number that represents a row in a table's display. For example, if a user clicks a table row in a filtered table, then this method can be used to return the table's underlying TableModel row index for that row. Click here for more information.Update: The simpler way of getting the selected object is to call the newly added
getSelectedItem()
method(s), which saves the client from having to get the index and then lookup the data. Further, it handles differences in filtering across different model implementations.This method is used as a means for models to translate user actions on a table to the underlying data model, since table models maintain a complete list of data, some of which may not be displayed, due to user filtering.
This is the companion method to
getViewRow(int)
- Parameters:
viewRow
- The table's row, as seen in the display.- Returns:
- the corresponding model row, based upon the table's row.
- See Also:
-
getViewRow
public int getViewRow(int modelRow) Returns a row number in the table (the view) for the given table model row number (the model). The given value is the unfiltered row value and the returned value is the filtered value.This is the companion method to
getModelRow(int)
- Parameters:
modelRow
- the row number in the unfiltered model.- Returns:
- the row in the table for the given model row.
-
getRowObject
Returns the row object for the given view row index.- Parameters:
viewRow
- the desired row in terms of the UI (e.g., the table's row index)- Returns:
- the row object matching the given index
-
setSelectedItem
Select the given row object. No selection will be made if the object is filtered out of view. Passingnull
will clear the selection.- Parameters:
t
- the row object to select
-
setSelectedItems
Select the given row objects. No selection will be made if the objects are filtered out of view. Passing anull
list or an empty list will clear the selection.- Parameters:
items
- the row objects to select
-
scrollToSelectedRow
public void scrollToSelectedRow()Scrolls the view to the currently selected item. -
getSelectedItem
Returns the currently selected row object or null if there is no table selection.- Returns:
- the currently selected row object or null if there is no table selection.
-
getSelectedItems
Returns the currently selected row objects or an empty list if there is no selection.- Returns:
- the currently selected row objects or an empty list if there is no selection.
-
isInView
Returns true if the given row object is currently in the view of the table; false implies the object has been filtered out of view.- Parameters:
o
- the row object- Returns:
- true if in the view
-
isFiltered
public boolean isFiltered() -
getRowCount
public int getRowCount() -
getUnfilteredRowCount
public int getUnfilteredRowCount() -
createUniqueFilterPreferenceKey
Generates a key used to store user filter configuration state. You can override this method to generate unique keys yourself. You are required to override this method if you create multiple versions of a filter panel from the same place in your code, as multiple instances created in the same place will cause them all to share the same key and thus to have the same filter settings when they are created initially.As an example, consider a plugin that creates
n
providers. If each provider uses a filter panel, then each provider will share the same filter settings when that provider is created. If this is not what you want, then you need to override this method to generate a unique key for each provider.- Parameters:
jTable
- the table- Returns:
- a key used to store user filter configuration state.
-
getColumnTableFilter
Returns the ColumnTableFilter that has been set on this GTableFilterPanel or null if there is none.- Returns:
- the ColumnTableFilter that has been set.
-
getPreferenceKey
Return a unique key that can be used to store preferences for this table.- Returns:
- a unique key that can be used to store preferences for this table.
-