org.jdesktop.swingx.decorator
Class FilterPipeline

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

public class FilterPipeline
extends java.lang.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.

Author:
Ramesh Gupta
See Also:
Filter

Nested Class Summary
static class FilterPipeline.IdentityFilter
           
 
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.
 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()
           
 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.
 void setValueAt(java.lang.Object aValue, int row, int column)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getSortController

public SortController getSortController()

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:
java.lang.IllegalArgumentException - if adapter is null
java.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

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 java.lang.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(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 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)