1 19 20 package org.netbeans.modules.apisupport.project.suite; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.IOException ; 25 import java.util.Collections ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.Set ; 29 import javax.swing.event.ChangeEvent ; 30 import javax.swing.event.ChangeListener ; 31 import org.netbeans.api.project.Project; 32 import org.netbeans.api.project.ProjectManager; 33 import org.netbeans.modules.apisupport.project.NbModuleProject; 34 import org.netbeans.modules.apisupport.project.Util; 35 import org.netbeans.spi.project.SubprojectProvider; 36 import org.netbeans.spi.project.support.ant.AntProjectHelper; 37 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 38 import org.netbeans.spi.project.support.ant.PropertyUtils; 39 import org.openide.ErrorManager; 40 import org.openide.filesystems.FileObject; 41 42 46 final class SuiteSubprojectProviderImpl implements SubprojectProvider { 47 48 private Set <NbModuleProject> projects; 49 private final AntProjectHelper helper; 50 private final PropertyEvaluator eval; 51 52 private final Set <ChangeListener > listeners = new HashSet (); 53 private boolean reloadNeeded; 54 55 public SuiteSubprojectProviderImpl(AntProjectHelper helper, PropertyEvaluator eval) { 56 this.helper = helper; 57 this.eval = eval; 58 eval.addPropertyChangeListener(new PropertyChangeListener () { 59 public void propertyChange(PropertyChangeEvent evt) { 60 if ("modules".equals(evt.getPropertyName())) { SuiteSubprojectProviderImpl.this.reloadNeeded = true; 62 SuiteSubprojectProviderImpl.this.fireChange(); 63 } 64 } 65 }); 66 } 67 68 public Set <NbModuleProject> getSubprojects() { 69 if (projects == null || reloadNeeded) { 70 projects = loadProjects(); 71 reloadNeeded = false; 72 } 73 return projects; 74 } 75 76 public final void addChangeListener(ChangeListener l) { 77 synchronized (listeners) { 78 listeners.add(l); 79 } 80 } 81 82 public final void removeChangeListener(ChangeListener l) { 83 synchronized (listeners) { 84 listeners.remove(l); 85 } 86 } 87 88 private void fireChange() { 89 Iterator it; 90 ChangeEvent e = new ChangeEvent (this); 91 synchronized (listeners) { 92 if (listeners.isEmpty()) { 93 return; 94 } 95 it = new HashSet (listeners).iterator(); 96 } 97 while (it.hasNext()) { 98 ChangeListener l = (ChangeListener ) it.next(); 99 l.stateChanged(e); 100 } 101 } 102 103 private Set <NbModuleProject> loadProjects() { 104 Set <NbModuleProject> newProjects = new HashSet (); 105 String modules = eval.getProperty("modules"); if (modules != null) { 107 String [] pieces = PropertyUtils.tokenizePath(modules); 108 for (int i = 0; i < pieces.length; i++) { 109 FileObject dir = helper.resolveFileObject(pieces[i]); 110 if (dir != null) { 111 try { 112 Project subp = ProjectManager.getDefault().findProject(dir); 113 if (subp != null && subp instanceof NbModuleProject) { 114 newProjects.add((NbModuleProject) subp); 115 } 116 } catch (IOException e) { 117 Util.err.notify(ErrorManager.INFORMATIONAL, e); 118 } 119 } 120 } 121 } 122 return Collections.unmodifiableSet(newProjects); 123 } 124 125 } 126 | Popular Tags |