KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjar > project > ui > EjbContainerNode


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.modules.j2ee.ejbjar.project.ui;
21
22 import java.awt.Image JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import org.netbeans.api.java.classpath.ClassPath;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
27 import org.netbeans.modules.j2ee.spi.ejbjar.EjbNodesFactory;
28 import org.netbeans.spi.project.ui.support.CommonProjectActions;
29 import org.openide.filesystems.FileObject;
30 import org.openide.filesystems.Repository;
31 import org.openide.loaders.DataFolder;
32 import org.openide.loaders.DataObjectNotFoundException;
33 import org.openide.nodes.*;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36 import org.openide.util.Utilities;
37 import org.openide.util.lookup.Lookups;
38
39 /**
40  * @author Chris Webster
41  */

42 public class EjbContainerNode extends AbstractNode {
43     public static final String JavaDoc NAME = "EJBS"; // NOI18N
44

45     private static final String JavaDoc EJB_BADGE = "org/netbeans/modules/j2ee/ejbjar/project/ui/enterpriseBeansBadge.png"; // NOI18N
46

47     public EjbContainerNode(EjbJar model, ClassPath srcPath, FileObject ddFile, Project p, EjbNodesFactory nodesFactory) {
48         super(new EjbContainerChildren(model, srcPath, ddFile, nodesFactory), Lookups.singleton(p));
49         setName(EjbNodesFactory.CONTAINER_NODE_NAME);
50         setDisplayName(NbBundle.getMessage(EjbContainerNode.class, "LBL_node"));
51         setShortDescription(NbBundle.getMessage(EjbContainerNode.class, "HINT_node"));
52     }
53     
54     public Action JavaDoc[] getActions(boolean context) {
55         return new Action JavaDoc[] {
56             CommonProjectActions.newFileAction()
57         };
58     }
59     
60     public HelpCtx getHelpCtx() {
61         return HelpCtx.DEFAULT_HELP;
62         // When you have help, change to:
63
// return new HelpCtx(EjbContainerNode.class);
64
}
65     
66     public Image JavaDoc getIcon(int type) {
67         return computeIcon(false, type);
68     }
69     
70     public Image JavaDoc getOpenedIcon(int type) {
71         return computeIcon(true, type);
72     }
73     
74     private Image JavaDoc computeIcon(boolean opened, int type) {
75         Image JavaDoc image;
76         Node iconDelegate = getIconDelegate();
77         if (opened) {
78             image = iconDelegate != null ? iconDelegate.getOpenedIcon(type) : super.getOpenedIcon(type);
79         } else {
80             image = iconDelegate != null ? iconDelegate.getIcon(type) : super.getIcon(type);
81         }
82         Image JavaDoc badge = Utilities.loadImage(EJB_BADGE);
83         return Utilities.mergeImages(image, badge, 7, 7);
84     }
85     
86     private Node getIconDelegate() {
87         try {
88             return DataFolder.find(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate();
89         }
90         catch (DataObjectNotFoundException donfe) {
91             return null;
92         }
93     }
94 }
95
Popular Tags