org.netbeans.spi.project.ui.templates.support

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » project.ant » org.netbeans.spi.project.ui.templates.support 
org.netbeans.spi.project.ui.templates.support
Support for providing own templates visible in New File... action.

Project types may declare the templates for projects in the folder Templates/Projects on the system filesystem using a module XML layer file. Registering project type templates is similar to registering file templates described below. The wizard for a project can return {@link org.openide.loaders.DataObject}s or {@link org.openide.loaders.FileObject}s corresponding to the project directories of created files and/or files to be selected in newly created projects. The {@link org.openide.WizardDescriptor} may also have a property defined on it called setAsMain, which may be {@link Boolean#TRUE} (the default) or {@link Boolean#FALSE}, according to whether the (first returned) new project should be set as the main project or not.

Each project can also declare own file templates to be exposed it in New File... wizard. This permits users to create new files, which are of types supported by given project type. The project may also provide own iterator for project-specific customization of given file type.

The project type has to declare its file templates in the module's layer file in folder the Templates. The declaration should look as follows:

<folder name="Templates">
  <folder name="JSP_Servlet">
    <file name="JSP.jsp" url="templates/JSP.template">
      <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.web.core.Bundle"/>
      <attr name="template" boolvalue="true"/>
      <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/web/core/resources/JSP.html"/>
      <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.web.dd.wizards.PageIterator.createJspIterator"/>
      <attr name="templateCategory" stringvalue="web-types"/>
    </file>
  </folder>
</folder>

The subfolder of Templates folder specify the folder in which will be this templates present in templates chooser invoked from either New File... or New Project... wizard.
The subfolder should contain a file representing one template and its attributes: The file tag has to have a unique name to recognize in the SystemFileSystem and the url property which links to file pattern of the declared template.

The mandatory file's attributes are:

  • SystemFileSystem.localizingBundle specifies the ResourceBundle which contains the localized display name of template
  • template which must have value set to true otherwise the template will be ignored.

  • The optional attributes are:
  • instantiatingWizardURL links to a resource with a template's description
  • instantiatingIterator specifies a instance of {@link org.openide.WizardDescriptor.InstantiatingIterator} which instantiates the new file in specified target folder.
  • Note: a project type can declare own custom iterator with some project-specific customization, it's recommended to use the standardized target chooser exposed in {@link org.netbeans.spi.project.ui.templates.support.Templates#createSimpleTargetChooser(org.netbeans.api.project.Project,org.netbeans.api.project.SourceGroup[]) Templates.createSimpleTargetChooser(...)}, a similar target chooser offers JavaTemplates.createPackageChooser(...) for Java-oriented projects. The project type also can use a InstantiatingIterator published by other module, i.e. JavaTemplates.createJavaTemplateIterator() useful for Java-oriented templates in case of no needs to own customization. The last possibility is declaration no iterator, in this case will be used a generic iterator useful for simple file types without any specific needs, i.e. properties file.
    For project templates the instantiate() method should return a Set of FileObjects. FileObjects representing project directories will automatically be opened in the project and files tab. Other FileObjects (e.g. Java classes created by the wizard) will be opened in the editor area. Path of coresponding nodes will be expanded in the project or files tab.
    For file templates the instantiate() method should return Set of FileObjects which will then automaticaly opened in the editor. Path of coresponding nodes will be expanded in the project or files tab.
  • templateCategory files the template to some category. The template's categories helps to filter the templates according to type of project. You may specify multiple categories separated by commas, e.g.: some-type,some-other-type
  • There are two importatnt interfaces affecting the behavior of the templates. Implementation of these interfaces should reside in the project's lookup.

    The first one is {@link org.netbeans.spi.project.ui.PrivilegedTemplates}. It is used for the initial content of the popup menu of New File.... It simply should return names of file tempolates from system filesystem which should be contained in the popup menu. Example implementation follows:

    
    private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates {
    
        private static final String[] PRIVILEGED_NAMES = new String[] {
            "Templates/Classes/Class.java",
            "Templates/Classes/Package",
            "Templates/Classes/Interface.java",
            "Templates/GUIForms/JPanel.java",
            "Templates/GUIForms/JFrame.java",
        };
    
        public String[] getPrivilegedTemplates() {
            return PRIVILEGED_NAMES;
        }
    
    }
    

    The second interface is {@link org.netbeans.spi.project.ui.RecommendedTemplates}, which infulences the apperance of templates in the New File wizard according to project types. The implementation of the interface has to return array of Strings which corresponds to names of template categories listed in the templateCategory attribute of template files. All templates which list at least one recommended category in the templateCategory attribute will be listed for given project type.
    Note: if no templateCategory is declared then this template will be visible for each project regardless its type.

    Example implementation of RecommendedTemplates interface:

    
    private static final class RecommendedTemplatesImpl implements RecommendedTemplates {
        
        // List of primarily supported templates categories
        private static final String[] TYPES = new String[] { 
            "java-classes",         
            "java-main-class",      
            "java-forms",           
            "gui-java-application", 
            "java-beans",           
            "oasis-XML-catalogs",   
            "XML",                  
            "ant-script",           
            "ant-task",             
            "junit",                
            "simple-files"          
        };
    
        public String[] getRecommendedTypes() {
            return TYPES;
        }
    
    }
    


    There is a list of template categories and its relations to project's types in matrix:
    templateCategory
    java-classes
    java-classes-basic same as java-classes excluding Applet/JApplet
    java-main-class (all together could be pooled as generic-java)
    java-beans
    java-forms
    gui-java-application (all above could be pooled as java)
    web-types
    servlet-types
    XML
    oasis-XML-catalogs
    ant-script
    ant-task
    junit
    simple-files
    MIDP

    Supported File Types in Projects Matrix

    Projects:

    • JA - Java Application
    • JL - Java Library
    • JP - Java Project with Existing Sources
    • WA - Web Application
    • WP - Web Project with Existing Sources

    * - supported file type

    File Type \ Project JA JL JP WA WP
    Folder * * * * *
    Java Package * * * * *
    Java Class * * * * *
    Empty Java File * * * * *
    Java Interface * * * * *
    Java Exception * * * * *
    Java Main Class * * *    
    JApplet Form * * *    
    JDialog Form * * *    
    JFrame Form * * *    
    JInternalFrame Form * * *    
    JPanel Form * * *    
    Bean Form * * *    
    Applet Form * * *    
    Dialog Form * * *    
    Frame Form * * *    
    Panel Form * * *    
    Application *   *    
    MDI Application *   *    
    OK/Cancel Dialog * * *    
    Java Bean * * * * *
    BeanInfo * * * * *
    BeanInfo w/o Icon * * * * *
    Customizer * * * * *
    Property Editor * * * * *
    Simple JUnit TestCase * * *    
    File Type \ Project JA JL JP WA WP
    XML Document * * * * *
    DTD Entity * * * * *
    XML Schema * * * * *
    XSL Stylesheet * * * * *
    OASIS XML Catalog * * * * *
    XML Parsed Entity * * * * *
    Cascading Style Sheet * * * * *
    Empty Ant Script * * * * *
    Custom Task * * * * *
    HTML File * * * * *
    Properties File * * * * *
    Text File * * * * *
    JSP       * *
    Servlet   * * * *
    HTML       * *
    Web Module Listener       * *
    Filter       * *
    Tag File   * * * *
    Tag Handler   * * * *
    Tag Library Descriptor   * * * *

    Java Source File NameTypeComment
    Templates.javaClass Default implementations of template UI.
    www.java2java.com | Contact Us
    Copyright 2009 - 12 Demo Source and Support. All rights reserved.
    All other trademarks are property of their respective owners.