This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | Wizard needed for db access | ||
---|---|---|---|
Product: | apisupport | Reporter: | Geertjan Wielenga <geertjan> |
Component: | Templates | Assignee: | Martin Kozeny <mkozeny> |
Status: | NEW --- | ||
Severity: | blocker | CC: | err, jglick, jrechtacek, kganfield, rmichalsky, sreimers, tomwheeler |
Priority: | P3 | ||
Version: | 6.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: | |
Bug Depends on: | 146402 | ||
Bug Blocks: |
Description
Geertjan Wielenga
2008-12-11 11:18:27 UTC
Here's an example of what would need to be generated by this module (not very much): http://netbeans.dzone.com/news/eclipselink-netbeans-platform Basically, we need to take the existing JSR-296 Swing Framework CRUD generator and let it generate NetBeans Platform code instead, similar to the code discussed in the blog entry above (that's a very simple case but at least gets the user somewhere beyond zero). Thanks for the quick report. Now that we are into it, I would also like to suggest making the Collection, Set or List choices for the JPA entities creation wizard a little bit more flexible. For example, by allowing to specify any class implementing the required interface (Collection?) in the project's classpath. For example, something I sometimes do is generate from NB IDE and then edit the code to use the ObservableList from Beans Binding. I'll be nice to be able to accomplish that from within the wizard itself. I found out why the Persistence templates are not available under Netbeans Module projects. For those of you who want to know read on… Otherwise skip this lengthy email. It has to do with a RecommendedTemplates definition for each project and the templateCategory of the registered template wizard. In my case the j2ee.persistence templates all have a templateCategory called out as “persistence”. If none where provided then they would have been shown for all types of projects. Furthermore, the recommended types for a NB module project do NOT include the “persistence” category which is why it excludes these templates for the module projects. So it seems the easy fix would be to add “persistence” to the list of recommended types on the apisupport.ant project. Extract from layer.xml file in j2ee.persistence package: <filesystem> <folder name="Templates"> <folder name="Persistence"> <file name="Entity.java"> <attr name="template" boolvalue="true"/> <attr name="position" intvalue="100"/> <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.j2ee.persistence.wizard.entity.EntityWizard.create"/> <attr name="templateCategory" stringvalue="persistence"/> <attr name="templateWizardURL" urlvalue="nbresloc:/org/netbeans/modules/j2ee/persistence/ui/resources/EntityEJB.html"/> <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.j2ee.persistence.wizard.entity.Bundle"/> <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/java/resources/class.gif"/> </file> Extract from NbModuleProject.java in apisupport.ant package (note it doesn’t not contain “persistence”): private static final String[] RECOMMENDED_TYPES = { "java-classes", // NOI18N "java-main-class", // NOI18N "java-forms", // NOI18N "java-beans", // NOI18N "oasis-XML-catalogs", // NOI18N "REST-clients", // NOI18N "XML", // NOI18N "ant-script", // NOI18N "ant-task", // NOI18N "junit", // NOI18N "simple-files", // NOI18N UIUtil.TEMPLATE_CATEGORY, }; Extract from J2SEProject.java in java.j2seproject package: private static final String[] APPLICATION_TYPES = new String[] { "java-classes", // NOI18N "java-main-class", // NOI18N "java-forms", // NOI18N "gui-java-application", // NOI18N "java-beans", // NOI18N "persistence", // NOI18N "oasis-XML-catalogs", // NOI18N "XML", // NOI18N "ant-script", // NOI18N "ant-task", // NOI18N "web-service-clients", // NOI18N "REST-clients", // NOI18N "wsdl", // NOI18N // "servlet-types", // NOI18N // "web-types", // NOI18N "junit", // NOI18N // "MIDP", // NOI18N "simple-files" // NOI18N }; And finally and extract from OpenProjectList.java in projectui package that shows how it relies on the pair of templateCategory and recommended types to determine whether they are listed in the New File Wizard: static boolean isRecommended (Project p, FileObject primaryFile) { if (getRecommendedTypes (p) == null || getRecommendedTypes (p).length == 0) { // if no recommendedTypes are supported (i.e. freeform) -> disaply all templates return true; } Object o = primaryFile.getAttribute ("templateCategory"); // NOI18N if (o != null) { assert o instanceof String : primaryFile + " attr templateCategory = " + o; boolean ok = false; for (String category : getCategories((String) o)) { if (Arrays.asList (getRecommendedTypes (p)).contains (category)) { ok = true; break; } } return ok; } else { // issue 44871, if attr 'templateCategorized' is not set => all is ok // no category set, ok display it return true; } } private static String[] getRecommendedTypes (Project project) { if (project == null) { return null; } RecommendedTemplates rt = project.getLookup().lookup(RecommendedTemplates.class); return rt == null ? null :rt.getRecommendedTypes(); } private static List<String> getCategories (String source) { ArrayList<String> categories = new ArrayList<String> (); StringTokenizer cattok = new StringTokenizer (source, ","); // NOI18N while (cattok.hasMoreTokens ()) { categories.add (cattok.nextToken ().trim ()); } return categories; } (In reply to comment #3) > it seems the easy fix would be to add “persistence” to the list of > recommended types on the apisupport.ant project. Yes, the fix is trivial. The work is in testing that all of the templates in that category in fact work as advertised in NBM projects. Note that this issue as originally reported was for a template in the New Project wizard, though adding the Persistence category into the New File wizard for NBM projects would be a sensible related change. I think it's a task for j2ee/persistence rather than db. To enable persistence for specific project type it's not enough just to add persistence category, corresponding project should implement some persistence providers, listeners etc (scopelistener etc, it's easy to compare with j2se project for example to see what is implemented for persistence support). Not sure who should be responsible for the issue, at least there should be some cooperation with project owner to get proper resources location etc or even easier for project owner to implement everything. agree it's not db task anyway Afraid as project owner I know nothing about the APIs involved; not even sure how to really test that they are working correctly if they were to be implemented. I see org.netbeans.modules.java.j2seproject.J2SEPersistenceProvider but this looks rather complicated; probably this should be factored into java.api.common for ease of reuse from other Ant-based project types? (org.netbeans.modules.web.project.WebPersistenceProvider looks very similar but they are not identical; it is unclear whether the differences are intrinsic, or just a result of bugs being fixed in one but not the other.) One more persistence support implementation sample is maven.persistence module. Can't say much regarding difference yet. It may have sense to refactor persistence providers implementation into one place as it seems to contain a lot of duplication. (In reply to comment #10) > One more persistence support implementation sample is maven.persistence module. Right, I intentionally skipped over that since it can be assumed to be a quite different implementation, whereas Ant-based projects typically have large commonalities in service implementations. In the case of the persistence services it looks like these were introduced - and blindly copied around - before java.api.common was in use. |