borland Packages Class Hierarchy dbswing Package
java.lang.Object +----com.borland.dbswing.DBTreeNavBinder +----com.borland.dbswing.DBTreeDataBinder
Variables Constructors Properties Methods
Implements DBDataBinder, AccessListener, ColumnAware, DataChangeListener, DataSetAware, Designable, NavigationListener, PropertyChangeListener, Serializable, EventListener, TreeModelListener, TreeSelectionListener
DBTreeDataBinder
maps a JTree's
selected value to a DataSet
Column
value. More generally, DBTreeDataBinder
can map any selected value obtained from a TreeModel
to a DataSet
value. In particular, DBTreeDataBinder
can be used to make a JTree
write its currently selected value to a DataSet
, and to update its currently selected value when the DataSet
value changes.
DBTreeDataBinder
is the default binder used by JdbTree
.
There are two other ways to use a DBTreeDataBinder
to make a tree data aware:
JTree
property to a JTree
, or subclass of JTree
.
TreeModel
and TreeSelectionModel
data-aware by setting DBTreeDataBinder's
treeModel
and treeSelectionModel
properties, or by adding DBTreeDataBinder
as a TreeSelectionListener
to the component. If you adopt this approach, you are responsible for opening the DataSet
.
In either case, you must also set DBTreeDataBinder's
dataSet
and columnName
properties to indicate the DataSet
and Column
to which the tree value is to be written and from which the tree value is to be read.
Note that DBTreeDataBinder
can read and write values between the tree and the specified DataSet
only if the TreeNodes
are of type javax.swing.tree.DefaultMutableTreeNode
. The value read from the tree is the value returned by the DefaultMutableTreeNode.getUserObject()
method. The object returned by getUserObject()
is assumed to be of the same data type as that of Column
columnName
. The DataSet
value is always written to the TreeModel
using the javax.swing.tree.MutableTreeNode.setUserObject()
method. The object passed to setUserObject()
is of the same data type as that of Column
columnName
.
Besides writing a value to a DataSet
when a tree value is selected, DBTreeDataBinder
also ensures that the selected tree value indicates the current value of the DataSet
Column
to which it is attached. When attempting to match the DataSet
value with a user object in the tree, DBTreeDataBinder
searches the tree in depth-first order until it encounters a user object with an equals()
method that returns true with the DataSet
value passed as the parameter. That user object's tree node then becomes the currently selected value in the tree. You can override the findUserObject()
method in a subclass to change the tree traversal algorithm. If the user object is anything other than a String
, it should usually override equals()
so that it returns true
when the contents of the two user objects have the same value, even if they are different instances.
If the value in the DataSet
doesn't match a value in the tree, DBTreeDataBinder
, by default, clears the tree selection so no value is selected in the tree. You can, however, set the unknownDataValueMode
property to one of the following values to specify alternative behavior:
DataSet
value can't be found in the tree.
jTree
property if the DataSet
value can't be found in the tree.
DataSet
value if it doesn't match any value in the tree and clears the current tree selection.
DBTreeDataBinder
can assign a single value only to a DataSet
Column
and it always uses the TreeSelectionModel's
first selection value (TreeSelectionModel.getSelectionPath()
) as the currently selected value, regardless of the selection mode of the model.
If you specify a TreeSelection
and TreeModel
individually instead of setting the JTree
property, be sure both models are working on the same model data.
JTree jTree = new JTree(); DBTreeDataBinder dBTreeDataBinder = new DBTreeDataBinder(); // Set the tree's TreeModel. // You must build a TreeModel outside of the code show here. // JBuilder has no component that can load a tree from a DataSet. jTree.setModel(treeModel); // when a value is selected from the tree, it is written // to the "path" column of DataSet dataSet dBTreeDataBinder.setJTree(jTree); dBTreeDataBinder.setDataSet(dataSet); dBTreeDataBinder.setColumnName("path");dbSwing can synchronize a tree with a
DataSet
so that navigation in the DataSet
changes the tree selection and selection in the tree navigates the DataSet
(instead of editing it). To do that, use a DBTreeNavBinder
instead of a DBTreeDataBinder
.
JdbTree
, JdbNavTree
, DBTreeNavBinder
public DBTreeDataBinder()Creates a
DBTreeDataBinder
. Calls the null
constructor of its superclass.
public DBTreeDataBinder(JTree jTree)Creates a
DBTreeDataBinder
that makes the specified JTree
data-aware. Calls the null
constructor of its superclass.
jTree
JTree
to which this DBTreeDataBinder
binds to make it data-aware.
public int getUnknownDataValueMode() public void setUnknownDataValueMode(int mode)Returns and sets the policy for setting the tree selection when synchronizing a tree with its
dataSet
value when the value can't be located in the tree. These are the possible values:
DataSet
value can't be found in the tree.
JTree
property if the DataSet
value can't be found in the tree.
DataSet
value if it doesn't match any value in the tree and clears the current tree selection.
protected void bindColumnProperties()Sets the
font
, foreground
, and background
properties from the column properties of the same names if these properties are not explicitly set.