com.sas.table
Class DataTableSortController

com.sas.table.DataTableSortController
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.ComponentInterface, com.sas.LinkPropertiesInterface, com.sas.ModelInterface, com.sas.ViewInterface, MultipleValueEventSourceInterface, java.awt.event.ItemListener, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.util.EventListener

public class DataTableSortController
implements java.awt.event.ItemListener

DataTableSortController sorts a dataset based on column selections made in a TableView. DataTableSortController is an adapter which listens for ItemEvent events from a TableView. If a column is selected, that column is added to a PROC SORT statement to sort the input dataset by that column. If additional columns are selected, the dataset will be sorted on those columns. For example, if a dataset SASUSER.SURVEY includes three columns: DATE, TIME, and RESPONSE, then clicking on the TIME column will sort by TIME. If you then clicked on date, the adapter will sort by DATE TIME. When a column is selected, it is moved to the front of the list of BY variables. If that column is already at the front, the sort order is toggled between ascending and descending order for that column. After sorting, the TableView's model is the sorted WORK dataset.

This adapter has options to either sort the dataset in place, or use WORK datasets so that the original dataset does not get modified.

Clicking on the blank upper-left cell of the table resets the TableView back to the original dataset if the sorts are not being done in place and also clears the list of BY variables.

Usage

To add a DataTableSortController adapter to a TableView on the frame without using the constuctor, you must designate the TableView on the frame as the TableView to be used by the DataTableSortController by using setTableView(TableView) with the name of the TableView as the parameter. To connect a DataSetInterface to a DataTableSortController without using the constuctor, you must designate the DatSetInterface on the frame as the DataSetInterface to be used by the DataTableSortController by using setModelInterface(DataSetInterface) with the name of the DataSetInterface as the parameter.

See Also:
Serialized Form

Nested Class Summary
protected  class DataTableSortController.ColumnSort
           
 
Field Summary
protected  com.sas.sasserver.dataset.DataSetInterface dataSetInterface
          The DataSetInterface which used to connect to the dataset
protected  boolean enabled
          Whether or not the DataTableSortController is enabled (TRUE) and will act on the TableView or will not affect the TableView (FALSE).
protected  boolean inPlace
          Whether or not the new sorted dataset will replace the previous dataset (TRUE) or be stored to a temporary dataset to be displayed (FALSE)
protected  int maxSortedColumns
          The maximum number of columns which can be stored in the BY list of variables.
protected  java.lang.String originalDataSet
          Name of the original dataset with any options from which the sorted output is based
protected  java.lang.String originalDataSetName
          Name of the original dataset from which the sorted output is based
protected  SASProcedureTemplate proc
          Template used to create a PROC statement
protected  java.util.Vector sortedVector
          A Vector of the column names to be used in the BY list in order as they will appear
protected  TableView tableView
          The TableView that all actions are taken from and where the dataSet is displayed
protected  java.lang.String workDataSetName
          Name of the output dataset to which the sorted output is stored
 
Constructor Summary
DataTableSortController()
          Null Constructor Constructor equal to DataTableSortController(null, null, 0)
DataTableSortController(TableView tv, com.sas.sasserver.dataset.DataSetInterface dsi)
          Constructor equal to DataTableSortController(tv, dsi, 0)
DataTableSortController(TableView tv, com.sas.sasserver.dataset.DataSetInterface dsi, int numColumns)
          Constructor that sets TableView, DataSetInterface, and number of columns with parameters.
 
Method Summary
 com.sas.sasserver.dataset.DataSetInterface getDataSetInterface()
          Returns dataSetInterface
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
          Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about a DataTableSortController.
 int getMaxSortedColumns()
          Returns maxSortedColumns
protected  java.lang.String getOriginalDataSet()
          Returns originalDataSet
protected  java.lang.String getOriginalDataSetName()
          Returns originalDataSetName
 java.util.Vector getRequiredInterfaces()
          Creates list of required interfaces, in this case only DataSetInterface, and return list
 SASProcedureTemplate getSortProcedure()
          Returns proc
protected  java.lang.String getSortStatement()
          Creates the list of BY variables to be used by the PROC
 TableView getTableView()
          Returns tableView
 java.lang.String getWorkDataSetName()
          Returns workDataSetName
 boolean isEnabled()
          Returns enabled
 boolean isInPlace()
          Returns inPlace
 void itemStateChanged(java.awt.event.ItemEvent event)
          Handles a column selected in the TableView and sorts the DataSet appropriately.
protected  SASProcedureTemplate newSortProcedure()
          Creates the basis for a new PROC template
protected  java.lang.String newWorkDataSetName()
          Creates a temporary dataset name to store the output of a sort procedure if one does not exist
 void propertyChange(java.beans.PropertyChangeEvent prop)
          Handles the upper-left corner cell selected in the tableView and resets the sort.
 void reset()
          Reload original dataset into TableView and remove all variables from the BY list
 void setDataSetInterface(com.sas.sasserver.dataset.DataSetInterface dsi)
          Sets dataSetInterface
 void setEnabled(boolean val)
          Sets enabled
 void setInPlace(boolean val)
          Sets inPlace
 void setMaxSortedColumns(int numCol)
          Sets maxSortedColumns
 void setModelInterface(com.sas.ModelInterface model)
          Attaches model and calls setDataSetInterface if model is an instance of DataSetInterface
 void setSortProcedure(SASProcedureTemplate newSort)
          Sets proc
 void setTableView(TableView tv)
          Sets tableView
 void setWorkDataSetName(java.lang.String wds)
          Sets workDataSetName
protected  void sortDataset(java.lang.String strSort)
          Creates connection to data source and submits procedure
 

Field Detail

tableView

protected TableView tableView
The TableView that all actions are taken from and where the dataSet is displayed


dataSetInterface

protected com.sas.sasserver.dataset.DataSetInterface dataSetInterface
The DataSetInterface which used to connect to the dataset


maxSortedColumns

protected int maxSortedColumns
The maximum number of columns which can be stored in the BY list of variables. If maxSortedColumns equals zero, then the number of variables in the BY list can be up to or equal to the total number of columns in the dataset.


enabled

protected boolean enabled
Whether or not the DataTableSortController is enabled (TRUE) and will act on the TableView or will not affect the TableView (FALSE).


inPlace

protected boolean inPlace
Whether or not the new sorted dataset will replace the previous dataset (TRUE) or be stored to a temporary dataset to be displayed (FALSE)


sortedVector

protected java.util.Vector sortedVector
A Vector of the column names to be used in the BY list in order as they will appear


proc

protected SASProcedureTemplate proc
Template used to create a PROC statement


originalDataSetName

protected java.lang.String originalDataSetName
Name of the original dataset from which the sorted output is based


originalDataSet

protected java.lang.String originalDataSet
Name of the original dataset with any options from which the sorted output is based


workDataSetName

protected java.lang.String workDataSetName
Name of the output dataset to which the sorted output is stored

Constructor Detail

DataTableSortController

public DataTableSortController()
Null Constructor Constructor equal to DataTableSortController(null, null, 0)


DataTableSortController

public DataTableSortController(TableView tv,
                               com.sas.sasserver.dataset.DataSetInterface dsi)
Constructor equal to DataTableSortController(tv, dsi, 0)

Parameters:
tv - The TableView to allow sorting in.
dsi - The DataSetinterface that is the model of the TableView.

DataTableSortController

public DataTableSortController(TableView tv,
                               com.sas.sasserver.dataset.DataSetInterface dsi,
                               int numColumns)
Constructor that sets TableView, DataSetInterface, and number of columns with parameters.

Parameters:
tv - The TableView to allow sorting in.
dsi - The DataSetInterface that is the model of the TableView.
numColumns - The maximum number of columns to keep in the list of BY variables.
Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about a DataTableSortController.

Returns:
the ExtendedBeanInfo for this class

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent prop)
Handles the upper-left corner cell selected in the tableView and resets the sort.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Overrides:
propertyChange in class com.sas.Component
Parameters:
prop - Instance of PropertyChangeEvent
See Also:
PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)

itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent event)
Handles a column selected in the TableView and sorts the DataSet appropriately.

Specified by:
itemStateChanged in interface java.awt.event.ItemListener
Parameters:
event - Instance of ItemEvent

newSortProcedure

protected SASProcedureTemplate newSortProcedure()
Creates the basis for a new PROC template

Returns:
a new template for a PROC template

reset

public void reset()
Reload original dataset into TableView and remove all variables from the BY list


getSortStatement

protected java.lang.String getSortStatement()
Creates the list of BY variables to be used by the PROC

Returns:
BY variable list in a String

getSortProcedure

public SASProcedureTemplate getSortProcedure()
Returns proc

Returns:
PROC statement in a procedure template format

setSortProcedure

public void setSortProcedure(SASProcedureTemplate newSort)
Sets proc

Parameters:
newSort - PROC statement in a procedure template format

sortDataset

protected void sortDataset(java.lang.String strSort)
Creates connection to data source and submits procedure

Parameters:
strSort - Entire PROC statement in a String format

getRequiredInterfaces

public java.util.Vector getRequiredInterfaces()
Creates list of required interfaces, in this case only DataSetInterface, and return list

Specified by:
getRequiredInterfaces in interface com.sas.ViewInterface
Overrides:
getRequiredInterfaces in class com.sas.Component
Returns:
List of required interfaces necessary
See Also:
ViewInterface.getRequiredInterfaces()

setModelInterface

public void setModelInterface(com.sas.ModelInterface model)
Attaches model and calls setDataSetInterface if model is an instance of DataSetInterface

Specified by:
setModelInterface in interface com.sas.ViewInterface
Overrides:
setModelInterface in class com.sas.Component
Parameters:
model - Model for DataTableSortController class
See Also:
ViewInterface.setModelInterface(com.sas.ModelInterface)

getMaxSortedColumns

public int getMaxSortedColumns()
Returns maxSortedColumns

Returns:
Number of columns that be sorted on in the BY list at one time. Returning zero will default to sorting all columns.

setMaxSortedColumns

public void setMaxSortedColumns(int numCol)
Sets maxSortedColumns

Parameters:
numCol - Number of columns that can be sorted on in the BY list at one time. Passing in zero will default to sorting all columns.

newWorkDataSetName

protected java.lang.String newWorkDataSetName()
Creates a temporary dataset name to store the output of a sort procedure if one does not exist


isInPlace

public boolean isInPlace()
Returns inPlace

Returns:
boolean representing whether the output dataset currently replaces the input dataset

setInPlace

public void setInPlace(boolean val)
Sets inPlace

Parameters:
val - boolean representing whether the output dataset will replace the input dataset

setDataSetInterface

public void setDataSetInterface(com.sas.sasserver.dataset.DataSetInterface dsi)
Sets dataSetInterface

Parameters:
dsi - DataSetInterface from which to get the input dataset

getDataSetInterface

public com.sas.sasserver.dataset.DataSetInterface getDataSetInterface()
Returns dataSetInterface

Returns:
Current DataSetInterface containing the input dataset

setTableView

public void setTableView(TableView tv)
Sets tableView

Parameters:
tv - TableView to display the datasets

getTableView

public TableView getTableView()
Returns tableView

Returns:
Current TableView used to display the datasets

getOriginalDataSetName

protected java.lang.String getOriginalDataSetName()
Returns originalDataSetName

Returns:
Input dataset name as String

getOriginalDataSet

protected java.lang.String getOriginalDataSet()
Returns originalDataSet

Returns:
Input dataset name with any options as String

getWorkDataSetName

public java.lang.String getWorkDataSetName()
Returns workDataSetName

Returns:
Output dataset as String

setWorkDataSetName

public void setWorkDataSetName(java.lang.String wds)
Sets workDataSetName

Parameters:
wds - Temporary output dataset as string

isEnabled

public boolean isEnabled()
Returns enabled

Returns:
boolean representing whether the DataTableSortController is curently enabled

setEnabled

public void setEnabled(boolean val)
Sets enabled

Parameters:
val - boolean representing whether the DataTableSortController will be enabled



Copyright © 2009 SAS Institute Inc. All Rights Reserved.