org.jdesktop.swingx.decorator
Class FilterPipeline

java.lang.Object
  extended by org.jdesktop.swingx.decorator.FilterPipeline

public class FilterPipeline
extends Object

A FilterPipeline is used to define the set of filters for a data-aware component such as a JXList or a JXTable. Filtering involves interposing one or more filters in a FilterPipeline 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 = new Filter[] {
      new PatternFilter("S.*", 0, 1),    // regex, matchflags, column
      new ShuttleSorter(1, false),   // column 1, descending
      new ShuttleSorter(0, true),    // column 0, ascending
  };
  FilterPipeline pipeline = new FilterPipeline(filters);
  JXTable  table = new JXTable(model);
  table.setFilters(pipeline);
 
This is all you need to do in order to use 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
static class FilterPipeline.IdentityFilter
           
protected  class FilterPipeline.SorterBasedSortController
           
 
Field Summary
protected  EventListenerList listenerList
           
 
Constructor Summary
FilterPipeline()
          Creates an empty open pipeline.
FilterPipeline(Filter... inList)
          Constructs a new FilterPipeline populated with the specified filters that are applied in the order they appear in the list.
 
Method Summary
 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 a ComponentAdapter 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 registered PipelineListener objects that the contents of this pipeline has changed.
protected  void fireSortOrderChanged()
          Notifies all registered PipelineListener objects that the contents of this pipeline has changed.
 void flush()
          Flushes the pipeline by initiating a refresh on the first filter, if any, in this pipeline.
 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 this FilterPipeline.
 SortController getSortController()
           
protected  Sorter getSorter()
          Returns the sorter that the output of the filter pipeline is piped through.
 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(Object aValue, int row, int column)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerList

protected EventListenerList listenerList
Constructor Detail

FilterPipeline

public FilterPipeline()
Creates an empty open pipeline.


FilterPipeline

public FilterPipeline(Filter... inList)
Constructs a new FilterPipeline 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 a ComponentAdapter 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 - the ComponentAdapter to assign
Throws:
IllegalArgumentException - if adapter is null
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. Cascades filterChanged 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 a filterChanged notification to all PipelineListener 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 the convertRowIndexToModel method of the last Filter, 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 the convertRowIndexToModel method of the last Filter, if any, in this pipeline.

Parameters:
row - row index in model coordinates
Returns:
row index in view coordinates

getValueAt

public Object getValueAt(int row,
                         int column)
Returns the value of the cell at the specified coordinates.

Parameters:
row - in view coordinates
column - in model coordinates
Returns:
the value of the cell at the specified coordinates

setValueAt

public void setValueAt(Object aValue,
                       int row,
                       int column)

isCellEditable

public boolean isCellEditable(int row,
                              int column)

flush

public void flush()
Flushes the pipeline by initiating a refresh on the first filter, if any, in this pipeline. After that filter has refreshed itself, it sends a filterChanged notification to this pipeline, and the pipeline responds by initiating a refresh on the next filter, if any, in this pipeline. Eventualy, when there are no more filters left in the pipeline, it broadcasts a PipelineEvent signaling a PipelineEvent.CONTENTS_CHANGED message to all PipelineListener 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 - the PipelineListener 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 - the PipelineListener to be removed

getPipelineListeners

public PipelineListener[] getPipelineListeners()
Returns an array of all the pipeline listeners registered on this FilterPipeline.

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 registered PipelineListener objects that the contents of this pipeline has changed. The event instance is lazily created.


fireSortOrderChanged

protected void fireSortOrderChanged()
Notifies all registered PipelineListener objects that the contents of this pipeline has changed.