Java Code Examples for org.netbeans.api.project.ProjectInformation#addPropertyChangeListener()
The following examples show how to use
org.netbeans.api.project.ProjectInformation#addPropertyChangeListener() .
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: ModulesNodeFactory.java From netbeans with Apache License 2.0 | 6 votes |
public SuiteComponentNode(final NbModuleProject suiteComponent) { super(Children.LEAF, Lookups.fixed(new Object[] {suiteComponent})); ProjectInformation info = ProjectUtils.getInformation(suiteComponent); setName(info.getName()); setDisplayName(info.getDisplayName()); setIconBaseWithExtension(NbModuleProject.NB_PROJECT_ICON_PATH); info.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { ImportantFilesNodeFactory.getNodesSyncRP().post(new Runnable() { public void run() { if (ProjectInformation.PROP_DISPLAY_NAME.equals(evt.getPropertyName())) { SuiteComponentNode.this.setDisplayName((String) evt.getNewValue()); } else if (ProjectInformation.PROP_NAME.equals(evt.getPropertyName())) { SuiteComponentNode.this.setName((String) evt.getNewValue()); } } }); } }); }
Example 2
Source File: SuiteProjectTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testProjectInformation() throws Exception { SuiteProject p = TestBase.generateSuite(getWorkDir(), "Sweet Stuff"); ProjectInformation i = ProjectUtils.getInformation(p); assertEquals("Sweet_Stuff", i.getName()); assertEquals("Sweet Stuff", i.getDisplayName()); BrandingModel model = new SuiteBrandingModel(new SuiteProperties(p, p.getHelper(), p.getEvaluator(), Collections.<NbModuleProject>emptySet())); model.init(); assertEquals("sweet_stuff", model.getName()); assertEquals("Sweet Stuff", model.getTitle()); TestBase.TestPCL l = new TestBase.TestPCL(); i.addPropertyChangeListener(l); EditableProperties ep = p.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); ep.setProperty("app.name", "sweetness"); ep.setProperty("app.title", "Sweetness is Now!"); p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); assertEquals(new HashSet<String>(Arrays.asList(ProjectInformation.PROP_NAME, ProjectInformation.PROP_DISPLAY_NAME)), l.changed); assertEquals("Sweet_Stuff", i.getName()); assertEquals("Sweetness is Now!", i.getDisplayName()); model = new SuiteBrandingModel(new SuiteProperties(p, p.getHelper(), p.getEvaluator(), Collections.<NbModuleProject>emptySet())); model.init(); assertEquals("sweetness", model.getName()); assertEquals("Sweetness is Now!", model.getTitle()); }
Example 3
Source File: ParseXMLContentTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testRecognizeTwoFeaturesProject() throws Exception { assertFalse("Autoupdate is not enabled", au.isEnabled()); assertFalse("Favorites is not enabled", fav.isEnabled()); FileObject prjFO1 = root.getFileObject("1st"); FileObject prjFO2 = root.getFileObject("2nd"); assertTrue("Recognized as project", ProjectManager.getDefault().isProject(prjFO1)); Project p = ProjectManager.getDefault().findProject(prjFO1); assertNotNull("Project found", p); assertTrue("Recognized as project", ProjectManager.getDefault().isProject(prjFO2)); Project p2 = ProjectManager.getDefault().findProject(prjFO2); assertNotNull("Project found", p2); ProjectOpenedHook open = p.getLookup().lookup(ProjectOpenedHook.class); assertNotNull("Open hook found", open); ProjectInformation info = p.getLookup().lookup(ProjectInformation.class); assertNotNull("Info about icon", info); assertNotNull("Icon provided", info.getIcon()); info.addPropertyChangeListener(this); assertNull("No test factory in project", p.getLookup().lookup(TestFactory.class)); assertNull("No test factory in project", p2.getLookup().lookup(TestFactory.class)); assertNull("No test factory2 in project", p.getLookup().lookup(TestFactory2.class)); assertNull("No test factory2 in project", p2.getLookup().lookup(TestFactory2.class)); TestFactory.recognize.add(prjFO1); TestFactory2.recognize.add(prjFO2); OpenProjects.getDefault().open(new Project[] { p, p2 }, false); assertEquals("No Dialog currently created", 0, DD.cnt); List<Project> arr = Arrays.asList(OpenProjects.getDefault().openProjects().get()); assertEquals("Both projects open is there", 2, arr.size()); Project newP = arr.get(0).getLookup().lookup(Project.class); if (p == newP) { fail("New project is made available, not old: " + newP); } Project newP2 = arr.get(1).getLookup().lookup(Project.class); if (p2 == newP2) { fail("New project is made available, not old: " + newP2); } if (newP.getClass() == newP2.getClass()) { fail("Types of the project shall be different: " + newP + " == " + newP2); } assertEquals("Right type", TestFactory.class, newP.getClass()); TestFactory tf = (TestFactory)newP; assertEquals("Open hook called", 1, tf.opened); assertEquals("Project info changed", 1, change); tf.assertListeners("One listener attached"); assertEquals("Info delegates", "x", info.getName()); assertEquals("Info delegates2", "y", info.getDisplayName()); assertEquals("Info delegates icon", null, info.getIcon()); OpenProjects.getDefault().close (new Project[] { newP, newP2 }); if (OpenProjects.getDefault().getOpenProjects().length != 0) { fail("All projects shall be closed: " + Arrays.asList(OpenProjects.getDefault().getOpenProjects())); } assertNotNull("Test factory in opened project", p.getLookup().lookup(TestFactory.class)); assertNotNull("Test factory2 in not yet opened project", p2.getLookup().lookup(TestFactory2.class)); assertTrue("Favorites is enabled", fav.isEnabled()); assertTrue("Autoupdate is enabled", au.isEnabled()); }
Example 4
Source File: ProjectOnDemandTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testRecognizeDocBookProject() throws Exception { FileObject prjFO1 = root.getFileObject("1st"); FileObject prjFO2 = root.getFileObject("2nd"); assertTrue("Recognized as project", ProjectManager.getDefault().isProject(prjFO1)); Project p = ProjectManager.getDefault().findProject(prjFO1); assertNotNull("Project found", p); assertTrue("Recognized as project", ProjectManager.getDefault().isProject(prjFO2)); Project p2 = ProjectManager.getDefault().findProject(prjFO2); assertNotNull("Project found", p2); ProjectOpenedHook open = p.getLookup().lookup(ProjectOpenedHook.class); assertNotNull("Open hook found", open); ProjectInformation info = p.getLookup().lookup(ProjectInformation.class); assertNotNull("Info about icon", info); assertNotNull("Icon provided", info.getIcon()); info.addPropertyChangeListener(this); LogicalViewProvider lvp = p.getLookup().lookup(LogicalViewProvider.class); assertNotNull("Provider done", lvp); Node n = lvp.createLogicalView(); assertNotNull("Node provided", n); assertNull("Nothing found", lvp.findPath(n, "")); assertEquals("One child: " + n.getChildren().snapshot(), 1, n.getChildren().getNodesCount(true)); assertNull("No test factory in project", p.getLookup().lookup(TestFactory.class)); assertNull("No test factory in project", p2.getLookup().lookup(TestFactory.class)); TestFactory.recognize.add(prjFO1); TestFactory.recognize.add(prjFO2); OpenProjects.getDefault().open(new Project[] { p }, false); assertEquals("No Dialog currently created", 0, DD.cnt); List<Project> arr = Arrays.asList(OpenProjects.getDefault().openProjects().get()); assertEquals("However one instance is there", 1, arr.size()); Project newP = arr.get(0).getLookup().lookup(Project.class); if (p == newP) { fail("New project is made available, not old: " + newP); } assertEquals("Right type", TestFactory.class, newP.getClass()); TestFactory tf = (TestFactory)newP; assertEquals("Open hook called", 1, tf.opened); assertEquals("Project info changed", 1, change); tf.assertListeners("One listener attached"); assertEquals("Info delegates", "x", info.getName()); assertEquals("Info delegates2", "y", info.getDisplayName()); assertEquals("Info delegates icon", null, info.getIcon()); LogicalViewProvider lvp2 = p.getLookup().lookup(LogicalViewProvider.class); assertNotNull("Provider created", lvp2); if (lvp == lvp2) { fail("Should be different, the real: " + lvp2); } Node r = lvp2.createLogicalView(); assertNotNull("Root found", r); assertEquals("Same name", n.getName(), r.getName()); assertEquals("Same display name", n.getDisplayName(), r.getDisplayName()); assertEquals("Two children", 2, r.getChildren().getNodesCount(true)); assertEquals("Two children", 2, n.getChildren().getNodesCount(true)); OpenProjects.getDefault().close (new Project[] { newP }); if (OpenProjects.getDefault().getOpenProjects().length != 0) { fail("All projects shall be closed: " + Arrays.asList(OpenProjects.getDefault().getOpenProjects())); } assertNotNull("Test factory in opened project", p.getLookup().lookup(TestFactory.class)); assertNotNull("Test factory in not yet opened project", p2.getLookup().lookup(TestFactory.class)); }
Example 5
Source File: ProjectWithDependenciesTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testRecognizeUMLTooProject() throws Exception { FileObject prjFO1 = root.getFileObject("1st"); FileObject prjFO2 = root.getFileObject("2nd"); assertTrue("Recognized as project", ProjectManager.getDefault().isProject(prjFO1)); Project p = ProjectManager.getDefault().findProject(prjFO1); assertNotNull("Project found", p); assertTrue("Recognized as project", ProjectManager.getDefault().isProject(prjFO2)); Project p2 = ProjectManager.getDefault().findProject(prjFO2); assertNotNull("Project found", p2); ProjectOpenedHook open = p.getLookup().lookup(ProjectOpenedHook.class); assertNotNull("Open hook found", open); ProjectInformation info = p.getLookup().lookup(ProjectInformation.class); assertNotNull("Info about icon", info); assertNotNull("Icon provided", info.getIcon()); info.addPropertyChangeListener(this); assertNull("No test factory in project", p.getLookup().lookup(TestFactory.class)); assertNull("No test factory in project", p2.getLookup().lookup(TestFactory.class)); assertNull("No test factory2 in project", p.getLookup().lookup(TestFactory2.class)); assertNull("No test factory2 in project", p2.getLookup().lookup(TestFactory2.class)); TestFactory.recognize.add(prjFO1); TestFactory.subprojects.add(p2); TestFactory2.recognize.add(prjFO2); OpenProjects.getDefault().open(new Project[] { p }, false); assertEquals("No Dialog currently created", 0, DD.cnt); List<Project> arr = Arrays.asList(OpenProjects.getDefault().openProjects().get()); assertEquals("However one instance is there", 1, arr.size()); Project newP = arr.get(0).getLookup().lookup(Project.class); if (p == newP) { fail("New project is made available, not old: " + newP); } assertEquals("Right type", TestFactory.class, newP.getClass()); TestFactory tf = (TestFactory)newP; assertEquals("Open hook called", 1, tf.opened); assertEquals("Project info changed", 1, change); tf.assertListeners("One listener attached"); assertEquals("Info delegates", "x", info.getName()); assertEquals("Info delegates2", "y", info.getDisplayName()); assertEquals("Info delegates icon", null, info.getIcon()); OpenProjects.getDefault().close (new Project[] { newP }); if (OpenProjects.getDefault().getOpenProjects().length != 0) { fail("All projects shall be closed: " + Arrays.asList(OpenProjects.getDefault().getOpenProjects())); } assertNotNull("Test factory in opened project", p.getLookup().lookup(TestFactory.class)); assertNotNull("Test factory2 in not yet opened project", p2.getLookup().lookup(TestFactory2.class)); }
Example 6
Source File: ProjectFalsePositiveTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testRecognizeDocBookProject() throws Exception { FileObject prjFO1 = root.getFileObject("1st"); FileObject prjFO2 = root.getFileObject("2nd"); assertTrue("Recognized as project", ProjectManager.getDefault().isProject(prjFO1)); Project p = ProjectManager.getDefault().findProject(prjFO1); assertNotNull("Project found", p); assertTrue("Recognized as project", ProjectManager.getDefault().isProject(prjFO2)); Project p2 = ProjectManager.getDefault().findProject(prjFO2); assertNotNull("Project found", p2); ProjectOpenedHook open = p.getLookup().lookup(ProjectOpenedHook.class); assertNotNull("Open hook found", open); ProjectInformation info = p.getLookup().lookup(ProjectInformation.class); assertNotNull("Info about icon", info); assertNotNull("Icon provided", info.getIcon()); info.addPropertyChangeListener(this); assertNull("No test factory in project", p.getLookup().lookup(TestFactory.class)); assertNull("No test factory in project", p2.getLookup().lookup(TestFactory.class)); TestFactory.recognize.add(prjFO1); OpenProjects.getDefault().open(new Project[] { p }, false); assertEquals("No Dialog currently created", 0, DD.cnt); List<Project> arr = Arrays.asList(OpenProjects.getDefault().openProjects().get()); assertEquals("However one instance is there", 1, arr.size()); Project newP = arr.get(0).getLookup().lookup(Project.class); if (p == newP) { fail("New project is made available, not old: " + newP); } assertEquals("Right type", TestFactory.class, newP.getClass()); TestFactory tf = (TestFactory)newP; assertEquals("Open hook called", 1, tf.opened); assertEquals("Project info changed", 1, change); tf.assertListeners("One listener attached"); assertEquals("Info delegates", "x", info.getName()); assertEquals("Info delegates2", "y", info.getDisplayName()); assertEquals("Info delegates icon", null, info.getIcon()); OpenProjects.getDefault().close (new Project[] { newP }); if (OpenProjects.getDefault().getOpenProjects().length != 0) { fail("All projects shall be closed: " + Arrays.asList(OpenProjects.getDefault().getOpenProjects())); } assertNotNull("Test factory in opened project", p.getLookup().lookup(TestFactory.class)); assertFalse("No longer suspected to be project", ProjectManager.getDefault().isProject(p2.getProjectDirectory()) ); assertNull("Lookup of the false possitive project", p2.getLookup().lookup(Object.class)); }
Example 7
Source File: ProjectConvertorFactoryTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testProjectConvertor() throws IOException { final TestProject.OpenHook oh1 = new TestProject.OpenHook(); final TestProject.OpenHook oh2 = new TestProject.OpenHook(); TestProject.Factory.LOOKUP_FACTORY = new Callable<Lookup>() { @Override public Lookup call() throws Exception { return Lookups.fixed( oh1, oh2, new TestPI(projectDir), new ProjectAdditionalService()); } }; final Lookup clp = Lookups.singleton(new ConvertorAdditionalServicePermanent()); final Lookup clt = ProjectConvertors.createProjectConvertorLookup(new ConvertorAdditionalServiceTransient()); final Lookup cl = new ProxyLookup(clp, clt); TestProject.Convertor.LOOKUP_FACTORY = new Callable<Lookup>() { @Override public Lookup call() throws Exception { return cl; } }; TestProject.Convertor.CALLBACK = new Runnable() { @Override public void run() { try { ((Closeable)clt).close(); } catch (IOException ioe) { throw new RuntimeException(ioe); } } }; final Project artPrj = ProjectManager.getDefault().findProject(projectDir); assertNotNull(artPrj); assertEquals(projectDir, artPrj.getProjectDirectory()); final ProjectInformation artPi = artPrj.getLookup().lookup(ProjectInformation.class); assertNotNull(artPi); assertEquals(projectDir.getName(), artPi.getDisplayName()); assertNotNull(artPrj.getLookup().lookup(ConvertorAdditionalServicePermanent.class)); assertNotNull(artPrj.getLookup().lookup(ConvertorAdditionalServiceTransient.class)); assertNull(artPrj.getLookup().lookup(ProjectAdditionalService.class)); final MockPropertyChangeListener ml = new MockPropertyChangeListener( ProjectInformation.PROP_DISPLAY_NAME, ProjectInformation.PROP_NAME, ProjectInformation.PROP_ICON); artPi.addPropertyChangeListener(ml); OpenProjects.getDefault().open(new Project[]{artPrj}, false); assertTrue(OpenProjects.getDefault().isProjectOpen(artPrj)); assertNotNull(projectDir.getFileObject(TestProject.PROJECT_MARKER)); final Project realPrj = ProjectManager.getDefault().findProject(projectDir); assertNotNull(realPrj); assertNotSame(artPrj, realPrj); assertNotSame(artPrj.getClass(), realPrj.getClass()); assertEquals(artPrj, realPrj); assertNull(realPrj.getLookup().lookup(ConvertorAdditionalServicePermanent.class)); assertNull(realPrj.getLookup().lookup(ConvertorAdditionalServiceTransient.class)); assertNotNull(realPrj.getLookup().lookup(ProjectAdditionalService.class)); assertNotNull(artPrj.getLookup().lookup(ConvertorAdditionalServicePermanent.class)); assertNull(artPrj.getLookup().lookup(ConvertorAdditionalServiceTransient.class)); assertNotNull(artPrj.getLookup().lookup(ProjectAdditionalService.class)); assertEquals(1, oh1.openCalls.get()); assertEquals(0, oh1.closeCalls.get()); assertEquals(1, oh2.openCalls.get()); assertEquals(0, oh2.closeCalls.get()); OpenProjects.getDefault().close(new Project[]{realPrj}); assertFalse(OpenProjects.getDefault().isProjectOpen(artPrj)); assertFalse(OpenProjects.getDefault().isProjectOpen(realPrj)); assertEquals(1, oh1.openCalls.get()); assertEquals(1, oh1.closeCalls.get()); assertEquals(1, oh2.openCalls.get()); assertEquals(1, oh2.closeCalls.get()); //Artificial ProjectInformation should be updated and events should be fired assertEquals(projectDir.getPath(), artPi.getDisplayName()); ml.assertEvents( ProjectInformation.PROP_DISPLAY_NAME, ProjectInformation.PROP_NAME, ProjectInformation.PROP_ICON); }