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: * EjbGroupTreeNodes.java
043: *
044: * Created on February 24, 2005, 10:23 AM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.ui;
048:
049: import org.netbeans.modules.visualweb.ejb.datamodel.EjbGroup;
050: import org.netbeans.modules.visualweb.ejb.datamodel.EjbInfo;
051: import org.netbeans.modules.visualweb.ejb.datamodel.MethodInfo;
052: import java.util.*;
053: import javax.swing.tree.DefaultMutableTreeNode;
054: import javax.swing.tree.TreeNode;
055:
056: /**
057: * The tree hierarchy for a given EJB group
058: *
059: * @author cao
060: */
061: public class EjbGroupTreeNodes {
062:
063: private EjbGroup ejbGroup;
064: private DefaultMutableTreeNode root;
065: private MethodNode firstToBeSelectedNode;
066:
067: public EjbGroupTreeNodes(EjbGroup ejbGrp) {
068: this .ejbGroup = ejbGrp;
069: buildTree();
070: }
071:
072: public TreeNode getRoot() {
073: return this .root;
074: }
075:
076: public MethodNode geFirstNodeToBeSelected() {
077: return firstToBeSelectedNode;
078: }
079:
080: // Build the tree for the given ejb group
081: private void buildTree() {
082: // The root of the tree is the group name
083: root = new DefaultMutableTreeNode(ejbGroup.getName());
084:
085: // Add all the session ejbs as the children of the root
086: boolean firstMethod = true;
087: boolean found1stConfigurableMethod = false;
088: for (Iterator iter = ejbGroup.getSessionBeans().iterator(); iter
089: .hasNext();) {
090: EjbInfo ejb = (EjbInfo) iter.next();
091: DefaultMutableTreeNode ejbNode = new DefaultMutableTreeNode(
092: ejb.getJNDIName());
093: root.add(ejbNode);
094:
095: // Add the method nodes as the children of this session ejb node
096: for (Iterator mIter = ejb.getMethods().iterator(); mIter
097: .hasNext();) {
098: MethodInfo method = (MethodInfo) mIter.next();
099:
100: // Do not show create() methods
101: if (!method.isBusinessMethod())
102: continue;
103:
104: MethodNode methodNode = new MethodNode(method);
105: ejbNode.add(methodNode);
106:
107: // By default, the first method node in the tree is to be selected
108: if (firstMethod) {
109: firstToBeSelectedNode = methodNode;
110: firstMethod = false;
111:
112: // Found the first configurable method
113: if (method.isMethodConfigurable())
114: found1stConfigurableMethod = true;
115: } else {
116: if (!found1stConfigurableMethod
117: && method.isMethodConfigurable()) {
118: firstToBeSelectedNode = methodNode;
119: found1stConfigurableMethod = true;
120: }
121: }
122: }
123: }
124:
125: }
126:
127: public static class MethodNode extends DefaultMutableTreeNode {
128: private MethodInfo methodInfo;
129:
130: public MethodNode(MethodInfo method) {
131: super (method.getName());
132: this .methodInfo = method;
133: }
134:
135: public MethodInfo getMethod() {
136: return this.methodInfo;
137: }
138: }
139:
140: }
|