本文整理汇总了Java中org.netbeans.api.project.Sources.addChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java Sources.addChangeListener方法的具体用法?Java Sources.addChangeListener怎么用?Java Sources.addChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.project.Sources
的用法示例。
在下文中一共展示了Sources.addChangeListener方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
void init(Project p) {
Sources sources = ProjectUtils.getSources(p);
sources.addChangeListener(this);
SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
roots = new FileObject[groups.length];
for (int i = 0; i < groups.length; i++) {
SourceGroup group = groups[i];
FileObject rootFolder = group.getRootFolder();
roots[i] = rootFolder;
rootFolder.addRecursiveListener(this);
//scan(rootFolder);
rootsToScan.add(rootFolder);
}
scanningTask = RP.post(this);
DependencyProjectProvider prov = p.getLookup().lookup(DependencyProjectProvider.class);
if (prov != null) {
projectDependencyManager = new ProjectDependencyManager(prov);
}
}
示例2: testNewlyCreatedSourceGroup
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
public void testNewlyCreatedSourceGroup() throws Exception { // #200969
TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion><groupId>g</groupId><artifactId>a</artifactId><version>0</version></project>");
FileObject main = FileUtil.createFolder(d, "src/main/java");
Project p = ProjectManager.getDefault().findProject(d);
Sources s = ProjectUtils.getSources(p);
SourceGroup[] grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
assertEquals(1, grps.length);
assertEquals(main, grps[0].getRootFolder());
MockChangeListener l = new MockChangeListener();
s.addChangeListener(l);
SourceGroup g2 = SourceGroupModifier.createSourceGroup(p, JavaProjectConstants.SOURCES_TYPE_JAVA, JavaProjectConstants.SOURCES_HINT_TEST);
l.assertEvent();
grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
assertEquals(2, grps.length);
assertEquals(main, grps[0].getRootFolder());
assertEquals(g2, grps[1]);
}
示例3: testManuallyDeletedSourceGroup
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
public void testManuallyDeletedSourceGroup() throws Exception { // #204545
TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion><groupId>g</groupId><artifactId>a</artifactId><version>0</version></project>");
FileObject main = FileUtil.createFolder(d, "src/main/java");
FileObject test = FileUtil.createFolder(d, "src/test/java");
Project p = ProjectManager.getDefault().findProject(d);
Sources s = ProjectUtils.getSources(p);
SourceGroup[] grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
assertEquals(2, grps.length);
assertEquals(main, grps[0].getRootFolder());
assertEquals(test, grps[1].getRootFolder());
MockChangeListener l = new MockChangeListener();
s.addChangeListener(l);
test.getParent().delete();
l.assertEvent();
grps = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
assertEquals(1, grps.length);
assertEquals(main, grps[0].getRootFolder());
}
示例4: testSourceRootDeletion
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
public void testSourceRootDeletion() throws Exception {
// Cf. #40845. Need to fire a change if a root is deleted while project is open.
Sources s = sh.createSources();
SourceGroup[] groups = s.getSourceGroups("java");
assertEquals("should have src1dir plus src3dir", 2, groups.length);
assertEquals("group #1 is src1dir", src1dir, groups[0].getRootFolder());
assertEquals("group #2 is src3dir", src3dir, groups[1].getRootFolder());
MockChangeListener l = new MockChangeListener();
s.addChangeListener(l);
src3dir.delete();
l.msg("got a change after src3dir deleted").assertEvent();
groups = s.getSourceGroups("java");
assertEquals("should have just src1dir", 1, groups.length);
assertEquals("group #1 is src1dir", src1dir, groups[0].getRootFolder());
src1dir.delete();
l.msg("got a change after src1dir deleted").assertEvent();
groups = s.getSourceGroups("java");
assertEquals("should have no dirs", 0, groups.length);
FileObject src5dir = scratch.createFolder("nonesuch");
l.msg("got a change after src5dir created").assertEvent();
groups = s.getSourceGroups("java");
assertEquals("should have src15dir now", 1, groups.length);
assertEquals("group #1 is src5dir", src5dir, groups[0].getRootFolder());
}
示例5: setProjectFiles
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
private void setProjectFiles(Project project) {
Sources sources = ProjectUtils.getSources(project); // returns singleton
if (sourcesListener == null) {
sourcesListener = WeakListeners.change(this, sources);
sources.addChangeListener(sourcesListener);
}
setGroups(Arrays.asList(sources.getSourceGroups(Sources.TYPE_GENERIC)), project.getProjectDirectory());
}
示例6: testSourceRootChanges
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
public void testSourceRootChanges() throws Exception {
FileObject top = FileUtil.toFileObject(copyFolder(FileUtil.toFile(egdirFO.getFileObject("extsrcroot"))));
FreeformProject extsrcroot_ = (FreeformProject) ProjectManager.getDefault().findProject(top.getFileObject("proj"));
Sources s = ProjectUtils.getSources(extsrcroot_);
SourceGroup[] groups = s.getSourceGroups("java");
assertEquals("one Java group", 1, groups.length);
assertEquals("right root folder", top.getFileObject("src"), groups[0].getRootFolder());
TestCL l = new TestCL();
s.addChangeListener(l);
Element data = extsrcroot_.getPrimaryConfigurationData();
Element folders = XMLUtil.findElement(data, "folders", FreeformProjectType.NS_GENERAL);
assertNotNull("have <folders>", folders);
List<Element> sourceFolders = XMLUtil.findSubElements(folders);
assertEquals("have 2 <source-folder>s", 2, sourceFolders.size());
Element sourceFolder = sourceFolders.get(1);
Element location = XMLUtil.findElement(sourceFolder, "location", FreeformProjectType.NS_GENERAL);
assertNotNull("have <location>", location);
NodeList nl = location.getChildNodes();
assertEquals("one child (text)", 1, nl.getLength());
location.removeChild(nl.item(0));
location.appendChild(location.getOwnerDocument().createTextNode("../src2"));
extsrcroot_.putPrimaryConfigurationData(data);
assertEquals("got a change in Sources", 1, l.changeCount());
groups = s.getSourceGroups("java");
assertEquals("one Java group", 1, groups.length);
assertEquals("right root folder", top.getFileObject("src2"), groups[0].getRootFolder());
}
示例7: createLookup
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
private Lookup createLookup(ProjectInformation info, AuxiliaryConfiguration aux, AntProjectHelper helper, FileBuiltQueryImplementation fileBuilt, final SourcesHelper sourcesHelper) {
Sources srcs = sourcesHelper.createSources();
srcs.addChangeListener(new ChangeListener() {
@Override public void stateChanged(ChangeEvent e) {
// added source root, probably via SourceGroupModifiedImplementation
getLookup().lookup(ModuleActions.class).refresh();
}
});
ExtraSJQEvaluator eJSQEval = new ExtraSJQEvaluator();
ic.add(this);
ic.add(info);
ic.add(aux);
ic.add(helper.createCacheDirectoryProvider());
ic.add(helper.createAuxiliaryProperties());
ic.add(new SavedHook());
ic.add(UILookupMergerSupport.createProjectOpenHookMerger(new OpenedHook()));
ic.add(new ModuleActions(this));
ic.add(new ClassPathProviderImpl(this));
ic.add(new SourceForBinaryImpl(this));
ic.add(new BinaryForSourceImpl(this));
ic.add(LookupMergerSupport.createSFBLookupMerger());
ic.add(createESQI(eJSQEval));
ic.add(new JavadocForBinaryImpl(this));
ic.add(LookupMergerSupport.createJFBLookupMerger());
ic.add(createEJQI(eJSQEval));
ic.add(new UnitTestForSourceQueryImpl(this));
ic.add(new ModuleLogicalView(this));
ic.add(new SubprojectProviderImpl(this));
ic.add(fileBuilt);
ic.add(new AccessibilityQueryImpl(this));
ic.add(new SourceLevelQueryImpl(this));
//ic.add(new ProjectWhiteListQueryImplementation(this));
ic.add(new ProjectWhiteListQueryImplementation(this));
ic.add(new NbModulePackageModifierImplementation(this));
ic.add(helper.createSharabilityQuery2(evaluator(), new String[0], new String[]{
"${build.dir}", // NOI18N
}));
ic.add(srcs);
ic.add(sourcesHelper.createSourceGroupModifierImplementation()); // XXX only for unit tests, will need custom impl for qa-functional
ic.add(new AntArtifactProviderImpl(this, helper, evaluator()));
ic.add(new CustomizerProviderImpl(this, getHelper(), evaluator()));
ic.add(new NbModuleProviderImpl(this));
ic.add(new NbRefactoringProviderImpl(this));
ic.add(new NbProjectProviderImpl(this));
ic.add(new PrivilegedTemplatesImpl());
ic.add(new ModuleProjectClassPathExtender(this));
ic.add(new LocalizedBundleInfoProvider());
ic.add(new ModuleOperations(this));
ic.add(LookupProviderSupport.createSourcesMerger());
ic.add(UILookupMergerSupport.createPrivilegedTemplatesMerger());
ic.add(UILookupMergerSupport.createRecommendedTemplatesMerger());
ic.add(new TemplateAttributesProvider(this, getHelper(), getModuleType() == NbModuleType.NETBEANS_ORG));
ic.add(new FileEncodingQueryImpl());
ic.add(new AnnotationProcessingQueryImpl(this));
ic.add(new PlatformJarProviderImpl());
if (getModuleType() == NbModuleType.SUITE_COMPONENT) {
ic.add(new SuiteProviderImpl());
}
Lookup baseLookup = new AbstractLookup(ic);
return LookupProviderSupport.createCompositeLookup(baseLookup, "Projects/org-netbeans-modules-apisupport-project/Lookup"); //NOI18N
}
示例8: logicalViewForProject
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
@NonNull
final Node logicalViewForProject(
@NonNull final Project project,
final Union2<LogicalViewProvider,org.openide.util.Pair<Sources,SourceGroup[]>> data,
final boolean[] projectInLookup) {
Node node;
if (!data.hasFirst()) {
LOG.log(
Level.WARNING,
"Warning - project of {0} in {1} failed to supply a LogicalViewProvider in its lookup", // NOI18N
new Object[]{
project.getClass(),
FileUtil.getFileDisplayName(project.getProjectDirectory())
});
final Sources sources = data.second().first();
final SourceGroup[] groups = data.second().second();
sources.removeChangeListener(this);
sources.addChangeListener(this);
if (groups.length > 0) {
node = PhysicalView.createNodeForSourceGroup(groups[0], project);
} else {
node = Node.EMPTY;
}
} else {
final LogicalViewProvider lvp = data.first();
node = lvp.createLogicalView();
if (!project.equals(node.getLookup().lookup(Project.class))) {
// Various actions, badging, etc. are not going to work.
LOG.log(
Level.WARNING,
"Warning - project {0} failed to supply itself in the lookup of the root node of its own logical view", // NOI18N
ProjectUtils.getInformation(project).getName());
//#114664
if (projectInLookup != null) {
projectInLookup[0] = false;
}
}
}
node.addNodeListener(WeakListeners.create(NodeListener.class, this, node));
return node;
}
示例9: addNotify
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
@Override
public void addNotify() {
Sources srcs = ProjectUtils.getSources(project);
srcs.addChangeListener(this);
}
示例10: testSourceLocationChangesFired
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
public void testSourceLocationChangesFired() throws Exception {
Sources s = sh.createSources();
// Listen to changes.
MockChangeListener l = new MockChangeListener();
s.addChangeListener(l);
// Check baseline GENERIC sources.
SourceGroup[] groups = s.getSourceGroups(Sources.TYPE_GENERIC);
assertEquals("should have maindir plus src2dir plus src3dir", 3, groups.length);
assertEquals("group #1 is src2dir", src2dir, groups[0].getRootFolder());
assertEquals("group #2 is src3dir", src3dir, groups[1].getRootFolder());
assertEquals("group #3 is maindir", maindir, groups[2].getRootFolder());
l.assertNoEvents();
// Now change one of them to a different dir.
EditableProperties p = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
p.setProperty("src2.dir", "../../src4");
p.setProperty("src2a.dir", "nonsense");
h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, p);
ProjectManager.getDefault().saveProject(project);
l.msg("got change in GENERIC sources").assertEvent();
// Check new values.
groups = s.getSourceGroups(Sources.TYPE_GENERIC);
assertEquals("should have maindir plus src4dir plus src3dir", 3, groups.length);
assertEquals("group #1 is src4dir", src4dir, groups[0].getRootFolder());
assertEquals("group #2 is src3dir", src3dir, groups[1].getRootFolder());
assertEquals("group #3 is maindir", maindir, groups[2].getRootFolder());
// Check 'java' type groups also.
groups = s.getSourceGroups("java");
assertEquals("should have src1dir plus src3dir", 2, groups.length);
assertEquals("group #1 is src1dir", src1dir, groups[0].getRootFolder());
assertEquals("group #2 is src3dir", src3dir, groups[1].getRootFolder());
l.assertNoEvents();
p = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
p.setProperty("src1.dir", "does-not-exist");
h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, p);
ProjectManager.getDefault().saveProject(project);
l.msg("got change in java sources").assertEvent();
groups = s.getSourceGroups("java");
assertEquals("should have just src3dir", 1, groups.length);
assertEquals("group #2 is src3dir", src3dir, groups[0].getRootFolder());
l.assertNoEvents();
// #47451: should not fire changes for unrelated properties.
p = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
p.setProperty("irrelevant", "value");
h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, p);
ProjectManager.getDefault().saveProject(project);
l.msg("no changes fired from an unrelated property").assertNoEvents();
}
示例11: testSourcesMerger
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
public void testSourcesMerger() {
SourcesImpl impl0 = createImpl("group0");
SourcesImpl impl1 = createImpl("group1");
SourcesImpl impl2 = createImpl("group2");
SourcesImpl impl3 = createImpl("group3");
Lookup base = Lookups.fixed(impl0, LookupProviderSupport.createSourcesMerger());
LookupProviderImpl2 pro1 = new LookupProviderImpl2();
LookupProviderImpl2 pro2 = new LookupProviderImpl2();
LookupProviderImpl2 pro3 = new LookupProviderImpl2();
InstanceContent provInst = new InstanceContent();
Lookup providers = new AbstractLookup(provInst);
provInst.add(pro1);
provInst.add(pro2);
pro1.ic.add(impl1);
pro2.ic.add(impl2);
pro3.ic.add(impl3);
DelegatingLookupImpl del = new DelegatingLookupImpl(base, providers, "<irrelevant>");
Sources srcs = del.lookup(Sources.class);
assertNotNull(srcs);
SourceGroup[] grps = srcs.getSourceGroups("java");
assertEquals(3, grps.length);
//now let's add another module to the bunch and see if the new SG appears
provInst.add(pro3);
srcs = del.lookup(Sources.class);
assertNotNull(srcs);
grps = srcs.getSourceGroups("java");
assertEquals(4, grps.length);
//now let's remove another module to the bunch and see if the SG disappears
provInst.remove(pro2);
srcs = del.lookup(Sources.class);
assertNotNull(srcs);
grps = srcs.getSourceGroups("java");
assertEquals(3, grps.length);
//lets remove one and listen for changes...
srcs = del.lookup(Sources.class);
MockChangeListener ch = new MockChangeListener();
srcs.addChangeListener(ch);
provInst.remove(pro1);
ch.assertEvent();
grps = srcs.getSourceGroups("java");
assertEquals(2, grps.length);
provInst.add(pro2);
ch.assertEvent();
grps = srcs.getSourceGroups("java");
assertEquals(3, grps.length);
}
示例12: testFiring
import org.netbeans.api.project.Sources; //导入方法依赖的package包/类
@RandomlyFails // on various builders, and w/o dump despite timeOut
public void testFiring() throws Exception {
final Sources s = project.getLookup().lookup(Sources.class);
final SourceRoots roots = ((J2SEProject)project).getSourceRoots();
SourceGroup[] groups = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
assertEquals(2, groups.length);
class EventCounter implements ChangeListener {
final AtomicInteger count = new AtomicInteger();
public @Override void stateChanged(ChangeEvent e) {
count.incrementAndGet();
}
}
final EventCounter counter = new EventCounter();
s.addChangeListener(counter);
final URL[] oldRootUrls = roots.getRootURLs();
final String[] oldRootLabels = roots.getRootNames();
final String[] oldRootProps = roots.getRootProperties();
final FileObject newRoot = projdir.createFolder("new_src"); //NOI18N
//test: adding of src root should fire once
URL[] newRootUrls = new URL[oldRootUrls.length+1];
System.arraycopy(oldRootUrls, 0, newRootUrls, 0, oldRootUrls.length);
newRootUrls[newRootUrls.length-1] = newRoot.toURL();
String[] newRootLabels = new String[oldRootLabels.length+1];
for (int i=0; i< oldRootLabels.length; i++) {
newRootLabels[i] = roots.getRootDisplayName(oldRootLabels[i], oldRootProps[i]);
}
newRootLabels[newRootLabels.length-1] = newRoot.getName();
roots.putRoots(newRootUrls, newRootLabels);
assertEquals(1, counter.count.get());
groups = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
assertEquals(3, groups.length);
//test: removing of src root should fire once
counter.count.set(0);
newRootUrls = new URL[oldRootUrls.length];
System.arraycopy(oldRootUrls, 0, newRootUrls, 0, oldRootUrls.length);
newRootLabels = new String[oldRootLabels.length];
for (int i=0; i< oldRootLabels.length; i++) {
newRootLabels[i] = roots.getRootDisplayName(oldRootLabels[i], oldRootProps[i]);
}
roots.putRoots(newRootUrls, newRootLabels);
assertEquals(1, counter.count.get());
groups = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
assertEquals(2, groups.length);
}