# HG changeset patch # User Jesse Glick # Date 1311027006 14400 #200175: annotation to register templates. diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/resources/layer.xml b/apisupport.ant/src/org/netbeans/modules/apisupport/project/resources/layer.xml --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/resources/layer.xml +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/resources/layer.xml @@ -43,38 +43,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/Bundle.properties b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/Bundle.properties --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/Bundle.properties +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/Bundle.properties @@ -42,10 +42,6 @@ # System file system Templates/Project/APISupport=NetBeans Modules -Templates/Project/APISupport/emptyModule=Module -Templates/Project/APISupport/emptySuite=Module Suite -Templates/Project/APISupport/emptyApplication=NetBeans Platform Application -Templates/Project/APISupport/libraryModule=Library Wrapper Module # general CTL_BrowseButton_o=Br&owse... diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/NewNbModuleWizardIterator.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/NewNbModuleWizardIterator.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/NewNbModuleWizardIterator.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/NewNbModuleWizardIterator.java @@ -50,7 +50,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import javax.swing.JComponent; @@ -68,7 +67,9 @@ import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.loaders.Template; import org.openide.util.NbBundle; +import org.openide.util.NbBundle.Messages; /** * Wizard to create a new NetBeans Module project. @@ -76,6 +77,10 @@ * @author Martin Krauskopf */ public class NewNbModuleWizardIterator implements WizardDescriptor.AsynchronousInstantiatingIterator { + + private static final String FOLDER = "Project/APISupport"; + private static final String MODULE_ICON = "org/netbeans/modules/apisupport/project/resources/module.png"; + private static final String SUITE_ICON = "org/netbeans/modules/apisupport/project/suite/resources/suite.png"; enum Type { /** Either standalone module, suite component or NB.org module. */ @@ -119,7 +124,9 @@ * Returns wizard for creating NetBeans module in general - i.e. either * standalone module, suite component or NB.org module. */ - public static NewNbModuleWizardIterator createModuleIterator(Map m) { + @Template(folder = FOLDER, position = 100, displayName = "#template_module", iconBase = MODULE_ICON, description = "../../resources/emptyModule.html") + @Messages("template_module=Module") + public static NewNbModuleWizardIterator createModuleIterator() { return new NewNbModuleWizardIterator(Type.MODULE); } @@ -133,10 +140,14 @@ return iterator; } + @Template(folder = FOLDER, position = 200, displayName = "#template_suite", iconBase = SUITE_ICON, description = "../../resources/emptySuite.html") + @Messages("template_suite=Module Suite") public static NewNbModuleWizardIterator createSuiteIterator() { return new NewNbModuleWizardIterator(Type.SUITE); } + @Template(folder = FOLDER, position = 400, displayName = "#template_application", iconBase = SUITE_ICON, description = "../../resources/emptyApplication.html") + @Messages("template_application=NetBeans Platform Application") public static NewNbModuleWizardIterator createApplicationIterator() { return new NewNbModuleWizardIterator(Type.APPLICATION); } @@ -154,6 +165,8 @@ return iterator; } + @Template(folder = FOLDER, position = 300, displayName = "#template_library_module", iconBase = MODULE_ICON, description = "../../resources/libraryModule.html") + @Messages("template_library_module=Library Wrapper Module") public static NewNbModuleWizardIterator createLibraryModuleIterator() { return new NewNbModuleWizardIterator(Type.LIBRARY_MODULE); } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/NewTemplateVisualPanel.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/NewTemplateVisualPanel.java --- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/NewTemplateVisualPanel.java +++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/wizard/NewTemplateVisualPanel.java @@ -43,7 +43,7 @@ package org.netbeans.modules.apisupport.project.ui.wizard; import org.netbeans.modules.apisupport.project.api.BasicVisualPanel; -import org.openide.util.NbBundle; +import static org.netbeans.modules.apisupport.project.ui.wizard.Bundle.*; abstract class NewTemplateVisualPanel extends BasicVisualPanel { @@ -52,27 +52,27 @@ NewTemplateVisualPanel(final NewModuleProjectData data) { super(data.getSettings()); this.data = data; - String resource; + String title; switch (data.getWizardType()) { case SUITE: - resource = "emptySuite"; // NOI18N + title = template_suite(); break; case APPLICATION: - resource = "emptyApplication"; // NOI18N + title = template_application(); break; case MODULE: case SUITE_COMPONENT: - resource = "emptyModule"; // NOI18N + title = template_module(); break; case LIBRARY_MODULE: - resource = "libraryModule"; // NOI18N + title = template_library_module(); break; default: assert false : "Unknown wizard type = " + data.getWizardType(); - resource = ""; + title = ""; } data.getSettings().putProperty("NewProjectWizard_Title", // NOI18N - NbBundle.getMessage(NewTemplateVisualPanel.class, "Templates/Project/APISupport/" + resource)); + title); } protected NewModuleProjectData getData() { diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml @@ -49,123 +49,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/Bundle.properties b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/Bundle.properties --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/Bundle.properties +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/Bundle.properties @@ -41,7 +41,6 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -Templates/NetBeansModuleDevelopment/newAction=Action LBL_ActionWizardTitle=Action # Action Type panel (1.step) diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/NewActionIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/NewActionIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/NewActionIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/NewActionIterator.java @@ -49,22 +49,20 @@ import org.netbeans.modules.apisupport.project.ui.wizard.common.CreatedModifiedFiles; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; +import org.openide.loaders.Template; +import org.openide.util.NbBundle.Messages; /** * Wizard for creating new Actions. * * @author Martin Krauskopf */ -final class NewActionIterator extends BasicWizardIterator { +@Template(folder="NetBeansModuleDevelopment", displayName="#template", iconBase="org/netbeans/modules/apisupport/project/ui/resources/newAction.png", position=100, description="../../resources/newAction.html", category="nbm-specific") +@Messages("template=Action") +public final class NewActionIterator extends BasicWizardIterator { private DataModel data; - private NewActionIterator() {} - - public static NewActionIterator createIterator() { - return new NewActionIterator(); - } - public Set instantiate() throws IOException { CreatedModifiedFiles cmf = data.getCreatedModifiedFiles(); cmf.run(); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/codegenerator/NewCodeGeneratorIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/codegenerator/NewCodeGeneratorIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/codegenerator/NewCodeGeneratorIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/codegenerator/NewCodeGeneratorIterator.java @@ -52,6 +52,7 @@ import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; +import org.openide.loaders.Template; /** * Wiziard for creating ne Code Generators @@ -164,6 +165,7 @@ * layer.xml entrypoint * @return instance */ + @Template(folder = "NetBeansModuleDevelopment", position = 1200, displayName = "#Templates/NetBeansModuleDevelopment/newCodeGenerator", iconBase = "org/netbeans/modules/apisupport/project/ui/resources/newCodeGenerator.png", description = "/org/netbeans/modules/apisupport/project/ui/resources/newCodeGenerator.html", category = "nbm-specific") public static NewCodeGeneratorIterator createIterator() { return new NewCodeGeneratorIterator(); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/javahelp/NewJavaHelpIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/javahelp/NewJavaHelpIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/javahelp/NewJavaHelpIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/javahelp/NewJavaHelpIterator.java @@ -57,6 +57,7 @@ import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; +import org.openide.loaders.Template; import org.openide.modules.SpecificationVersion; import org.openide.util.Exceptions; @@ -69,6 +70,7 @@ private NewJavaHelpIterator.DataModel data; + @Template(folder = "NetBeansModuleDevelopment", position = 900, displayName = "#Templates/NetBeansModuleDevelopment/newJavaHelp", iconBase = "org/netbeans/modules/apisupport/project/ui/resources/newJavaHelp.png", description = "/org/netbeans/modules/apisupport/project/ui/resources/newJavaHelp.html", category = "nbm-specific") public static NewJavaHelpIterator createIterator() { return new NewJavaHelpIterator(); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/layer/NewLayerIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/layer/NewLayerIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/layer/NewLayerIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/layer/NewLayerIterator.java @@ -47,7 +47,9 @@ import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; +import org.openide.loaders.Template; +@Template(folder = "NetBeansModuleDevelopment", position = 1300, displayName = "#template_label", iconBase = "org/netbeans/modules/apisupport/project/ui/resources/layerObject.gif", description = "/org/netbeans/modules/apisupport/project/ui/resources/newLayer.html", category = "nbm-specific") public class NewLayerIterator extends BasicWizardIterator { private BasicDataModel data; diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/NewLibraryDescriptor.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/NewLibraryDescriptor.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/NewLibraryDescriptor.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/NewLibraryDescriptor.java @@ -55,6 +55,7 @@ import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; import org.openide.filesystems.FileSystem; +import org.openide.loaders.Template; /** * Wizard J2SE Library Descriptor for registering @@ -66,6 +67,7 @@ NewLibraryDescriptor.DataModel data; + @Template(folder = "NetBeansModuleDevelopment", position = 1100, displayName = "#Templates/NetBeansModuleDevelopment/emptyLibraryDescriptor", iconBase = "org/netbeans/modules/apisupport/project/ui/resources/libraries.gif", description = "/org/netbeans/modules/apisupport/project/ui/resources/emptyLibraryDescriptor.html", category = "nbm-specific") public static NewLibraryDescriptor createIterator() { return new NewLibraryDescriptor(); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/Bundle.properties b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/Bundle.properties --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/Bundle.properties +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/Bundle.properties @@ -42,7 +42,6 @@ # Sample ResourceBundle properties file LBL_LoaderWizardTitle=File Type -Templates/NetBeansModuleDevelopment/newLoader=File Type # FileRecognitionPanel: texts of components LBL_FileRecognition_Title=File Recognition diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/NewLoaderIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/NewLoaderIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/NewLoaderIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/NewLoaderIterator.java @@ -69,7 +69,9 @@ import org.openide.filesystems.FileUtil; import org.openide.loaders.DataFolder; import org.openide.loaders.DataObject; +import org.openide.loaders.Template; import org.openide.modules.SpecificationVersion; +import org.openide.util.NbBundle.Messages; import org.openide.xml.XMLUtil; /** @@ -77,16 +79,19 @@ * * @author Milos Kleint */ -final class NewLoaderIterator extends BasicWizardIterator { +@Template( + folder="NetBeansModuleDevelopment", + position=500, + displayName="#template", + iconBase="org/netbeans/modules/apisupport/project/ui/resources/newLoader.png", + description="../../resources/newLoader.html", + category="nbm-specific" +) +@Messages("template=File Type") +public final class NewLoaderIterator extends BasicWizardIterator { private NewLoaderIterator.DataModel data; - private NewLoaderIterator() { /* Use factory method. */ }; - - public static NewLoaderIterator createIterator() { - return new NewLoaderIterator(); - } - public Set instantiate() throws IOException { CreatedModifiedFiles cmf = data.getCreatedModifiedFiles(); cmf.run(); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/moduleinstall/NewModuleInstallIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/moduleinstall/NewModuleInstallIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/moduleinstall/NewModuleInstallIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/moduleinstall/NewModuleInstallIterator.java @@ -49,6 +49,7 @@ import org.netbeans.modules.apisupport.project.ui.wizard.common.CreatedModifiedFiles; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; +import org.openide.loaders.Template; /** * Wizard for creating Module Installer. @@ -61,6 +62,7 @@ private NewModuleInstallIterator() {} + @Template(folder = "NetBeansModuleDevelopment", position = 700, displayName = "#Templates/NetBeansModuleDevelopment/newModuleInstall", iconBase = "org/netbeans/modules/apisupport/project/ui/wizard/moduleinstall/module.png", description = "/org/netbeans/modules/apisupport/project/ui/resources/newModuleInstall.html", category = "nbm-specific") public static NewModuleInstallIterator createIterator() { return new NewModuleInstallIterator(); } diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/resources/module.png b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/moduleinstall/module.png copy from apisupport.ant/src/org/netbeans/modules/apisupport/project/resources/module.png copy to apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/moduleinstall/module.png diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle.properties b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle.properties --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle.properties +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle.properties @@ -41,7 +41,6 @@ # made subject to such option by the copyright holder. LBL_OptionsWizardTitle=Options Panel -Templates/NetBeansModuleDevelopment/newOptions=Options Panel # NameAndLocationPanel: texts of components LBL_OptionsPanel0_Title=Choose Panel Type diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/options/NewOptionsIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/options/NewOptionsIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/options/NewOptionsIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/options/NewOptionsIterator.java @@ -58,6 +58,8 @@ import org.netbeans.modules.apisupport.project.api.Util; import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; +import org.openide.loaders.Template; +import org.openide.util.NbBundle.Messages; import org.openide.util.Utilities; import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; @@ -71,16 +73,21 @@ * @author Radek Matous * @author Max Sauer */ -final class NewOptionsIterator extends BasicWizardIterator { +@Template( + folder="NetBeansModuleDevelopment", + position=400, + displayName="#template", + iconBase="org/netbeans/modules/apisupport/project/ui/resources/newOptions.png", + description="../../resources/newOptions.html", + category="nbm-specific" +) +@Messages("template=Options Panel") +public final class NewOptionsIterator extends BasicWizardIterator { private NewOptionsIterator.DataModel data; private NewOptionsIterator() { /* Use factory method. */ } - public static NewOptionsIterator createIterator() { - return new NewOptionsIterator(); - } - public Set instantiate() throws IOException { CreatedModifiedFiles cmf = data.getCreatedModifiedFiles(); cmf.run(); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/project/NewProjectIterator.java @@ -73,6 +73,8 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; +import org.openide.loaders.Template; +import org.openide.loaders.Template; /** * Wizard for creating new project templates. @@ -93,8 +95,7 @@ "org.openide.awt", // NOI18N }; - private NewProjectIterator() { /* Use factory method. */ }; - + @Template(folder = "NetBeansModuleDevelopment", position = 1000, displayName = "#Templates/NetBeansModuleDevelopment/newProject", iconBase = "org/netbeans/modules/apisupport/project/ui/resources/newProject.png", description = "/org/netbeans/modules/apisupport/project/ui/resources/newProject.html", category = "nbm-specific") public static NewProjectIterator createIterator() { return new NewProjectIterator(); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/quicksearch/NewQuickSearchIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/quicksearch/NewQuickSearchIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/quicksearch/NewQuickSearchIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/quicksearch/NewQuickSearchIterator.java @@ -51,6 +51,7 @@ import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; +import org.openide.loaders.Template; /** * Wizard for creating new providers for QuickSearch SPI @@ -80,6 +81,7 @@ * layer.xml entrypoint * @return instance */ + @Template(folder = "NetBeansModuleDevelopment", position = 800, displayName = "#Templates/NetBeansModuleDevelopment/newQuickSearch", iconBase = "org/netbeans/modules/apisupport/project/ui/resources/newQuickSearch.png", description = "/org/netbeans/modules/apisupport/project/ui/resources/newQuickSearch.html", category = "nbm-specific") public static NewQuickSearchIterator createIterator() { return new NewQuickSearchIterator(); } diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/updatecenter/Bundle.properties b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/updatecenter/Bundle.properties --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/updatecenter/Bundle.properties +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/updatecenter/Bundle.properties @@ -40,7 +40,6 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -Templates/NetBeansModuleDevelopment/newUpdateCenter=Update Center LBL_NewUpdateCenterWizardTitle=Update Center LBL_UpdateCenterRegistrationPanel_Title=Update Center Declaration diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/updatecenter/NewUpdateCenterIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/updatecenter/NewUpdateCenterIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/updatecenter/NewUpdateCenterIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/updatecenter/NewUpdateCenterIterator.java @@ -51,20 +51,27 @@ import org.netbeans.modules.apisupport.project.api.LayerHandle; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; +import org.openide.loaders.Template; +import org.openide.util.NbBundle.Messages; /** * Wizard for creating new update catalog. * * @author Jiri Rechtacek */ -final class NewUpdateCenterIterator extends BasicWizardIterator { +@Template( + folder="NetBeansModuleDevelopment", + position=600, + displayName="#template", + iconBase="org/netbeans/modules/apisupport/project/ui/resources/newUpdateCenter.png", + description="../../resources/newUpdateCenter.html", + category="nbm-specific" +) +@Messages("template=Update Center") +public final class NewUpdateCenterIterator extends BasicWizardIterator { private DataModel data; - public static NewUpdateCenterIterator createIterator() { - return new NewUpdateCenterIterator(); - } - public Set instantiate() throws IOException { CreatedModifiedFiles cmf = data.refreshCreatedModifiedFiles(); cmf.run(); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/Bundle.properties b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/Bundle.properties --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/Bundle.properties +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/Bundle.properties @@ -40,8 +40,6 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -# Sample ResourceBundle properties file -Templates/NetBeansModuleDevelopment/newWindow=Window LBL_TCWizardTitle=Window # NameAndLocationPanel: texts of components diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java @@ -62,7 +62,9 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; +import org.openide.loaders.Template; import org.openide.modules.SpecificationVersion; +import org.openide.util.NbBundle.Messages; import org.openide.windows.WindowManager; /** @@ -70,16 +72,19 @@ * * @author Milos Kleint */ -final class NewTCIterator extends BasicWizardIterator { +@Template( + folder="NetBeansModuleDevelopment", + position=200, + displayName="#template", + iconBase="org/netbeans/modules/apisupport/project/ui/resources/newTC.png", + description="../../resources/newTC.html", + category="nbm-specific" +) +@Messages("template=Window") +public final class NewTCIterator extends BasicWizardIterator { private NewTCIterator.DataModel data; - private NewTCIterator() { /* Use factory method. */ }; - - public static NewTCIterator createIterator() { - return new NewTCIterator(); - } - public Set instantiate() throws IOException { CreatedModifiedFiles cmf = data.getCreatedModifiedFiles(); cmf.run(); diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/Bundle.properties b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/Bundle.properties --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/Bundle.properties +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/Bundle.properties @@ -40,7 +40,6 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -Templates/NetBeansModuleDevelopment/newWizard=Wizard LBL_WizardWizardTitle=Wizard # Wizard Type panel (1.step) diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/NewWizardIterator.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/NewWizardIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/NewWizardIterator.java +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/NewWizardIterator.java @@ -49,22 +49,27 @@ import org.netbeans.modules.apisupport.project.ui.wizard.common.CreatedModifiedFiles; import org.netbeans.modules.apisupport.project.ui.wizard.common.BasicWizardIterator; import org.openide.WizardDescriptor; +import org.openide.loaders.Template; +import org.openide.util.NbBundle.Messages; /** * Wizard for creating new Wizards. * * @author Martin Krauskopf */ -final class NewWizardIterator extends BasicWizardIterator { +@Template( + folder="NetBeansModuleDevelopment", + position=300, + displayName="#template", + iconBase="org/netbeans/modules/apisupport/project/ui/resources/newWizard.png", + description="../../resources/newWizard.html", + category="nbm-specific" +) +@Messages("template=Wizard") +public final class NewWizardIterator extends BasicWizardIterator { private DataModel data; - private NewWizardIterator() {} - - public static NewWizardIterator createIterator() { - return new NewWizardIterator(); - } - public Set instantiate() throws IOException { CreatedModifiedFiles cmf = data.getCreatedModifiedFiles(); cmf.run(); diff --git a/apisupport.refactoring/src/org/netbeans/modules/apisupport/hints/Hinter.java b/apisupport.refactoring/src/org/netbeans/modules/apisupport/hints/Hinter.java --- a/apisupport.refactoring/src/org/netbeans/modules/apisupport/hints/Hinter.java +++ b/apisupport.refactoring/src/org/netbeans/modules/apisupport/hints/Hinter.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; @@ -351,7 +352,7 @@ * @param wc Java source context * @param modifiers the element's modifiers to append to * @param type canonical name of the annotation type - * @param parameters simple parameters of String or primitive type (null values are skipped) + * @param parameters simple parameters of String or primitive type or String[] (null values are skipped) * @return the expanded modifiers tree */ public @CheckReturnValue ModifiersTree addAnnotation(WorkingCopy wc, ModifiersTree modifiers, String type, Map parameters) { @@ -363,9 +364,25 @@ } List arguments = new ArrayList(); for (Map.Entry entry : parameters.entrySet()) { - if (entry.getValue() != null) { - arguments.add(make.Assignment(make.Identifier(entry.getKey()), make.Literal(entry.getValue()))); + Object value = entry.getValue(); + ExpressionTree valueTree; + if (value instanceof Object[]) { + Object[] array = (Object[]) value; + if (array.length == 1) { + valueTree = make.Literal(array[0]); + } else { + List elements = new ArrayList(); + for (Object o : array) { + elements.add(make.Literal(o)); + } + valueTree = make.NewArray(null, Collections.emptyList(), elements); + } + } else if (value != null) { + valueTree = make.Literal(value); + } else { + continue; } + arguments.add(make.Assignment(make.Identifier(entry.getKey()), valueTree)); } return make.addModifiersAnnotation(modifiers, make.Annotation(make.QualIdent(ann), arguments)); } diff --git a/apisupport.refactoring/src/org/netbeans/modules/apisupport/hints/TemplateHinter.java b/apisupport.refactoring/src/org/netbeans/modules/apisupport/hints/TemplateHinter.java new file mode 100644 --- /dev/null +++ b/apisupport.refactoring/src/org/netbeans/modules/apisupport/hints/TemplateHinter.java @@ -0,0 +1,138 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.apisupport.hints; + +import java.util.LinkedHashMap; +import com.sun.source.tree.ModifiersTree; +import java.net.URL; +import java.util.Map; +import java.util.concurrent.Callable; +import javax.lang.model.element.Element; +import org.netbeans.api.java.source.GeneratorUtilities; +import org.netbeans.api.java.source.WorkingCopy; +import org.netbeans.modules.apisupport.hints.Hinter.Context; +import org.netbeans.spi.editor.hints.Severity; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.NotifyDescriptor.Message; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle.Messages; +import org.openide.util.NbCollections; +import org.openide.util.lookup.ServiceProvider; +import static org.netbeans.modules.apisupport.hints.Bundle.*; + +@ServiceProvider(service=Hinter.class) +public class TemplateHinter implements Hinter { + + @Messages({ + "TemplateHinter_content_file=Replace with @Template", + "# {0} - file attribute name", "TemplateHinter_unrecognized_attr=Unrecognized template attribute: {0}" + }) + public @Override void process(final Context ctx) throws Exception { + final FileObject file = ctx.file(); + if (!file.isData()) { + return; + } + Object iterator = file.getAttribute("literal:instantiatingIterator"); + if (iterator == null) { + iterator = file.getAttribute("literal:templateWizardIterator"); + } + if (iterator == null) { + return; + } + if (file.getSize() > 0) { + // XXX currently only handle virtual templates + ctx.addHint(Severity.WARNING, TemplateHinter_content_file()); + return; + } + for (String attr : NbCollections.iterable(file.getAttributes())) { + if (!attr.matches("instantiatingIterator|templateWizardIterator|template|displayName|iconBase|position|instantiatingWizardURL|templateWizardURL|templateCategory")) { + ctx.addHint(Severity.WARNING, TemplateHinter_unrecognized_attr(attr)); + return; + } + } + final Object _iterator = iterator; + ctx.addStandardAnnotationHint(new Callable() { + public @Override Void call() throws Exception { + if (!annotationsAvailable(ctx)) { + return null; + } + ctx.findAndModifyDeclaration(_iterator, new Context.ModifyDeclarationTask() { + public @Override void run(WorkingCopy wc, Element declaration, ModifiersTree modifiers) throws Exception { + Map params = new LinkedHashMap(); + FileObject file = ctx.file(); + params.put("folder", FileUtil.getRelativePath(file.getFileSystem().findResource("Templates"), file.getParent())); + params.put("position", file.getAttribute("position")); + params.put("displayName", ctx.bundlevalue(file.getAttribute("literal:displayName"), declaration)); + params.put("iconBase", file.getAttribute("iconBase")); + URL desc = (URL) file.getAttribute("instantiatingWizardURL"); + if (desc == null) { + desc = (URL) file.getAttribute("templateWizardURL"); + } + if (desc != null) { + // XXX could relativize it + params.put("description", desc.getPath()); + } + String category = (String) file.getAttribute("templateCategory"); + if (category != null) { + params.put("category", category.split(",")); + } + // XXX use @Templates where necessary + ModifiersTree nue = ctx.addAnnotation(wc, modifiers, "org.openide.loaders.Template", params); + ctx.delete(file); + wc.rewrite(modifiers, GeneratorUtilities.get(wc).importFQNs(nue)); + } + }); + return null; + } + }); + } + + @Messages("TemplateHinter.missing_dep=You must add a dependency on org.openide.loaders (7.29+) before using this fix.") + private boolean annotationsAvailable(Context ctx) { + if (ctx.canAccess("org.openide.loaders.Template")) { + return true; + } else { + DialogDisplayer.getDefault().notify(new Message(Bundle.TemplateHinter_missing_dep(), NotifyDescriptor.WARNING_MESSAGE)); + return false; + } + } + +} diff --git a/beans/nbproject/project.xml b/beans/nbproject/project.xml --- a/beans/nbproject/project.xml +++ b/beans/nbproject/project.xml @@ -137,6 +137,15 @@ + org.netbeans.modules.java.project + + + + 1 + 1.39 + + + org.netbeans.modules.java.source diff --git a/beans/src/org/netbeans/modules/beans/beaninfo/BIDataLoader.java b/beans/src/org/netbeans/modules/beans/beaninfo/BIDataLoader.java --- a/beans/src/org/netbeans/modules/beans/beaninfo/BIDataLoader.java +++ b/beans/src/org/netbeans/modules/beans/beaninfo/BIDataLoader.java @@ -91,6 +91,9 @@ @Override protected FileObject findPrimaryFile(FileObject fo) { + if (fo.getAttribute("template") != null && fo.getAttribute("javax.script.ScriptEngine") != null) { + return null; // as in JavaDataLoader + } return isBeanInfo(fo)? fo: null; } diff --git a/beans/src/org/netbeans/modules/beans/resources/mf-layer.xml b/beans/src/org/netbeans/modules/beans/resources/mf-layer.xml --- a/beans/src/org/netbeans/modules/beans/resources/mf-layer.xml +++ b/beans/src/org/netbeans/modules/beans/resources/mf-layer.xml @@ -43,76 +43,19 @@ Version 2 license, then the option applies only if the new code is made subject to such option by the copyright holder. --> - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - diff --git a/beans/src/org/netbeans/modules/beans/resources/Bean.html b/beans/src/org/netbeans/modules/beans/resources/templates/Bean.html rename from beans/src/org/netbeans/modules/beans/resources/Bean.html rename to beans/src/org/netbeans/modules/beans/resources/templates/Bean.html diff --git a/beans/src/org/netbeans/modules/beans/resources/templates/Bean.template b/beans/src/org/netbeans/modules/beans/resources/templates/Bean.java.template rename from beans/src/org/netbeans/modules/beans/resources/templates/Bean.template rename to beans/src/org/netbeans/modules/beans/resources/templates/Bean.java.template diff --git a/beans/src/org/netbeans/modules/beans/resources/BeanInfo.html b/beans/src/org/netbeans/modules/beans/resources/templates/BeanInfo.html rename from beans/src/org/netbeans/modules/beans/resources/BeanInfo.html rename to beans/src/org/netbeans/modules/beans/resources/templates/BeanInfo.html diff --git a/beans/src/org/netbeans/modules/beans/resources/templates/BeanInfo.template b/beans/src/org/netbeans/modules/beans/resources/templates/BeanInfo.java.template rename from beans/src/org/netbeans/modules/beans/resources/templates/BeanInfo.template rename to beans/src/org/netbeans/modules/beans/resources/templates/BeanInfo.java.template diff --git a/beans/src/org/netbeans/modules/beans/resources/Beans.html b/beans/src/org/netbeans/modules/beans/resources/templates/Beans.html rename from beans/src/org/netbeans/modules/beans/resources/Beans.html rename to beans/src/org/netbeans/modules/beans/resources/templates/Beans.html diff --git a/beans/src/org/netbeans/modules/beans/resources/Customizer.html b/beans/src/org/netbeans/modules/beans/resources/templates/Customizer.html rename from beans/src/org/netbeans/modules/beans/resources/Customizer.html rename to beans/src/org/netbeans/modules/beans/resources/templates/Customizer.html diff --git a/beans/src/org/netbeans/modules/beans/resources/templates/Customizer.template b/beans/src/org/netbeans/modules/beans/resources/templates/Customizer.java.template rename from beans/src/org/netbeans/modules/beans/resources/templates/Customizer.template rename to beans/src/org/netbeans/modules/beans/resources/templates/Customizer.java.template diff --git a/beans/src/org/netbeans/modules/beans/resources/templates/BeanInfoNoIcon.template b/beans/src/org/netbeans/modules/beans/resources/templates/NoIconBeanInfo.java.template rename from beans/src/org/netbeans/modules/beans/resources/templates/BeanInfoNoIcon.template rename to beans/src/org/netbeans/modules/beans/resources/templates/NoIconBeanInfo.java.template diff --git a/beans/src/org/netbeans/modules/beans/resources/PropertyEditor.html b/beans/src/org/netbeans/modules/beans/resources/templates/PropertyEditor.html rename from beans/src/org/netbeans/modules/beans/resources/PropertyEditor.html rename to beans/src/org/netbeans/modules/beans/resources/templates/PropertyEditor.html diff --git a/beans/src/org/netbeans/modules/beans/resources/templates/PropertyEditor.template b/beans/src/org/netbeans/modules/beans/resources/templates/PropertyEditor.java.template rename from beans/src/org/netbeans/modules/beans/resources/templates/PropertyEditor.template rename to beans/src/org/netbeans/modules/beans/resources/templates/PropertyEditor.java.template diff --git a/beans/src/org/netbeans/modules/beans/resources/templates/package-info.java b/beans/src/org/netbeans/modules/beans/resources/templates/package-info.java new file mode 100644 --- /dev/null +++ b/beans/src/org/netbeans/modules/beans/resources/templates/package-info.java @@ -0,0 +1,49 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +@JavaTemplates.Registrations({ + @JavaTemplates.Registration(@Template(folder="Beans", position=100, content="Bean.java.template", displayName="org.netbeans.modules.beans.Bundle#Templates/Beans/Bean.java", description="Bean.html", category="java-beans", scriptEngine="freemarker")), + @JavaTemplates.Registration(@Template(folder="Beans", position=200, content="BeanInfo.java.template", displayName="org.netbeans.modules.beans.Bundle#Templates/Beans/BeanInfo.java", description="BeanInfo.html", category="java-beans", scriptEngine="freemarker")), + @JavaTemplates.Registration(@Template(folder="Beans", position=300, content="NoIconBeanInfo.java.template", displayName="org.netbeans.modules.beans.Bundle#Templates/Beans/NoIconBeanInfo.java", description="BeanInfo.html", category="java-beans", scriptEngine="freemarker")), + @JavaTemplates.Registration(@Template(folder="Beans", position=400, content={"Customizer.java.template", "Customizer.form.template"}, displayName="org.netbeans.modules.beans.Bundle#Templates/Beans/Customizer.java", description="Customizer.html", category="java-beans", scriptEngine="freemarker")), + @JavaTemplates.Registration(@Template(folder="Beans", position=600, content="PropertyEditor.java.template", displayName="org.netbeans.modules.beans.Bundle#Templates/Beans/PropertyEditor.java", description="PropertyEditor.html", category="java-beans", scriptEngine="freemarker")) +}) +package org.netbeans.modules.beans.resources.templates; + +import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates; +import org.openide.loaders.Template; diff --git a/html/src/org/netbeans/modules/html/mf-layer.xml b/html/src/org/netbeans/modules/html/mf-layer.xml --- a/html/src/org/netbeans/modules/html/mf-layer.xml +++ b/html/src/org/netbeans/modules/html/mf-layer.xml @@ -46,27 +46,6 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/html/src/org/netbeans/modules/html/package-info.java b/html/src/org/netbeans/modules/html/package-info.java new file mode 100644 --- /dev/null +++ b/html/src/org/netbeans/modules/html/package-info.java @@ -0,0 +1,47 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +@Templates({ + @Template(folder="Other", position=100, displayName="#Templates/Other/html.html", content="templates/html.html", scriptEngine="freemarker", category="simple-files", description="TemplateHelp.html"), + @Template(folder="Other", position=200, displayName="#Templates/Other/xhtml.xhtml", content="templates/xhtml.xhtml", scriptEngine="freemarker", category="simple-files", description="XhtmlTemplateHelp.html"), +}) +package org.netbeans.modules.html; + +import org.openide.loaders.Template; +import org.openide.loaders.Templates; + diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml @@ -48,43 +48,10 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/Bundle.properties b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/Bundle.properties --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/Bundle.properties +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/Bundle.properties @@ -40,11 +40,7 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -#System file system -Templates/Project/Standard/emptyJ2SE.xml=Java Application -Templates/Project/Standard/emptyJ2SElibrary.xml=Java Class Library Templates/Project/Standard=Java -Templates/Project/Standard/existingJ2SE.xml= Java Project with Existing Sources #New project wizard TXT_DefaultPackageName=mypkg diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/NewJ2SEProjectWizardIterator.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/NewJ2SEProjectWizardIterator.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/NewJ2SEProjectWizardIterator.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/wizards/NewJ2SEProjectWizardIterator.java @@ -66,7 +66,9 @@ import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.loaders.Template; import org.openide.util.NbBundle; +import org.openide.util.NbBundle.Messages; /** * Wizard to create a new J2SE project. @@ -83,19 +85,24 @@ private WizardType type; - /** Create a new wizard iterator. */ - public NewJ2SEProjectWizardIterator() { - this(WizardType.APP); - } - - public NewJ2SEProjectWizardIterator(WizardType type) { + private NewJ2SEProjectWizardIterator(WizardType type) { this.type = type; } - + + @Template(folder="Project/Standard", position=100, displayName="#template_app", iconBase="org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.png", description="../resources/emptyProject.html") + @Messages("template_app=Java Application") + public static NewJ2SEProjectWizardIterator app() { + return new NewJ2SEProjectWizardIterator(WizardType.APP); + } + + @Template(folder="Project/Standard", position=200, displayName="#template_library", iconBase="org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.png", description="../resources/emptyLibrary.html") + @Messages("template_library=Java Class Library") public static NewJ2SEProjectWizardIterator library() { return new NewJ2SEProjectWizardIterator(WizardType.LIB); } - + + @Template(folder="Project/Standard", position=300, displayName="#template_existing", iconBase="org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.png", description="../resources/existingProject.html") + @Messages("template_existing=Java Project with Existing Sources") public static NewJ2SEProjectWizardIterator existing() { return new NewJ2SEProjectWizardIterator(WizardType.EXT); } diff --git a/java.project/nbproject/project.xml b/java.project/nbproject/project.xml --- a/java.project/nbproject/project.xml +++ b/java.project/nbproject/project.xml @@ -206,7 +206,9 @@ org.openide.loaders - + + 7.29 + org.openide.modules diff --git a/java.project/src/org/netbeans/modules/java/project/JavaTemplatesProcessor.java b/java.project/src/org/netbeans/modules/java/project/JavaTemplatesProcessor.java new file mode 100644 --- /dev/null +++ b/java.project/src/org/netbeans/modules/java/project/JavaTemplatesProcessor.java @@ -0,0 +1,87 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.project; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates; +import org.openide.filesystems.annotations.LayerBuilder; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.loaders.AbstractTemplateProcessor; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service=Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class JavaTemplatesProcessor extends AbstractTemplateProcessor { + + @Override public Set getSupportedAnnotationTypes() { + return new HashSet(Arrays.asList(JavaTemplates.Registration.class.getCanonicalName(), JavaTemplates.Registrations.class.getCanonicalName())); + } + + @Override protected boolean handleProcess(Set annotations, RoundEnvironment roundEnv) throws LayerGenerationException { + if (roundEnv.processingOver()) { + return false; + } + for (Element e : roundEnv.getElementsAnnotatedWith(JavaTemplates.Registration.class)) { + process(e, e.getAnnotation(JavaTemplates.Registration.class)); + } + for (Element e : roundEnv.getElementsAnnotatedWith(JavaTemplates.Registrations.class)) { + for (JavaTemplates.Registration r : e.getAnnotation(JavaTemplates.Registrations.class).value()) { + process(e, r); + } + } + return true; + } + + private void process(Element e, JavaTemplates.Registration r) throws LayerGenerationException { + LayerBuilder.File f = process(e, r.value()).methodvalue("instantiatingIterator", JavaTemplates.class.getName(), "createJavaTemplateIterator"); + if (r.value().iconBase().isEmpty() && /* not a form file! */r.value().content().length == 1) { + f.stringvalue("iconBase", /* JavaNode.JAVA_ICON_BASE */"org/netbeans/modules/java/resources/class.png"); + } + f.write(); + } + +} diff --git a/java.project/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplates.java b/java.project/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplates.java --- a/java.project/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplates.java +++ b/java.project/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplates.java @@ -44,11 +44,16 @@ package org.netbeans.spi.java.project.support.ui.templates; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import org.netbeans.api.project.Project; import org.netbeans.modules.java.project.JavaTargetChooserPanel; import org.netbeans.modules.java.project.NewJavaFileWizardIterator; import org.netbeans.api.project.SourceGroup; import org.openide.WizardDescriptor; +import org.openide.loaders.Template; /** * Default implementations of Java-specific template UI. @@ -113,9 +118,32 @@ /** Creates new WizardIterator containing standard Package chooser * @return WizardIterator consisting of one panel containing package chooser + * @see Registration */ public static WizardDescriptor.InstantiatingIterator createJavaTemplateIterator () { return new NewJavaFileWizardIterator (); } + /** + * Specialized version of {@link Template} for Java source files. + * @see #createJavaTemplateIterator + * @see Registrations + * @since XXX + */ + @Target(ElementType.PACKAGE) + @Retention(RetentionPolicy.SOURCE) + public @interface Registration { + Template value(); + } + + /** + * Multiple registrations. + * @since XXX + */ + @Target(ElementType.PACKAGE) + @Retention(RetentionPolicy.SOURCE) + public @interface Registrations { + Registration[] value(); + } + } diff --git a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/Bundle.properties b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/Bundle.properties --- a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/Bundle.properties +++ b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/Bundle.properties @@ -44,9 +44,6 @@ repo.netbeans=NetBeans PublicPackagesPanel.jLabel1.text=&Public packages: -template.module=NetBeans Module -template.suite=NetBeans Module Suite -template.app=NetBeans Application NbmWizardPanelVisual.panel.accessiblename=additional properties of the project NbmWizardPanelVisual.panel.accessibledesc=Select the additional project properties. diff --git a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java --- a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java +++ b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java @@ -80,6 +80,7 @@ import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; +import org.openide.loaders.Template; import org.openide.util.NbBundle.Messages; import static org.netbeans.modules.maven.apisupport.Bundle.*; @@ -116,15 +117,21 @@ private NbmWizardIterator(Archetype archetype) { this.archetype = archetype; } - + + @Template(folder="Project/Maven2", position=400, displayName="#template.module", iconBase="org/netbeans/modules/maven/apisupport/nbmicon.png", description="NbModuleDescription.html") + @Messages("template.module=NetBeans Module") public static NbmWizardIterator createNbModuleIterator() { return new NbmWizardIterator(NB_MODULE_ARCH); } + @Template(folder="Project/Maven2", position=500, displayName="#template.app", iconBase="org/netbeans/modules/maven/apisupport/suiteicon.png", description="NbAppDescription.html") + @Messages("template.app=NetBeans Application") public static NbmWizardIterator createNbAppIterator() { return new NbmWizardIterator(NB_APP_ARCH); } + @Template(folder="Project/Maven2", position=450, displayName="#template.suite", iconBase="org/netbeans/modules/maven/apisupport/suiteicon.png", description="NbSuiteDescription.html") + @Messages("template.suite=NetBeans Module Suite") public static NbmWizardIterator createNbSuiteIterator() { return new NbmWizardIterator(NB_SUITE_ARCH); } diff --git a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/layer.xml b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/layer.xml --- a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/layer.xml +++ b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/layer.xml @@ -57,34 +57,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/maven/src/org/netbeans/modules/maven/resources/nbmicon.png b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/nbmicon.png rename from maven/src/org/netbeans/modules/maven/resources/nbmicon.png rename to maven.apisupport/src/org/netbeans/modules/maven/apisupport/nbmicon.png diff --git a/maven/src/org/netbeans/modules/maven/resources/suiteicon.png b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/suiteicon.png rename from maven/src/org/netbeans/modules/maven/resources/suiteicon.png rename to maven.apisupport/src/org/netbeans/modules/maven/apisupport/suiteicon.png diff --git a/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java b/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java --- a/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java +++ b/maven/src/org/netbeans/modules/maven/NbMavenProjectImpl.java @@ -575,9 +575,9 @@ put(NbMavenProject.TYPE_EJB, "org/netbeans/modules/maven/resources/maven_ejb_module_16.png"); //NOI18N put(NbMavenProject.TYPE_EAR, "org/netbeans/modules/maven/resources/maven_enterprise_application_16.png"); //NOI18N put(NbMavenProject.TYPE_POM, "org/netbeans/modules/maven/resources/Maven2Icon.gif"); //NOI18N - put(NbMavenProject.TYPE_NBM, "org/netbeans/modules/maven/resources/nbmicon.png"); //NOI18N + put(NbMavenProject.TYPE_NBM, "org/netbeans/modules/maven/apisupport/nbmicon.png"); //NOI18N put(NbMavenProject.TYPE_OSGI, "org/netbeans/modules/maven/resources/maven_osgi_16.png"); //NOI18N - put(NbMavenProject.TYPE_NBM_APPLICATION, "org/netbeans/modules/maven/resources/suiteicon.png"); //NOI18N + put(NbMavenProject.TYPE_NBM_APPLICATION, "org/netbeans/modules/maven/apisupport/suiteicon.png"); //NOI18N } }); diff --git a/openide.loaders/apichanges.xml b/openide.loaders/apichanges.xml --- a/openide.loaders/apichanges.xml +++ b/openide.loaders/apichanges.xml @@ -109,6 +109,23 @@ + + + Introduced Template + + + + + +

+ Introduced a new annotation for registering (file or project) templates. +

+
+ + + + +
DataEditorSupport constructor with Lookup parameter diff --git a/openide.loaders/manifest.mf b/openide.loaders/manifest.mf --- a/openide.loaders/manifest.mf +++ b/openide.loaders/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.loaders -OpenIDE-Module-Specification-Version: 7.28 +OpenIDE-Module-Specification-Version: 7.29 OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0 OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml diff --git a/openide.loaders/nbproject/project.xml b/openide.loaders/nbproject/project.xml --- a/openide.loaders/nbproject/project.xml +++ b/openide.loaders/nbproject/project.xml @@ -122,7 +122,7 @@ - 7.19 + 7.51 diff --git a/openide.loaders/src/org/netbeans/modules/openide/loaders/TemplateProcessor.java b/openide.loaders/src/org/netbeans/modules/openide/loaders/TemplateProcessor.java new file mode 100644 --- /dev/null +++ b/openide.loaders/src/org/netbeans/modules/openide/loaders/TemplateProcessor.java @@ -0,0 +1,79 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.openide.loaders; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.loaders.AbstractTemplateProcessor; +import org.openide.loaders.Template; +import org.openide.loaders.Templates; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service=Processor.class) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class TemplateProcessor extends AbstractTemplateProcessor { + + @Override public Set getSupportedAnnotationTypes() { + return new HashSet(Arrays.asList(Template.class.getCanonicalName(), Templates.class.getCanonicalName())); + } + + @Override protected boolean handleProcess(Set annotations, RoundEnvironment roundEnv) throws LayerGenerationException { + if (roundEnv.processingOver()) { + return false; + } + for (Element e : roundEnv.getElementsAnnotatedWith(Template.class)) { + process(e, e.getAnnotation(Template.class)).write(); + } + for (Element e : roundEnv.getElementsAnnotatedWith(Templates.class)) { + for (Template t : e.getAnnotation(Templates.class).value()) { + process(e, t).write(); + } + } + return true; + } + +} diff --git a/openide.loaders/src/org/netbeans/modules/templates/ScriptingCreateFromTemplateHandler.java b/openide.loaders/src/org/netbeans/modules/templates/ScriptingCreateFromTemplateHandler.java --- a/openide.loaders/src/org/netbeans/modules/templates/ScriptingCreateFromTemplateHandler.java +++ b/openide.loaders/src/org/netbeans/modules/templates/ScriptingCreateFromTemplateHandler.java @@ -64,6 +64,9 @@ */ @ServiceProvider(service=CreateFromTemplateHandler.class) public class ScriptingCreateFromTemplateHandler extends CreateFromTemplateHandler { + + public static final String SCRIPT_ENGINE_ATTR = "javax.script.ScriptEngine"; + private static ScriptEngineManager manager; private static final String ENCODING_PROPERTY_NAME = "encoding"; //NOI18N @@ -121,7 +124,7 @@ } private static ScriptEngine engine(FileObject fo) { - Object obj = fo.getAttribute("javax.script.ScriptEngine"); // NOI18N + Object obj = fo.getAttribute(SCRIPT_ENGINE_ATTR); // NOI18N if (obj instanceof ScriptEngine) { return (ScriptEngine)obj; } diff --git a/openide.loaders/src/org/openide/actions/SaveAsTemplateAction.java b/openide.loaders/src/org/openide/actions/SaveAsTemplateAction.java --- a/openide.loaders/src/org/openide/actions/SaveAsTemplateAction.java +++ b/openide.loaders/src/org/openide/actions/SaveAsTemplateAction.java @@ -50,6 +50,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import org.netbeans.modules.templates.ScriptingCreateFromTemplateHandler; import org.openide.cookies.SaveCookie; import org.openide.filesystems.FileObject; import org.openide.loaders.*; @@ -155,7 +156,7 @@ newTemplate.setTemplate(true); if (templateSample == null) { // a fallback if no template sample found - newTemplate.getPrimaryFile ().setAttribute ("javax.script.ScriptEngine", "freemarker"); // NOI18N + newTemplate.getPrimaryFile().setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "freemarker"); // NOI18N } else { setTemplateAttributes (newTemplate.getPrimaryFile (), getAttributes (templateSample.getPrimaryFile ())); } diff --git a/openide.loaders/src/org/openide/loaders/AbstractTemplateProcessor.java b/openide.loaders/src/org/openide/loaders/AbstractTemplateProcessor.java new file mode 100644 --- /dev/null +++ b/openide.loaders/src/org/openide/loaders/AbstractTemplateProcessor.java @@ -0,0 +1,135 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.openide.loaders; + +import java.net.URI; +import java.net.URISyntaxException; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import org.netbeans.modules.templates.ScriptingCreateFromTemplateHandler; +import org.openide.WizardDescriptor.InstantiatingIterator; +import org.openide.filesystems.annotations.LayerBuilder; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; + +/** + * Performs basic logic of processing {@link Template} registrations. + * While {@code @Template} itself is automatically processed, it is possible to + * have more domain-specific annotations that add further metadata. + * This class may be used to create the basic registration. + * @since 7.29 + */ +public abstract class AbstractTemplateProcessor extends LayerGeneratingProcessor { + + /** + * Performs basic template registration. + * @param e the originating element + * @param t a template annotation associated with element + * @return a layer file on which {@link LayerBuilder.File#write} must still be called + * @throws LayerGenerationException in case of problems + */ + protected final LayerBuilder.File process(Element e, Template t) throws LayerGenerationException { + LayerBuilder builder = layer(e); + String basename; + if (t.content().length > 0) { + basename = basename(t.content()[0]); + } else { + if (e.getKind() == ElementKind.CLASS) { + basename = ((TypeElement) e).getQualifiedName().toString().replace('.', '-'); + } else if (e.getKind() == ElementKind.METHOD) { + basename = ((TypeElement) e.getEnclosingElement()).getQualifiedName().toString().replace('.', '-') + '-' + e.getSimpleName(); + } else { + throw new LayerGenerationException("cannot use @Template on a package without specifying content", e); + } + } + String folder = "Templates/" + t.folder() + '/'; + LayerBuilder.File f = builder.file(folder + basename); + f.boolvalue("template", true); + f.position(t.position()); + if (!t.displayName().isEmpty()) { + f.bundlevalue("displayName", t.displayName()); + } + if (!t.iconBase().isEmpty()) { + builder.validateResource(t.iconBase(), e, t, "iconBase", true); + f.stringvalue("iconBase", t.iconBase()); + } + if (!t.description().isEmpty()) { + f.urlvalue("instantiatingWizardURL", contentURI(e, t.description(), builder, t, "description")); + } + if (e.getKind() != ElementKind.PACKAGE) { + f.instanceAttribute("instantiatingIterator", InstantiatingIterator.class); + } + if (t.content().length > 0) { + f.url(contentURI(e, t.content()[0], builder, t, "content").toString()); + for (int i = 1; i < t.content().length; i++) { + builder.file(folder + basename(t.content()[i])).url(contentURI(e, t.content()[i], builder, t, "content").toString()).position(0).write(); + } + } + if (!t.scriptEngine().isEmpty()) { + f.stringvalue(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, t.scriptEngine()); + } + if (t.category().length > 0) { + StringBuilder sb = new StringBuilder(); + for (String c : t.category()) { + if (sb.length() > 0) { + sb.append(','); + } + sb.append(c); + } + f.stringvalue("templateCategory", sb.toString()); + } + return f; + } + + private static String basename(String relativeResource) { + return relativeResource.replaceFirst(".+/", "").replaceFirst("[.]template$", ""); + } + + private static URI contentURI(Element e, String relativePath, LayerBuilder builder, Template t, String annotationMethod) throws LayerGenerationException { + String path = LayerBuilder.absolutizeResource(e, relativePath); + builder.validateResource(path, e, t, annotationMethod, false); + try { + return new URI("nbresloc", "/" + path, null).normalize(); + } catch (URISyntaxException x) { + throw new LayerGenerationException("could not translate " + path, e); + } + } + +} diff --git a/openide.loaders/src/org/openide/loaders/Template.java b/openide.loaders/src/org/openide/loaders/Template.java new file mode 100644 --- /dev/null +++ b/openide.loaders/src/org/openide/loaders/Template.java @@ -0,0 +1,117 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.openide.loaders; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import javax.script.ScriptEngineFactory; +import org.openide.WizardDescriptor.InstantiatingIterator; + +/** + * Registers a template the user can select. + * May be placed on a class (with a default constructor) or static method (with no arguments) + * to register an {@link InstantiatingIterator} for a custom template; + * or on a package to register a plain-file template with no custom behavior. + * @since 7.29 + * @see TemplateWizard + * @see Templates + * @see AbstractTemplateProcessor + */ +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PACKAGE}) +@Retention(RetentionPolicy.SOURCE) +public @interface Template { + + /** + * Subfolder in which to place the template, such as {@code Other} or {@code Project/Standard}. + */ + String folder(); + + /** + * Optional position within {@link #folder}. + */ + int position() default Integer.MAX_VALUE; + + /** + * File contents, as resources relative to the package of this declaration. + * A nonempty list is mandatory for a template registered on a package. + * For a template with a custom iterator, the content may be omitted, though it may still be specified. + *

Normally only a single file is specified, but for a multifile data object, list the primary entry first. + *

The file basenames (incl. extension) of the actual template files (as in {@link TemplateWizard#getTemplate}) + * will be taken from the basename of the content resources, though a {@code .template} suffix + * may be appended to prevent template resources in a source project from being misinterpreted. + * For a "pure" custom iterator with no specified content, the template basename + * will be the FQN of the class or method defining it but with {@code -} for {@code .} characters, + * e.g. {@code pkg-Class-method}. + */ + String[] content() default {}; + + /** + * Localized label for the template. + * Mandatory unless {@link #content} is specified, in which case it would be defaulted by the data node. + * May use the usual {@code #key} syntax. + */ + String displayName() default ""; + + // XXX should this assume an absolute resource path, or permit relative paths, or either? check for consistency with other annotations, and consider #196452 + /** + * Icon to use for the template. + * Mandatory unless {@link #content} is specified, in which case it would be defaulted by the data node. + */ + String iconBase() default ""; + + /** + * Optional but recommended relative resource path to an HTML description of the template. + * @see TemplateWizard#getDescription + */ + String description() default ""; + + /** + * Optional name of a script engine to use when processing file content, such as {@code freemarker}. + * @see ScriptEngineFactory#getNames + */ + String scriptEngine() default ""; + + /** + * Optional list of categories interpreted by the project system. + */ + String[] category() default {}; + +} diff --git a/openide.loaders/src/org/openide/loaders/TemplateWizard.java b/openide.loaders/src/org/openide/loaders/TemplateWizard.java --- a/openide.loaders/src/org/openide/loaders/TemplateWizard.java +++ b/openide.loaders/src/org/openide/loaders/TemplateWizard.java @@ -65,6 +65,7 @@ /** Wizard for creation of new objects from a template. * * @author Jaroslav Tulach, Jiri Rechtacek +* @see Template */ public class TemplateWizard extends WizardDescriptor { /** EA that defines the wizards description */ @@ -832,6 +833,7 @@ * use of putProperty method and read it using getProperty. *

* Implements Node.Cookie since version 2.13 + * @see Template */ public interface Iterator extends WizardDescriptor.Iterator, java.io.Serializable, org.openide.nodes.Node.Cookie { diff --git a/openide.loaders/src/org/openide/loaders/Templates.java b/openide.loaders/src/org/openide/loaders/Templates.java new file mode 100644 --- /dev/null +++ b/openide.loaders/src/org/openide/loaders/Templates.java @@ -0,0 +1,54 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.openide.loaders; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * May be used to register multiple plain-file {@link Template}s from a single package. + * @since 7.29 + */ +@Target(ElementType.PACKAGE) +@Retention(RetentionPolicy.SOURCE) +public @interface Templates { + Template[] value(); +} diff --git a/openide.loaders/test/unit/src/org/netbeans/modules/templates/Bug138973Test.java b/openide.loaders/test/unit/src/org/netbeans/modules/templates/Bug138973Test.java --- a/openide.loaders/test/unit/src/org/netbeans/modules/templates/Bug138973Test.java +++ b/openide.loaders/test/unit/src/org/netbeans/modules/templates/Bug138973Test.java @@ -102,7 +102,7 @@ FileObject templateFile = FileUtil.createData(templatesFolder, TEMPLATE_NAME_EXT); templateFile.setAttribute ("template", Boolean.TRUE); - templateFile.setAttribute("javax.script.ScriptEngine", "js"); + templateFile.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); byte[] templateBytes = TESTING_TEXT.getBytes("ISO-8859-1"); InputStream source = new ByteArrayInputStream(templateBytes); OutputStream target = templateFile.getOutputStream(); diff --git a/openide.loaders/test/unit/src/org/netbeans/modules/templates/IndentEngineIntTest.java b/openide.loaders/test/unit/src/org/netbeans/modules/templates/IndentEngineIntTest.java --- a/openide.loaders/test/unit/src/org/netbeans/modules/templates/IndentEngineIntTest.java +++ b/openide.loaders/test/unit/src/org/netbeans/modules/templates/IndentEngineIntTest.java @@ -93,7 +93,7 @@ String txt = "print('

'); print(title); print('

');"; os.write(txt.getBytes()); os.close(); - fo.setAttribute("javax.script.ScriptEngine", "JavaScript"); + fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "JavaScript"); DataObject obj = DataObject.find(fo); diff --git a/openide.loaders/test/unit/src/org/netbeans/modules/templates/SCFTHandlerTest.java b/openide.loaders/test/unit/src/org/netbeans/modules/templates/SCFTHandlerTest.java --- a/openide.loaders/test/unit/src/org/netbeans/modules/templates/SCFTHandlerTest.java +++ b/openide.loaders/test/unit/src/org/netbeans/modules/templates/SCFTHandlerTest.java @@ -113,7 +113,7 @@ String txt = "print('

'); print(title); print('

');"; os.write(txt.getBytes()); os.close(); - fo.setAttribute("javax.script.ScriptEngine", "js"); + fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); DataObject obj = DataObject.find(fo); @@ -138,7 +138,7 @@ String txt = "print('

'); print(nameAndExt); print('

')"; os.write(txt.getBytes()); os.close(); - fo.setAttribute("javax.script.ScriptEngine", "js"); + fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); DataObject obj = DataObject.find(fo); @@ -165,14 +165,14 @@ String txt = "print('

'); print(nameAndExt); print('

')"; os.write(txt.getBytes()); os.close(); - fo.setAttribute("javax.script.ScriptEngine", "js"); + fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); FileObject fo2 = FileUtil.createData(root, "j.form"); OutputStream os2 = fo2.getOutputStream(); String txt2 = "print('

'); print(nameAndExt); print('

')"; os2.write(txt2.getBytes()); os2.close(); - fo2.setAttribute("javax.script.ScriptEngine", "js"); + fo2.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); DataObject obj = DataObject.find(fo); assertEquals("Both files", 2, obj.files().size()); @@ -215,7 +215,7 @@ "print('');"; os.write(txt.getBytes()); os.close(); - fo.setAttribute("javax.script.ScriptEngine", "js"); + fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); DataObject obj = DataObject.find(fo); @@ -262,7 +262,7 @@ FileObject xml = FileUtil.createData(xmldir, "class.txt"); OutputStream os = xml.getOutputStream(); FileUtil.copy(getClass().getResourceAsStream("utf8.xml"), os); - xml.setAttribute("javax.script.ScriptEngine", "js"); + xml.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); os.close(); DataObject obj = DataObject.find(xml); @@ -298,8 +298,8 @@ FileObject root = fs.getRoot(); FileObject fo = FileUtil.createData(root, "simpleObject.java"); FileObject fo2 = FileUtil.createData(root, "simpleObject.form"); - fo.setAttribute("javax.script.ScriptEngine", "js"); - fo2.setAttribute("javax.script.ScriptEngine", "js"); + fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); + fo2.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); Charset set = Charset.forName("iso-8859-2"); OutputStream os = fo2.getOutputStream(); diff --git a/openide.loaders/test/unit/src/org/netbeans/modules/templates/ScriptingCreateFromTemplateTest.java b/openide.loaders/test/unit/src/org/netbeans/modules/templates/ScriptingCreateFromTemplateTest.java --- a/openide.loaders/test/unit/src/org/netbeans/modules/templates/ScriptingCreateFromTemplateTest.java +++ b/openide.loaders/test/unit/src/org/netbeans/modules/templates/ScriptingCreateFromTemplateTest.java @@ -89,7 +89,7 @@ assertEquals("content/unknown", fo.getMIMEType()); fo.setAttribute ("template", Boolean.TRUE); assertEquals("content/unknown", fo.getMIMEType()); - fo.setAttribute("javax.script.ScriptEngine", "js"); + fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); DataObject obj = DataObject.find(fo); DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target")); @@ -118,7 +118,7 @@ os.write("println('#!/usr/bin/perl'); print('# ');println(license);print('# ');print(name);print(' in ');println(nameAndExt);".getBytes()); os.close(); template.setAttribute("template", true); - template.setAttribute("javax.script.ScriptEngine", "js"); + template.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); Map parameters = new HashMap(); parameters.put("license", "GPL"); parameters.put(CreateFromTemplateHandler.FREE_FILE_EXTENSION, true); @@ -163,7 +163,7 @@ os.write("test".getBytes()); os.close(); fo.setAttribute ("template", Boolean.TRUE); - fo.setAttribute("javax.script.ScriptEngine", "js"); + fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); MockServices.setServices(MockMimeLookup.class); MockMimeLookup.setInstances(MimePath.parse("content/unknown"), new TestEditorKit()); diff --git a/projectuiapi/src/org/netbeans/spi/project/ui/PrivilegedTemplates.java b/projectuiapi/src/org/netbeans/spi/project/ui/PrivilegedTemplates.java --- a/projectuiapi/src/org/netbeans/spi/project/ui/PrivilegedTemplates.java +++ b/projectuiapi/src/org/netbeans/spi/project/ui/PrivilegedTemplates.java @@ -44,6 +44,8 @@ package org.netbeans.spi.project.ui; +import org.openide.loaders.Template; + /** * List of templates which should be in the initial "privileged" list * when making a new file. @@ -65,6 +67,8 @@ /** * Lists privileged templates. * @return full paths to privileged templates, e.g. Templates/Other/XmlFile.xml + * @see Template#folder + * @see Template#content */ public String[] getPrivilegedTemplates(); diff --git a/projectuiapi/src/org/netbeans/spi/project/ui/RecommendedTemplates.java b/projectuiapi/src/org/netbeans/spi/project/ui/RecommendedTemplates.java --- a/projectuiapi/src/org/netbeans/spi/project/ui/RecommendedTemplates.java +++ b/projectuiapi/src/org/netbeans/spi/project/ui/RecommendedTemplates.java @@ -44,6 +44,8 @@ package org.netbeans.spi.project.ui; +import org.openide.loaders.Template; + /** * List of template types supported by a project when making a new file. * An instance should be placed in {@link org.netbeans.api.project.Project#getLookup} @@ -58,6 +60,7 @@ /** * Lists supported template types. * @return types of supported templates (should match template file attribute names) + * @see Template#category */ public String[] getRecommendedTypes(); diff --git a/projectuiapi/src/org/netbeans/spi/project/ui/templates/support/package.html b/projectuiapi/src/org/netbeans/spi/project/ui/templates/support/package.html --- a/projectuiapi/src/org/netbeans/spi/project/ui/templates/support/package.html +++ b/projectuiapi/src/org/netbeans/spi/project/ui/templates/support/package.html @@ -58,7 +58,7 @@ 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: +in folder the Templates. The declaration should look as follows (or @Template may be used):

<folder name="Templates">