1 19 20 package org.netbeans.modules.j2ee.clientproject.ui; 21 22 23 import java.awt.Dialog ; 24 import java.awt.Image ; 25 import java.awt.event.ActionEvent ; 26 import java.beans.BeanInfo ; 27 import java.beans.PropertyChangeEvent ; 28 import java.beans.PropertyChangeListener ; 29 import java.io.IOException ; 30 import java.io.File ; 31 import java.net.MalformedURLException ; 32 import java.net.URI ; 33 import java.net.URL ; 34 import java.text.MessageFormat ; 35 import java.util.ArrayList ; 36 import java.util.Arrays ; 37 import java.util.Collection ; 38 import java.util.Collections ; 39 import java.util.HashSet ; 40 import java.util.Iterator ; 41 import java.util.LinkedList ; 42 import java.util.List ; 43 import java.util.Set ; 44 import javax.swing.AbstractAction ; 45 import javax.swing.Action ; 46 import javax.swing.Icon ; 47 import javax.swing.ImageIcon ; 48 import javax.swing.JButton ; 49 import javax.swing.JFileChooser ; 50 import javax.swing.filechooser.FileFilter ; 51 import org.openide.DialogDescriptor; 52 import org.openide.DialogDisplayer; 53 import org.openide.ErrorManager; 54 import org.openide.filesystems.FileObject; 55 import org.openide.filesystems.FileUtil; 56 import org.openide.filesystems.Repository; 57 import org.openide.filesystems.URLMapper; 58 import org.openide.loaders.DataFolder; 59 import org.openide.nodes.AbstractNode; 60 import org.openide.nodes.Children; 61 import org.openide.nodes.Node; 62 import org.openide.util.NbBundle; 63 import org.openide.util.RequestProcessor; 64 import org.openide.util.Utilities; 65 import org.openide.util.lookup.Lookups; 66 import org.openide.windows.WindowManager; 67 import org.netbeans.api.project.SourceGroup; 68 import org.netbeans.api.project.Project; 69 import org.netbeans.api.project.ant.AntArtifact; 70 import org.netbeans.api.project.libraries.Library; 71 import org.netbeans.api.project.libraries.LibraryManager; 72 import org.netbeans.api.java.classpath.ClassPath; 73 import org.netbeans.api.java.project.JavaProjectConstants; 74 import org.netbeans.api.project.FileOwnerQuery; 75 import org.netbeans.spi.project.support.ant.AntProjectHelper; 76 import org.netbeans.spi.project.support.ant.EditableProperties; 77 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 78 import org.netbeans.spi.project.support.ant.PropertyUtils; 79 import org.netbeans.spi.project.support.ant.ReferenceHelper; 80 import org.netbeans.spi.java.project.support.ui.PackageView; 81 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 82 import org.netbeans.modules.j2ee.clientproject.UpdateHelper; 83 import org.netbeans.modules.j2ee.clientproject.classpath.AppClientProjectClassPathExtender; 84 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AntArtifactChooser; 85 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientClassPathUi; 86 import org.netbeans.modules.j2ee.clientproject.ui.customizer.LibrariesChooser; 87 88 89 90 91 95 final class LibrariesNode extends AbstractNode { 96 97 private static final Image ICON_BADGE = Utilities.loadImage("org/netbeans/modules/j2ee/clientproject/ui/resources/libraries-badge.png"); static final RequestProcessor rp = new RequestProcessor (); 99 private static Icon folderIconCache; 100 private static Icon openedFolderIconCache; 101 102 private final String displayName; 103 private final Action [] librariesNodeActions; 104 105 106 121 LibrariesNode (String displayName, Project project, PropertyEvaluator eval, UpdateHelper helper, ReferenceHelper refHelper, 122 String classPathProperty, String [] classPathIgnoreRef, String platformProperty, String j2eePlatformProperty, 123 Action [] librariesNodeActions, String includedLibrariesElement) { 124 super (new LibrariesChildren (eval, helper, refHelper, classPathProperty, classPathIgnoreRef, platformProperty, j2eePlatformProperty, includedLibrariesElement), Lookups.singleton(project)); 125 this.displayName = displayName; 126 this.librariesNodeActions = librariesNodeActions; 127 } 128 129 public String getDisplayName () { 130 return this.displayName; 131 } 132 133 public String getName () { 134 return this.getDisplayName(); 135 } 136 137 public Image getIcon( int type ) { 138 return computeIcon( false, type ); 139 } 140 141 public Image getOpenedIcon( int type ) { 142 return computeIcon( true, type ); 143 } 144 145 public Action [] getActions(boolean context) { 146 return this.librariesNodeActions; 147 } 148 149 public boolean canCopy() { 150 return false; 151 } 152 153 public static Action createAddProjectAction (Project p, String classPathId, String includedLibrariesElement) { 155 return new AddProjectAction (p, classPathId, includedLibrariesElement); 156 } 157 158 public static Action createAddLibraryAction (Project p, AntProjectHelper helper, String classPathId, String includedLibrariesElement) { 159 return new AddLibraryAction (p, helper, classPathId, includedLibrariesElement); 160 } 161 162 public static Action createAddFolderAction (Project p, String classPathId, String includedLibrariesElement) { 163 return new AddFolderAction (p, classPathId, includedLibrariesElement); 164 } 165 166 171 static synchronized Icon getFolderIcon (boolean opened) { 172 if (openedFolderIconCache == null) { 173 Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); 174 openedFolderIconCache = new ImageIcon (n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)); 175 folderIconCache = new ImageIcon (n.getIcon(BeanInfo.ICON_COLOR_16x16)); 176 } 177 if (opened) { 178 return openedFolderIconCache; 179 } 180 else { 181 return folderIconCache; 182 } 183 } 184 185 private Image computeIcon( boolean opened, int type ) { 186 Icon icon = getFolderIcon(opened); 187 Image image = ((ImageIcon )icon).getImage(); 188 image = Utilities.mergeImages(image, ICON_BADGE, 7, 7 ); 189 return image; 190 } 191 192 private static class LibrariesChildren extends Children.Keys implements PropertyChangeListener { 194 195 196 199 private static final String LIBRARY_PREFIX = "${libs."; 201 204 private static final String ANT_ARTIFACT_PREFIX = "${reference."; 208 private static final String FILE_REF_PREFIX = "${file.reference."; 212 private static final String REF_PREFIX = "${"; 214 private static final String LIBRARIES_ICON = "org/netbeans/modules/j2ee/clientproject/ui/resources/libraries.gif"; private static final String ARCHIVE_ICON = "org/netbeans/modules/j2ee/clientproject/ui/resources/jar.gif"; 217 private final PropertyEvaluator eval; 218 private final UpdateHelper helper; 219 private final ReferenceHelper refHelper; 220 private final String classPathProperty; 221 private final String platformProperty; 222 private final String j2eePlatformProperty; 223 private final Set <String > classPathIgnoreRef; 224 private final String includedLibrariesElement; 225 226 private ClassPath fsListener; 230 231 232 LibrariesChildren (PropertyEvaluator eval, UpdateHelper helper, ReferenceHelper refHelper, 233 String classPathProperty, String [] classPathIgnoreRef, String platformProperty, String j2eePlatformProperty, 234 String includedLibrariesElement) { 235 this.eval = eval; 236 this.helper = helper; 237 this.refHelper = refHelper; 238 this.classPathProperty = classPathProperty; 239 this.classPathIgnoreRef = new HashSet <String >(Arrays.asList(classPathIgnoreRef)); 240 this.platformProperty = platformProperty; 241 this.j2eePlatformProperty = j2eePlatformProperty; 242 this.includedLibrariesElement = includedLibrariesElement; 243 } 244 245 public void propertyChange(PropertyChangeEvent evt) { 246 String propName = evt.getPropertyName(); 247 if (classPathProperty.equals(propName) || ClassPath.PROP_ROOTS.equals(propName)) { 248 synchronized (this) { 249 if (fsListener!=null) { 250 fsListener.removePropertyChangeListener (this); 251 } 252 } 253 rp.post (new Runnable () { 254 public void run () { 255 setKeys(getKeys()); 256 } 257 }); 258 } 259 } 260 261 protected void addNotify() { 262 this.eval.addPropertyChangeListener (this); 263 this.setKeys(getKeys ()); 264 } 265 266 protected void removeNotify() { 267 this.eval.removePropertyChangeListener(this); 268 synchronized (this) { 269 if (fsListener!=null) { 270 fsListener.removePropertyChangeListener (this); 271 fsListener = null; 272 } 273 } 274 this.setKeys(Collections.EMPTY_SET); 275 } 276 277 protected Node[] createNodes(Object obj) { 278 Node[] result = null; 279 if (obj instanceof Key) { 280 Key key = (Key) obj; 281 switch (key.getType()) { 282 case Key.TYPE_PLATFORM: 283 result = new Node[] {PlatformNode.create(eval, platformProperty)}; 284 break; 285 case Key.TYPE_J2EE_PLATFORM: 286 Project project = FileOwnerQuery.getOwner(helper.getAntProjectHelper().getProjectDirectory()); 287 result = new Node[] {J2eePlatformNode.create(project, eval, j2eePlatformProperty)}; 288 break; 289 case Key.TYPE_PROJECT: 290 result = new Node[] {new ProjectNode(key.getProject(), key.getArtifactLocation(), helper, eval, refHelper, key.getClassPathId(), 291 key.getEntryId(), includedLibrariesElement)}; 292 break; 293 case Key.TYPE_LIBRARY: 294 result = new Node[] {ActionFilterNode.create(PackageView.createPackageView(key.getSourceGroup()), 295 helper, eval, refHelper, key.getClassPathId(), key.getEntryId(), includedLibrariesElement)}; 296 break; 297 } 298 } 299 if (result == null) { 300 assert false : "Unknown key type"; result = new Node[0]; 302 } 303 return result; 304 } 305 306 private List <Key> getKeys () { 307 EditableProperties projectSharedProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 308 EditableProperties projectPrivateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 309 EditableProperties privateProps = PropertyUtils.getGlobalProperties(); 310 List <URL > rootsList = new ArrayList <URL >(); 311 List <Key> result = getKeys(projectSharedProps, projectPrivateProps, privateProps, classPathProperty, rootsList); 312 FileObject projectDir = helper.getAntProjectHelper().getProjectDirectory(); 314 if (platformProperty!=null && projectDir !=null && projectDir.isValid() && !projectDir.isVirtual()) { 315 result.add(new Key()); 316 } 317 if (j2eePlatformProperty != null) { 318 result.add(new Key(true)); 319 } 320 ClassPath cp = ClassPathSupport.createClassPath ((URL [])rootsList.toArray(new URL [rootsList.size()])); 323 cp.addPropertyChangeListener (this); 324 cp.getRoots(); 325 synchronized (this) { 326 fsListener = cp; 327 } 328 return result; 329 } 330 331 private List <Key> getKeys(EditableProperties projectSharedProps, EditableProperties projectPrivateProps, 332 EditableProperties privateProps, String currentClassPath, List <URL > rootsList) { 333 List <Key> result = new ArrayList <Key>(); 334 String raw = projectSharedProps.getProperty (currentClassPath); 335 if (raw == null) { 336 raw = projectPrivateProps.getProperty(currentClassPath); 337 } 338 if (raw == null) { 339 raw = privateProps.getProperty(currentClassPath); 340 } 341 if (raw == null) { 342 return result; 343 } 344 List <String > pe = new ArrayList <String >(Arrays.asList(PropertyUtils.tokenizePath( raw ))); 345 while (pe.size()>0){ 346 String prop = (String ) pe.remove(0); 347 String propName = org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport.getAntPropertyName (prop); 348 if (classPathIgnoreRef.contains(propName)) { 349 continue; 350 } 351 else if (prop.startsWith( LIBRARY_PREFIX )) { 352 String eval = prop.substring( LIBRARY_PREFIX.length(), prop.lastIndexOf('.') ); Library lib = LibraryManager.getDefault().getLibrary (eval); 355 if (lib != null) { 356 List roots = lib.getContent("classpath"); Icon libIcon = new ImageIcon (Utilities.loadImage(LIBRARIES_ICON)); 358 for (Iterator it = roots.iterator(); it.hasNext();) { 359 URL rootUrl = (URL ) it.next(); 360 rootsList.add (rootUrl); 361 FileObject root = URLMapper.findFileObject (rootUrl); 362 if (root != null) { 363 String displayName; 364 if ("jar".equals(rootUrl.getProtocol())) { FileObject file = FileUtil.getArchiveFile (root); 366 displayName = file.getNameExt(); 367 } 368 else { 369 File file = FileUtil.toFile (root); 370 if (file != null) { 371 displayName = file.getAbsolutePath(); 372 } 373 else { 374 displayName = root.getNameExt(); 375 } 376 } 377 displayName = MessageFormat.format ( 378 NbBundle.getMessage (LibrariesNode.class,"TXT_LibraryPartFormat"), 379 new Object [] {lib.getDisplayName(), displayName}); 380 SourceGroup sg = new LibrariesSourceGroup (root, displayName, libIcon, libIcon); 381 result.add (new Key(sg,currentClassPath, propName)); 382 } 383 } 384 } 385 } 387 else if (prop.startsWith(ANT_ARTIFACT_PREFIX)) { 388 Object ret[] = refHelper.findArtifactAndLocation(prop); 390 if ( ret[0] != null && ret[1] != null) { 391 AntArtifact artifact = (AntArtifact)ret[0]; 392 URI uri = (URI ) ret[1]; 393 result.add (new Key(artifact, uri, currentClassPath, propName)); 394 } 395 } 396 else if (prop.startsWith(FILE_REF_PREFIX)) { 397 String evaluatedRef = eval.getProperty(propName); 399 if (evaluatedRef != null) { 400 File file = helper.getAntProjectHelper().resolveFile(evaluatedRef); 401 SourceGroup sg = createFileSourceGroup(file,rootsList); 402 if (sg !=null) { 403 result.add (new Key(sg,currentClassPath, propName)); 404 } 405 } 406 } 407 else if (prop.startsWith(REF_PREFIX)) { 408 result.addAll(getKeys(projectSharedProps, projectPrivateProps, privateProps,propName, rootsList)); 410 } 411 else { 412 File file = helper.getAntProjectHelper().resolveFile(prop); 414 SourceGroup sg = createFileSourceGroup(file,rootsList); 415 if (sg !=null) { 416 result.add ( new Key(sg,currentClassPath, propName)); 417 } 418 } 419 } 420 return result; 421 } 422 423 private static SourceGroup createFileSourceGroup (File file, List <URL > rootsList) { 424 Icon icon; 425 Icon openedIcon; 426 String displayName; 427 try { 428 URL url = file.toURI().toURL(); 429 if (FileUtil.isArchiveFile(url)) { 430 url = FileUtil.getArchiveRoot(url); 431 icon = openedIcon = new ImageIcon (Utilities.loadImage(ARCHIVE_ICON)); 432 displayName = file.getName(); 433 } 434 else { 435 String sURL = url.toExternalForm(); 436 if (!sURL.endsWith("/")) { url = new URL (sURL+"/"); } 439 icon = getFolderIcon (false); 440 openedIcon = getFolderIcon (true); 441 displayName = file.getAbsolutePath(); 442 } 443 rootsList.add(url); 444 FileObject root = URLMapper.findFileObject (url); 445 if (root != null) { 446 return new LibrariesSourceGroup (root,displayName,icon,openedIcon); 447 } 448 } catch (MalformedURLException e) { 449 ErrorManager.getDefault().notify(e); 450 } 451 return null; 452 } 453 } 454 455 private static class Key { 456 static final int TYPE_PLATFORM = 0; 457 static final int TYPE_LIBRARY = 1; 458 static final int TYPE_PROJECT = 2; 459 static final int TYPE_J2EE_PLATFORM = 3; 460 461 private int type; 462 private String classPathId; 463 private String entryId; 464 private SourceGroup sg; 465 private AntArtifact antArtifact; 466 private URI uri; 467 468 Key () { 469 this.type = TYPE_PLATFORM; 470 } 471 472 Key (boolean j2ee) { 473 this.type = j2ee ? TYPE_J2EE_PLATFORM : TYPE_PLATFORM; 474 } 475 476 Key (SourceGroup sg, String classPathId, String entryId) { 477 this.type = TYPE_LIBRARY; 478 this.sg = sg; 479 this.classPathId = classPathId; 480 this.entryId = entryId; 481 } 482 483 Key (AntArtifact a, URI uri, String classPathId, String entryId) { 484 this.type = TYPE_PROJECT; 485 this.antArtifact = a; 486 this.uri = uri; 487 this.classPathId = classPathId; 488 this.entryId = entryId; 489 } 490 491 public int getType () { 492 return this.type; 493 } 494 495 public String getClassPathId () { 496 return this.classPathId; 497 } 498 499 public String getEntryId () { 500 return this.entryId; 501 } 502 503 public SourceGroup getSourceGroup () { 504 return this.sg; 505 } 506 507 public AntArtifact getProject () { 508 return this.antArtifact; 509 } 510 511 public URI getArtifactLocation () { 512 return this.uri; 513 } 514 515 public int hashCode() { 516 int hashCode = this.type<<16; 517 switch (this.type) { 518 case TYPE_LIBRARY: 519 hashCode ^= this.sg == null ? 0 : this.sg.hashCode(); 520 break; 521 case TYPE_PROJECT: 522 hashCode ^= this.antArtifact == null ? 0 : this.antArtifact.hashCode(); 523 break; 524 } 525 return hashCode; 526 } 527 528 public boolean equals(Object obj) { 529 if (!(obj instanceof Key)) { 530 return false; 531 } 532 Key other = (Key) obj; 533 if (other.type != type) { 534 return false; 535 } 536 switch (type) { 537 case TYPE_LIBRARY: 538 return (this.sg == null ? other.sg == null : this.sg.equals(other.sg)) && 539 (this.classPathId == null ? other.classPathId == null : this.classPathId.equals (other.classPathId)) && 540 (this.entryId == null ? other.entryId == null : this.entryId.equals (other.entryId)); 541 case TYPE_PROJECT: 542 return (this.antArtifact == null ? other.antArtifact == null : this.antArtifact.equals(other.antArtifact)) && 543 (this.classPathId == null ? other.classPathId == null : this.classPathId.equals (other.classPathId)) && 544 (this.entryId == null ? other.entryId == null : this.entryId.equals (other.entryId)); 545 case TYPE_PLATFORM: 546 case TYPE_J2EE_PLATFORM: 547 return true; 548 default: 549 throw new IllegalStateException (); 550 } 551 } 552 } 553 554 private static class AddProjectAction extends AbstractAction { 555 556 private final Project project; 557 private final String classPathId; 558 private final String includedLibrariesElement; 559 560 public AddProjectAction (Project project, String classPathId, String includedLibrariesElement) { 561 super( NbBundle.getMessage( LibrariesNode.class, "LBL_AddProject_Action" ) ); 562 this.project = project; 563 this.classPathId = classPathId; 564 this.includedLibrariesElement = includedLibrariesElement; 565 } 566 567 public void actionPerformed(ActionEvent e) { 568 AntArtifactChooser.ArtifactItem artifactItems[] = AntArtifactChooser.showDialog(JavaProjectConstants.ARTIFACT_TYPE_JAR, project, null); 569 if ( artifactItems != null ) { 570 addArtifacts( artifactItems ); 571 } 572 } 573 574 private void addArtifacts (AntArtifactChooser.ArtifactItem[] artifactItems) { 575 AppClientProjectClassPathExtender cpExtender = (AppClientProjectClassPathExtender) project.getLookup().lookup(AppClientProjectClassPathExtender.class); 576 if (cpExtender != null) { 577 try { 578 cpExtender.addAntArtifacts(classPathId, artifactItems, includedLibrariesElement ); 579 } catch (IOException ioe) { 580 ErrorManager.getDefault().notify(ioe); 581 } 582 } 583 else { 584 ErrorManager.getDefault().log ("AppClientProjectClassPathExtender not found in the project lookup of project: "+project.getProjectDirectory().getPath()); } 586 } 587 } 588 589 private static class AddLibraryAction extends AbstractAction { 590 591 private final Project project; 592 private final AntProjectHelper helper; 593 private final String classPathId; 594 private final String includedLibrariesElement; 595 596 public AddLibraryAction (Project project, AntProjectHelper helper, String classPathId, String includedLibrariesElement) { 597 super( NbBundle.getMessage( LibrariesNode.class, "LBL_AddLibrary_Action" ) ); 598 this.project = project; 599 this.helper = helper; 600 this.classPathId = classPathId; 601 this.includedLibrariesElement = includedLibrariesElement; 602 } 603 604 public void actionPerformed(ActionEvent e) { 605 Object [] options = new Object [] { 606 new JButton (NbBundle.getMessage (AppClientClassPathUi.class,"LBL_AddLibrary")), 607 DialogDescriptor.CANCEL_OPTION 608 }; 609 ((JButton )options[0]).setEnabled(false); 610 ((JButton )options[0]).getAccessibleContext().setAccessibleDescription (NbBundle.getMessage (AppClientClassPathUi.class,"AD_AddLibrary")); 611 LibrariesChooser panel = new LibrariesChooser ((JButton )options[0], Collections.EMPTY_SET); 613 DialogDescriptor desc = new DialogDescriptor(panel,NbBundle.getMessage( AppClientClassPathUi.class, "LBL_CustomizeCompile_Classpath_AddLibrary" ), 614 true, options, options[0], DialogDescriptor.DEFAULT_ALIGN,null,null); 615 Dialog dlg = DialogDisplayer.getDefault().createDialog(desc); 616 dlg.setVisible(true); 617 if (desc.getValue() == options[0]) { 618 addLibraries(panel.getSelectedLibraries()); 619 } 620 dlg.dispose(); 621 } 622 623 private void addLibraries (Library[] libraries) { 624 AppClientProjectClassPathExtender cpExtender = (AppClientProjectClassPathExtender) project.getLookup().lookup(AppClientProjectClassPathExtender.class); 625 if (cpExtender != null) { 626 try { 627 cpExtender.addLibraries(classPathId, libraries, includedLibrariesElement); 628 } catch (IOException ioe) { 629 ErrorManager.getDefault().notify(ioe); 630 } 631 } 632 else { 633 ErrorManager.getDefault().log ("EjbJarProjectClassPathExtender not found in the project lookup of project: "+project.getProjectDirectory().getPath()); } 635 } 636 } 637 638 private static class AddFolderAction extends AbstractAction { 639 640 private final Project project; 641 private final String classPathId; 642 private final String includedLibrariesElement; 643 644 public AddFolderAction (Project project, String classPathId, String includedLibrariesElement) { 645 super( NbBundle.getMessage( LibrariesNode.class, "LBL_AddFolder_Action" ) ); 646 this.project = project; 647 this.classPathId = classPathId; 648 this.includedLibrariesElement = includedLibrariesElement; 649 } 650 651 public void actionPerformed(ActionEvent e) { 652 JFileChooser chooser = new JFileChooser (); 653 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 654 chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES ); 655 chooser.setMultiSelectionEnabled( true ); 656 chooser.setDialogTitle( NbBundle.getMessage( LibrariesNode.class, "LBL_AddJar_DialogTitle" ) ); FileFilter fileFilter = new SimpleFileFilter ( 658 NbBundle.getMessage( LibrariesNode.class, "LBL_ZipJarFolderFilter" ), new String [] {"ZIP","JAR"} ); chooser.setAcceptAllFileFilterUsed( false ); 662 chooser.setFileFilter(fileFilter); 663 File curDir = FoldersListSettings.getDefault().getLastUsedClassPathFolder(); 664 chooser.setCurrentDirectory (curDir); 665 int option = chooser.showOpenDialog( WindowManager.getDefault().getMainWindow() ); 666 if ( option == JFileChooser.APPROVE_OPTION ) { 667 File files[] = chooser.getSelectedFiles(); 668 addJarFiles( files, fileFilter ); 669 curDir = FileUtil.normalizeFile(chooser.getCurrentDirectory()); 670 FoldersListSettings.getDefault().setLastUsedClassPathFolder(curDir); 671 } 672 } 673 674 private void addJarFiles (File [] files, FileFilter fileFilter) { 675 AppClientProjectClassPathExtender cpExtender = (AppClientProjectClassPathExtender) project.getLookup().lookup(AppClientProjectClassPathExtender.class); 676 if (cpExtender != null) { 677 List <FileObject> fileObjects = new LinkedList <FileObject>(); 678 for (int i = 0; i < files.length; i++) { 679 if (fileFilter.accept(files[i])) { 680 FileObject fo = FileUtil.toFileObject (files[i]); 681 assert fo != null : files[i]; 682 fileObjects.add(fo); 683 } 684 } 685 try { 686 FileObject[] fileObjectArray = new FileObject[fileObjects.size()]; 687 fileObjects.toArray(fileObjectArray); 688 cpExtender.addArchiveFiles(classPathId, fileObjectArray, includedLibrariesElement); 689 } catch (IOException ioe) { 690 ErrorManager.getDefault().notify(ioe); 691 } 692 } 693 else { 694 ErrorManager.getDefault().log ("EjbJarProjectClassPathExtender not found in the project lookup of project: "+project.getProjectDirectory().getPath()); } 696 } 697 698 } 699 700 private static class SimpleFileFilter extends FileFilter { 701 702 private String description; 703 private Collection extensions; 704 705 706 public SimpleFileFilter (String description, String [] extensions) { 707 this.description = description; 708 this.extensions = Arrays.asList(extensions); 709 } 710 711 public boolean accept(File f) { 712 if (f.isDirectory()) 713 return true; 714 try { 715 return FileUtil.isArchiveFile(f.toURI().toURL()); 716 } catch (MalformedURLException mue) { 717 ErrorManager.getDefault().notify(mue); 718 return false; 719 } 720 } 721 722 public String getDescription() { 723 return this.description; 724 } 725 } 726 } 727 728 729 | Popular Tags |