001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.insync.live;
043:
044: import com.sun.rave.designtime.DesignBean;
045: import java.util.Enumeration;
046: import javax.swing.tree.TreeNode;
047:
048: import com.sun.rave.designtime.faces.FacetDescriptor;
049:
050: /**
051: * FacetTreeNode - represents facets in a Tree such as the app outline
052: *
053: * @author Tor Norbye
054: * @version 1.0
055: */
056: public class FacetTreeNode implements TreeNode {
057:
058: private FacetDescriptor fd;
059: private SourceDesignBean parent;
060: private DesignBean bean;
061: private int index;
062:
063: FacetTreeNode(SourceDesignBean parent, FacetDescriptor fd, int index) {
064: this .parent = parent;
065: this .fd = fd;
066: this .index = index;
067: if (parent instanceof FacesDesignBean) {
068: FacesDesignBean fdb = (FacesDesignBean) parent;
069: bean = fdb.getFacet(fd.getName());
070: }
071: }
072:
073: /** Return the name of this facet */
074: public String getName() {
075: return fd.getName();
076: }
077:
078: int getIndex() {
079: return index;
080: }
081:
082: /** Return the DesignBean associated with this FacetDescriptor, if any.
083: * Returns null if there is no current DesignBean for the facet.
084: */
085: public DesignBean getDesignBean() {
086: return bean;
087: }
088:
089: public TreeNode getChildAt(int childIndex) {
090: if (bean != null && bean instanceof TreeNode) {
091: return ((TreeNode) bean).getChildAt(childIndex);
092: }
093: return null;
094: }
095:
096: public int getChildCount() {
097: if (bean != null && bean instanceof TreeNode) {
098: return ((TreeNode) bean).getChildCount();
099: }
100: return 0;
101: }
102:
103: public TreeNode getParent() {
104: return parent;
105: }
106:
107: public int getIndex(TreeNode node) {
108: if (bean != null && bean instanceof TreeNode) {
109: return ((TreeNode) bean).getIndex(node);
110: }
111: return -1;
112: }
113:
114: public boolean getAllowsChildren() {
115: if (bean != null && bean instanceof TreeNode) {
116: return ((TreeNode) bean).getAllowsChildren();
117: }
118: return false;
119: }
120:
121: public boolean isLeaf() {
122: if (bean != null && bean instanceof TreeNode) {
123: return ((TreeNode) bean).isLeaf();
124: }
125: return true;
126: }
127:
128: // Note: using old Enumeration only for old NetBeans code
129: public Enumeration children() {
130: if (bean != null && bean instanceof TreeNode) {
131: return ((TreeNode) bean).children();
132: }
133: return null;
134: }
135:
136: public String toString() {
137: if (bean != null) {
138: return fd.getName() + ": " + bean.getInstanceName();
139: }
140: return fd.getName();
141: }
142: }
|