001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.j2ee.archive.ui;
043:
044: import java.awt.Image;
045: import javax.swing.Action;
046: import javax.swing.event.ChangeEvent;
047: import javax.swing.event.ChangeListener;
048: import javax.swing.event.EventListenerList;
049: import org.netbeans.api.queries.VisibilityQuery;
050: import org.openide.filesystems.FileObject;
051: import org.openide.loaders.ChangeableDataFilter;
052: import org.openide.loaders.DataFilter;
053: import org.openide.loaders.DataFolder;
054: import org.openide.loaders.DataObject;
055: import org.openide.nodes.FilterNode;
056: import org.openide.nodes.Node;
057: import org.openide.util.NbBundle;
058: import org.openide.util.actions.SystemAction;
059:
060: /**
061: *
062: * @author ludo
063: * Node for all the config files of all the sub-modules of this bianry archive
064: */
065: public class ConfigFilesNode extends FilterNode {
066: private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter();
067:
068: //private static Image CONFIGURATION_FILES_BADGE = Utilities.loadImage( "org/netbeans/modules/j2ee/earproject/ui/resources/archive.gif", true ); // NOI18N
069:
070: public ConfigFilesNode(DataFolder folder) {
071: super (folder.getNodeDelegate(), folder
072: .createNodeChildren(VISIBILITY_QUERY_FILTER));
073: }
074:
075: public Image getIcon(int type) {
076: return computeIcon(false, type);
077: }
078:
079: public Image getOpenedIcon(int type) {
080: return computeIcon(true, type);
081: }
082:
083: private Image computeIcon(boolean opened, int type) {
084: Node folderNode = getOriginal();
085: Image image = opened ? folderNode.getOpenedIcon(type)
086: : folderNode.getIcon(type);
087: return image;
088: }
089:
090: public boolean canCopy() {
091: return false;
092: }
093:
094: public boolean canCut() {
095: return false;
096: }
097:
098: public boolean canRename() {
099: return false;
100: }
101:
102: public boolean canDestroy() {
103: return false;
104: }
105:
106: public Action[] getActions(boolean context) {
107: return new Action[] {
108: //CommonProjectActions.newFileAction(),
109: //SystemAction.get(org.openide.actions.NewTemplateAction.class),
110: SystemAction.get(org.openide.actions.FindAction.class), };
111: }
112:
113: public String getDisplayName() {
114: return NbBundle.getMessage(RootNode.class, "LBL_Node_DocBase"); //NOI18N
115: }
116:
117: protected static final class VisibilityQueryDataFilter implements
118: ChangeListener, ChangeableDataFilter {
119:
120: EventListenerList ell = new EventListenerList();
121:
122: public VisibilityQueryDataFilter() {
123: VisibilityQuery.getDefault().addChangeListener(this );
124: }
125:
126: public boolean acceptDataObject(DataObject obj) {
127: boolean retVal = false;
128: FileObject fo = obj.getPrimaryFile();
129: if (!"classes".equals(fo.getName())
130: && !"lib".equals(fo.getName())) { // NOI18N
131: retVal = VisibilityQuery.getDefault().isVisible(fo);
132: }
133: return retVal;
134: }
135:
136: public void stateChanged(ChangeEvent e) {
137: Object[] listeners = ell.getListenerList();
138: ChangeEvent event = null;
139: for (int i = listeners.length - 2; i >= 0; i -= 2) {
140: if (listeners[i] == ChangeListener.class) {
141: if (event == null) {
142: event = new ChangeEvent(this );
143: }
144: ((ChangeListener) listeners[i + 1])
145: .stateChanged(event);
146: }
147: }
148: }
149:
150: public void addChangeListener(ChangeListener listener) {
151: ell.add(ChangeListener.class, listener);
152: }
153:
154: public void removeChangeListener(ChangeListener listener) {
155: ell.remove(ChangeListener.class, listener);
156: }
157:
158: }
159:
160: }
|