use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class TreeXML method generateTree.
public void generateTree(MWebProject m_project, MTree thisTree) {
MTreeNode root = thisTree.getRoot();
xmlTree.append(appendNode(root));
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class SimpleTreeModel method createFrom.
// End Yamel Senih
/**
*
* @param root
* @return SimpleTreeModel
*/
public static SimpleTreeModel createFrom(MTreeNode root) {
SimpleTreeModel model = null;
Enumeration<?> nodeEnum = root.children();
DefaultTreeNode<Object> stRoot = new DefaultTreeNode<Object>(root, nodeEnum.hasMoreElements() ? new ArrayList<TreeNode<Object>>() : null);
while (nodeEnum.hasMoreElements()) {
MTreeNode childNode = (MTreeNode) nodeEnum.nextElement();
DefaultTreeNode<Object> stNode = childNode.getChildCount() > 0 ? new DefaultTreeNode<Object>(childNode, new ArrayList<TreeNode<Object>>()) : new DefaultTreeNode<Object>(childNode);
stRoot.getChildren().add(stNode);
if (childNode.getChildCount() > 0) {
populate(stNode, childNode);
}
}
model = new SimpleTreeModel(stRoot);
return model;
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class SimpleTreeModel method initADTree.
/**
* @param tree
* @param AD_Tree_ID
* @param windowNo
* @param editable
* @param whereClause
* @param trxName
* @return SimpleTreeModel
*/
public static SimpleTreeModel initADTree(Tree tree, int AD_Tree_ID, int windowNo, boolean editable, String whereClause, String trxName) {
// Change to where clause
MTree vTree = new MTree(Env.getCtx(), AD_Tree_ID, editable, true, false, whereClause, trxName);
MTreeNode root = vTree.getRoot();
SimpleTreeModel treeModel = SimpleTreeModel.createFrom(root);
treeModel.setItemDraggable(true);
treeModel.addOnDropEventListener(new ADTreeOnDropListener(tree, treeModel, vTree, windowNo));
Treecols treeCols = new Treecols();
tree.appendChild(treeCols);
Treecol treeCol = new Treecol();
treeCols.appendChild(treeCol);
tree.setPageSize(-1);
try {
tree.setItemRenderer(treeModel);
tree.setModel(treeModel);
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to setup tree");
}
return treeModel;
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class SimpleTreeModel method populate.
private static void populate(DefaultTreeNode<Object> stNode, MTreeNode root) {
Enumeration<?> nodeEnum = root.children();
while (nodeEnum.hasMoreElements()) {
MTreeNode childNode = (MTreeNode) nodeEnum.nextElement();
DefaultTreeNode<Object> stChildNode = childNode.getChildCount() > 0 ? new DefaultTreeNode<Object>(childNode, new ArrayList<TreeNode<Object>>()) : new DefaultTreeNode<Object>(childNode);
stNode.getChildren().add(stChildNode);
if (childNode.getChildCount() > 0) {
populate(stChildNode, childNode);
}
}
}
use of org.compiere.model.MTreeNode in project adempiere by adempiere.
the class SimpleTreeModel method find.
/**
* @param fromNode
* @param recordId
* @return DefaultTreeNode
*/
public DefaultTreeNode<Object> find(DefaultTreeNode<Object> fromNode, int recordId) {
if (fromNode == null)
fromNode = getRoot();
MTreeNode data = (MTreeNode) fromNode.getData();
if (data.getNode_ID() == recordId)
return fromNode;
// This will have no children causing a NPE error in isLeaf().
try {
if (isLeaf(fromNode))
return null;
} catch (NullPointerException e) {
logger.severe("Uninitialized node exists in tree. Node ID: " + data.getNode_ID());
return null;
}
int cnt = getChildCount(fromNode);
for (int i = 0; i < cnt; i++) {
DefaultTreeNode<Object> child = (DefaultTreeNode<Object>) getChild(fromNode, i);
DefaultTreeNode<Object> treeNode = find(child, recordId);
if (treeNode != null)
return treeNode;
}
return null;
}
Aggregations