KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > LogicalViewNode


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.earproject.ui;
21
22 import java.awt.Image JavaDoc;
23 import java.beans.BeanInfo JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import javax.swing.Icon JavaDoc;
26 import javax.swing.ImageIcon JavaDoc;
27 import org.netbeans.modules.j2ee.earproject.ui.actions.AddModuleAction;
28 import org.netbeans.spi.project.support.ant.AntProjectHelper;
29 import org.openide.filesystems.Repository;
30 import org.openide.loaders.DataFolder;
31 import org.openide.nodes.AbstractNode;
32 import org.openide.nodes.Node;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35 import org.openide.util.Utilities;
36 import org.openide.util.actions.SystemAction;
37 import org.openide.util.lookup.Lookups;
38
39 /**
40  * Represents the <em>J2EE Modules</em> node in the EAR project's logical view.
41  *
42  * @author vkraemer
43  * @author Ludovic Champenois
44  */

45 public final class LogicalViewNode extends AbstractNode {
46     
47     static final String JavaDoc J2EE_MODULES_NAME = "j2ee.modules"; // NOI18N
48
private static Image JavaDoc J2EE_MODULES_BADGE = Utilities.loadImage( "org/netbeans/modules/j2ee/earproject/ui/resources/application_16.gif", true ); // NOI18N
49
private static Icon JavaDoc folderIconCache;
50     private static Icon JavaDoc openedFolderIconCache;
51     private final AntProjectHelper model;
52     
53     public LogicalViewNode(AntProjectHelper model) {
54         super(new LogicalViewChildren(model), Lookups.fixed( new Object JavaDoc[] { model }));
55         this.model = model;
56         // Set FeatureDescriptor stuff:
57
setName(J2EE_MODULES_NAME);
58         setDisplayName(NbBundle.getMessage(LogicalViewNode.class, "LBL_LogicalViewNode"));
59         setShortDescription(NbBundle.getMessage(LogicalViewNode.class, "HINT_LogicalViewNode"));
60     }
61     
62     public Image JavaDoc getIcon( int type ) {
63         return computeIcon( false, type );
64     }
65     
66     public Image JavaDoc getOpenedIcon( int type ) {
67         return computeIcon( true, type );
68     }
69     /**
70      * Returns Icon of folder on active platform
71      * @param opened should the icon represent opened folder
72      * @return the folder icon
73      */

74     static synchronized Icon JavaDoc getFolderIcon (boolean opened) {
75         if (openedFolderIconCache == null) {
76             Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate();
77             openedFolderIconCache = new ImageIcon JavaDoc(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
78             folderIconCache = new ImageIcon JavaDoc(n.getIcon(BeanInfo.ICON_COLOR_16x16));
79         }
80         if (opened) {
81             return openedFolderIconCache;
82         }
83         else {
84             return folderIconCache;
85         }
86     }
87
88     private Image JavaDoc computeIcon( boolean opened, int type ) {
89         Icon JavaDoc icon = getFolderIcon(opened);
90         Image JavaDoc image = ((ImageIcon JavaDoc)icon).getImage();
91         image = Utilities.mergeImages(image, J2EE_MODULES_BADGE, 7, 7 );
92         return image;
93     }
94
95     // Create the popup menu:
96
public Action JavaDoc[] getActions(boolean context) {
97         return new Action JavaDoc[] {
98             SystemAction.get(AddModuleAction.class),
99         };
100     }
101     
102     public HelpCtx getHelpCtx() {
103         return HelpCtx.DEFAULT_HELP;
104         // When you have help, change to:
105
// return new HelpCtx(LogicalViewNode.class);
106
}
107     
108     // Handle copying and cutting specially:
109
public boolean canCopy() {
110         return false;
111     }
112     
113 }
114
Popular Tags