KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > xml > test > actions > WebPagesNode


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.xml.test.actions;
21
22 import java.lang.reflect.Constructor JavaDoc;
23 import javax.swing.tree.TreePath JavaDoc;
24 import org.netbeans.jellytools.ProjectsTabOperator;
25 import org.netbeans.jellytools.nodes.Node;
26 import org.netbeans.jemmy.operators.JTreeOperator;
27
28 /** AbstractNode Class
29  * @author ms113234 */

30 public class WebPagesNode extends Node {
31     private static ProjectsTabOperator projectTabOperator = new ProjectsTabOperator();
32     
33     /** creates new DriversNode
34      * @param tree JTreeOperator of tree
35      * @param treePath String tree path */

36     public WebPagesNode(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 WebPagesNode(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 WebPagesNode(Node parent, String JavaDoc treePath) {
51     super(parent, treePath);
52     }
53     
54     
55     /** This method tests if the specified children exists.
56      * @param displayName children name
57      * @return true if the specified children exists
58      */

59     
60     public static WebPagesNode getInstance(String JavaDoc projectName){
61     projectTabOperator.invoke();
62     JTreeOperator tree = projectTabOperator.tree();
63     Node node = new Node(tree, projectName);
64     return new WebPagesNode(node, "Web Pages");
65     }
66     
67     public boolean containsChild(String JavaDoc displayName) {
68     String JavaDoc[] drivers = this.getChildren();
69     for (int i = 0 ; i < drivers.length ; i++) {
70         if (displayName.equals(drivers[i]) ) return true;
71     }
72     return false;
73     }
74     
75     /** This method creates a new node operator for child.
76      * @param displayName children name
77      * @param clazz children class
78      * @return children node
79      */

80     public Node getChild(String JavaDoc displayName, Class JavaDoc clazz) {
81     if (!Node.class.isAssignableFrom(clazz)) {
82         throw new IllegalArgumentException JavaDoc(clazz + " is not instance of org.netbeans.jellytools.nodes.Node");
83     }
84     if (!this.containsChild(displayName) ) return null;
85     Node node = null;
86     try {
87         Constructor JavaDoc constructor = clazz.getConstructor(new Class JavaDoc[] {Node.class, String JavaDoc.class});
88         node = (Node) constructor.newInstance(new Object JavaDoc[] {this, displayName});
89     } catch (Exception JavaDoc ex) {
90         throw new RuntimeException JavaDoc("Cannot instantiate " + clazz, ex);
91     }
92     return node;
93     }
94     
95 }
96
Popular Tags