Java Code Examples for org.netbeans.api.project.Sources#addChangeListener()
The following examples show how to use
org.netbeans.api.project.Sources#addChangeListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenSourcesImplTest.java From netbeans with Apache License 2.0 | 6 votes |
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]); }
Example 2
Source File: MavenSourcesImplTest.java From netbeans with Apache License 2.0 | 6 votes |
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()); }
Example 3
Source File: SourcesHelperTest.java From netbeans with Apache License 2.0 | 6 votes |
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()); }
Example 4
Source File: SourceMapsScanner.java From netbeans with Apache License 2.0 | 6 votes |
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); } }
Example 5
Source File: DDDataObject.java From netbeans with Apache License 2.0 | 6 votes |
private void init (FileObject fo,DDDataLoader loader) { // added ValidateXMLCookie InputSource in = DataObjectAdapters.inputSource(this); CheckXMLCookie checkCookie = new CheckXMLSupport(in); getCookieSet().add(checkCookie); ValidateXMLCookie validateCookie = new ValidateXMLSupport(in); getCookieSet().add(validateCookie); if (!FileUtil.isArchiveFile(getPrimaryFile())) { Project project = FileOwnerQuery.getOwner (getPrimaryFile ()); if (project != null) { Sources sources = ProjectUtils.getSources(project); sources.addChangeListener (this); refreshSourceFolders ( sources ); } } addPropertyChangeListener(this); }
Example 6
Source File: ClientDataObject.java From netbeans with Apache License 2.0 | 6 votes |
private void init(FileObject fo, ClientDataLoader loader) { // added ValidateXMLCookie InputSource in = DataObjectAdapters.inputSource(this); CheckXMLCookie checkCookie = new CheckXMLSupport(in); getCookieSet().add(checkCookie); ValidateXMLCookie validateCookie = new ValidateXMLSupport(in); getCookieSet().add(validateCookie); Project project = FileOwnerQuery.getOwner(getPrimaryFile()); if (project != null) { Sources sources = ProjectUtils.getSources(project); sources.addChangeListener(this); } refreshSourceFolders(); addPropertyChangeListener(this); }
Example 7
Source File: EarDataObject.java From netbeans with Apache License 2.0 | 5 votes |
private void refreshSourceFolders () { ArrayList srcRootList = new ArrayList (); Project project = FileOwnerQuery.getOwner (getPrimaryFile ()); if (project != null) { Sources sources = ProjectUtils.getSources(project); sources.removeChangeListener (this); sources.addChangeListener (this); SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (int i = 0; i < groups.length; i++) { org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(groups[i].getRootFolder()); if (ejbModule != null && ejbModule.getDeploymentDescriptor() != null) { try { FileObject fo = groups[i].getRootFolder(); srcRootList.add(groups[i].getRootFolder()); FileSystem fs = fo.getFileSystem(); fs.removeFileChangeListener(this); fs.addFileChangeListener(this); } catch (FileStateInvalidException ex) { Exceptions.printStackTrace(ex); } } } } srcRoots = (FileObject []) srcRootList.toArray (new FileObject [srcRootList.size ()]); }
Example 8
Source File: ProjectsRootNode.java From netbeans with Apache License 2.0 | 5 votes |
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()); }
Example 9
Source File: ConfFilesNodeFactory.java From netbeans with Apache License 2.0 | 5 votes |
protected 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))); }
Example 10
Source File: EarDataObject.java From netbeans with Apache License 2.0 | 5 votes |
private void init (FileObject fo,EarDataLoader loader) { // added ValidateXMLCookie InputSource in = DataObjectAdapters.inputSource(this); ValidateXMLCookie validateCookie = new ValidateXMLSupport(in); getCookieSet().add(validateCookie); Project project = FileOwnerQuery.getOwner (getPrimaryFile ()); if (project != null) { Sources sources = ProjectUtils.getSources(project); sources.addChangeListener (this); } refreshSourceFolders (); }
Example 11
Source File: FreeformSourcesTest.java From netbeans with Apache License 2.0 | 5 votes |
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()); }
Example 12
Source File: SourcesNodeFactory.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void addNotify() { Sources srcs = ProjectUtils.getSources(project); srcs.addChangeListener(this); }
Example 13
Source File: SourcesNodeFactory.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void addNotify() { Sources srcs = ProjectUtils.getSources(project); srcs.addChangeListener(this); }
Example 14
Source File: NbModuleProject.java From netbeans with Apache License 2.0 | 4 votes |
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 }
Example 15
Source File: ProjectsRootNode.java From netbeans with Apache License 2.0 | 4 votes |
@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; }
Example 16
Source File: SourcesHelperTest.java From netbeans with Apache License 2.0 | 4 votes |
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(); }
Example 17
Source File: J2SESourcesTest.java From netbeans with Apache License 2.0 | 4 votes |
@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); }
Example 18
Source File: LookupProviderSupportTest.java From netbeans with Apache License 2.0 | 4 votes |
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); }