1 19 20 package org.netbeans.modules.project.ui; 21 22 import java.awt.Color ; 23 import java.awt.EventQueue ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.beans.PropertyChangeEvent ; 27 import java.beans.PropertyChangeListener ; 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.net.URI ; 31 import java.text.Collator ; 32 import java.text.MessageFormat ; 33 import java.util.ArrayList ; 34 import java.util.Collections ; 35 import java.util.HashMap ; 36 import java.util.Iterator ; 37 import java.util.List ; 38 import java.util.Map ; 39 import java.util.Set ; 40 import javax.swing.DefaultListModel ; 41 import javax.swing.Icon ; 42 import javax.swing.ImageIcon ; 43 import javax.swing.JFileChooser ; 44 import javax.swing.ListModel ; 45 import javax.swing.SwingUtilities ; 46 import javax.swing.UIManager ; 47 import javax.swing.filechooser.FileFilter ; 48 import javax.swing.filechooser.FileSystemView ; 49 import javax.swing.filechooser.FileView ; 50 import org.netbeans.api.project.Project; 51 import org.netbeans.api.project.ProjectManager; 52 import org.netbeans.api.project.ProjectUtils; 53 import org.netbeans.api.queries.CollocationQuery; 54 import org.netbeans.spi.project.SubprojectProvider; 55 import org.openide.ErrorManager; 56 import org.openide.filesystems.FileObject; 57 import org.openide.filesystems.FileUtil; 58 import org.openide.util.NbBundle; 59 import org.openide.util.RequestProcessor; 60 import org.openide.util.Utilities; 61 62 65 public class ProjectChooserAccessory extends javax.swing.JPanel 66 implements ActionListener , PropertyChangeListener { 67 68 private RequestProcessor.Task updateSubprojectsTask; 69 private ModelUpdater modelUpdater; 70 71 private Boolean tempSetAsMain; 72 73 private Map <Project,Set <? extends Project>> subprojectsCache = new HashMap <Project,Set <? extends Project>>(); 75 76 public ProjectChooserAccessory( JFileChooser chooser, boolean isOpenSubprojects, boolean isOpenAsMain ) { 77 initComponents(); 78 79 modelUpdater = new ModelUpdater(); 80 updateSubprojectsTask = new RequestProcessor(ModelUpdater.class.getName()).create(modelUpdater); 81 updateSubprojectsTask.setPriority( Thread.MIN_PRIORITY ); 82 83 jCheckBoxSubprojects.setSelected( isOpenSubprojects ); 85 jCheckBoxSubprojects.addActionListener( this ); 86 87 jCheckBoxMain.setSelected( isOpenAsMain ); 89 jCheckBoxMain.addActionListener( this ); 90 91 chooser.addPropertyChangeListener( this ); 93 94 jListSubprojects.setModel( new DefaultListModel () ); 96 97 setAccessoryEnablement( false, 0 ); 100 } 101 102 107 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 109 110 jLabelProjectName = new javax.swing.JLabel (); 111 jTextFieldProjectName = new javax.swing.JTextField (); 112 jCheckBoxMain = new javax.swing.JCheckBox (); 113 jCheckBoxSubprojects = new javax.swing.JCheckBox (); 114 jScrollPaneSubprojects = new javax.swing.JScrollPane (); 115 jListSubprojects = new javax.swing.JList (); 116 117 setLayout(new java.awt.GridBagLayout ()); 118 119 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (0, 12, 0, 0))); 120 jLabelProjectName.setLabelFor(jTextFieldProjectName); 121 org.openide.awt.Mnemonics.setLocalizedText(jLabelProjectName, org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "LBL_PrjChooser_ProjectName_Label")); 122 gridBagConstraints = new java.awt.GridBagConstraints (); 123 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 124 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 125 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 0); 126 add(jLabelProjectName, gridBagConstraints); 127 jLabelProjectName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AN_ProjectName")); 128 jLabelProjectName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AD_ProjectName")); 129 130 jTextFieldProjectName.setEditable(false); 131 gridBagConstraints = new java.awt.GridBagConstraints (); 132 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 133 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 134 gridBagConstraints.weightx = 1.0; 135 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 136 add(jTextFieldProjectName, gridBagConstraints); 137 138 org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxMain, org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "LBL_PrjChooser_Main_CheckBox")); 139 jCheckBoxMain.setMargin(new java.awt.Insets (2, 0, 2, 2)); 140 gridBagConstraints = new java.awt.GridBagConstraints (); 141 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 142 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 143 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 144 add(jCheckBoxMain, gridBagConstraints); 145 jCheckBoxMain.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "ACSD_ProjectChooserAccessory_jCheckBoxMain")); 146 147 org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxSubprojects, org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "LBL_PrjChooser_Subprojects_CheckBox")); 148 jCheckBoxSubprojects.setMargin(new java.awt.Insets (2, 0, 2, 2)); 149 gridBagConstraints = new java.awt.GridBagConstraints (); 150 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 151 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 152 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 0); 153 add(jCheckBoxSubprojects, gridBagConstraints); 154 jCheckBoxSubprojects.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "ACSD_ProjectChooserAccessory_jCheckBoxSubprojects")); 155 156 jListSubprojects.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 157 jListSubprojects.setEnabled(false); 158 jScrollPaneSubprojects.setViewportView(jListSubprojects); 159 jListSubprojects.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "ACSN_ProjectChooserAccessory_jListSubprojects")); 160 jListSubprojects.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "ACSD_ProjectChooserAccessory_jListSubprojects")); 161 162 gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 164 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 165 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 166 gridBagConstraints.weightx = 1.0; 167 gridBagConstraints.weighty = 1.0; 168 add(jScrollPaneSubprojects, gridBagConstraints); 169 170 } 172 173 private javax.swing.JCheckBox jCheckBoxMain; 175 private javax.swing.JCheckBox jCheckBoxSubprojects; 176 private javax.swing.JLabel jLabelProjectName; 177 private javax.swing.JList jListSubprojects; 178 private javax.swing.JScrollPane jScrollPaneSubprojects; 179 private javax.swing.JTextField jTextFieldProjectName; 180 182 184 public void actionPerformed( ActionEvent e ) { 185 if ( e.getSource() == jCheckBoxSubprojects ) { 186 OpenProjectListSettings.getInstance().setOpenSubprojects( jCheckBoxSubprojects.isSelected() ); 187 } 188 else if ( e.getSource() == jCheckBoxMain ) { 189 OpenProjectListSettings.getInstance().setOpenAsMain( jCheckBoxMain.isSelected() ); 190 } 191 } 192 193 public void propertyChange( PropertyChangeEvent e ) { 194 if ( JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals( e.getPropertyName() ) || 195 JFileChooser.SELECTED_FILES_CHANGED_PROPERTY.equals( e.getPropertyName() ) ) { 196 197 JFileChooser chooser = (JFileChooser )e.getSource(); 199 final ListModel spListModel = jListSubprojects.getModel(); 200 201 202 final File [] projectDirs; 203 if ( chooser.isMultiSelectionEnabled() ) { 204 projectDirs = chooser.getSelectedFiles(); 205 } 206 else { 207 projectDirs = new File [] { chooser.getSelectedFile() }; 208 } 209 210 jTextFieldProjectName.setText(NbBundle.getMessage(ProjectChooserAccessory.class, "MSG_PrjChooser_WaitMessage")); 212 RequestProcessor.getDefault().post(new Runnable () { 213 public void run() { 214 215 final List <Project> projects = new ArrayList <Project>( projectDirs.length ); 216 for (File dir : projectDirs) { 217 if (dir != null) { 218 Project project = getProject(FileUtil.normalizeFile(dir)); 219 if ( project != null ) { 220 projects.add( project ); 221 } 222 } 223 } 224 225 EventQueue.invokeLater(new Runnable () { 226 public void run() { 227 228 if ( !projects.isEmpty() ) { 229 setAccessoryEnablement( true, projects.size() ); 231 232 if ( projects.size() == 1 ) { 233 String projectName = ProjectUtils.getInformation(projects.get(0)).getDisplayName(); 234 jTextFieldProjectName.setText( projectName ); 235 jTextFieldProjectName.setToolTipText( projectName ); 236 } 237 else { 238 jTextFieldProjectName.setText(NbBundle.getMessage(ProjectChooserAccessory.class, "LBL_PrjChooser_Multiselection", projects.size())); 239 240 StringBuffer toolTipText = new StringBuffer ( "<html>" ); for(Iterator <Project> it = projects.iterator(); it.hasNext();) { 242 Project p = it.next(); 243 toolTipText.append( ProjectUtils.getInformation( p ).getDisplayName() ); 244 if ( it.hasNext() ) { 245 toolTipText.append( "<br>" ); } 247 } 248 toolTipText.append( "</html>" ); jTextFieldProjectName.setToolTipText( toolTipText.toString() ); 250 } 251 252 if (spListModel instanceof DefaultListModel ) { 253 ((DefaultListModel )spListModel).clear(); 254 } else { 255 jListSubprojects.setListData (new String [0]); 256 } 257 258 if (modelUpdater != null) { modelUpdater.projects = projects; 260 updateSubprojectsTask.schedule( 100 ); 261 } 262 } 263 else { 264 jTextFieldProjectName.setText( "" ); if (modelUpdater != null) { modelUpdater.projects = null; 268 } 269 270 if (spListModel instanceof DefaultListModel ) { 271 ((DefaultListModel )spListModel).clear(); 272 } else { 273 jListSubprojects.setListData (new String [0]); 274 } 275 276 setAccessoryEnablement( false, 0 ); 278 279 if (projectDirs.length == 1 && projectDirs[0] != null) { 281 File dir = FileUtil.normalizeFile(projectDirs[0]); 282 FileObject fo = FileUtil.toFileObject(dir); 283 if (fo != null && fo.isFolder() && ProjectManager.getDefault().isProject(fo)) { 284 try { 285 Project prj = ProjectManager.getDefault().findProject(fo); 286 if (prj == null) { 287 jTextFieldProjectName.setText(NbBundle.getMessage(ProjectChooserAccessory.class, "LBL_PrjChooser_Unrecognized")); 288 jLabelProjectName.setEnabled(true); 290 jTextFieldProjectName.setEnabled(true); 291 } 292 } catch (IOException x) { 293 String msg = x.toString(); 294 ErrorManager.Annotation[] anns = ErrorManager.getDefault().findAnnotations(x); 295 for (int i = 0; i < anns.length; i++) { 296 if (anns[i].getLocalizedMessage() != null) { 297 msg = anns[i].getLocalizedMessage(); 298 break; 299 } 300 } 301 jTextFieldProjectName.setText(msg); 302 jTextFieldProjectName.setCaretPosition(0); 303 Color error = UIManager.getColor("nb.errorForeground"); if (error != null) { 305 jTextFieldProjectName.setForeground(error); 306 } 307 jLabelProjectName.setEnabled(true); 309 jTextFieldProjectName.setEnabled(true); 310 } 311 } 312 } 313 } 314 315 } 316 }); 317 } 318 }); 319 } 320 else if ( JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals( e.getPropertyName() ) ) { 321 setAccessoryEnablement( false, 0 ); 323 } 324 } 325 326 327 329 private static boolean isProjectDir( File dir ) { 330 boolean retVal = false; 331 if (dir != null) { 332 FileObject fo = convertToValidDir(dir); 333 if (fo != null) { 334 if ( Utilities.isUnix() && fo.getParent() != null && fo.getParent().getParent() == null ) { 335 retVal = false; } 337 else { 338 retVal = ProjectManager.getDefault().isProject( fo ); 339 } 340 } 341 } 342 return retVal; 343 } 344 345 private static FileObject convertToValidDir(File f) { 346 FileObject fo; 347 File testFile = new File ( f.getPath() ); 348 if ( testFile == null || testFile.getParent() == null ) { 349 return null; 352 } 353 354 357 if ( !testFile.isDirectory() ) { 358 return null; 359 } 360 361 fo = FileUtil.toFileObject(FileUtil.normalizeFile(f)); 362 return fo; 363 } 364 365 private static Project getProject( File dir ) { 366 return OpenProjectList.fileToProject( dir ); 367 } 368 369 private void setAccessoryEnablement( boolean enable, int numberOfProjects ) { 370 jLabelProjectName.setEnabled( enable ); 371 jTextFieldProjectName.setEnabled( enable ); 372 jTextFieldProjectName.setForeground(null); 373 jCheckBoxSubprojects.setEnabled( enable ); 374 jScrollPaneSubprojects.setEnabled( enable ); 375 376 if ( numberOfProjects <= 1 ) { 377 if ( tempSetAsMain != null ) { 378 jCheckBoxMain.setSelected(tempSetAsMain); 379 tempSetAsMain = null; 380 } 381 jCheckBoxMain.setEnabled( enable ); 382 } 383 else if ( tempSetAsMain == null ) { 384 tempSetAsMain = jCheckBoxMain.isSelected(); 385 jCheckBoxMain.setSelected( false ); 386 jCheckBoxMain.setEnabled( false ); 387 } 388 389 } 390 391 393 static void addSubprojects(Project p, List <Project> result, Map <Project,Set <? extends Project>> cache) { 394 Set <? extends Project> subprojects = cache.get(p); 395 if (subprojects == null) { 396 SubprojectProvider spp = p.getLookup().lookup(SubprojectProvider.class); 397 if (spp != null) { 398 subprojects = spp.getSubprojects(); 399 } else { 400 subprojects = Collections.emptySet(); 401 } 402 cache.put(p, subprojects); 403 } 404 for (Project sp : subprojects) { 405 if ( !result.contains( sp ) ) { 406 result.add( sp ); 407 408 addSubprojects(sp, result, cache); 411 } 412 } 413 414 } 415 416 421 private static String relativizePath(File f1, File f2) { 422 if (f1 == null || f2 == null) { 423 return null; 424 } 425 if (!CollocationQuery.areCollocated(f1, f2)) { 426 return null; 427 } 428 StringBuffer b = new StringBuffer (); 430 File base = f1; 431 String filepath = f2.getAbsolutePath(); 432 while (!filepath.startsWith(slashify(base.getAbsolutePath()))) { 433 base = base.getParentFile(); 434 if (base == null) { 435 return null; 436 } 437 if (base.equals(f2)) { 438 b.append(".."); return b.toString(); 441 } 442 b.append("../"); } 444 URI u = base.toURI().relativize(f2.toURI()); 445 assert !u.isAbsolute() : u + " from " + f1 + " and " + f2 + " with common root " + base; 446 b.append(u.getPath()); 447 if (b.charAt(b.length() - 1) == '/') { 448 b.setLength(b.length() - 1); 451 } 452 return b.toString(); 453 } 454 private static String slashify(String path) { 455 if (path.endsWith(File.separator)) { 456 return path; 457 } else { 458 return path + File.separatorChar; 459 } 460 } 461 462 463 465 467 public static JFileChooser createProjectChooser( boolean defaultAccessory ) { 468 469 ProjectManager.getDefault().clearNonProjectCache(); 471 OpenProjectListSettings opls = OpenProjectListSettings.getInstance(); 472 JFileChooser chooser = new ProjectFileChooser(); 473 chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); 474 475 if ("GTK".equals(javax.swing.UIManager.getLookAndFeel().getID())) { chooser.putClientProperty("GTKFileChooser.showDirectoryIcons", Boolean.TRUE); } 480 481 chooser.setApproveButtonText( NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonText" ) ); chooser.setApproveButtonMnemonic( NbBundle.getMessage( ProjectChooserAccessory.class, "MNM_PrjChooser_ApproveButtonText" ).charAt (0) ); chooser.setApproveButtonToolTipText (NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonTooltipText")); chooser.setDialogTitle( NbBundle.getMessage( ProjectChooserAccessory.class, "LBL_PrjChooser_Title" ) ); chooser.setAcceptAllFileFilterUsed( false ); 488 chooser.setFileFilter( ProjectDirFilter.INSTANCE ); 489 490 chooser.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AN_ProjectChooserAccessory")); 492 chooser.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AD_ProjectChooserAccessory")); 493 494 495 if ( defaultAccessory ) { 496 chooser.setAccessory( new ProjectChooserAccessory( chooser, opls.isOpenSubprojects(), opls.isOpenAsMain() ) ); 497 } 498 499 File currDir = null; 500 String dir = opls.getLastOpenProjectDir(); 501 if ( dir != null ) { 502 File d = new File ( dir ); 503 if ( d.exists() && d.isDirectory() ) { 504 currDir = d; 505 } 506 } 507 508 FileUtil.preventFileChooserSymlinkTraversal(chooser, currDir); 509 chooser.setFileView( new ProjectFileView( chooser.getFileSystemView() ) ); 510 511 return chooser; 512 513 } 514 515 public void removeNotify() { super.removeNotify(); 517 modelUpdater = null; 518 subprojectsCache = null; 519 updateSubprojectsTask = null; 520 } 521 522 524 private static class ProjectFileChooser extends JFileChooser { 525 526 public void approveSelection() { 527 File dir = FileUtil.normalizeFile(getSelectedFile()); 528 529 if ( isProjectDir( dir ) && getProject( dir ) != null ) { 530 super.approveSelection(); 531 } 532 else { 533 setCurrentDirectory( dir ); 534 } 535 536 } 537 538 539 } 540 541 private static class ProjectDirFilter extends FileFilter { 542 543 private static final FileFilter INSTANCE = new ProjectDirFilter( ); 544 545 public boolean accept( File f ) { 546 547 if ( f.isDirectory() ) { 548 return true; } 550 551 return false; 552 } 553 554 public String getDescription() { 555 return NbBundle.getMessage( ProjectDirFilter.class, "LBL_PrjChooser_ProjectDirectoryFilter_Name" ); } 557 558 } 559 560 private static class ProjectFileView extends FileView { 561 562 private static final Icon BADGE = new ImageIcon (Utilities.loadImage("org/netbeans/modules/project/ui/resources/projectBadge.gif")); private static final Icon EMPTY = new ImageIcon (Utilities.loadImage("org/netbeans/modules/project/ui/resources/empty.gif")); 565 private FileSystemView fsv; 566 private Icon lastOriginal; 567 private Icon lastMerged; 568 569 public ProjectFileView( FileSystemView fsv ) { 570 this.fsv = fsv; 571 } 572 573 public Icon getIcon(File _f) { 574 if (!_f.exists()) { 575 return null; 579 } 580 File f = FileUtil.normalizeFile(_f); 581 Icon original = fsv.getSystemIcon(f); 582 if (original == null) { 583 original = EMPTY; 585 } 586 if ( isProjectDir( f ) ) { 587 if ( original.equals( lastOriginal ) ) { 588 return lastMerged; 589 } 590 lastOriginal = original; 591 lastMerged = new MergedIcon(original, BADGE, -1, -1); 592 return lastMerged; 593 } 594 else { 595 return original; 596 } 597 } 598 599 600 } 601 602 private static class MergedIcon implements Icon { 603 604 private Icon icon1; 605 private Icon icon2; 606 private int xMerge; 607 private int yMerge; 608 609 MergedIcon( Icon icon1, Icon icon2, int xMerge, int yMerge ) { 610 611 this.icon1 = icon1; 612 this.icon2 = icon2; 613 614 if ( xMerge == -1 ) { 615 xMerge = icon1.getIconWidth() - icon2.getIconWidth(); 616 } 617 618 if ( yMerge == -1 ) { 619 yMerge = icon1.getIconHeight() - icon2.getIconHeight(); 620 } 621 622 this.xMerge = xMerge; 623 this.yMerge = yMerge; 624 } 625 626 public int getIconHeight() { 627 return Math.max( icon1.getIconHeight(), yMerge + icon2.getIconHeight() ); 628 } 629 630 public int getIconWidth() { 631 return Math.max( icon1.getIconWidth(), yMerge + icon2.getIconWidth() ); 632 } 633 634 public void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y) { 635 icon1.paintIcon( c, g, x, y ); 636 icon2.paintIcon( c, g, x + xMerge, y + yMerge ); 637 } 638 639 } 640 641 private class ModelUpdater implements Runnable { 642 643 volatile List <Project> projects; 645 private DefaultListModel subprojectsToSet; 646 647 public void run() { 648 649 if ( !SwingUtilities.isEventDispatchThread() ) { 650 List <Project> currentProjects = projects; 651 if ( currentProjects == null ) { 652 return; 653 } 654 Map <Project,Set <? extends Project>> cache = subprojectsCache; 655 if (cache == null) { 656 return; 657 } 658 659 jListSubprojects.setListData (new String [] {NbBundle.getMessage (ProjectChooserAccessory.class, "MSG_PrjChooser_WaitMessage")}); 660 661 List <Project> subprojects = new ArrayList <Project>(currentProjects.size() * 5); 662 for (Project p : currentProjects) { 663 addSubprojects(p, subprojects, cache); } 665 666 List <String > subprojectNames = new ArrayList <String >(subprojects.size()); 667 if ( !subprojects.isEmpty() ) { 668 String pattern = NbBundle.getMessage( ProjectChooserAccessory.class, "LBL_PrjChooser_SubprojectName_Format" ); File pDir = currentProjects.size() == 1 ? 670 FileUtil.toFile( currentProjects.get(0).getProjectDirectory() ) : 671 null; 672 673 for (Project p : subprojects) { 675 FileObject spDir = p.getProjectDirectory(); 676 677 String relPath = null; 679 if ( pDir != null ) { relPath = relativizePath(pDir, FileUtil.toFile( spDir )); 681 } 682 683 if (relPath == null) { 684 relPath = FileUtil.getFileDisplayName(spDir); 686 } 687 String displayName = MessageFormat.format( 688 pattern, 689 ProjectUtils.getInformation(p).getDisplayName(), 690 relPath); 691 subprojectNames.add(displayName); 692 } 693 694 Collections.sort( subprojectNames, Collator.getInstance() ); 696 } 697 if ( currentProjects != projects ) { 698 return; 699 } 700 DefaultListModel listModel = new DefaultListModel (); 701 for (String displayName : subprojectNames) { 703 listModel.addElement(displayName); 704 } 705 subprojectsToSet = listModel; 706 SwingUtilities.invokeLater( this ); 707 return; 708 } 709 else { 710 if ( projects == null ) { 711 ListModel spListModel = jListSubprojects.getModel(); 712 if (spListModel instanceof DefaultListModel ) { 713 ((DefaultListModel )spListModel).clear(); 714 } else { 715 jListSubprojects.setListData (new String [0]); 716 } 717 jCheckBoxSubprojects.setEnabled( false ); 718 } 719 else { 720 jListSubprojects.setModel(subprojectsToSet); 721 jCheckBoxSubprojects.setEnabled( !subprojectsToSet.isEmpty() ); 723 projects = null; 724 } 725 } 726 727 } 728 729 730 } 731 732 733 } 734 | Popular Tags |