Search in sources :

Example 6 with MTreeNode

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

the class VTreePanel method mouseClicked.

//  keyPressed
/*************************************************************************/
/**
	 *  Mouse clicked
	 *  @param e event
	 */
protected void mouseClicked(MouseEvent e) {
    //  *** JTree ***
    if (e.getSource() instanceof JTree) {
        //  Left Double Click
        if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 0) {
            int selRow = tree.getRowForLocation(e.getX(), e.getY());
            if (selRow != -1) {
                MTreeNode tn = (MTreeNode) tree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
                setSelectedNode(tn);
            }
        } else //  Right Click for PopUp
        if ((m_editable || m_hasBar) && SwingUtilities.isRightMouseButton(e)) {
            int selRow = tree.getRowForLocation(e.getX(), e.getY());
            if (selRow != -1) {
                tree.setSelectionRow(selRow);
            }
            if (//  need select first
            tree.getSelectionPath() != null) {
                MTreeNode nd = (MTreeNode) tree.getSelectionPath().getLastPathComponent();
                if (//  only add leaves to bar
                nd.isLeaf())
                    mBarAdd.setEnabled(true);
                else
                    mBarAdd.setEnabled(false);
                Rectangle r = tree.getPathBounds(tree.getSelectionPath());
                popMenuTree.show(tree, (int) r.getMaxX(), (int) r.getY());
            }
        }
    } else //  *** JButton ***
    if (e.getSource() instanceof JButton) {
        if (SwingUtilities.isRightMouseButton(e)) {
            m_buttonSelected = (CButton) e.getSource();
            popMenuBar.show(m_buttonSelected, e.getX(), e.getY());
        }
    }
//  JButton
}
Also used : MTreeNode(org.compiere.model.MTreeNode) JTree(javax.swing.JTree) Rectangle(java.awt.Rectangle) JButton(javax.swing.JButton) CButton(org.compiere.swing.CButton)

Example 7 with MTreeNode

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

the class VTreePanel method selectID.

//  setSelectedNode
/**
	 *  Select ID in Tree
	 *  @param nodeID	Node ID
	 *  @param show	scroll to node
	 * 	@return true if selected
	 */
private boolean selectID(int nodeID, boolean show) {
    if (m_root == null)
        return false;
    log.config("NodeID=" + nodeID + ", Show=" + show + ", root=" + m_root);
    //  try to find the node
    MTreeNode node = m_root.findNode(nodeID);
    if (node != null) {
        TreePath treePath = new TreePath(node.getPath());
        log.config("Node=" + node + ", Path=" + treePath.toString());
        tree.setSelectionPath(treePath);
        if (show) {
            //	expand it
            tree.makeVisible(treePath);
            tree.scrollPathToVisible(treePath);
        }
        return true;
    }
    log.info("Node not found; ID=" + nodeID);
    return false;
}
Also used : MTreeNode(org.compiere.model.MTreeNode) TreePath(javax.swing.tree.TreePath)

Example 8 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 9 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 10 with MTreeNode

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

the class TreeXML method appendNode.

private String appendNode(MTreeNode thisNode) {
    StringBuffer tempTree = new StringBuffer();
    Integer ID = new Integer(thisNode.getNode_ID());
    MContainer container = m_map.get(ID);
    //	
    int size = thisNode.getChildCount();
    for (int i = 0; i < size; i++) {
        MTreeNode child = (MTreeNode) thisNode.getChildAt(i);
        ID = new Integer(child.getNode_ID());
        container = m_map.get(ID);
        if (container == null) {
            continue;
        }
        if (!container.isActive())
            continue;
        //
        tempTree.append("<treenode>");
        tempTree.append("<CM_Container_ID>" + container.get_ID() + "</CM_Container_ID>");
        tempTree.append("<Name>" + container.getName() + "</Name>");
        tempTree.append("<Title>" + container.getTitle() + "</Title>");
        tempTree.append("<RelativeURL>" + container.getRelativeURL() + "</RelativeURL>");
        tempTree.append("<Description>" + container.getDescription() + "</Description>");
        tempTree.append("<children>" + child.getChildCount() + "</children>");
        xmlContainer = container.get_xmlString(xmlContainer);
        if (child.isSummary())
            tempTree.append(appendNode(child));
        tempTree.append("</treenode>");
    }
    return tempTree.toString();
}
Also used : MTreeNode(org.compiere.model.MTreeNode) MContainer(org.compiere.model.MContainer)

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