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 |
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 | | * | * | * | * |
|