Search in sources :

Example 16 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class AdempiereTreeModel method saveChangedNodes.

public void saveChangedNodes(MTreeNode from, MTreeNode to) {
    int AD_Tree_ID = m_MTree.getAD_Tree_ID();
    Trx trx = Trx.get(Trx.createTrxName("AdempiereTreeModel"), true);
    try {
        for (int i = 0; i < from.getChildCount(); i++) {
            MTreeNode nd = (MTreeNode) from.getChildAt(i);
            String whereClause = "AD_Tree_ID=" + AD_Tree_ID + " AND Node_ID=" + nd.getNode_ID();
            PO tree = MTable.get(Env.getCtx(), m_MTree.getNodeTableName()).getPO(whereClause, trx.getTrxName());
            if (tree.get_ValueAsInt("Parent_ID") != from.getNode_ID() || tree.get_ValueAsInt("SeqNo") != i) {
                tree.set_CustomColumn("Parent_ID", from.getNode_ID());
                tree.set_CustomColumn("SeqNo", i);
                tree.saveEx();
            }
        }
        if (from != to) {
            // Renumber and set parent ID for the children of the 'to' node.
            int nextSeqNo = 0;
            for (int i = 0; i < to.getChildCount(); i++) {
                // Skip the entry of the 'from' node to avoid duplication
                if (i == Integer.parseInt(from.getSeqNo()))
                    continue;
                MTreeNode nd = (MTreeNode) to.getChildAt(i);
                String whereClause = "AD_Tree_ID=" + AD_Tree_ID + " AND Node_ID=" + nd.getNode_ID();
                PO tree = MTable.get(Env.getCtx(), m_MTree.getNodeTableName()).getPO(whereClause, trx.getTrxName());
                if (tree.get_ValueAsInt("Parent_ID") != to.getNode_ID() || tree.get_ValueAsInt("SeqNo") < nextSeqNo) {
                    tree.set_CustomColumn("Parent_ID", to.getNode_ID());
                    tree.set_CustomColumn("SeqNo", nextSeqNo++);
                    tree.saveEx();
                } else {
                    nextSeqNo = tree.get_ValueAsInt("SeqNo") + 1;
                }
            }
        }
        trx.commit(true);
    } catch (Exception e) {
        trx.rollback();
        log.log(Level.SEVERE, "move", e);
    }
    trx.close();
    trx = null;
    log.config("complete");
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Trx(org.compiere.util.Trx) PO(org.compiere.model.PO)

Example 17 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class ADTreeOnDropListener method moveNode.

/**
	 *	Move TreeNode
	 *	@param	movingNode	The node to be moved
	 *	@param	toNode		The target node
	 */
private void moveNode(DefaultTreeNode movingNode, DefaultTreeNode toNode) {
    log.info(movingNode.toString() + " to " + toNode.toString());
    if (movingNode == toNode)
        return;
    MTreeNode toMNode = (MTreeNode) toNode.getData();
    DefaultTreeNode newParent;
    int index;
    if (//	drop on a child node
    !toMNode.isSummary()) {
        moveNode(movingNode, toNode, false);
    } else //	drop on a summary node
    {
        //prompt user to select insert after or drop into the summary node
        int[] path = treeModel.getPath(toNode);
        Treeitem toItem = tree.renderItemByPath(path);
        tree.setSelectedItem(toItem);
        Events.sendEvent(tree, new Event(Events.ON_SELECT, tree));
        MenuListener listener = new MenuListener(movingNode, toNode);
        //TODO: translation
        Menupopup popup = new Menupopup();
        Menuitem menuItem = new Menuitem("Insert After");
        menuItem.setValue("InsertAfter");
        menuItem.setParent(popup);
        menuItem.addEventListener(Events.ON_CLICK, listener);
        menuItem = new Menuitem("Move Into");
        menuItem.setValue("MoveInto");
        menuItem.setParent(popup);
        menuItem.addEventListener(Events.ON_CLICK, listener);
        popup.setPage(tree.getPage());
        popup.open(toItem.getTreerow());
    }
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Treeitem(org.zkoss.zul.Treeitem) Menupopup(org.zkoss.zul.Menupopup) Menuitem(org.zkoss.zul.Menuitem) DefaultTreeNode(org.zkoss.zul.DefaultTreeNode) Event(org.zkoss.zk.ui.event.Event) DropEvent(org.zkoss.zk.ui.event.DropEvent)

Example 18 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class MenuPanel method generateMenu.

private void generateMenu(Treechildren treeChildren, MTreeNode mNode) {
    Enumeration<?> nodeEnum = mNode.children();
    while (nodeEnum.hasMoreElements()) {
        MTreeNode mChildNode = (MTreeNode) nodeEnum.nextElement();
        Treeitem treeitem = new Treeitem();
        treeChildren.appendChild(treeitem);
        treeitem.setLabel(mChildNode.getName());
        treeitem.setTooltiptext(mChildNode.getDescription());
        if (mChildNode.getChildCount() != 0) {
            treeitem.setOpen(false);
            Treechildren treeItemChildren = new Treechildren();
            generateMenu(treeItemChildren, mChildNode);
            if (treeItemChildren.getChildren().size() != 0)
                treeitem.appendChild(treeItemChildren);
            treeitem.getTreerow().addEventListener(Events.ON_CLICK, this);
        } else {
            treeitem.setValue(String.valueOf(mChildNode.getNode_ID()));
            if (mChildNode.isReport())
                treeitem.setImage(ServletFns.resolveThemeURL("~./images/mReport.png"));
            else if (mChildNode.isProcess() || mChildNode.isTask())
                treeitem.setImage(ServletFns.resolveThemeURL("~./images/mProcess.png"));
            else if (mChildNode.isWorkFlow())
                treeitem.setImage(ServletFns.resolveThemeURL("~./images/mWorkFlow.png"));
            else
                treeitem.setImage(ServletFns.resolveThemeURL("~./images/mWindow.png"));
            // Elaine 2008/07/24
            treeitem.getTreerow().setDraggable("favourite");
            treeitem.getTreerow().addEventListener(Events.ON_CLICK, this);
        }
    }
}
Also used : MTreeNode(org.compiere.model.MTreeNode) Treeitem(org.zkoss.zul.Treeitem) Treechildren(org.zkoss.zul.Treechildren)

Example 19 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class TreeSearchPanel method addTreeItem.

private void addTreeItem(DefaultTreeNode<?> node) {
    Object data = node.getData();
    if (data instanceof MTreeNode) {
        MTreeNode mNode = (MTreeNode) data;
        treeNodeItemMap.put(mNode.getName(), node);
    }
}
Also used : MTreeNode(org.compiere.model.MTreeNode)

Example 20 with MTreeNode

use of org.compiere.model.MTreeNode in project adempiere by adempiere.

the class MenuPanel method init.

private void init() {
    ctx = Env.getCtx();
    int adRoleId = Env.getAD_Role_ID(ctx);
    int adTreeId = getTreeId(ctx, adRoleId);
    MTree mTree = new MTree(ctx, adTreeId, false, true, null);
    MTreeNode rootNode = mTree.getRoot();
    initComponents();
    initMenu(rootNode);
    pnlSearch.initialise();
}
Also used : MTreeNode(org.compiere.model.MTreeNode) MTree(org.compiere.model.MTree)

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