Search in sources :

Example 86 with TreePath

use of javax.swing.tree.TreePath 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 87 with TreePath

use of javax.swing.tree.TreePath in project adempiere by adempiere.

the class RadioButtonTreeCellRenderer method printTree.

public void printTree(TreePath path, TreeModel model, TreeCheckingModel checkingModel) {
    log.fine("In printTree");
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    log.fine("Node: " + node);
    log.fine("isPathCheckbox: " + checkingModel.isPathCheckBox(getPath(node)));
    for (TreePath childPath : getChildrenPath(path, model)) {
        printTree(childPath, model, checkingModel);
    }
    return;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath)

Example 88 with TreePath

use of javax.swing.tree.TreePath in project adempiere by adempiere.

the class RadioButtonTreeCellRenderer method getTreeCellRendererComponent.

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    log.fine("row: " + row);
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
    log.fine("treeNode.getLevel: " + treeNode.getLevel());
    nodeUserObject m_nodeUserObject = (nodeUserObject) treeNode.getUserObject();
    log.fine("m_nodeUserObject.toString: " + m_nodeUserObject.toString());
    log.fine("m_nodeUserObject.M_Product.getName: " + m_nodeUserObject.M_Product.getName());
    log.fine("value.toString: " + value.toString());
    label.setText(value.toString());
    TreeCheckingModel checkingModel = ((CheckboxTree) tree).getCheckingModel();
    //printTree(new TreePath(tree.getModel().getRoot()), tree.getModel(), checkingModel);
    TreePath path = tree.getPathForRow(row);
    boolean enabled = checkingModel.isPathEnabled(path);
    boolean checked = checkingModel.isPathChecked(path);
    //	    	boolean checkBoxed = checkingModel.isPathCheckBox(path);
    checked = checkingModel.isPathChecked(path);
    //	    	boolean grayed = checkingModel.isPathGreyed(path);
    button.setEnabled(true);
    button.setSelected(checked);
    m_nodeUserObject.isChosen = checked;
    log.fine("m_nodeUserObject.isChosen" + m_nodeUserObject.isChosen);
    if (m_nodeUserObject.isCheckbox || treeNode.isRoot()) {
        panel.add(checkBox);
        panel.remove(button);
        log.fine("checked: " + checked);
        log.fine("enabled: " + enabled);
        checkBox.setEnabled(enabled);
        checkBox.setSelected(checked);
        if (treeNode.isRoot()) {
            checkBox.setSelected(true);
            checkBox.setEnabled(false);
            m_nodeUserObject.isMandatory = true;
        }
        if (m_nodeUserObject.isMandatory) {
            checkBox.setSelected(true);
            checkBox.setEnabled(false);
        }
    } else {
        panel.remove(checkBox);
        panel.add(button);
    }
    panel.add(label);
    m_nodeUserObject.isChosen = checked;
    log.fine("m_nodeUserObject.isChosen: " + m_nodeUserObject.isChosen);
    if (m_nodeUserObject.bom != null) {
        log.fine("m_nodeUserObject.bom not null");
        log.fine("m_nodeUserObject.bom product_id: " + m_nodeUserObject.bom.getM_Product_ID());
        if (m_nodeUserObject.bomLine == null) {
            log.fine("m_nodeUserObject.bomLine is null");
            DefaultMutableTreeNode m_treeNode = getTreeNodeForNodeUserObject(m_nodeUserObject);
            if (!m_treeNode.isRoot()) {
                DefaultMutableTreeNode m_treeNodeParent = (DefaultMutableTreeNode) m_treeNode.getParent();
                if (m_treeNodeParent.isRoot()) {
                    m_nodeUserObject.isMandatory = true;
                }
                nodeUserObject m_nodeUserObjectParent = (nodeUserObject) m_treeNodeParent.getUserObject();
                if (m_nodeUserObjectParent.bom != null) {
                    log.fine("m_nodeUserObjectParent.bom is not null");
                    log.fine("m_nodeUserObjectParent.bom.pp_product_bom_id: " + m_nodeUserObjectParent.bom.get_ID());
                    log.fine("m_nodeUserObject.M_Product.get_ID: " + m_nodeUserObject.M_Product.get_ID());
                    if (getComponentTypeUsingBOMParent(m_nodeUserObjectParent.bom.get_ID(), m_nodeUserObject.M_Product.get_ID()).equals(MPPProductBOMLine.COMPONENTTYPE_Variant) || getComponentTypeUsingBOMParent(m_nodeUserObjectParent.bom.get_ID(), m_nodeUserObject.M_Product.get_ID()).equals(MPPProductBOMLine.COMPONENTTYPE_Component)) {
                        log.fine("Type is checkbox");
                        if (!m_nodeUserObject.isCheckbox) {
                            m_nodeUserObject.isCheckbox = true;
                            panel.remove(label);
                            panel.add(checkBox);
                            panel.add(label);
                            panel.remove(button);
                            if (!m_nodeUserObject.isChosen) {
                                checkBox.setSelected(false);
                                m_nodeUserObject.isChosen = false;
                            } else {
                                checkBox.setSelected(true);
                                m_nodeUserObject.isMandatory = true;
                                m_nodeUserObject.isChosen = true;
                            }
                        }
                    }
                } else {
                    log.fine("Type is checkbox");
                    if (!m_nodeUserObject.isCheckbox) {
                        panel.remove(label);
                        panel.add(checkBox);
                        panel.add(label);
                        panel.remove(button);
                    }
                }
            }
        } else {
            log.fine("m_nodeUserObject.bomLine is not null");
            log.fine("m_nodeUserObject.M_Product.get_ID: " + m_nodeUserObject.M_Product.get_ID());
            log.fine("m_nodeUserObject.bomLine.getM_Product_ID: " + m_nodeUserObject.bomLine.getM_Product_ID());
            log.fine("m_nodeUserObject.isCheckbox: " + m_nodeUserObject.isCheckbox);
        }
    }
    panel.setBackground(Color.white);
    log.fine("m_nodeUserObject.isChosen: " + m_nodeUserObject.isChosen);
    return panel;
}
Also used : TreeCheckingModel(it.cnr.imaa.essi.lablib.gui.checkboxtree.TreeCheckingModel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) CheckboxTree(it.cnr.imaa.essi.lablib.gui.checkboxtree.CheckboxTree)

Example 89 with TreePath

use of javax.swing.tree.TreePath in project adempiere by adempiere.

the class DefaultCheckboxTreeCellRenderer method getTreeCellRendererComponent.

/**
         * Decorates this renderer based on the passed in components.
         */
public Component getTreeCellRendererComponent(JTree tree, Object object, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    /*
         * most of the rendering is delegated to the wrapped
         * DefaultTreeCellRenderer, the rest depends on the TreeCheckingModel
         */
    this.label.getTreeCellRendererComponent(tree, object, selected, expanded, leaf, row, hasFocus);
    if (tree instanceof CheckboxTree) {
        TreeCheckingModel checkingModel = ((CheckboxTree) tree).getCheckingModel();
        TreePath path = tree.getPathForRow(row);
        this.checkBox.setEnabled(checkingModel.isPathEnabled(path));
        boolean checked = checkingModel.isPathChecked(path);
        boolean greyed = checkingModel.isPathGreyed(path);
        if (checked && !greyed) {
            this.checkBox.setState(State.CHECKED);
        }
        if (!checked && greyed) {
            this.checkBox.setState(State.GREY_UNCHECKED);
        }
        if (checked && greyed) {
            this.checkBox.setState(State.GREY_CHECKED);
        }
        if (!checked && !greyed) {
            this.checkBox.setState(State.UNCHECKED);
        }
    }
    return this;
}
Also used : TreePath(javax.swing.tree.TreePath)

Example 90 with TreePath

use of javax.swing.tree.TreePath in project adempiere by adempiere.

the class DefaultTreeCheckingModel method uncheckSubTree.

/**
         * Unchecks the subtree with root path.
         * 
         * @param path root of the tree to be unchecked
         */
public void uncheckSubTree(TreePath path) {
    removeFromCheckedPathsSet(path);
    removeFromGreyedPathsSet(path);
    Object node = path.getLastPathComponent();
    int childrenNumber = this.model.getChildCount(node);
    for (int childIndex = 0; childIndex < childrenNumber; childIndex++) {
        TreePath childPath = path.pathByAddingChild(this.model.getChild(node, childIndex));
        uncheckSubTree(childPath);
    }
}
Also used : TreePath(javax.swing.tree.TreePath)

Aggregations

TreePath (javax.swing.tree.TreePath)539 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)177 ArrayList (java.util.ArrayList)58 TreeNode (javax.swing.tree.TreeNode)56 Nullable (org.jetbrains.annotations.Nullable)49 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)46 JTree (javax.swing.JTree)34 NotNull (org.jetbrains.annotations.NotNull)32 Test (org.junit.Test)22 Tree (com.intellij.ui.treeStructure.Tree)21 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)21 TreeSelectionListener (javax.swing.event.TreeSelectionListener)21 MouseEvent (java.awt.event.MouseEvent)18 Point (java.awt.Point)17 ActionEvent (java.awt.event.ActionEvent)15 KeyEvent (java.awt.event.KeyEvent)12 EVTask (net.sourceforge.processdash.ev.EVTask)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 KeyAdapter (java.awt.event.KeyAdapter)11 List (java.util.List)11