sos.reports
Class CellReportSelectionModel

java.lang.Object
  |
  +--sos.reports.AbstractReportSelectionModel
        |
        +--sos.reports.CellReportSelectionModel
All Implemented Interfaces:
ReportSelectionModel, java.io.Serializable

public class CellReportSelectionModel
extends AbstractReportSelectionModel
implements ReportSelectionModel, java.io.Serializable

A selection model for table cells and cell contents. It behaves exactly like cell selection in javax.swing.JTable.

This selection model can handle the selection of either the cell elements themselves or their content elements, depending on the flag passed to the constructor. Also, this model controls whether or not cells (or cell contents) are selectable if they fall in a header or footer row or column.

By default, selection ranges are allowed. To control multiple selection, use setSelectionMode.

Before moving the selection to a cell, this model invokes isCellSelectable, allowing subclasses to easily customize cell selection. For example, a client who wishes to ignore cells in the first three columns may customize CellReportSelectionModel as follows:

  CellReportSelectionModel model = new CellReportSelectionModel() {
    protected boolean isCellSelectable( CellElement cellElement )
    {
      if( !super.isTierSelectable( cellElement ))
        return false;

      if( cellElement.getFirstTier( TableElement.COLUMN ).getIndex() < 3 )
        return false;

      return true;
    }
  };
 
Warning: CellReportSelectionModel is intended to be used to control the selection within a single table. Clients may see unspecified results if the same selection model is used across multiple tables.

Since:
1.0
See Also:
TierReportSelectionModel, CellElement.getContent()

Constructor Summary
CellReportSelectionModel()
          Creates an instance of CellReportSelectionModel where the cell contents are selectable and headers and footers are not selectable.
CellReportSelectionModel(boolean contentSelectable)
          Creates an instance of CellReportSelectionModel where the cell contents are selectable if specified and headers and footers are not selectable.
CellReportSelectionModel(boolean contentSelectable, boolean headerRowSelectable, boolean headerColumnSelectable, boolean footerRowSelectable, boolean footerColumnSelectable)
          Creates an instance of CellReportSelectionModel where the cell contents, headers, and footers are selectable if specified.
 
Method Summary
 boolean canSelect(Element element, boolean toggle, boolean extend)
          Returns true if the specified element is selectable given the current selection and the state of toggle and extend.
 void clearSelection()
          Clears the current selection, if any.
 Element getAnchorSelectionElement()
          Returns the element passed to the last successful invocation of select with the extend paramter set to false.
 Element getLeadSelectionElement()
          Returns the element passed to the last successful invocation of select.
 java.util.Set getSelectedElements()
          Returns the set of selected elements.
 int getSelectionMode(int tierType)
          Returns the selection mode for the specified tier type.
protected  boolean isCellSelectable(CellElement cellElement)
          Returns true if the specified cell element is allowed to be selected.
 boolean isFooterSelectable(int tierType)
          Returns true if elements residing in footer tiers are selectable.
 boolean isHeaderSelectable(int tierType)
          Returns true if elements residing in header tiers are selectable.
 boolean isSelected(Element element)
          Returns true if the specified element is selected.
 void select(Element element, boolean toggle, boolean extend)
          Changes the selection.
 void setAnchorSelectionElement(Element element)
          Sets the anchor selection element.
 void setFooterSelectable(int tierType, boolean selectable)
          Specifies if elements residing in footer tiers are selectable.
 void setHeaderSelectable(int tierType, boolean selectable)
          Specifies if elements residing in header tiers are selectable.
 void setLeadSelectionElement(Element element)
          Sets the lead selection element.
 void setSelectedElements(java.util.Set elements)
          Sets the selection to the report elements in the specified set.
 void setSelectionMode(int tierType, int selectionMode)
          Sets the selection mode for the specified tier type.
 
Methods inherited from class sos.reports.AbstractReportSelectionModel
addReportSelectionListener, fireSelectionChanged, fireSelectionChanged, fireSelectionChanged, getValueIsAdjusting, removeReportSelectionListener, reportChanged, setValueIsAdjusting
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sos.reports.ReportSelectionModel
addReportSelectionListener, getValueIsAdjusting, removeReportSelectionListener, reportChanged, setValueIsAdjusting
 

Constructor Detail

CellReportSelectionModel

public CellReportSelectionModel()
Creates an instance of CellReportSelectionModel where the cell contents are selectable and headers and footers are not selectable.

See Also:
CellReportSelectionModel(boolean,boolean,boolean,boolean,boolean)

CellReportSelectionModel

public CellReportSelectionModel(boolean contentSelectable)
Creates an instance of CellReportSelectionModel where the cell contents are selectable if specified and headers and footers are not selectable.

Parameters:
contentSelectable - true if the content element of cells are selectable; false if the cell element themselves are selectable
See Also:
CellReportSelectionModel(boolean,boolean,boolean,boolean,boolean)

CellReportSelectionModel

public CellReportSelectionModel(boolean contentSelectable,
                                boolean headerRowSelectable,
                                boolean headerColumnSelectable,
                                boolean footerRowSelectable,
                                boolean footerColumnSelectable)
Creates an instance of CellReportSelectionModel where the cell contents, headers, and footers are selectable if specified. By default, the selection modes will be ListSelectionModel.MULTIPLE_INTERVAL_SELECTION in both directions.

Parameters:
contentSelectable - true if the content element of cells are selectable; false if the cell element themselves are selectable
headerRowSelectable - true if elements residing in header rows are selectable
headerColumnSelectable - true if elements residing in header columns are selectable
footerRowSelectable - true if elements residing in footer rows are selectable
footerColumnSelectable - true if elements residing in footer columns are selectable
Method Detail

canSelect

public boolean canSelect(Element element,
                         boolean toggle,
                         boolean extend)
Description copied from interface: ReportSelectionModel
Returns true if the specified element is selectable given the current selection and the state of toggle and extend. A subsequent call to select with the same arguments will throw a NotSelectableException if and only if this invocation returns false.

Specified by:
canSelect in interface ReportSelectionModel
Parameters:
element - report element on which the selection change is made
toggle - whether or not the selection should be toggled
extend - whether or not the selection should be extended to include the specified element
Returns:
true if the selection can succeed
See Also:
ReportSelectionModel.select(sos.reports.Element, boolean, boolean)

clearSelection

public void clearSelection()
Description copied from interface: ReportSelectionModel
Clears the current selection, if any. A subsequent call to getSelectedElements will return an empty set.

Specified by:
clearSelection in interface ReportSelectionModel

getAnchorSelectionElement

public Element getAnchorSelectionElement()
Description copied from interface: ReportSelectionModel
Returns the element passed to the last successful invocation of select with the extend paramter set to false.

Specified by:
getAnchorSelectionElement in interface ReportSelectionModel
Returns:
the element passed to the last successful invocation of select with the extend paramter set to false

getLeadSelectionElement

public Element getLeadSelectionElement()
Description copied from interface: ReportSelectionModel
Returns the element passed to the last successful invocation of select.

Specified by:
getLeadSelectionElement in interface ReportSelectionModel
Returns:
the element passed to the last successful invocation of select

getSelectedElements

public java.util.Set getSelectedElements()
Description copied from interface: ReportSelectionModel
Returns the set of selected elements.

Specified by:
getSelectedElements in interface ReportSelectionModel

getSelectionMode

public int getSelectionMode(int tierType)
Returns the selection mode for the specified tier type.

Parameters:
tierType - the direction in question. TableElement.ROW means along the y axis; TableElement.COLUMN means along the x axis.
Returns:
one of ListSelectionEvent.MULTIPLE_INTERVAL_SELECTION, ListSelectionEvent.SINGLE_INTERVAL_SELECTION, or ListSelectionEvent.SINGLE_SELECTION
Throws:
java.lang.IllegalArgumentException - if tierType is not TableElement.ROW or TableElement.COLUMN
See Also:
setSelectionMode(int, int)

isCellSelectable

protected boolean isCellSelectable(CellElement cellElement)
Returns true if the specified cell element is allowed to be selected. This implementation returns true for body cells, for header cells if isHeaderSelectable returns false, and for footer cells if isFooterSelectable return false. Subclasses may override this method to further restrict cell selection.

Parameters:
cellElement - the cell element in consideration
Returns:
true if cellElement is selectable

isFooterSelectable

public boolean isFooterSelectable(int tierType)
Returns true if elements residing in footer tiers are selectable.

Parameters:
tierType - the type of tier in question
Returns:
true if cell elements falling in a footer tier can be selected
Throws:
java.lang.IllegalArgumentException - if tierType is not TableElement.ROW or TableElement.COLUMN
See Also:
setFooterSelectable(int, boolean)

isHeaderSelectable

public boolean isHeaderSelectable(int tierType)
Returns true if elements residing in header tiers are selectable.

Parameters:
tierType - the type of tier in question
Returns:
true if cell elements falling in a header tier can be selected
Throws:
java.lang.IllegalArgumentException - if tierType is not TableElement.ROW or TableElement.COLUMN
See Also:
setHeaderSelectable(int, boolean)

isSelected

public boolean isSelected(Element element)
Description copied from interface: ReportSelectionModel
Returns true if the specified element is selected.

Specified by:
isSelected in interface ReportSelectionModel
Parameters:
element - report element in question
Returns:
true if element is in the selection

select

public void select(Element element,
                   boolean toggle,
                   boolean extend)
            throws NotSelectableException
Description copied from interface: ReportSelectionModel
Changes the selection.

Specified by:
select in interface ReportSelectionModel
Parameters:
element - report element on which the selection change is made
toggle - whether or not the selection should be toggled
extend - whether or not the selection should be extended to include the specified element
Throws:
NotSelectableException - if the action cannot be carried out because one or more of the needed report elements are not selectable
See Also:
ReportSelectionModel.canSelect(sos.reports.Element, boolean, boolean)

setAnchorSelectionElement

public void setAnchorSelectionElement(Element element)
                               throws NotSelectableException
Description copied from interface: ReportSelectionModel
Sets the anchor selection element.

Specified by:
setAnchorSelectionElement in interface ReportSelectionModel
Parameters:
element - report element to use as the anchor
Throws:
NotSelectableException - if element is not selectable
See Also:
ReportSelectionModel.getAnchorSelectionElement()

setFooterSelectable

public void setFooterSelectable(int tierType,
                                boolean selectable)
Specifies if elements residing in footer tiers are selectable.

Parameters:
tierType - the type of tier in question
selectable - true if cell elements falling in a footer tier can be selected
Throws:
java.lang.IllegalArgumentException - if tierType is not TableElement.ROW or TableElement.COLUMN
See Also:
isFooterSelectable(int)

setHeaderSelectable

public void setHeaderSelectable(int tierType,
                                boolean selectable)
Specifies if elements residing in header tiers are selectable.

Parameters:
tierType - the type of tier in question
selectable - true if cell elements falling in a header tier can be selected
Throws:
java.lang.IllegalArgumentException - if tierType is not TableElement.ROW or TableElement.COLUMN
See Also:
isHeaderSelectable(int)

setLeadSelectionElement

public void setLeadSelectionElement(Element element)
                             throws NotSelectableException
Description copied from interface: ReportSelectionModel
Sets the lead selection element.

Specified by:
setLeadSelectionElement in interface ReportSelectionModel
Parameters:
element - report element to use as the lead anchor
Throws:
NotSelectableException - if element is not selectable
See Also:
ReportSelectionModel.getLeadSelectionElement()

setSelectedElements

public void setSelectedElements(java.util.Set elements)
                         throws NotSelectableException
Description copied from interface: ReportSelectionModel
Sets the selection to the report elements in the specified set.

Specified by:
setSelectedElements in interface ReportSelectionModel
Parameters:
elements - report elements to be selected
Throws:
NotSelectableException - if any element in the set is not selectable

setSelectionMode

public void setSelectionMode(int tierType,
                             int selectionMode)
Sets the selection mode for the specified tier type.

Parameters:
tierType - the direction to set the mode. TableElement.ROW means along the y axis; TableElement.COLUMN means along the x axis.
selectionMode - the ability to select ranges and multiple elements
Throws:
java.lang.IllegalArgumentException - if tierType is not TableElement.ROW or TableElement.COLUMN or selectionMode is not one of ListSelectionEvent.MULTIPLE_INTERVAL_SELECTION, ListSelectionEvent.SINGLE_INTERVAL_SELECTION, or ListSelectionEvent.SINGLE_SELECTION
See Also:
getSelectionMode(int)


Copyright 2003, 2004 Side of Software (SOS). All rights reserved.