Search in sources :

Example 1 with TreeCheckingModel

use of it.cnr.imaa.essi.lablib.gui.checkboxtree.TreeCheckingModel 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)

Aggregations

CheckboxTree (it.cnr.imaa.essi.lablib.gui.checkboxtree.CheckboxTree)1 TreeCheckingModel (it.cnr.imaa.essi.lablib.gui.checkboxtree.TreeCheckingModel)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1