KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > archive > ui > ConfigFilesNode


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.archive.ui;
21
22 import java.awt.Image JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import javax.swing.event.ChangeEvent JavaDoc;
25 import javax.swing.event.ChangeListener JavaDoc;
26 import javax.swing.event.EventListenerList JavaDoc;
27 import org.netbeans.api.queries.VisibilityQuery;
28 import org.netbeans.spi.project.ui.support.CommonProjectActions;
29 import org.openide.filesystems.FileObject;
30 import org.openide.loaders.ChangeableDataFilter;
31 import org.openide.loaders.DataFilter;
32 import org.openide.loaders.DataFolder;
33 import org.openide.loaders.DataObject;
34 import org.openide.nodes.FilterNode;
35 import org.openide.nodes.Node;
36 import org.openide.util.NbBundle;
37 import org.openide.util.actions.SystemAction;
38
39 /**
40  *
41  * @author ludo
42  * Node for all the config files of all the sub-modules of this bianry archive
43  */

44 public class ConfigFilesNode extends FilterNode {
45     private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter();
46     
47     //private static Image CONFIGURATION_FILES_BADGE = Utilities.loadImage( "org/netbeans/modules/j2ee/earproject/ui/resources/archive.gif", true ); // NOI18N
48

49     public ConfigFilesNode(DataFolder folder) {
50         super(folder.getNodeDelegate(), folder.createNodeChildren(VISIBILITY_QUERY_FILTER));
51     }
52     
53     public Image JavaDoc getIcon( int type ) {
54         return computeIcon( false, type );
55     }
56     
57     public Image JavaDoc getOpenedIcon( int type ) {
58         return computeIcon( true, type );
59     }
60     
61     private Image JavaDoc computeIcon( boolean opened, int type ) {
62         Node folderNode = getOriginal();
63         Image JavaDoc image = opened ? folderNode.getOpenedIcon( type ) : folderNode.getIcon( type );
64         return image;
65     }
66     
67     public boolean canCopy() {
68         return false;
69     }
70     
71     public boolean canCut() {
72         return false;
73     }
74     
75     public boolean canRename() {
76         return false;
77     }
78     
79     public boolean canDestroy() {
80         return false;
81     }
82     
83     public Action JavaDoc[] getActions( boolean context ) {
84         return new Action JavaDoc[] {
85             //CommonProjectActions.newFileAction(),
86
//SystemAction.get(org.openide.actions.NewTemplateAction.class),
87
SystemAction.get(org.openide.actions.FindAction.class),
88         };
89     }
90     
91     public String JavaDoc getDisplayName() {
92         return NbBundle.getMessage(RootNode.class, "LBL_Node_DocBase"); //NOI18N
93
}
94     
95     protected static final class VisibilityQueryDataFilter implements ChangeListener JavaDoc, ChangeableDataFilter {
96         
97         EventListenerList JavaDoc ell = new EventListenerList JavaDoc();
98         
99         public VisibilityQueryDataFilter() {
100             VisibilityQuery.getDefault().addChangeListener( this );
101         }
102         
103         public boolean acceptDataObject(DataObject obj) {
104             boolean retVal = false;
105             FileObject fo = obj.getPrimaryFile();
106             if (!"classes".equals(fo.getName()) && !"lib".equals(fo.getName())) { // NOI18N
107
retVal = VisibilityQuery.getDefault().isVisible( fo );
108             }
109             return retVal;
110         }
111         
112         public void stateChanged( ChangeEvent JavaDoc e) {
113             Object JavaDoc[] listeners = ell.getListenerList();
114             ChangeEvent JavaDoc event = null;
115             for (int i = listeners.length-2; i>=0; i-=2) {
116                 if (listeners[i] == ChangeListener JavaDoc.class) {
117                     if ( event == null) {
118                         event = new ChangeEvent JavaDoc( this );
119                     }
120                     ((ChangeListener JavaDoc)listeners[i+1]).stateChanged( event );
121                 }
122             }
123         }
124         
125         public void addChangeListener( ChangeListener JavaDoc listener ) {
126             ell.add( ChangeListener JavaDoc.class, listener );
127         }
128         
129         public void removeChangeListener( ChangeListener JavaDoc listener ) {
130             ell.remove( ChangeListener JavaDoc.class, listener );
131         }
132         
133     }
134
135  
136 }
137
Popular Tags