KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jellytools > modules > xml > catalog > nodes > AbstractNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.jellytools.modules.xml.catalog.nodes;
21
22 import java.lang.reflect.Constructor JavaDoc;
23 import javax.swing.tree.TreePath JavaDoc;
24 import org.netbeans.jellytools.RuntimeTabOperator;
25 import org.netbeans.jellytools.nodes.Node;
26 import org.netbeans.jemmy.operators.JTreeOperator;
27
28 /** AbstractNode Class
29  * @author ms113234 */

30 public abstract class AbstractNode extends Node {
31     private static RuntimeTabOperator runtimeTabOperator;
32
33     /** creates new DriversNode
34      * @param tree JTreeOperator of tree
35      * @param treePath String tree path */

36     public AbstractNode(JTreeOperator tree, String JavaDoc treePath) {
37         super(tree, treePath);
38     }
39     
40     /** creates new DriversNode
41      * @param tree JTreeOperator of tree
42      * @param treePath TreePath of node */

43     public AbstractNode(JTreeOperator tree, TreePath JavaDoc treePath) {
44         super(tree, treePath);
45     }
46     
47     /** creates new DriversNode
48      * @param parent parent Node
49      * @param treePath String tree path from parent Node */

50     public AbstractNode(Node parent, String JavaDoc treePath) {
51         super(parent, treePath);
52     }
53     
54     /** This method tests if the specified children exists.
55      * @param displayName children name
56      * @return true if the specified children exists
57      */

58     public boolean containsChild(String JavaDoc displayName) {
59         String JavaDoc[] drivers = this.getChildren();
60         for (int i = 0 ; i < drivers.length ; i++) {
61             if (displayName.equals(drivers[i]) ) {
62                 return true;
63             }
64         }
65         return false;
66     }
67     
68     /** This method creates a new node operator for child.
69      * @param displayName children name
70      * @param clazz children class
71      * @return children node
72      */

73     public Node getChild(String JavaDoc displayName, Class JavaDoc clazz) {
74         if (!Node.class.isAssignableFrom(clazz)) {
75             throw new IllegalArgumentException JavaDoc(clazz + " is not instance of org.netbeans.jellytools.nodes.Node");
76         }
77         if (!this.containsChild(displayName) ) {
78             return null;
79         }
80         Node node = null;
81         try {
82             Constructor JavaDoc constructor = clazz.getConstructor(new Class JavaDoc[] {Node.class, String JavaDoc.class});
83             node = (Node) constructor.newInstance(new Object JavaDoc[] {this, displayName});
84         } catch (Exception JavaDoc ex) {
85             throw new RuntimeException JavaDoc("Cannot instantiate " + clazz, ex);
86         }
87         return node;
88     }
89     
90     public static synchronized RuntimeTabOperator getRuntimeTab() {
91         if (runtimeTabOperator == null) {
92             RuntimeTabOperator.invoke();
93             runtimeTabOperator = new RuntimeTabOperator();
94         }
95         if (!runtimeTabOperator.isVisible()) {
96             runtimeTabOperator.invoke();
97         }
98         return runtimeTabOperator;
99     }
100 }
101
Popular Tags