diff -r 1d3b47a829ee api.templates/apichanges.xml
--- a/api.templates/apichanges.xml Wed Feb 04 11:19:46 2015 +0100
+++ b/api.templates/apichanges.xml Wed Feb 04 12:19:01 2015 +0100
@@ -54,6 +54,20 @@
+
+
+ Package like Target Chooser for HTML Wizards
+
+
+
+
+
+ One can use targetChooser:java
+ to request Java-like target chooser showing java packages.
+
+
+
HTML UI for Templates
diff -r 1d3b47a829ee api.templates/arch.xml
--- a/api.templates/arch.xml Wed Feb 04 11:19:46 2015 +0100
+++ b/api.templates/arch.xml Wed Feb 04 12:19:01 2015 +0100
@@ -361,6 +361,7 @@
+
It is very common that the HTML file creation wizards (either
controled by JavaScript or by
Java) need to allow user to specify
@@ -368,13 +369,26 @@
to ensure its UI is consistent with the rest of the environment,
one can just include following code snippet in the HTML file and
leave its actual rendering on the system:
+
<section data-bind="step: 'targetChooser'" >
</section>
-
+
+
Such section will then be replaced by a panel which provides appropriate
UI for choosing target directory as well as name for the newly created
file.
+
+
+
+ In case one prefers more Java-like chooser, it is possible to use
+ 'targetChooser:java'
as name of the step. Then all
+ Java source groups in target project will be listed and presented
+ in a typical Java package view selection mode. Once can use different
+ suffix than java
to list other types of source groups.
+ This feature requires presence of org.netbeans.modules.java.project.ui
+ module, otherwise the target chooser falls back to classical one.
+
@@ -511,7 +525,12 @@
- No.
+
+ Uses reflection to access JavaTemplates
from module
+ org.netbeans.modules.java.project.ui
in order to
+ create Java-like package chooser. If the module is not available,
+ the wizard falls back to classical target chooser.
+
diff -r 1d3b47a829ee api.templates/manifest.mf
--- a/api.templates/manifest.mf Wed Feb 04 11:19:46 2015 +0100
+++ b/api.templates/manifest.mf Wed Feb 04 12:19:01 2015 +0100
@@ -2,5 +2,5 @@
AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.netbeans.api.templates
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/templates/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.2
+OpenIDE-Module-Specification-Version: 1.3
OpenIDE-Module-Recommends: org.netbeans.templates.IndentEngine
diff -r 1d3b47a829ee apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/wizardHTML.html
--- a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/wizardHTML.html Wed Feb 04 11:19:46 2015 +0100
+++ b/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/wizard/wizardHTML.html Wed Feb 04 12:19:01 2015 +0100
@@ -30,7 +30,10 @@
diff -r 1d3b47a829ee java.project.ui/arch.xml
--- a/java.project.ui/arch.xml Wed Feb 04 11:19:46 2015 +0100
+++ b/java.project.ui/arch.xml Wed Feb 04 12:19:01 2015 +0100
@@ -637,6 +637,13 @@
not depend on project-specific APIs and there is no declarative registration
for DataNode
context menus.
+
+ Templatesui module is using reflection to access
+ JavaTemplates
class from this module
+ in order to
+ create Java-like package chooser.
+
+
diff -r 1d3b47a829ee java.project.ui/manifest.mf
--- a/java.project.ui/manifest.mf Wed Feb 04 11:19:46 2015 +0100
+++ b/java.project.ui/manifest.mf Wed Feb 04 12:19:01 2015 +0100
@@ -3,7 +3,7 @@
OpenIDE-Module-Layer: org/netbeans/modules/java/project/ui/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/ui/Bundle.properties
OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker
-OpenIDE-Module-Specification-Version: 1.64
+OpenIDE-Module-Specification-Version: 1.65
OpenIDE-Module-Recommends: org.netbeans.spi.java.project.runner.JavaRunnerImplementation
AutoUpdate-Show-In-Client: false
diff -r 1d3b47a829ee java.project.ui/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplates.java
--- a/java.project.ui/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplates.java Wed Feb 04 11:19:46 2015 +0100
+++ b/java.project.ui/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplates.java Wed Feb 04 12:19:01 2015 +0100
@@ -44,11 +44,12 @@
package org.netbeans.spi.java.project.support.ui.templates;
-import org.netbeans.api.annotations.common.StaticResource;
import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectUtils;
import org.netbeans.modules.java.project.ui.JavaTargetChooserPanel;
import org.netbeans.modules.java.project.ui.NewJavaFileWizardIterator;
import org.netbeans.api.project.SourceGroup;
+import org.netbeans.api.project.Sources;
import org.openide.WizardDescriptor;
import org.netbeans.api.templates.TemplateRegistration;
@@ -72,6 +73,14 @@
public static WizardDescriptor.Panel createPackageChooser(Project project, SourceGroup[] folders) throws IllegalArgumentException {
return createPackageChooser(project, folders, null);
}
+
+ // friend API method used from templatesui module
+ static WizardDescriptor.Panel createPackageChooser(Object project, String type) throws Exception {
+ Project p = (Project) project;
+ Sources src = ProjectUtils.getSources(p);
+ SourceGroup[] groups = src.getSourceGroups(type);
+ return JavaTemplates.createPackageChooser(p, groups);
+ }
/**
* Create a Java-oriented target chooser suitable for templates which are Java
diff -r 1d3b47a829ee java.project.ui/test/unit/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplatesTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java.project.ui/test/unit/src/org/netbeans/spi/java/project/support/ui/templates/JavaTemplatesTest.java Wed Feb 04 12:19:01 2015 +0100
@@ -0,0 +1,64 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2015 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 2015 Sun Microsystems, Inc.
+ */
+package org.netbeans.spi.java.project.support.ui.templates;
+
+import java.lang.reflect.Method;
+import org.junit.Test;
+
+/**
+ * @author Jaroslav Tulach
+ */
+public class JavaTemplatesTest {
+
+ public JavaTemplatesTest() {
+ }
+
+ @Test
+ public void testCreatePackageChooserForTemplatesUIExists() throws Exception {
+ ClassLoader l = JavaTemplatesTest.class.getClassLoader();
+ Class> clazz = Class.forName("org.netbeans.spi.java.project.support.ui.templates.JavaTemplates", true, l); // NOI18N
+ Method create = clazz.getDeclaredMethod("createPackageChooser", Object.class, String.class); // NOI18N
+ create.setAccessible(true);
+ }
+
+
+}
diff -r 1d3b47a829ee templatesui/src/org/netbeans/modules/templatesui/AbstractWizard.java
--- a/templatesui/src/org/netbeans/modules/templatesui/AbstractWizard.java Wed Feb 04 11:19:46 2015 +0100
+++ b/templatesui/src/org/netbeans/modules/templatesui/AbstractWizard.java Wed Feb 04 12:19:01 2015 +0100
@@ -44,9 +44,11 @@
import java.awt.Dimension;
import java.io.IOException;
import java.io.InterruptedIOException;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -73,7 +75,6 @@
import org.openide.WizardValidationException;
import org.openide.loaders.DataObject;
import org.openide.loaders.TemplateWizard;
-import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
@@ -154,9 +155,18 @@
cnt = 1;
}
for (int i = 0; i < cnt; i++) {
- if (steps.size() > i && "targetChooser".equals(steps.get(i))) { // NOI18N
- panels.add(wizard.targetChooser());
- continue;
+ if (steps.size() > i) {
+ final String panelName = steps.get(i);
+ if ("targetChooser".equals(panelName)) { // NOI18N
+ panels.add(wizard.targetChooser());
+ continue;
+ }
+ final String tcPrefix = "targetChooser:"; // NOI18N
+ if (panelName != null && panelName.startsWith(tcPrefix)) {
+ WizardDescriptor.Panel panel = aw.getChooser(wizard, panelName.substring(tcPrefix.length()));
+ panels.add(panel);
+ continue;
+ }
}
final HTMLPanel p = new HTMLPanel(i, aw);
panels.add(p);
@@ -395,7 +405,7 @@
List names = new ArrayList<>();
for (Object s : obj) {
String id = stringOrId(s, "text", "id"); // NOI18N
- if ("targetChooser".equals(id)) { // NOI18N
+ if (id != null && id.equals("targetChooser") || id.startsWith("targetChooser:")) { // NOI18N
id = Bundle.LBL_TargetPanel_Name();
}
names.add(id);
@@ -549,4 +559,37 @@
@JavaScriptBody(args = { "raw" }, body = "ko.applyBindings(raw);")
static native void applyBindings(Object raw);
+
+ Map> choosers;
+ WizardDescriptor.Panel getChooser(TemplateWizard wizard, String type) {
+ if (choosers == null) {
+ choosers = new HashMap<>();
+ }
+ WizardDescriptor.Panel panel = choosers.get(type);
+
+ if (panel == null) {
+ try {
+ ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
+ if (l == null) {
+ l = Thread.currentThread().getContextClassLoader();
+ }
+ if (l == null) {
+ l = AbstractWizard.class.getClassLoader();
+ }
+ Class> clazz = Class.forName("org.netbeans.spi.java.project.support.ui.templates.JavaTemplates", true, l); // NOI18N
+ Method create = clazz.getDeclaredMethod("createPackageChooser", Object.class, String.class); // NOI18N
+ create.setAccessible(true);
+ panel = (WizardDescriptor.Panel) create.invoke(
+ null, wizard.getProperty("project"), type // NOI18N
+ );
+ } catch (Throwable t) {
+ LOG.log(Level.WARNING, "Cannot create targetChooser for type " + type + " using default. "
+ + "Don't forget to include org.netbeans.modules.java.project.ui module in your application.", t
+ );
+ panel = wizard.targetChooser();
+ }
+ choosers.put(type, panel);
+ }
+ return panel;
+ }
}