Package org.jdesktop.swingx.decorator
Class FilterPipeline
- java.lang.Object
-
- org.jdesktop.swingx.decorator.FilterPipeline
-
public class FilterPipeline extends java.lang.ObjectA
FilterPipelineis used to define the set offiltersfor a data-aware component such as aJXListor aJXTable. Filtering involves interposing one or more filters in aFilterPipelinebetween 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.
This is all you need to do in order to useFilter[] filters = newFilter[] { newPatternFilter("S.*", 0, 1), // regex, matchflags, column newShuttleSorter(1, false), // column 1, descending newShuttleSorter(0, true), // column 0, ascending };FilterPipelinepipeline = newFilterPipeline(filters);JXTabletable = 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 classFilterPipeline.IdentityFilterprotected classFilterPipeline.SorterBasedSortController
-
Field Summary
Fields Modifier and Type Field Description protected javax.swing.event.EventListenerListlistenerList
-
Constructor Summary
Constructors Constructor Description FilterPipeline()Creates an empty open pipeline.FilterPipeline(Filter... inList)Constructs a newFilterPipelinepopulated 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 voidaddPipelineListener(PipelineListener l)Adds a listener to the list that's notified each time there is a change to this pipeline.voidassign(ComponentAdapter adapter)Assigns aComponentAdapterto this pipeline if no adapter has previously been assigned to the pipeline.intconvertRowIndexToModel(int row)Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters.intconvertRowIndexToView(int row)Convert row index from model coordinates to view coordinates accounting for the presence of sorters and filters.protected SortControllercreateDefaultSortController()protected voidfilterChanged(Filter filter)Called when the specified filter has changed.protected voidfireContentsChanged()Notifies all registeredPipelineListenerobjects that the contents of this pipeline has changed.protected voidfireSortOrderChanged()Notifies all registeredPipelineListenerobjects that the contents of this pipeline has changed.voidflush()intgetInputSize()returns the unfiltered data adapter size or 0 if unassigned.intgetOutputSize()Returns the number of records in the filtered view.PipelineListener[]getPipelineListeners()Returns an array of all the pipeline listeners registered on thisFilterPipeline.SortControllergetSortController()protected SortergetSorter()Returns the sorter that the output of the filter pipeline is piped through.java.lang.ObjectgetValueAt(int row, int column)Returns the value of the cell at the specified coordinates.booleanisAssigned()booleanisCellEditable(int row, int column)voidremovePipelineListener(PipelineListener l)Removes a listener from the list that's notified each time there is a change to this pipeline.protected voidsetSorter(Sorter sorter)Sets the sorter that the output of the filter pipeline is piped through.voidsetValueAt(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 newFilterPipelinepopulated 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 aComponentAdapterto 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- theComponentAdapterto 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. CascadesfilterChangednotifications 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 afilterChangednotification to allPipelineListenerobjects 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 theconvertRowIndexToModelmethod 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 theconvertRowIndexToModelmethod 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 arefreshon the firstfilter, if any, in this pipeline. After that filter has refreshed itself, it sends afilterChangednotification to this pipeline, and the pipeline responds by initiating arefreshon the nextfilter, if any, in this pipeline. Eventualy, when there are no more filters left in the pipeline, it broadcasts aPipelineEventsignaling aPipelineEvent.CONTENTS_CHANGEDmessage to allPipelineListenerobjects 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- thePipelineListenerto 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- thePipelineListenerto be removed
-
getPipelineListeners
public PipelineListener[] getPipelineListeners()
Returns an array of all the pipeline listeners registered on thisFilterPipeline.- Returns:
- all of this pipeline's
PipelineListeners, 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 registeredPipelineListenerobjects that the contents of this pipeline has changed. The event instance is lazily created.
-
fireSortOrderChanged
protected void fireSortOrderChanged()
Notifies all registeredPipelineListenerobjects that the contents of this pipeline has changed.
-
-