Search in sources :

Example 26 with MTreeNode

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));
}
Also used : MTreeNode(org.compiere.model.MTreeNode)

Example 27 with MTreeNode

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;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) ArrayList(java.util.ArrayList)

Example 28 with MTreeNode

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;
}
Also used : Treecol(org.zkoss.zul.Treecol) MTreeNode(org.compiere.model.MTreeNode) Treecols(org.zkoss.zul.Treecols) MTree(org.compiere.model.MTree)

Example 29 with MTreeNode

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);
        }
    }
}
Also used : MTreeNode(org.compiere.model.MTreeNode) ArrayList(java.util.ArrayList)

Example 30 with MTreeNode

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;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode)

Aggregations

MTreeNode (org.compiere.model.MTreeNode)38 MTree (org.compiere.model.MTree)9 DefaultTreeNode (org.zkoss.zul.DefaultTreeNode)8 Treeitem (org.zkoss.zul.Treeitem)7 JTree (javax.swing.JTree)5 ArrayList (java.util.ArrayList)4 Enumeration (java.util.Enumeration)4 TreePath (javax.swing.tree.TreePath)4 MContainer (org.compiere.model.MContainer)3 BorderLayout (java.awt.BorderLayout)2 JButton (javax.swing.JButton)2 JToolBar (javax.swing.JToolBar)2 AdempiereTaskPaneUI (org.adempiere.plaf.AdempiereTaskPaneUI)2 SimpleTreeModel (org.adempiere.webui.component.SimpleTreeModel)2 org.apache.ecs.xhtml.a (org.apache.ecs.xhtml.a)2 org.apache.ecs.xhtml.body (org.apache.ecs.xhtml.body)2 org.apache.ecs.xhtml.head (org.apache.ecs.xhtml.head)2 org.apache.ecs.xhtml.link (org.apache.ecs.xhtml.link)2 MCStage (org.compiere.model.MCStage)2 JXTaskPane (org.jdesktop.swingx.JXTaskPane)2