/*
 * ICESOFT COMMERCIAL SOURCE CODE LICENSE V 1.1
 *
 * The contents of this file are subject to the ICEsoft Commercial Source
 * Code License Agreement V1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the
 * License at
 * http://www.icesoft.com/license/commercial-source-v1.1.html
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * Copyright 2009-2015 ICEsoft Technologies Canada, Corp. All Rights Reserved.
 */
package com.icesoft.faces.facelets.component.selectiontree;

import com.icesoft.faces.component.tree.IceUserObject;
import com.icesoft.faces.facelets.component.tristatecheckbox.TriStateCheckbox;

import javax.swing.tree.DefaultMutableTreeNode;

/**
 * Tree userObject for the SelectionTreeModel
 *
 * @author philip.breau@icesoft.com
 */
public class SelectionTreeNodeUserObject extends IceUserObject {

    private static final long serialVersionUID = 1715781941265993223L;
    protected SelectionTreeModel tree;
    protected TriStateCheckbox checkbox;

    /**
     * This constructor will automatically create the associated TriStateCheckbox with
     * the initial unchecked state.
     *
     * @param tree The SelectionTreeModel
     * @param node The SelectionTreeNode
     */
    public SelectionTreeNodeUserObject(SelectionTreeModel tree, SelectionTreeNode node) {
        super(node);
        this.tree = tree;
        init(node);
        setExpanded(false);
        this.checkbox = new TriStateCheckbox(TriStateCheckbox.UNCHECKED_CHECKED_ORDER);
    }

    public SelectionTreeNodeUserObject(SelectionTreeModel tree, SelectionTreeNode node, boolean disabled) {
        super(node);
        this.tree = tree;
        init(node);
        setExpanded(false);
        this.checkbox = new TriStateCheckbox(TriStateCheckbox.UNCHECKED_CHECKED_ORDER);
        this.checkbox.setDisabled(disabled);
    }

    private void init(DefaultMutableTreeNode node) {
        setLeafIcon("/xmlhttp/css/xp/css-images/tree_document.gif");
        setBranchContractedIcon("/xmlhttp/css/xp/css-images/tree_folder_close.gif");
        setBranchExpandedIcon("/xmlhttp/css/xp/css-images/tree_folder_open.gif");
        node.setUserObject(this);
    }


    /**
     * @param tree The SelectionTreeModel
     */
    public void setTree(SelectionTreeModel tree) {
        this.tree = tree;
    }

    /**
     * @return The TriStateCheckbox associated with this tree user object
     */
    public TriStateCheckbox getCheckbox() {
        return checkbox;
    }

    /**
     * @return The SelectionTreeModel
     */
    public SelectionTreeModel getTree() {
        return tree;
    }


}


