qx.ui.treevirtual
Class SimpleTreeDataModel

java.lang.Object
  extended by qx.core.Object
      extended by qx.core.Target
          extended by qx.ui.table.model.Abstract
              extended by qx.ui.table.model.Simple
                  extended by qx.ui.treevirtual.SimpleTreeDataModel
All Implemented Interfaces:
ITableModel

public class SimpleTreeDataModel
extends Simple

A simple tree data model used as the table model

The object structure of a single node of the tree is:

{
  // USER-PROVIDED ATTRIBUTES
  // ------------------------
  type           : qx.ui.treevirtual.SimpleTreeDataModel.Type.LEAF,
  parentNodeId   : 23,    // index of the parent node in _nodeArr

  label          : "My Documents",
  bSelected      : true,  // true if node is selected; false otherwise.
  bOpened        : true,  // true (-), false (+)
  bHideOpenClose : false, // whether to hide the open/close button
  icon           : "images/folder.gif",
  iconSelected   : "images/folder_selected.gif",

  cellStyle      : "background-color:cyan"
  labelStyle     : "background-color:red;color:white"

  // USER-PROVIDED COLUMN DATA
  columnData     : [
                     null, // null at index of tree column (typically 0)
                     "text of column 1",
                     "text of column 2"
                   ],

  // APPLICATION-, MIXIN-, and SUBCLASS-PROVIDED CUSTOM DATA
  data           : {
                     application :
                     {
                         // application-specific user data goes in here
                         foo: "bar",
                         ...
                     },
                     MDragAndDropSupport :
                     {
                         // Data required for the Drag & Drop mixin.
                         // When a mixin is included, its constructor
                         // should create this object, named according
                         // to the mixin or subclass name (empty or
                         // otherwise)
                     },
                     ... // Additional mixins or subclasses.
                   },

  // INTERNALLY-CALCULATED ATTRIBUTES
  // --------------------------------
  // The following properties need not (and should not) be set by the
  // caller, but are automatically calculated.  Some are used internally,
  // while others may be of use to event listeners.

  nodeId         : 42,   // The index in _nodeArr, useful to event listeners.
  children       : [ ],  // each value is an index into _nodeArr

  level          : 2,    // The indentation level of this tree node

  bFirstChild    : true,
  lastChild      : [ false ],  // Array where the index is the column of
                               // indentation, and the value is a boolean.
                               // These are used to locate the
                               // appropriate "tree line" icon.
}


Constructor Summary
SimpleTreeDataModel()
           
 
Method Summary
 java.lang.Integer _addNode(java.lang.Integer parentNodeId, java.lang.String label, java.lang.Integer bOpened, boolean bHideOpenCloseButton, java.lang.Integer type, java.lang.String icon, java.lang.String iconSelected)
          Add a node to the tree.
 void _clearSelections()
          Clear all selections in the data model.
 java.lang.Integer addBranch(java.lang.Integer parentNodeId, java.lang.String label, boolean bOpened, boolean bHideOpenCloseButton, java.lang.String icon, java.lang.String iconSelected)
          Add a branch to the tree.
 java.lang.Integer addLeaf(java.lang.Integer parentNodeId, java.lang.String label, java.lang.String icon, java.lang.String iconSelected)
          Add a leaf to the tree.
 void clearData()
          Clears the tree of all nodes
 java.lang.Object getColumnData(java.lang.Integer nodeId, java.lang.Integer columnIndex)
          Retrieve the data from an additional column (a column other than the tree column) of the tree.
 java.lang.Object getData()
          Return the array of node data.
 java.lang.Object getNodeFromRow(java.lang.Integer rowIndex)
          This operation maps rowIndexes to nodes.
 java.lang.Object getNodeRowMap()
          Return the mapping of nodes to rendered rows.
 java.lang.Integer getRowCount()
          Returns the number of rows in the model.
 java.lang.Object getRowData(java.lang.Integer rowIndex)
          Returns the data of one row.
 void getRowFromNodeId(java.lang.Integer nodeId)
          This operation maps nodes to rowIndexes.
 java.lang.Object getSelectedNodes()
          Return the nodes that are currently selected.
 java.lang.Integer getSortColumnIndex()
          Returns the column index the model is sorted by.
 void getTree()
           
 java.lang.Integer getTreeColumn()
          Get the column in which the tree is to be displayed.
 java.lang.Object getValue(java.lang.Object columnIndex, java.lang.Object rowIndex)
           
 boolean isColumnSortable(java.lang.Integer columnIndex)
          Returns whether a column is sortable.
 void prune(java.lang.Object nodeReference, boolean bSelfAlso)
          Prune the tree by removing, recursively, all of a node’s children.
 void setColumnData(java.lang.Integer nodeId, java.lang.Integer columnIndex, java.lang.Object data)
          Add data to an additional column (a column other than the tree column) of the tree.
 void setColumnEditable(java.lang.Integer columnIndex, boolean editable)
          Sets whether a column is editable.
 void setData(java.lang.Object nodeArr)
          Sets the whole data en bulk, or notifies the data model that node modifications are complete.
 void setState(java.lang.Object nodeReference, java.lang.Object attributes)
          Set state attributes of a node.
 void setTree(java.lang.Object tree)
           
 void setTreeColumn(java.lang.Integer columnIndex)
          Specifies which column the tree is to be displayed in.
 void setValue(java.lang.Integer columnIndex, java.lang.Integer rowIndex, java.lang.Object value)
          Sets a cell value by column index.
 void sortByColumn(java.lang.Integer columnIndex, boolean ascending)
          Sorts the model by a column.
 
Methods inherited from class qx.ui.table.model.Simple
_clearSorting, _mapArray2RowArr, addRows, addRowsAsMapArray, getCaseSensitiveSorting, getRowDataAsMap, getValue, initCaseSensitiveSorting, isCaseSensitiveSorting, isColumnEditable, isSortAscending, removeRows, resetCaseSensitiveSorting, setCaseSensitiveSorting, setColumnSortable, setData, setDataAsMapArray, setEditable, setSortMethods, toggleCaseSensitiveSorting
 
Methods inherited from class qx.ui.table.model.Abstract
getColumnCount, getColumnId, getColumnIndexById, getColumnName, getValueById, prefetchRows, setColumnIds, setColumnNamesById, setColumnNamesByIndex, setColumns, setValueById
 
Methods inherited from class qx.core.Target
_dispatchEvent, addChangeSelectionListener, addChangeValueListener, addEventListener, addExecuteListener, addJavaEventListener, createDispatchChangeEvent, createDispatchDataEvent, createDispatchEvent, dispatchEvent, hasEventListeners, removeEventListener
 
Methods inherited from class qx.core.Object
_disposeFields, _disposeObjectDeep, _disposeObjects, base, dispose, get, getDisposed, isDisposed, reset, self, set, toHashCode, toString_
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTreeDataModel

public SimpleTreeDataModel()
Method Detail

_addNode

public java.lang.Integer _addNode(java.lang.Integer parentNodeId,
                                  java.lang.String label,
                                  java.lang.Integer bOpened,
                                  boolean bHideOpenCloseButton,
                                  java.lang.Integer type,
                                  java.lang.String icon,
                                  java.lang.String iconSelected)

Add a node to the tree.

NOTE: This method is for internal use and should not be called by users of this class. Instead, call addBranch(java.lang.Integer, java.lang.String, boolean, boolean, java.lang.String, java.lang.String) or addLeaf(java.lang.Integer, java.lang.String, java.lang.String, java.lang.String). There is no guarantee that the interface to this method will remain unchanged over time.


_clearSelections

public void _clearSelections()

Clear all selections in the data model. This method does not clear selections displayed in the widget, and is intended for internal use, not by users of this class.


addBranch

public java.lang.Integer addBranch(java.lang.Integer parentNodeId,
                                   java.lang.String label,
                                   boolean bOpened,
                                   boolean bHideOpenCloseButton,
                                   java.lang.String icon,
                                   java.lang.String iconSelected)

Add a branch to the tree.


addLeaf

public java.lang.Integer addLeaf(java.lang.Integer parentNodeId,
                                 java.lang.String label,
                                 java.lang.String icon,
                                 java.lang.String iconSelected)

Add a leaf to the tree.


clearData

public void clearData()

Clears the tree of all nodes


getColumnData

public java.lang.Object getColumnData(java.lang.Integer nodeId,
                                      java.lang.Integer columnIndex)

Retrieve the data from an additional column (a column other than the tree column) of the tree.


getData

public java.lang.Object getData()

Return the array of node data.

Overrides:
getData in class Simple

getNodeFromRow

public java.lang.Object getNodeFromRow(java.lang.Integer rowIndex)

This operation maps rowIndexes to nodes. It does the opposite job to getRowFromNodeId(java.lang.Integer). This function is useful to map selection (row based) to nodes.


getNodeRowMap

public java.lang.Object getNodeRowMap()

Return the mapping of nodes to rendered rows. This function is intended for use by the cell renderer, not by users of this class. It is also useful to select a node.


getRowCount

public java.lang.Integer getRowCount()
Description copied from interface: ITableModel

Returns the number of rows in the model.

Specified by:
getRowCount in interface ITableModel
Overrides:
getRowCount in class Simple

getRowData

public java.lang.Object getRowData(java.lang.Integer rowIndex)
Description copied from interface: ITableModel

Returns the data of one row. This function may be overriden by models which hold all data of a row in one object. By using this function, clients have a way of quickly retrieving the entire row data.

Important:Models which do not have their row data accessible in one object may return null.

Specified by:
getRowData in interface ITableModel
Overrides:
getRowData in class Simple

getRowFromNodeId

public void getRowFromNodeId(java.lang.Integer nodeId)

This operation maps nodes to rowIndexes. It does the opposite job to getNodeFromRow(java.lang.Integer).


getSelectedNodes

public java.lang.Object getSelectedNodes()

Return the nodes that are currently selected.


getSortColumnIndex

public java.lang.Integer getSortColumnIndex()

Returns the column index the model is sorted by. This model is never sorted, so -1 is returned.

Specified by:
getSortColumnIndex in interface ITableModel
Overrides:
getSortColumnIndex in class Simple

getTree

public void getTree()

getTreeColumn

public java.lang.Integer getTreeColumn()

Get the column in which the tree is to be displayed.


getValue

public java.lang.Object getValue(java.lang.Object columnIndex,
                                 java.lang.Object rowIndex)

isColumnSortable

public boolean isColumnSortable(java.lang.Integer columnIndex)
Description copied from interface: ITableModel

Returns whether a column is sortable.

Specified by:
isColumnSortable in interface ITableModel
Overrides:
isColumnSortable in class Simple

prune

public void prune(java.lang.Object nodeReference,
                  boolean bSelfAlso)

Prune the tree by removing, recursively, all of a node’s children. If requested, also remove the node itself.


setColumnData

public void setColumnData(java.lang.Integer nodeId,
                          java.lang.Integer columnIndex,
                          java.lang.Object data)

Add data to an additional column (a column other than the tree column) of the tree.


setColumnEditable

public void setColumnEditable(java.lang.Integer columnIndex,
                              boolean editable)
Description copied from class: Simple

Sets whether a column is editable.

Overrides:
setColumnEditable in class Simple

setData

public void setData(java.lang.Object nodeArr)

Sets the whole data en bulk, or notifies the data model that node modifications are complete.


setState

public void setState(java.lang.Object nodeReference,
                     java.lang.Object attributes)

Set state attributes of a node.


setTree

public void setTree(java.lang.Object tree)

setTreeColumn

public void setTreeColumn(java.lang.Integer columnIndex)

Specifies which column the tree is to be displayed in. The tree is displayed using the SimpleTreeDataCellRenderer. Other columns may be provided which use different cell renderers.


setValue

public void setValue(java.lang.Integer columnIndex,
                     java.lang.Integer rowIndex,
                     java.lang.Object value)
Description copied from interface: ITableModel

Sets a cell value by column index.

Specified by:
setValue in interface ITableModel
Overrides:
setValue in class Simple

sortByColumn

public void sortByColumn(java.lang.Integer columnIndex,
                         boolean ascending)
Description copied from interface: ITableModel

Sorts the model by a column.

Specified by:
sortByColumn in interface ITableModel
Overrides:
sortByColumn in class Simple


Copyright © 2008 1&1. All Rights Reserved.