All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viaoa.html.OATree Maven / Gradle / Ivy

/* 
This software and documentation is the confidential and proprietary 
information of ViaOA, Inc. ("Confidential Information").  
You shall not disclose such Confidential Information and shall use 
it only in accordance with the terms of the license agreement you 
entered into with ViaOA, Inc..

ViaOA, Inc. MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. ViaOA, Inc. SHALL NOT BE LIABLE FOR ANY DAMAGES
SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
THIS SOFTWARE OR ITS DERIVATIVES.
 
Copyright (c) 2001 ViaOA, Inc.
All rights reserved.
*/ 
package com.viaoa.html;


import java.lang.reflect.*;
import java.util.*;
import javax.swing.*;

import com.viaoa.hub.*;
import com.viaoa.util.*;


public class OATree extends OAHtmlComponent {
    private static final long serialVersionUID = 1L;
    protected OATreeNode root;
    protected String font;
    protected String imageNameCollapse = "treeCollapse.gif";
    protected String imageNameExpand = "treeExpand.gif";
    protected String imageNameCollapseForm = "treeCollapseForm.gif";
    protected String imageNameExpandForm = "treeExpandForm.gif";
    protected String imageNameNodeOpened = "treeOpen.gif";
    protected String imageNameNodeClosed = "treeClose.gif";
    protected String imageNameLeaf = "treeLeaf.gif";
    protected String imageNameSpacer = "treeSpacer.gif";
    protected String selectColor = "yellow";
    protected OATreeData selectData;
    protected OATreeData expandData;
    protected OATreeData collapseData;
    protected OATreeData expandFormData;
    protected OATreeData collapseFormData;
    protected String colorBackground;
    protected Object selectObject;
    protected boolean bShowNew=true;
    Vector vector = new Vector(25,25); // displayed nodes - OATreeData
    Vector vectorOld;
    private boolean bExpandingAll,bCollaspingAll;
    protected boolean bWrap;  // allow text to wrap

    public void expandAll() {
        bExpandingAll = true;
        getHtml();
        bExpandingAll = false;
    }
    public void collapseAll() {
        bCollaspingAll = true;
        getHtml();
        bCollaspingAll = false;
    }
    
    public OATree() {
        root = new OATreeNode(""); 
    }

    /** @return the selected object. */
    public Object getSelectedObject() {
        if (selectObject != null) return selectObject;
        if (selectData == null) return null;
        else return selectData.object;
    }

    /** set the selected object.  Note: this does not set the activeObject in the Hub or UpdateHub. */
    public void setSelectedObject(Object obj) {
        if (obj == null) selectData = null;
        selectObject = obj;
    }

    /** if false, then objects that are "new" are not displayed. Default: true */
    public void setShowNew(boolean b) {
        bShowNew = b;
    }
    public boolean getShowNew() {
        return bShowNew;
    }
    /** if false then displayed data will not wrap. Default: false */
    public void setAllowWrap(boolean b) {
        bWrap = b;
    }
    public boolean getAllowWrap() {
        return bWrap;
    }

    
    public void add(OATreeNode node) {
        if (node.hub == null && !node.titleFlag) {
            throw new RuntimeException("OATree.add() node is not a TitleNode and does not have a Hub assigned");
        }
        root.add(node);
        node.setTree(this);
    }
    
    protected boolean isExpanded(OATreeNode node, OATreeData parent, Object obj) {
        if (bExpandingAll) {
            // check for recursive nodes
            if (parent != null) {
                OATreeData p = parent;
                for ( ;p != null; p = p.parent) {
                    if (p.node == node) {
                        if (p.object == obj) return false;
                    }
                }
            }
            return true;
        }
        if (bCollaspingAll) return false;

        if (node.bExpandingAll) return true;
        if (node.bCollaspingAll) return false;
        
        if (node.treeNodeChildren.length == 0) return false;

        if (expandData != null) {
            if (obj == expandData.object) {
                if (areEqual(parent, expandData.parent)) return true;
            }
        }
        
        if (collapseData != null) {
            if (obj == collapseData.object) {
                if (areEqual(parent, collapseData.parent)) return false;
            }
        }

        if (vectorOld == null) return false;
        int x = vectorOld.size();
        for (int i=0; i");
        
        try {
            for (int i=0; i < root.treeNodeChildren.length; i++) {
                OATreeNode node = root.treeNodeChildren[i];
                node.getHtml(sb, this);
            }
        }
        catch (Exception e) {
            handleException(e,"getHtml()");
            sb.append("Exception Occured");
        }
        
        
        sb.append(System.getProperty("line.separator"));
        sb.append("");
        sb.append(System.getProperty("line.separator"));
        lastValue = new String(sb);
        return lastValue;
    }

    private String lastValue;
    public boolean needsRefreshed() {
        String s = lastValue;
        String s2 = getHtml();
        return (s == null || !s.equals(s2));
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy