1 19 20 package org.netbeans.modules.j2ee.earproject; 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeEvent ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 28 import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties; 29 import org.openide.util.Mutex; 30 import org.netbeans.api.project.Sources; 31 import org.netbeans.api.project.SourceGroup; 32 import org.netbeans.api.project.ProjectManager; 33 import org.netbeans.api.project.FileOwnerQuery; 34 import org.netbeans.spi.project.support.ant.SourcesHelper; 35 import org.netbeans.spi.project.support.ant.AntProjectHelper; 36 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 37 38 class EarSources implements Sources, PropertyChangeListener , ChangeListener { 39 40 private final AntProjectHelper helper; 41 private final PropertyEvaluator evaluator; 42 private Sources delegate; 43 private final List <ChangeListener > listeners = new ArrayList <ChangeListener >(); 44 private SourcesHelper sourcesHelper; 45 46 EarSources(AntProjectHelper helper, PropertyEvaluator evaluator) { 47 this.helper = helper; 48 this.evaluator = evaluator; 49 initSources(); } 51 52 53 public SourceGroup[] getSourceGroups(final String type) { 54 return (SourceGroup[]) ProjectManager.mutex().readAccess(new Mutex.Action() { 55 public Object run() { 56 if (delegate == null) { 57 delegate = initSources(); 58 delegate.addChangeListener(EarSources.this); 59 } 60 return delegate.getSourceGroups(type); 61 } 62 }); 63 } 64 65 private Sources initSources() { 66 sourcesHelper = new SourcesHelper(helper, evaluator); 67 String configFilesLabel = org.openide.util.NbBundle.getMessage(EarSources.class, "LBL_Node_ConfigBase"); sourcesHelper.addPrincipalSourceRoot("${"+EarProjectProperties.META_INF+"}", configFilesLabel, null, null); 69 ProjectManager.mutex().postWriteRequest(new Runnable () { 71 public void run() { 72 sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); 73 } 74 }); 75 return sourcesHelper.createSources(); 76 } 77 78 public void addChangeListener(ChangeListener changeListener) { 79 synchronized (listeners) { 80 listeners.add(changeListener); 81 } 82 } 83 84 public void removeChangeListener(ChangeListener changeListener) { 85 synchronized (listeners) { 86 listeners.remove(changeListener); 87 } 88 } 89 90 private void fireChange() { 91 ChangeListener [] _listeners; 92 synchronized (this) { 93 if (delegate != null) { 94 delegate.removeChangeListener(this); 95 delegate = null; 96 } 97 } 98 synchronized (listeners) { 99 if (listeners.isEmpty()) { 100 return; 101 } 102 _listeners = listeners.toArray(new ChangeListener [listeners.size()]); 103 } 104 ChangeEvent ev = new ChangeEvent (this); 105 for (int i = 0; i < _listeners.length; i++) { 106 _listeners[i].stateChanged(ev); 107 } 108 } 109 110 public void propertyChange(PropertyChangeEvent evt) { 111 } 112 113 public void stateChanged (ChangeEvent event) { 114 this.fireChange(); 115 } 116 117 } 118 | Popular Tags |