1 19 20 21 package org.netbeans.modules.j2ee.archive.ui; 22 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.ResourceBundle ; 28 import javax.swing.Action ; 29 import javax.swing.JSeparator ; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.api.project.ProjectUtils; 32 import org.netbeans.modules.j2ee.archive.project.ArchiveProject; 33 import org.netbeans.modules.j2ee.archive.project.ArchiveProjectProperties; 34 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; 35 import org.netbeans.spi.project.ActionProvider; 36 import org.netbeans.spi.project.ui.support.CommonProjectActions; 37 import org.netbeans.spi.project.ui.support.ProjectSensitiveActions; 38 import org.openide.ErrorManager; 39 import org.openide.filesystems.FileChangeListener; 40 import org.openide.filesystems.FileObject; 41 import org.openide.filesystems.FileSystem; 42 import org.openide.filesystems.Repository; 43 import org.openide.loaders.DataFolder; 44 import org.openide.loaders.DataObject; 45 import org.openide.loaders.DataObjectNotFoundException; 46 import org.openide.loaders.FolderLookup; 47 import org.openide.nodes.Children; 48 import org.openide.nodes.Node; 49 import org.openide.util.Lookup; 51 import org.openide.util.NbBundle; 52 import org.openide.util.actions.SystemAction; 53 import org.openide.util.lookup.Lookups; 54 55 public class RootNode extends org.openide.nodes.AbstractNode { 56 57 59 63 public RootNode(ArchiveProject ap) { 64 super(new LogicalViewChildren(ap), createLookup(ap)); 65 super.setName(ProjectUtils.getInformation(ap).getDisplayName()); 66 setIconBaseWithExtension("org/netbeans/modules/j2ee/archive/project/resources/application_assembler_16.gif"); 73 ArchiveProjectProperties app = ap.getArchiveProjectProperties(); 74 String sourceArchive = ap.getPropertyEvaluator().evaluate((String )app.get(ArchiveProjectProperties.SOURCE_ARCHIVE)); 75 setShortDescription(NbBundle.getMessage(RootNode.class,"LBL_ProjectToolTip", sourceArchive)); 77 } 78 79 public Action [] getActions( boolean context ) { 80 Action [] retVal; 81 if ( context ) { 82 retVal = super.getActions( true ); 83 } else { 84 retVal = getAdditionalActions(); 85 } 86 return retVal; 87 } 88 89 private Action [] getAdditionalActions() { 90 91 ResourceBundle bundle = NbBundle.getBundle(RootNode.class); 92 93 List actions = new ArrayList (30); 94 actions.add(CommonProjectActions.newFileAction()); 95 actions.add(null); 96 actions.add(ProjectSensitiveActions.projectCommandAction( 97 ActionProvider.COMMAND_BUILD, bundle.getString("LBL_BuildAction_Name"), null)); actions.add(ProjectSensitiveActions.projectCommandAction( 99 "verify", bundle.getString("LBL_VerifyAction_Name"), null)); actions.add(ProjectSensitiveActions.projectCommandAction( 101 ActionProvider.COMMAND_RUN, bundle.getString("LBL_RunAction_Name"), null)); actions.add(null); 103 actions.add(CommonProjectActions.setAsMainProjectAction()); 104 actions.add(CommonProjectActions.openSubprojectsAction()); 105 actions.add(CommonProjectActions.closeProjectAction()); 106 actions.add(null); 107 actions.add(CommonProjectActions.renameProjectAction()); 108 actions.add(CommonProjectActions.moveProjectAction()); 109 actions.add(CommonProjectActions.copyProjectAction()); 110 actions.add(CommonProjectActions.deleteProjectAction()); 111 actions.add(null); 112 actions.add(SystemAction.get( org.openide.actions.FindAction.class )); 113 114 116 try { 117 Repository repository = Repository.getDefault(); 118 FileSystem sfs = repository.getDefaultFileSystem(); 119 FileObject fo = sfs.findResource("Projects/Actions"); if (fo != null) { 121 DataObject dobj = DataObject.find(fo); 122 FolderLookup actionRegistry = new FolderLookup((DataFolder)dobj); 123 Lookup.Template query = new Lookup.Template(Object .class); 124 Lookup lookup = actionRegistry.getLookup(); 125 Iterator it = lookup.lookup(query).allInstances().iterator(); 126 if (it.hasNext()) { 127 actions.add(null); 128 } 129 while (it.hasNext()) { 130 Object next = it.next(); 131 if (next instanceof Action ) { 132 actions.add(next); 133 } else if (next instanceof JSeparator ) { 134 actions.add(null); 135 } 136 } 137 } 138 } catch (DataObjectNotFoundException ex) { 139 ErrorManager.getDefault().notify(ex); 141 } 142 143 actions.add(CommonProjectActions.customizeProjectAction()); 151 152 return (Action [])actions.toArray(new Action [actions.size()]); 153 } 154 155 static final class LogicalViewChildren extends Children.Keys implements FileChangeListener { 156 157 159 private static final String KEY_DOC_BASE = "docBase"; private static final String KEY_SETUP_DIR = "setupDir"; 162 private ArchiveProject project; 163 164 public LogicalViewChildren(ArchiveProject project) { 165 assert project != null; 166 this.project = project; 167 } 168 169 protected void addNotify() { 170 super.addNotify(); 171 project.getProjectDirectory().addFileChangeListener(this); 172 createNodes(); 173 } 174 175 private void createNodes() { 176 List l = new ArrayList (); 177 DataFolder docBaseDir = getFolder((String )project.getArchiveProjectProperties().get(ArchiveProjectProperties.PROXY_PROJECT_DIR)); if (docBaseDir != null) { 179 l.add(KEY_DOC_BASE); 180 } 181 l.add(KEY_SETUP_DIR); 182 183 String dir = (String )project.getArchiveProjectProperties().get(ArchiveProjectProperties.PROXY_PROJECT_DIR); 184 FileObject fo = project.getProjectDirectory().getFileObject("subarchives"); if (null != fo) { 186 FileObject subarchives[] = fo.getChildren(); 187 for (FileObject innerFo : subarchives) { 188 FileObject innerProj = null; 189 if (null != innerFo) { 190 innerProj = innerFo.getFileObject("tmpproj"); } 192 if (null != innerProj && innerProj.isFolder()) { 193 DataFolder folder = getFolder("subarchives/"+innerFo.getName()+"/"+dir); if (null == folder) { 195 continue; 196 } 197 Node n = new ModuleNode(folder, 198 NbBundle.getMessage(RootNode.class,"LBL_ModuleNode", project.getEarPath(innerFo.getName()))); 200 l.add(n); 201 } 202 } 203 } 204 setKeys(l); 205 } 206 207 protected void removeNotify() { 208 setKeys(Collections.EMPTY_SET); 209 project.getProjectDirectory().removeFileChangeListener(this); 210 super.removeNotify(); 211 } 212 213 protected Node[] createNodes(Object key) { 214 Node n = null; 215 if (key == KEY_DOC_BASE) { 216 n = new ConfigFilesNode(getFolder((String )project.getArchiveProjectProperties().get(ArchiveProjectProperties.PROXY_PROJECT_DIR))); 217 } else if (key == KEY_SETUP_DIR) { 218 n = J2eeProjectView.createServerResourcesNode(project); 219 } else { 220 n = (Node) key; 221 } 222 return n == null ? new Node[0] : new Node[] {n}; 223 } 224 225 private DataFolder getFolder(String dir) { 226 FileObject fo = project.getProjectDirectory(); 227 if (null == dir) { 228 return null; 229 } 230 if (null != fo) { 231 fo = fo.getFileObject(dir); 232 } 233 if (null == fo) { 234 return null; 235 } 236 237 fo = fo.getFileObject("web"); if (null != fo) { 240 fo = fo.getFileObject("WEB-INF"); if (fo != null) { 242 DataFolder df = DataFolder.findFolder(fo); 243 return df; 244 } else { 245 return null; 246 } 247 } 248 fo = project.getProjectDirectory().getFileObject(dir); 249 if (null == fo) { 250 return null; 251 } 252 fo = fo.getFileObject("src"); if (null == fo) { 254 return null; 255 } 256 fo = fo.getFileObject("conf"); if (null == fo) { 258 return null; 259 } 260 return DataFolder.findFolder(fo); 261 } 262 263 public void fileAttributeChanged(org.openide.filesystems.FileAttributeEvent fe) { 265 } 266 267 public void fileChanged(org.openide.filesystems.FileEvent fe) { 268 } 269 270 public void fileDataCreated(org.openide.filesystems.FileEvent fe) { 271 } 272 273 public void fileDeleted(org.openide.filesystems.FileEvent fe) { 274 } 280 281 public void fileFolderCreated(org.openide.filesystems.FileEvent fe) { 282 createNodes(); 284 } 285 286 public void fileRenamed(org.openide.filesystems.FileRenameEvent fe) { 287 createNodes(); 289 } 290 } 291 292 293 private static Lookup createLookup( Project project ) { 294 DataFolder rootFolder = DataFolder.findFolder( project.getProjectDirectory() ); 295 return Lookups.fixed( new Object [] { project, rootFolder } ); 297 } 298 299 303 308 320 322 325 434 } 435 | Popular Tags |