コード例 #1
0
ファイル: ClutoTree.java プロジェクト: hiralv/TableViewNew
 /**
  * Recursive traverse of tree to determine selections A leaf is selected if rsm is selected.
  * Nonleaf nodes are selected if all children are selected.
  *
  * @param tn node in the tree for which to determine selection
  * @param nodeidx the ordinal postion in the segments array
  * @param gsm the graph segments selection model
  * @param rsm the table row selection model
  * @return true if given node tn is selected, else false
  */
 private boolean selTraverse(
     TreeNode tn, int[] nodeidx, ListSelectionModel gsm, ListSelectionModel rsm) {
   boolean selected = true;
   if (!tn.isLeaf()) {
     // A nonleaf node is selected if all its children are selected.
     for (int i = 0; i < tn.getChildCount(); i++) {
       TreeNode cn = tn.getChildAt(i);
       selected &= selTraverse(cn, nodeidx, gsm, rsm);
     }
   } else {
     if (tn instanceof RowCluster) {
       // get the row index of the leaf node
       int ri = ((RowCluster) tn).getIndex();
       // A leaf is selected if its row is selected in the row selection rsm.
       selected = rsm.isSelectedIndex(ri);
     }
   }
   // Get the offset into the segments array
   int idx = nodeidx[0] * segOffset;
   if (selected) {
     gsm.addSelectionInterval(idx, idx + (segOffset - 1));
   } else {
     gsm.removeSelectionInterval(idx, idx + (segOffset - 1));
   }
   // Increment the nodeidx in the tree
   nodeidx[0]++;
   return selected;
 }
コード例 #2
0
ファイル: ClutoTree.java プロジェクト: hiralv/TableViewNew
 /**
  * Traververse the tree selecting rows coresponding to leaf nodes of the given node tn
  *
  * @param tn the node from which to start traversing
  * @param rsm the selection model in which to mark selected rows
  */
 private void selectTraverse(TreeNode tn, ListSelectionModel rsm) {
   if (!tn.isLeaf()) {
     for (int i = 0; i < tn.getChildCount(); i++) {
       TreeNode cn = tn.getChildAt(i);
       selectTraverse(cn, rsm);
     }
   } else {
     if (tn instanceof RowCluster) {
       int ri = ((RowCluster) tn).getIndex();
       rsm.addSelectionInterval(ri, ri);
     }
   }
 }