1 19 20 package org.netbeans.modules.j2ee.archive.ui; 21 22 import java.awt.Image ; 23 import javax.swing.Action ; 24 import javax.swing.event.ChangeEvent ; 25 import javax.swing.event.ChangeListener ; 26 import javax.swing.event.EventListenerList ; 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 44 public class ConfigFilesNode extends FilterNode { 45 private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter(); 46 47 49 public ConfigFilesNode(DataFolder folder) { 50 super(folder.getNodeDelegate(), folder.createNodeChildren(VISIBILITY_QUERY_FILTER)); 51 } 52 53 public Image getIcon( int type ) { 54 return computeIcon( false, type ); 55 } 56 57 public Image getOpenedIcon( int type ) { 58 return computeIcon( true, type ); 59 } 60 61 private Image computeIcon( boolean opened, int type ) { 62 Node folderNode = getOriginal(); 63 Image 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 [] getActions( boolean context ) { 84 return new Action [] { 85 SystemAction.get(org.openide.actions.FindAction.class), 88 }; 89 } 90 91 public String getDisplayName() { 92 return NbBundle.getMessage(RootNode.class, "LBL_Node_DocBase"); } 94 95 protected static final class VisibilityQueryDataFilter implements ChangeListener , ChangeableDataFilter { 96 97 EventListenerList ell = new EventListenerList (); 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())) { retVal = VisibilityQuery.getDefault().isVisible( fo ); 108 } 109 return retVal; 110 } 111 112 public void stateChanged( ChangeEvent e) { 113 Object [] listeners = ell.getListenerList(); 114 ChangeEvent event = null; 115 for (int i = listeners.length-2; i>=0; i-=2) { 116 if (listeners[i] == ChangeListener .class) { 117 if ( event == null) { 118 event = new ChangeEvent ( this ); 119 } 120 ((ChangeListener )listeners[i+1]).stateChanged( event ); 121 } 122 } 123 } 124 125 public void addChangeListener( ChangeListener listener ) { 126 ell.add( ChangeListener .class, listener ); 127 } 128 129 public void removeChangeListener( ChangeListener listener ) { 130 ell.remove( ChangeListener .class, listener ); 131 } 132 133 } 134 135 136 } 137 | Popular Tags |