# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\Users\mkleint\src\core-main2 # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: projectui/apichanges.xml --- projectui/apichanges.xml Base (BASE) +++ projectui/apichanges.xml Locally Modified (Based On LOCAL) @@ -54,6 +54,22 @@ + + + Added TemplateCategorySorter + + + + + +

+ Added a new SPI interface TemplatesCategorySorter allowing to post process the order of template categories for given project. + Implementations of this interface are to be put into project's lookup. If not present, standard layer ordering rules apply. +

+
+ + +
Added ProjectTemplates Index: projectui/nbproject/project.properties --- projectui/nbproject/project.properties Base (BASE) +++ projectui/nbproject/project.properties Locally Modified (Based On LOCAL) @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.6 -spec.version.base=1.39.0 +spec.version.base=1.40.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml Index: projectui/nbproject/project.xml --- projectui/nbproject/project.xml Base (BASE) +++ projectui/nbproject/project.xml Locally Modified (Based On LOCAL) @@ -279,6 +279,7 @@ org.netbeans.modules.team.ui org.netbeans.modules.welcome org.netbeans.modules.project.ui.api + org.netbeans.modules.project.ui.spi Index: projectui/src/org/netbeans/modules/project/ui/spi/TemplateCategorySorter.java --- projectui/src/org/netbeans/modules/project/ui/spi/TemplateCategorySorter.java Base (BASE) +++ projectui/src/org/netbeans/modules/project/ui/spi/TemplateCategorySorter.java Locally New @@ -0,0 +1,60 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.project.ui.spi; + +import java.util.List; +import org.openide.loaders.DataObject; + +/** + * post process the order of template categories for given project. Implementation to be included in project's lookup. + * @author mkleint + * @since 1.40 + */ +public interface TemplateCategorySorter { + + /** + * Sort the template categories + * @param original + * @return new ordering for the list. + */ + List sort(List original); +} Index: projectui/src/org/netbeans/modules/project/ui/TemplateChooserPanelGUI.java --- projectui/src/org/netbeans/modules/project/ui/TemplateChooserPanelGUI.java Base (BASE) +++ projectui/src/org/netbeans/modules/project/ui/TemplateChooserPanelGUI.java Locally Modified (Based On LOCAL) @@ -49,6 +49,7 @@ import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.swing.DefaultComboBoxModel; @@ -57,6 +58,7 @@ import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.project.Project; import static org.netbeans.modules.project.ui.Bundle.*; +import org.netbeans.modules.project.ui.spi.TemplateCategorySorter; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.loaders.DataFolder; @@ -281,9 +283,11 @@ private final class TemplateChildren extends ChildFactory.Detachable implements ActionListener { private final DataFolder folder; + private final boolean isRoot; - TemplateChildren(DataFolder folder) { + TemplateChildren(DataFolder folder, boolean root) { this.folder = folder; + isRoot = root; } @Override protected void addNotify() { @@ -295,8 +299,25 @@ } @Override protected boolean createKeys(List keys) { - for (DataObject d : folder.getChildren()) { + DataObject[] children = folder.getChildren(); + if (isRoot) { + Project p = getProject(); + TemplateCategorySorter tcs = p != null ? p.getLookup().lookup(TemplateCategorySorter.class) : null; + if (tcs != null) { + List dobjs = new ArrayList(); + for (DataObject d : children) { if (isFolderOfTemplates(d)) { + dobjs.add(d); + } + } + List sorted = tcs.sort(dobjs); + assert sorted.size() == dobjs.size(); + children = sorted.toArray(new DataObject[children.length]); + } + } + + for (DataObject d : children) { + if (isFolderOfTemplates(d)) { boolean leaf = true; for (DataObject child : ((DataFolder) d).getChildren()) { if (isFolderOfTemplates(child)) { @@ -311,7 +332,7 @@ } @Override protected Node createNodeForKey(TemplateKey k) { - return new FilterNode(k.d.getNodeDelegate(), k.leaf ? Children.LEAF : Children.create(new TemplateChildren((DataFolder) k.d), true)); + return new FilterNode(k.d.getNodeDelegate(), k.leaf ? Children.LEAF : Children.create(new TemplateChildren((DataFolder) k.d, false), true)); } @Override public void actionPerformed (ActionEvent event) { @@ -369,7 +390,7 @@ final class FileChooserBuilder implements TemplatesPanelGUI.Builder { @Override public Children createCategoriesChildren(DataFolder folder) { - return Children.create(new TemplateChildren(folder), true); + return Children.create(new TemplateChildren(folder, true), true); } @Override public Children createTemplatesChildren(DataFolder folder) {