|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.storage.jdbc.JDBCToTreeModelAdapter
public class JDBCToTreeModelAdapter
The JDBCToTreeModelAdapter allows JDBC data sources to be
displayed in any viewer that requires a model of type
javax.swing.tree.TreeModel
, mainly being a javax.swing.JTree
.
The data source must have three specific columns within it: text, level, and index.
These three columns must be designated in order for the levels within the tree to be
displayed correctly.
The adapter requires a java.sql.Connection
object and a query statement.
They can be passed in on the constructor or set via methods.
The setConnection()
method will apply the connection object. The
setQueryStatement()
method will apply the SQL query statement. When
non-null values for both connection and query statement have been
applied, the adapter is initialized and ready to use.
The query statement must be a SQL query that is valid for the JDBC data source. This may include a blank statement, if valid.
The setTextColumnName method can be used to specify a single column from the result set that contains the values to be
displayed in the tree nodes. If more control is desired on what is displayed in the tree nodes, then a column values transform
can be set on the adapter, via the setColumnValuesTransform
method. The retrieveAllColumnValues
property
must be set to true in order for the column values transform to be used. If a column values transform has been specified and the
retrieveAllColumnValues
is true, then the adapter will use the specified column values transform to transform the Map
containing column names (all uppercased) mapped to column values into a single Object which is used in the tree node.
If the retrieveAllColumnValues
property is true, but no column values transform has been set, then the Object used in
the tree node will be a Map containing the column names (all uppercased) mapped to the column values.
The adapter can be configured and used within a webAF project. Add a
com.sas.storage.jdbc.JDBCConnection
component to your project. Open the customizer and
specify the values needed for your JDBC connection.These include driver name and URL.
Now open the customizer for the adapter.
Specify the value for JDBC Connection using the top combo box. The drop-down list
will show all JDBC Connection objects that exist in your project.
You can set the properties for query statement, the three designated columns,
autoCommit, and read-only, as well.
Field Summary | |
---|---|
protected java.lang.String |
indexColumnName
Column name of index column |
protected boolean |
inInit
True if the adapter is in initializion to prevent re-initialization from taking place concurrently |
protected int |
initialLevelsRead
Number of levels initially read |
protected java.lang.String |
levelColumnName
Column name of level column |
protected javax.swing.event.EventListenerList |
listenerList
List of listeners |
protected com.sas.util.transforms.TransformInterface |
nodeTransform
The transform used to transform a row of column values into a Node to be added to the tree model |
static java.lang.String |
RB_KEY
|
protected java.lang.String |
textColumnName
Column name of text column |
protected javax.swing.tree.DefaultTreeModel |
treeModel
TreeModel to store node values |
protected java.lang.String |
whereClause
The where clause applied for this particular node |
Fields inherited from class com.sas.storage.jdbc.JDBCColumnValuesAdapter |
---|
columnValuesTransform, retrieveAllColumnValues |
Fields inherited from class com.sas.storage.jdbc.JDBCAdapter |
---|
autoCommit, CLASS_NAME, columnInfoUsed, conn, designTime, displayTransform, forwardOnly, initialized, isRowCountKnown, LABEL, meta, NAME, printWarnings, queryRowCountDisabled, queryStatement, readOnly, result, resultSetRequeryUsed, resultSetType, resultSetUsed, retrieveNumericTypesAsDouble, rowCount, rowCountQueryString, rowNumber, spcs, stmt, trimUsed |
Constructor Summary | |
---|---|
JDBCToTreeModelAdapter()
Default constructor |
|
JDBCToTreeModelAdapter(java.sql.Connection conn,
java.lang.String queryStatement)
Constructor used to create an initialized adapter. |
|
JDBCToTreeModelAdapter(java.sql.ResultSet result)
Constructor used to connect an adapter directly to a previously created ResultSet. |
Method Summary | |
---|---|
void |
addChildren(java.lang.Object parentNode,
java.sql.ResultSet queryResult)
Creates and adds children to the parentNode based on level, index, and text values in the
specified resultSet . |
void |
addTreeModelListener(javax.swing.event.TreeModelListener l)
Adds a listener for the TreeModelEvent posted after the tree changes. |
void |
fireCellEvent(int row,
int column)
Fire a specific event for a model signaling that one cell has changed. |
void |
fireModelEvent()
Fire a default event for a model signaling the some aspect of the model has changed. |
void |
fireModelEvent(java.util.EventObject event)
Fire a specific event for a model signaling that some aspect of the model has changed. |
java.lang.Object |
getChild(java.lang.Object parent,
int index)
Returns the child of parent at the index given in the parent's child array. |
int |
getChildCount(java.lang.Object parent)
Returns the number of children of parent. |
static com.sas.beans.ExtendedBeanInfo |
getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this JDBCToTreeModelAdapter. |
java.lang.String |
getIndexColumnName()
Returns the name of the column in the data sourcet that contains the index values. |
int |
getIndexOfChild(java.lang.Object parent,
java.lang.Object child)
Returns the index of child in parent. |
int |
getInitialLevelsRead()
Returns the number of initial levels that should be read when the adapter initializes. |
java.lang.String |
getLevelColumnName()
Returns the name of the column in the data source that contains the level values. |
com.sas.util.transforms.TransformInterface |
getNodeTransform()
Retruns the transform that will be used to transform a Map containing column names (all uppercased) mapped to column values from a row in the result set into an IndexedMutableTreeNode. |
java.lang.Object |
getRoot()
Returns the root of the tree. |
java.lang.String |
getTextColumnName()
Returns the name of the column in the data source that contains the text values. |
protected void |
init()
Creates the Statement, ResultSet, and ResultSetMetaData objects using the queryStatement whenever the initialized field is false. |
boolean |
isLeaf(java.lang.Object node)
Returns true if node is a leaf. |
protected boolean |
readChildren(java.lang.Object node)
Read the children for this node and load them into the tree model for future access if the node has not yet been read. |
void |
removeTreeModelListener(javax.swing.event.TreeModelListener l)
Removes a listener previously added with addTreeModelListener(). |
void |
setIndexColumnName(java.lang.String indexColumnName)
Sets the name of the column in the data source that contains the index values. |
void |
setInitialLevelsRead(int initialLevelsRead)
Sets the number of initial levels that should be read when the adapter initializes. |
void |
setLevelColumnName(java.lang.String levelColumnName)
Sets the name of the column in the data source that contains the level values. |
void |
setNodeTransform(com.sas.util.transforms.TransformInterface nodeTransform)
Sets the transform that will be used to transform a Map containing column names (all uppercased) mapped to column values from a row in the result set into an IndexedMutableTreeNode. |
void |
setTextColumnName(java.lang.String textColumnName)
Sets the name of the column in the data source that contains the text values. |
void |
valueForPathChanged(javax.swing.tree.TreePath path,
java.lang.Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. |
Methods inherited from class com.sas.storage.jdbc.JDBCColumnValuesAdapter |
---|
getColumnValuesMap, getColumnValuesTransform, isRetrieveAllColumnValues, retrieveColumnValueAt, retrieveValueAt, setColumnValuesTransform, setRetrieveAllColumnValues |
Field Detail |
---|
public static final java.lang.String RB_KEY
protected javax.swing.event.EventListenerList listenerList
protected int initialLevelsRead
protected java.lang.String levelColumnName
protected java.lang.String indexColumnName
protected java.lang.String textColumnName
protected javax.swing.tree.DefaultTreeModel treeModel
protected boolean inInit
protected com.sas.util.transforms.TransformInterface nodeTransform
protected java.lang.String whereClause
Constructor Detail |
---|
public JDBCToTreeModelAdapter()
public JDBCToTreeModelAdapter(java.sql.ResultSet result)
result
- ResultSet to use.public JDBCToTreeModelAdapter(java.sql.Connection conn, java.lang.String queryStatement)
conn
- A java.sql.Connection
object.queryStatement
- A SQL query that is valid for the database
represented by conn
.Method Detail |
---|
public void addTreeModelListener(javax.swing.event.TreeModelListener l)
addTreeModelListener
in interface javax.swing.tree.TreeModel
l
- The listener to addpublic void removeTreeModelListener(javax.swing.event.TreeModelListener l)
removeTreeModelListener
in interface javax.swing.tree.TreeModel
l
- The listener to removepublic int getInitialLevelsRead()
public void setInitialLevelsRead(int initialLevelsRead)
initialLevelsRead
- The number of levels that should be loaded
By default, the initial number of levels read is three: one for the root, another for its
children to be visible, and the third level to detect whether the children are leaf nodes.
Setting initial values to any value less than one will read all levels.
public java.lang.String getLevelColumnName()
getLevelColumnName
in interface LevelDataInterface
public void setLevelColumnName(java.lang.String levelColumnName)
setLevelColumnName
in interface LevelDataInterface
levelColumnName
- The name of column that contains level valuespublic java.lang.String getIndexColumnName()
getIndexColumnName
in interface LevelDataInterface
public void setIndexColumnName(java.lang.String indexColumnName)
setIndexColumnName
in interface LevelDataInterface
indexColumnName
- The name of column that contains index valuespublic java.lang.String getTextColumnName()
getTextColumnName
in interface LevelDataInterface
public void setTextColumnName(java.lang.String textColumnName)
setTextColumnName
in interface LevelDataInterface
textColumnName
- The name of column that contains text valuesprotected void init()
queryStatement
whenever the initialized field is false.
init
in class JDBCAdapter
java.lang.IllegalStateException
- If the Connection or queryStatement
are null.public void addChildren(java.lang.Object parentNode, java.sql.ResultSet queryResult)
parentNode
based on level, index, and text values in the
specified resultSet
. The cursor of the resultSet
should be positioned before the first row.
In order to be successfully added as a new child to the parentNode
, the level value
must be one greater than the level of the parentNode
, and the index value must be greater
than the parentNode
's index and less than the parentNode
's next relative's index.
parentNode
- The node to which to add the new childrenpublic void setNodeTransform(com.sas.util.transforms.TransformInterface nodeTransform)
nodeTransform
- the transform used to transform a Map containing column names (all uppercased) mapped to column values from
a row in the result set into an IndexedMutableTreeNodepublic com.sas.util.transforms.TransformInterface getNodeTransform()
protected boolean readChildren(java.lang.Object node)
node
- The node in which the children should be read
public java.lang.Object getChild(java.lang.Object parent, int index)
getChild
in interface javax.swing.tree.TreeModel
parent
- A node in the tree, obtained from this data sourceindex
- Valid index of parent
public boolean isLeaf(java.lang.Object node)
isLeaf
in interface javax.swing.tree.TreeModel
node
- A node in the tree, obtained from this data source
public int getChildCount(java.lang.Object parent)
getChildCount
in interface javax.swing.tree.TreeModel
parent
- A node in the tree, obtained from this data source
public void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
valueForPathChanged
in interface javax.swing.tree.TreeModel
path
- Path to the node that the user has altered.newValue
- The new value from the TreeCellEditor.public int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
getIndexOfChild
in interface javax.swing.tree.TreeModel
public java.lang.Object getRoot()
getRoot
in interface javax.swing.tree.TreeModel
public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
public void fireCellEvent(int row, int column)
fireCellEvent
in class JDBCAdapter
row
- row number of the cell that has been modifiedcolumn
- column number of the cell that has been modifiedpublic void fireModelEvent(java.util.EventObject event)
fireModelEvent
in class JDBCAdapter
event
- Event that must be cast that should be firedpublic void fireModelEvent()
fireModelEvent
in class JDBCAdapter
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |