Package org.jdesktop.swingx.decorator
Class FilterPipeline
- java.lang.Object
-
- org.jdesktop.swingx.decorator.FilterPipeline
-
public class FilterPipeline extends java.lang.Object
A
FilterPipeline
is used to define the set offilters
for a data-aware component such as aJXList
or aJXTable
. Filtering involves interposing one or more filters in aFilterPipeline
between a data model and a view to change the apparent order and/or number of records in the data model. The order of filters in the filter pipeline determines the order in which each filter is applied. The output from one filter in the pipeline is piped as the input to the next filter in the pipeline.Filter
[] filters = newFilter
[] { newPatternFilter
("S.*", 0, 1), // regex, matchflags, column newShuttleSorter
(1, false), // column 1, descending newShuttleSorter
(0, true), // column 0, ascending };FilterPipeline
pipeline = newFilterPipeline
(filters);JXTable
table = newJXTable
(model); table.setFilters(pipeline);FilterPipeline
. Most of the methods in this class are only for advanced developers who want to write their own filter subclasses and want to override the way a filter pipeline works.- See Also:
Filter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
FilterPipeline.IdentityFilter
protected class
FilterPipeline.SorterBasedSortController
-
Field Summary
Fields Modifier and Type Field Description protected javax.swing.event.EventListenerList
listenerList
-
Constructor Summary
Constructors Constructor Description FilterPipeline()
Creates an empty open pipeline.FilterPipeline(Filter... inList)
Constructs a newFilterPipeline
populated with the specified filters that are applied in the order they appear in the list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPipelineListener(PipelineListener l)
Adds a listener to the list that's notified each time there is a change to this pipeline.void
assign(ComponentAdapter adapter)
Assigns aComponentAdapter
to this pipeline if no adapter has previously been assigned to the pipeline.int
convertRowIndexToModel(int row)
Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters.int
convertRowIndexToView(int row)
Convert row index from model coordinates to view coordinates accounting for the presence of sorters and filters.protected SortController
createDefaultSortController()
protected void
filterChanged(Filter filter)
Called when the specified filter has changed.protected void
fireContentsChanged()
Notifies all registeredPipelineListener
objects that the contents of this pipeline has changed.protected void
fireSortOrderChanged()
Notifies all registeredPipelineListener
objects that the contents of this pipeline has changed.void
flush()
int
getInputSize()
returns the unfiltered data adapter size or 0 if unassigned.int
getOutputSize()
Returns the number of records in the filtered view.PipelineListener[]
getPipelineListeners()
Returns an array of all the pipeline listeners registered on thisFilterPipeline
.SortController
getSortController()
protected Sorter
getSorter()
Returns the sorter that the output of the filter pipeline is piped through.java.lang.Object
getValueAt(int row, int column)
Returns the value of the cell at the specified coordinates.boolean
isAssigned()
boolean
isCellEditable(int row, int column)
void
removePipelineListener(PipelineListener l)
Removes a listener from the list that's notified each time there is a change to this pipeline.protected void
setSorter(Sorter sorter)
Sets the sorter that the output of the filter pipeline is piped through.void
setValueAt(java.lang.Object aValue, int row, int column)
-
-
-
Constructor Detail
-
FilterPipeline
public FilterPipeline()
Creates an empty open pipeline.
-
FilterPipeline
public FilterPipeline(Filter... inList)
Constructs a newFilterPipeline
populated with the specified filters that are applied in the order they appear in the list. Since filters maintain state about the view to which they are attached, an instance of a filter may not ever be used in more than one pipeline.- Parameters:
inList
- array of filters
-
-
Method Detail
-
setSorter
protected void setSorter(Sorter sorter)
Sets the sorter that the output of the filter pipeline is piped through. This is the sorter that is installed interactively on a view by a user action. This method is responsible for doing all the bookkeeping to assign/cleanup pipeline/adapter assignments.- Parameters:
sorter
- the interactive sorter, if any; null otherwise.
-
getSorter
protected Sorter getSorter()
Returns the sorter that the output of the filter pipeline is piped through. This is the sorter that is installed interactively on a view by a user action.- Returns:
- the interactive sorter, if any; null otherwise.
-
getSortController
public SortController getSortController()
-
createDefaultSortController
protected SortController createDefaultSortController()
-
assign
public final void assign(ComponentAdapter adapter)
Assigns aComponentAdapter
to this pipeline if no adapter has previously been assigned to the pipeline. Once an adapter has been assigned to this pipeline, any attempt to change that will cause an exception to be thrown.- Parameters:
adapter
- theComponentAdapter
to assign- Throws:
java.lang.IllegalArgumentException
- if adapter is nulljava.lang.IllegalStateException
- if an adapter is already assigned to this pipeline and the new adapter is not the same the existing adapter
-
isAssigned
public boolean isAssigned()
- Returns:
- true if an adapter has been assigned, false otherwise
-
filterChanged
protected void filterChanged(Filter filter)
Called when the specified filter has changed. CascadesfilterChanged
notifications to the next filter in the pipeline after the specified filter. If the specified filter is the last filter in the pipeline, this method broadcasts afilterChanged
notification to allPipelineListener
objects registered with this pipeline.- Parameters:
filter
- a filter in this pipeline that has changed in any way
-
getInputSize
public int getInputSize()
returns the unfiltered data adapter size or 0 if unassigned.- Returns:
- the unfiltered data adapter size or 0 if unassigned
-
getOutputSize
public int getOutputSize()
Returns the number of records in the filtered view.- Returns:
- the number of records in the filtered view
-
convertRowIndexToModel
public int convertRowIndexToModel(int row)
Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters. This is essentially a pass-through to theconvertRowIndexToModel
method of the lastFilter
, if any, in this pipeline.- Parameters:
row
- row index in view coordinates- Returns:
- row index in model coordinates
-
convertRowIndexToView
public int convertRowIndexToView(int row)
Convert row index from model coordinates to view coordinates accounting for the presence of sorters and filters. This is essentially a pass-through to theconvertRowIndexToModel
method of the lastFilter
, if any, in this pipeline.- Parameters:
row
- row index in model coordinates- Returns:
- row index in view coordinates
-
getValueAt
public java.lang.Object getValueAt(int row, int column)
Returns the value of the cell at the specified coordinates.- Parameters:
row
- in view coordinatescolumn
- in model coordinates- Returns:
- the value of the cell at the specified coordinates
-
setValueAt
public void setValueAt(java.lang.Object aValue, int row, int column)
-
isCellEditable
public boolean isCellEditable(int row, int column)
-
flush
public void flush()
Flushes the pipeline by initiating arefresh
on the firstfilter
, if any, in this pipeline. After that filter has refreshed itself, it sends afilterChanged
notification to this pipeline, and the pipeline responds by initiating arefresh
on the nextfilter
, if any, in this pipeline. Eventualy, when there are no more filters left in the pipeline, it broadcasts aPipelineEvent
signaling aPipelineEvent.CONTENTS_CHANGED
message to allPipelineListener
objects registered with this pipeline.
-
addPipelineListener
public void addPipelineListener(PipelineListener l)
Adds a listener to the list that's notified each time there is a change to this pipeline.- Parameters:
l
- thePipelineListener
to be added
-
removePipelineListener
public void removePipelineListener(PipelineListener l)
Removes a listener from the list that's notified each time there is a change to this pipeline.- Parameters:
l
- thePipelineListener
to be removed
-
getPipelineListeners
public PipelineListener[] getPipelineListeners()
Returns an array of all the pipeline listeners registered on thisFilterPipeline
.- Returns:
- all of this pipeline's
PipelineListener
s, or an empty array if no pipeline listeners are currently registered - See Also:
addPipelineListener(org.jdesktop.swingx.decorator.PipelineListener)
,removePipelineListener(org.jdesktop.swingx.decorator.PipelineListener)
-
fireContentsChanged
protected void fireContentsChanged()
Notifies all registeredPipelineListener
objects that the contents of this pipeline has changed. The event instance is lazily created.
-
fireSortOrderChanged
protected void fireSortOrderChanged()
Notifies all registeredPipelineListener
objects that the contents of this pipeline has changed.
-
-