KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > wizards > JavaChildren


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 2004 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit.wizards;
21
22 import org.openide.filesystems.FileObject;
23 import org.openide.loaders.DataObject;
24 import org.openide.nodes.Children;
25 import org.openide.nodes.FilterNode;
26 import org.openide.nodes.Node;
27
28 /**
29  * Displays folders and Java source files under a source node.
30  * @author Marian Petras, Jesse Glick
31  */

32 public class JavaChildren extends FilterNode.Children {
33
34     private static final String JavaDoc JAVA_MIME_TYPE = "text/x-java"; //NOI18N
35

36     public JavaChildren(Node parent) {
37         super(parent);
38     }
39
40     @Override JavaDoc
41     protected Node[] createNodes(Node originalNode) {
42         Node newNode;
43         
44         DataObject dataObj = originalNode.getCookie(DataObject.class);
45         if (dataObj == null) {
46             newNode = copyNode(originalNode);
47         } else {
48             FileObject primaryFile = dataObj.getPrimaryFile();
49             if (primaryFile.isFolder()) {
50                 newNode = new FilterNode(originalNode, new JavaChildren(originalNode));
51             } else if (primaryFile.getMIMEType().equals(JAVA_MIME_TYPE)) {
52                 newNode = new FilterNode(originalNode, Children.LEAF);
53                 newNode.setDisplayName(primaryFile.getName());
54             } else {
55                 newNode = null;
56             }
57         }
58
59         return (newNode != null) ? new Node[] {newNode}
60                                  : new Node[0];
61     }
62     
63 }
64
Popular Tags