1 19 20 package org.netbeans.modules.j2ee.clientproject; 21 22 23 import java.io.File ; 24 import java.beans.PropertyChangeEvent ; 25 import java.beans.PropertyChangeListener ; 26 import org.openide.util.Mutex; 27 import org.netbeans.api.project.ProjectManager; 28 import org.netbeans.spi.queries.SharabilityQueryImplementation; 29 import org.netbeans.spi.project.support.ant.AntProjectHelper; 30 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 31 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 32 33 34 35 36 39 public class AppClientSharabilityQuery implements SharabilityQueryImplementation, PropertyChangeListener { 40 41 private final AntProjectHelper helper; 42 private final PropertyEvaluator evaluator; 43 private final SourceRoots srcRoots; 44 private final SourceRoots testRoots; 45 private SharabilityQueryImplementation delegate; 46 47 48 56 AppClientSharabilityQuery (AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots) { 57 this.helper = helper; 58 this.evaluator = evaluator; 59 this.srcRoots = srcRoots; 60 this.testRoots = testRoots; 61 this.srcRoots.addPropertyChangeListener(this); 62 this.testRoots.addPropertyChangeListener(this); 63 } 64 65 66 74 public int getSharability(final File file) { 75 Integer ret = (Integer ) ProjectManager.mutex().readAccess( new Mutex.Action() { 76 public Object run() { 77 synchronized (AppClientSharabilityQuery.this) { 78 if (delegate == null) { 79 delegate = createDelegate (); 80 } 81 return new Integer (delegate.getSharability (file)); 82 } 83 } 84 }); 85 return ret.intValue(); 86 } 87 88 public void propertyChange(PropertyChangeEvent evt) { 89 if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) { 90 synchronized (this) { 91 this.delegate = null; 92 } 93 } 94 } 95 96 private SharabilityQueryImplementation createDelegate () { 97 String [] srcProps = srcRoots.getRootProperties(); 98 String [] testProps = testRoots.getRootProperties(); 99 String [] props = new String [srcProps.length + testProps.length + 1]; 100 for (int i=0; i<srcProps.length; i++) { 101 props[i] = "${"+srcProps[i]+"}"; } 103 for (int i=0; i<testProps.length; i++) { 104 props[srcProps.length+i] = "${"+testProps[i]+"}"; } 106 props[props.length - 1] = "${" + AppClientProjectProperties.META_INF + "}"; return helper.createSharabilityQuery(this.evaluator, props, 108 new String [] { 109 "${" + AppClientProjectProperties.DIST_DIR + "}", "${" + AppClientProjectProperties.BUILD_DIR + "}", }); 112 } 113 114 } 115 | Popular Tags |