1 19 20 package org.netbeans.modules.j2ee.spi.ejbjar.support; 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.java.classpath.ClassPath; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.api.queries.VisibilityQuery; 30 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 31 import org.netbeans.modules.j2ee.spi.ejbjar.EjbNodesFactory; 32 import org.netbeans.modules.j2ee.ejbjar.project.ui.EjbContainerNode; 33 import org.netbeans.modules.j2ee.ejbjar.project.ui.ServerResourceNode; 34 import org.openide.ErrorManager; 35 import org.openide.actions.FindAction; 36 import org.openide.filesystems.FileObject; 37 import org.openide.loaders.ChangeableDataFilter; 38 import org.openide.loaders.DataFilter; 39 import org.openide.loaders.DataFolder; 40 import org.openide.loaders.DataObject; 41 import org.openide.nodes.FilterNode; 42 import org.openide.nodes.Node; 43 import org.openide.util.Lookup; 44 import org.openide.util.NbBundle; 45 import org.openide.util.Utilities; 46 import org.openide.util.actions.SystemAction; 47 48 52 public final class J2eeProjectView { 53 54 60 public static final String CONFIG_FILES_VIEW_NAME = "configurationFiles"; 62 private static EjbNodesFactory factoryInstance = null; 63 64 private J2eeProjectView() { 65 } 66 67 70 public static EjbNodesFactory getEjbNodesFactory () { 71 if (factoryInstance == null) { 72 factoryInstance = (EjbNodesFactory) Lookup.getDefault().lookup(EjbNodesFactory.class); 73 } 74 if (factoryInstance == null) { 75 ErrorManager.getDefault().log("No EjbNodesFactory instance available: Enterprise Beans nodes cannot be creater"); 76 } 77 return factoryInstance; 78 } 79 80 public static Node createServerResourcesNode (Project p) { 81 return new ServerResourceNode (p); 82 } 83 84 public static Node createEjbsView (EjbJar model, ClassPath srcPath, FileObject ddFile, Project p) { 85 return new EjbContainerNode(model, srcPath, ddFile, p, getEjbNodesFactory()); 86 } 87 88 public static Node createConfigFilesView (FileObject folder) { 89 return new DocBaseNode(DataFolder.findFolder(folder)); 90 } 91 92 private static final class DocBaseNode extends FilterNode { 93 private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter(); 94 95 private static Image CONFIGURATION_FILES_BADGE = 96 Utilities.loadImage( "org/netbeans/modules/j2ee/ejbjar/project/ui/ejbjar.gif", true ); 98 public DocBaseNode(DataFolder folder) { 99 super(folder.getNodeDelegate(), folder.createNodeChildren(VISIBILITY_QUERY_FILTER)); 100 } 101 102 public Image getIcon( int type ) { 103 return computeIcon( false, type ); 104 } 105 106 public Image getOpenedIcon( int type ) { 107 return computeIcon( true, type ); 108 } 109 110 private Image computeIcon( boolean opened, int type ) { 111 Node folderNode = getOriginal(); 112 Image image = opened ? folderNode.getOpenedIcon( type ) : folderNode.getIcon( type ); 113 return Utilities.mergeImages( image, CONFIGURATION_FILES_BADGE, 7, 7 ); 114 } 115 116 public String getName() { 117 return CONFIG_FILES_VIEW_NAME; 118 } 119 120 public String getDisplayName() { 121 return NbBundle.getMessage(J2eeProjectView.class, "LBL_Node_ConfigFiles"); } 123 124 public boolean canCopy() { 125 return false; 126 } 127 128 public boolean canCut() { 129 return false; 130 } 131 132 public boolean canRename() { 133 return false; 134 } 135 136 public boolean canDestroy() { 137 return false; 138 } 139 140 public Action [] getActions( boolean context ) { 141 return new Action [] { 142 SystemAction.get(FindAction.class), 143 }; 144 } 145 } 146 147 private static final class VisibilityQueryDataFilter implements ChangeListener , ChangeableDataFilter { 148 149 EventListenerList ell = new EventListenerList (); 150 151 public VisibilityQueryDataFilter() { 152 VisibilityQuery.getDefault().addChangeListener( this ); 153 } 154 155 public boolean acceptDataObject(DataObject obj) { 156 FileObject fo = obj.getPrimaryFile(); 157 return VisibilityQuery.getDefault().isVisible( fo ); 158 } 159 160 public void stateChanged( ChangeEvent e) { 161 Object [] listeners = ell.getListenerList(); 162 ChangeEvent event = null; 163 for (int i = listeners.length-2; i>=0; i-=2) { 164 if (listeners[i] == ChangeListener .class) { 165 if ( event == null) { 166 event = new ChangeEvent ( this ); 167 } 168 ((ChangeListener )listeners[i+1]).stateChanged( event ); 169 } 170 } 171 } 172 173 public void addChangeListener( ChangeListener listener ) { 174 ell.add( ChangeListener .class, listener ); 175 } 176 177 public void removeChangeListener( ChangeListener listener ) { 178 ell.remove( ChangeListener .class, listener ); 179 } 180 181 } 182 183 184 } 185 | Popular Tags |