1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.ui.logicalview; 21 import java.awt.event.ActionEvent ; 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.IOException ; 25 import java.math.BigDecimal ; 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Collections ; 29 import java.util.List ; 30 import javax.swing.AbstractAction ; 31 import javax.swing.Action ; 32 import javax.swing.SwingUtilities ; 33 import javax.swing.event.ChangeEvent ; 34 import javax.swing.event.ChangeListener ; 35 import org.netbeans.api.java.classpath.ClassPath; 36 import org.netbeans.api.java.project.JavaProjectConstants; 37 import org.netbeans.api.project.Project; 38 import org.netbeans.api.project.ProjectUtils; 39 import org.netbeans.api.project.SourceGroup; 40 import org.netbeans.api.project.Sources; 41 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; 42 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; 43 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 44 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 45 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 46 import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; 47 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; 48 import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; 49 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.CustomizerProviderImpl; 50 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; 51 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.CustomizerLibraries; 52 import org.netbeans.modules.j2ee.ejbjarproject.ui.logicalview.libraries.LibrariesNode; 53 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; 54 import org.netbeans.modules.websvc.api.client.WebServicesClientView; 55 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; 56 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientView; 57 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 58 import org.netbeans.modules.websvc.api.webservices.WebServicesView; 59 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; 60 import org.netbeans.modules.websvc.jaxws.api.JAXWSView; 61 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 62 import org.netbeans.spi.java.project.support.ui.PackageView; 63 import org.netbeans.spi.project.support.ant.AntProjectHelper; 64 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 65 import org.netbeans.spi.project.support.ant.ReferenceHelper; 66 67 import org.openide.ErrorManager; 68 import org.openide.filesystems.FileChangeAdapter; 69 import org.openide.filesystems.FileEvent; 70 import org.openide.filesystems.FileObject; 71 import org.openide.nodes.Children; 72 import org.openide.nodes.FilterNode; 73 import org.openide.nodes.Node; 74 import org.openide.util.NbBundle; 75 76 77 78 79 public final class LogicalViewChildren extends Children.Keys implements ChangeListener { 80 81 private static final boolean DISPLAY_EJB_NODE = 82 Boolean.getBoolean("org.netbeans.modules.j2ee.ejbjarproject.ui.logicalview.DISPLAY_EJB_NODE"); 84 85 public static final String KEY_TEST_DIR = "testDir"; public static final String KEY_DOC_BASE = "docBase"; public static final String KEY_EJBS = "ejbKey"; public static final String KEY_SERVICE_REFS = "serviceRefs"; public static final String WEBSERVICES_DIR = "webservicesDir"; public static final String KEY_SETUP_DIR = "setupDir"; public static final String KEY_LIBRARIES = "libraries"; public static final String KEY_TEST_LIBRARIES = "testLibraries"; 94 private static final String JAX_WS_PATH="nbproject/jax-ws.xml"; 96 private Sources sources; 97 private EjbJar jp; 98 private ClassPath cp; 99 private Project project; 100 private PropertyEvaluator evaluator; 101 private UpdateHelper updateHelper; 102 private ReferenceHelper refHelper; 103 private AntProjectHelper helper; 104 105 private JaxWsChangeListener jaxWsListener; 106 private MetaInfListener metaInfListener; 107 private WsdlCreationListener wsdlListener; 108 private JaxRPCChangeListener jaxrpcChangeListener; 109 private FileObject wsdlFolder; 110 111 113 public LogicalViewChildren(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper ) { 114 assert project != null; 115 this.project = project; 116 this.evaluator = evaluator; 119 this.updateHelper = updateHelper; 120 if (updateHelper != null) { 121 this.helper = updateHelper.getAntProjectHelper(); 122 } 123 this.refHelper = refHelper; 124 EjbJar jps[] = EjbJar.getEjbJars(project); 125 assert jps.length > 0; 126 jp = jps[0]; 127 128 sources = ProjectUtils.getSources(project); 129 assert sources != null; 130 cp = org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(getRoots()); 131 132 metaInfListener = new MetaInfListener(); 133 wsdlListener = new WsdlCreationListener(); 134 jaxrpcChangeListener = new JaxRPCChangeListener(); 135 jaxWsListener = new JaxWsChangeListener(); 136 } 137 138 private FileObject[] getRoots() { 139 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 140 FileObject[] roots = new FileObject[groups.length]; 141 for (int i = 0; i < groups.length; i++) { 142 roots[i] = groups[i].getRootFolder(); 143 } 144 return roots; 145 } 146 147 protected void addNotify() { 148 super.addNotify(); 149 sources.addChangeListener( this ); 150 151 JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class); 152 if (jaxWsModel!=null) jaxWsModel.addPropertyChangeListener(jaxWsListener); 153 154 EjbJar ejbModule = EjbJar.getEjbJar(helper.getProjectDirectory()); 155 if (ejbModule != null) { 156 FileObject metaInf = ejbModule.getMetaInf(); 157 if (metaInf!=null) { 158 metaInf.addFileChangeListener(metaInfListener); 159 metaInf.addFileChangeListener(jaxrpcChangeListener); 160 } 161 } 162 WebServicesClientSupport wsClientSupportImpl = 163 WebServicesClientSupport.getWebServicesClientSupport(helper.getProjectDirectory()); 164 FileObject wsdlDir = null; 165 try { 166 wsdlDir = wsClientSupportImpl.getWsdlFolder(false); 167 if (wsdlDir!=null) wsdlFolder = wsdlDir; 168 } catch (IOException ex) { 169 ex.printStackTrace(); 170 } 171 if (wsdlFolder != null) { 172 wsdlFolder.addFileChangeListener(wsdlListener); 173 } 174 175 createNodes(); 176 } 177 178 private void createNodes() { 179 List l = new ArrayList (); 180 l.add(KEY_EJBS); 181 182 JAXWSSupport jwss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 184 JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class); 185 if ((jwss != null) && 186 (jaxWsModel != null) && 187 (jaxWsModel.getServices() != null) && 188 (jaxWsModel.getServices().length > 0)) { 189 l.add(WEBSERVICES_DIR); 190 } else { 191 WebServicesSupport wss = WebServicesSupport.getWebServicesSupport(project.getProjectDirectory()); 192 if (wss!=null) { 193 List wServices = wss.getServices(); 194 if ((wServices != null) && (!wServices.isEmpty())) { 195 l.add(WEBSERVICES_DIR); 196 } 197 } 198 } 199 JAXWSClientSupport jwcss = JAXWSClientSupport.getJaxWsClientSupport(project.getProjectDirectory()); 200 if ((jwcss != null) && 201 (jaxWsModel != null) && 202 (jaxWsModel.getClients() != null) && 203 (jaxWsModel.getClients().length > 0)) { 204 l.add(KEY_SERVICE_REFS); 205 } else { 206 WebServicesClientSupport wscs = WebServicesClientSupport.getWebServicesClientSupport(project.getProjectDirectory()); 207 if (wscs!=null) { 208 List wsClients = wscs.getServiceClients(); 209 if ((wsClients != null) && (!wsClients.isEmpty())) { 210 l.add(KEY_SERVICE_REFS); 211 } 212 } 213 } 214 215 218 FileObject docBaseDir = jp.getMetaInf(); 219 if (docBaseDir != null) { 220 l.add(KEY_DOC_BASE); 221 } 222 223 l.add(KEY_SETUP_DIR); 224 225 l.addAll(getSourceRoots()); 226 227 l.add(KEY_LIBRARIES); 228 l.add(KEY_TEST_LIBRARIES); 229 230 setKeys(l); 231 } 232 233 protected void removeNotify() { 234 setKeys(Collections.EMPTY_SET); 235 sources.removeChangeListener( this ); 236 237 JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class); 238 if (jaxWsModel!=null) jaxWsModel.removePropertyChangeListener(jaxWsListener); 239 240 EjbJar ejbModule = EjbJar.getEjbJar(helper.getProjectDirectory()); 241 if (ejbModule != null) { 242 FileObject metaInf = ejbModule.getMetaInf(); 243 if (metaInf!=null) { 244 metaInf.removeFileChangeListener(metaInfListener); 245 metaInf.removeFileChangeListener(jaxrpcChangeListener); 246 } 247 } 248 249 if (wsdlFolder != null) { 250 wsdlFolder.removeFileChangeListener(wsdlListener); 251 } 252 253 setKeys(Collections.EMPTY_SET); 254 256 super.removeNotify(); 257 } 258 259 public Node[] createNodes(Object key) { 260 Node n = null; 261 if (key instanceof SourceGroupKey) { 262 n = new PackageViewFilterNode(((SourceGroupKey) key).group, project); 263 } else if (key == KEY_DOC_BASE) { 264 n = J2eeProjectView.createConfigFilesView(jp.getMetaInf()); 265 } else if (key == KEY_EJBS) { 266 org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = null; 267 FileObject dd = jp.getDeploymentDescriptor(); 268 try { 269 ejbJar = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(jp.getMetadataUnit()); 270 } catch (IOException ioe) { 271 ErrorManager.getDefault().notify(ioe); 272 } 273 if ((ejbJar != null && !ejbJar.getVersion().equals(new BigDecimal (ejbJar.VERSION_3_0))) || DISPLAY_EJB_NODE) { 274 n = J2eeProjectView.createEjbsView(ejbJar, cp, dd, project); 275 } 276 } else if (key == WEBSERVICES_DIR){ 277 EjbJar ejbModule = EjbJar.getEjbJar(helper.getProjectDirectory()); 278 279 java.util.Map properties = ((EjbJarProject)project).getAntProjectHelper().getStandardPropertyEvaluator().getProperties(); 280 String serverInstance = (String )properties.get("j2ee.server.instance"); J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance); 282 boolean jwsdpSupported = j2eePlatform!=null && j2eePlatform.isToolSupported(J2eePlatform.TOOL_JWSDP); 283 284 if (ejbModule!=null && ((EjbProjectConstants.JAVA_EE_5_LEVEL.equals(ejbModule.getJ2eePlatformVersion())) || (jwsdpSupported))) { 285 JAXWSView view = JAXWSView.getJAXWSView(); 286 n = view.createJAXWSView(project); 287 } else { 288 SourceGroup[] srcGroup = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 289 if (srcGroup.length > 0) { 290 FileObject srcRoot = srcGroup[0].getRootFolder(); 291 if (srcRoot != null) { 292 WebServicesView webServicesView = WebServicesView.getWebServicesView(srcRoot); 293 if (webServicesView != null) { 294 n = webServicesView.createWebServicesView(srcRoot); 295 } 296 } 297 } 298 } 299 } else if (key == KEY_SETUP_DIR) { 300 n = J2eeProjectView.createServerResourcesNode(project); 301 } else if (key == KEY_LIBRARIES) { 302 assert updateHelper != null; 303 assert evaluator != null; 304 assert refHelper != null; 305 n = new LibrariesNode( 306 NbBundle.getMessage(LogicalViewChildren.class,"CTL_LibrariesNode"), 307 project, 308 evaluator, 309 updateHelper, 310 refHelper, 311 EjbJarProjectProperties.JAVAC_CLASSPATH, 312 new String [] { EjbJarProjectProperties.BUILD_CLASSES_DIR }, 313 "platform.active", EjbJarProjectProperties.J2EE_SERVER_INSTANCE, 315 new Action [] { 316 LibrariesNode.createAddProjectAction(project, EjbJarProjectProperties.JAVAC_CLASSPATH, 317 ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES), 318 LibrariesNode.createAddLibraryAction(project, updateHelper.getAntProjectHelper(), 319 EjbJarProjectProperties.JAVAC_CLASSPATH, ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES), 320 LibrariesNode.createAddFolderAction(project, EjbJarProjectProperties.JAVAC_CLASSPATH, 321 ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES), 322 null, 323 new PreselectPropertiesAction(project, "Libraries", CustomizerLibraries.COMPILE), }, 325 ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES 326 ); 327 } 328 else if (key == KEY_SERVICE_REFS) { 329 333 java.util.Map properties = ((EjbJarProject)project).getAntProjectHelper().getStandardPropertyEvaluator().getProperties(); 334 String serverInstance = (String )properties.get("j2ee.server.instance"); J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance); 336 boolean jwsdpSupported = j2eePlatform!=null && j2eePlatform.isToolSupported(J2eePlatform.TOOL_JWSDP); 337 338 EjbJar ejbModule = EjbJar.getEjbJar(project.getProjectDirectory()); 339 if (ejbModule!=null && ((EjbProjectConstants.JAVA_EE_5_LEVEL.equals(ejbModule.getJ2eePlatformVersion())) || (jwsdpSupported))) { 340 JAXWSClientView view = JAXWSClientView.getJAXWSClientView(); 341 n = view.createJAXWSClientView(project); 342 } else { 343 FileObject clientRoot = helper.resolveFileObject(evaluator.getProperty(EjbJarProjectProperties.META_INF)); 344 if(clientRoot == null) { 345 clientRoot = helper.resolveFileObject(evaluator.getProperty(EjbJarProjectProperties.SRC_DIR)); 346 } 347 if (clientRoot != null) { 348 WebServicesClientView clientView = WebServicesClientView.getWebServicesClientView(clientRoot); 349 350 if(clientView != null) { 351 WebServicesClientSupport wss = WebServicesClientSupport.getWebServicesClientSupport(clientRoot); 352 if (wss != null) { 353 FileObject wsdlFolder = wss.getWsdlFolder(); 354 355 if(wsdlFolder != null) { 358 n = clientView.createWebServiceClientView(wsdlFolder); 359 } 360 } 361 } 362 } 363 } 364 } 365 else if (key == KEY_TEST_LIBRARIES) { 366 n = new LibrariesNode( 367 NbBundle.getMessage(LogicalViewChildren.class,"CTL_TestLibrariesNode"), 368 project, 369 evaluator, 370 updateHelper, 371 refHelper, 372 EjbJarProjectProperties.JAVAC_TEST_CLASSPATH, 373 new String [] { 374 EjbJarProjectProperties.BUILD_TEST_CLASSES_DIR, 375 EjbJarProjectProperties.JAVAC_CLASSPATH, 376 EjbJarProjectProperties.BUILD_CLASSES_DIR, 377 }, 378 null, 379 null, 380 new Action [] { 381 LibrariesNode.createAddProjectAction(project, EjbJarProjectProperties.JAVAC_TEST_CLASSPATH, null), 382 LibrariesNode.createAddLibraryAction(project, updateHelper.getAntProjectHelper(), EjbJarProjectProperties.JAVAC_TEST_CLASSPATH, null), 383 LibrariesNode.createAddFolderAction(project, EjbJarProjectProperties.JAVAC_TEST_CLASSPATH, null), 384 null, 385 new PreselectPropertiesAction(project, "Libraries", CustomizerLibraries.COMPILE_TESTS), }, 387 null 388 ); 389 } 390 391 return n == null ? new Node[0] : new Node[] {n}; 392 } 393 394 public void stateChanged( ChangeEvent e ) { 395 SwingUtilities.invokeLater (new Runnable () { 397 public void run () { 398 createNodes(); 399 } 400 }); 401 } 402 403 private Collection getSourceRoots() { 404 SourceGroup[] groups = sources.getSourceGroups( JavaProjectConstants.SOURCES_TYPE_JAVA ); 405 List result = new ArrayList (groups.length); 406 for (int i = 0; i < groups.length; i++) { 407 result.add(new SourceGroupKey(groups[i])); 408 } 409 return result; 410 } 411 412 private static class SourceGroupKey { 413 414 public final SourceGroup group; 415 public final FileObject fileObject; 416 417 SourceGroupKey( SourceGroup group ) { 418 this.group = group; 419 this.fileObject = group.getRootFolder(); 420 } 421 422 public int hashCode() { 423 return fileObject.hashCode(); 424 } 425 426 public boolean equals( Object obj ) { 427 if ( !(obj instanceof SourceGroupKey) ) { 428 return false; 429 } 430 else { 431 SourceGroupKey otherKey = (SourceGroupKey)obj; 432 String thisDisplayName = this.group.getDisplayName(); 433 String otherDisplayName = otherKey.group.getDisplayName (); 434 return fileObject.equals(otherKey.fileObject ) && 435 thisDisplayName == null ? otherDisplayName == null : thisDisplayName.equals(otherDisplayName); 436 } 437 } 438 } 439 440 453 455 private static class PackageViewFilterNode extends FilterNode { 456 457 private String nodeName; 458 private Project project; 459 private Action [] actions; 460 461 public PackageViewFilterNode(SourceGroup sourceGroup, Project project) { 462 super(PackageView.createPackageView(sourceGroup)); 463 this.project = project; 464 this.nodeName = "Sources"; 465 } 466 467 public Action [] getActions(boolean context) { 468 if (!context) { 469 if (actions == null) { 470 Action superActions[] = super.getActions(context); 471 actions = new Action [superActions.length + 2]; 472 System.arraycopy(superActions, 0, actions, 0, superActions.length); 473 actions[superActions.length] = null; 474 actions[superActions.length + 1] = new PreselectPropertiesAction(project, nodeName, null); 475 } 476 return actions; 477 } else { 478 return super.getActions(context); 479 } 480 } 481 } 482 483 private static class PreselectPropertiesAction extends AbstractAction { 484 485 private Project project; 486 private String nodeName; 487 private String panelName; 488 489 public PreselectPropertiesAction( Project project, String nodeName, String panelName ) { 490 super( NbBundle.getMessage( LogicalViewChildren.class, "LBL_Properties_Action" ) ); 491 this.project = project; 492 this.nodeName = nodeName; 493 this.panelName = panelName; 494 } 495 496 public void actionPerformed( ActionEvent e ) { 497 CustomizerProviderImpl cp = (CustomizerProviderImpl)project.getLookup().lookup( CustomizerProviderImpl.class ); 498 if ( cp != null ) { 499 cp.showCustomizer( nodeName, panelName ); 500 } 501 } 502 } 503 504 private final class JaxWsChangeListener implements PropertyChangeListener { 505 public void propertyChange(PropertyChangeEvent evt) { 506 507 SwingUtilities.invokeLater(new Runnable () { 508 public void run() { 509 createNodes(); 510 } 511 }); 512 } 513 } 514 515 private final class MetaInfListener extends FileChangeAdapter { 516 public void fileFolderCreated (FileEvent fe) { 517 if (fe.getFile().isFolder() && "wsdl".equals(fe.getFile().getName())) { fe.getFile().addFileChangeListener(wsdlListener); 519 wsdlFolder=fe.getFile(); 520 } 521 } 522 public void fileDeleted (FileEvent fe) { 523 if (fe.getFile().isFolder() && "wsdl".equals(fe.getFile().getName())) { fe.getFile().removeFileChangeListener(wsdlListener); 525 SwingUtilities.invokeLater(new Runnable () { 526 public void run() { 527 refreshKey(KEY_SERVICE_REFS); 528 } 529 }); 530 } 531 } 532 } 533 534 private final class WsdlCreationListener extends FileChangeAdapter { 535 536 public void fileDataCreated (FileEvent fe) { 537 if ("wsdl".equalsIgnoreCase(fe.getFile().getExt())) { SwingUtilities.invokeLater(new Runnable () { 539 public void run() { 540 refreshKey(KEY_SERVICE_REFS); 541 } 542 }); 543 } 544 } 545 546 public void fileDeleted (FileEvent fe) { 547 if ("wsdl".equalsIgnoreCase(fe.getFile().getExt())) { SwingUtilities.invokeLater(new Runnable () { 549 public void run() { 550 refreshKey(KEY_SERVICE_REFS); 551 } 552 }); 553 } 554 } 555 } 556 557 private final class JaxRPCChangeListener extends FileChangeAdapter { 558 559 String webservicesFile = "webservices.xml"; 560 public void fileDataCreated (FileEvent fe) { 561 if (webservicesFile.equalsIgnoreCase(fe.getFile().getNameExt())) { SwingUtilities.invokeLater(new Runnable () { 563 public void run() { 564 createNodes(); 565 } 566 }); 567 } 568 } 569 570 public void fileDeleted (FileEvent fe) { 571 if (webservicesFile.equalsIgnoreCase(fe.getFile().getNameExt())) { SwingUtilities.invokeLater(new Runnable () { 573 public void run() { 574 createNodes(); 575 } 576 }); 577 } 578 } 579 580 public void fileChanged(FileEvent fe) { 581 if (webservicesFile.equalsIgnoreCase(fe.getFile().getNameExt())) { SwingUtilities.invokeLater(new Runnable () { 583 public void run() { 584 createNodes(); 585 } 586 }); 587 } 588 } 589 } 590 } 591 592 593 | Popular Tags |