# HG changeset patch # User Milos Kleint # Date 1205765276 -3600 # Node ID 17953efeef2bfb4e778ed1a838727c2874ee9ef0 # Parent 027b9526757a026a35d813a41ad0255887ec4453 #122942 allow to place privilegedtemplates instances in node's lookup. Such an instance wil be used when constructing the popup menu under New> on that particular node, instead of falling back to the default proejct based instance. diff -r 027b9526757a -r 17953efeef2b projectui/src/org/netbeans/modules/project/ui/OpenProjectList.java --- a/projectui/src/org/netbeans/modules/project/ui/OpenProjectList.java Sun Mar 09 23:53:22 2008 -0700 +++ b/projectui/src/org/netbeans/modules/project/ui/OpenProjectList.java Mon Mar 17 15:47:56 2008 +0100 @@ -775,8 +775,8 @@ // Used from NewFile action - public List getTemplatesLRU( Project project ) { - List pLRU = getTemplateNamesLRU( project ); + public List getTemplatesLRU( Project project, PrivilegedTemplates priv ) { + List pLRU = getTemplateNamesLRU( project, priv ); List templates = new ArrayList(); FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); for( Iterator it = pLRU.iterator(); it.hasNext(); ) { @@ -1013,7 +1013,7 @@ } } - private ArrayList getTemplateNamesLRU( Project project ) { + private ArrayList getTemplateNamesLRU( Project project, PrivilegedTemplates priv ) { // First take recently used templates and try to find those which // are supported by the project. @@ -1021,25 +1021,31 @@ RecommendedTemplates rt = project.getLookup().lookup( RecommendedTemplates.class ); String rtNames[] = rt == null ? new String[0] : rt.getRecommendedTypes(); - PrivilegedTemplates pt = project.getLookup().lookup( PrivilegedTemplates.class ); - String ptNames[] = pt == null ? null : pt.getPrivilegedTemplates(); + PrivilegedTemplates pt = priv != null ? priv : project.getLookup().lookup( PrivilegedTemplates.class ); + String ptNames[] = pt == null ? null : pt.getPrivilegedTemplates(); ArrayList privilegedTemplates = new ArrayList( Arrays.asList( pt == null ? new String[0]: ptNames ) ); FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); - - synchronized (this) { - Iterator it = getRecentTemplates().iterator(); - for( int i = 0; i < NUM_TEMPLATES && it.hasNext(); i++ ) { - String templateName = it.next(); - FileObject fo = sfs.findResource( templateName ); - if ( fo == null ) { - it.remove(); // Does not exists remove - } - else if ( isRecommended( project, fo ) ) { - result.add( fo ); - privilegedTemplates.remove( templateName ); // Not to have it twice - } - else { - continue; + + if (priv == null) { + // when the privileged templates are part of the active lookup, + // do not mix them with the recent templates, but use only the privileged ones. + // eg. on Webservices node, one is not interested in a recent "jsp" file template.. + + synchronized (this) { + Iterator it = getRecentTemplates().iterator(); + for( int i = 0; i < NUM_TEMPLATES && it.hasNext(); i++ ) { + String templateName = it.next(); + FileObject fo = sfs.findResource( templateName ); + if ( fo == null ) { + it.remove(); // Does not exists remove + } + else if ( isRecommended( project, fo ) ) { + result.add( fo ); + privilegedTemplates.remove( templateName ); // Not to have it twice + } + else { + continue; + } } } } diff -r 027b9526757a -r 17953efeef2b projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java --- a/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java Sun Mar 09 23:53:22 2008 -0700 +++ b/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java Mon Mar 17 15:47:56 2008 +0100 @@ -61,6 +61,8 @@ import org.netbeans.modules.project.ui.NoProjectNew; import org.netbeans.modules.project.ui.OpenProjectList; import org.netbeans.modules.project.ui.ProjectUtilities; +import org.netbeans.spi.project.ui.PrivilegedTemplates; +import org.netbeans.spi.project.ui.RecommendedTemplates; import org.netbeans.spi.project.ui.templates.support.Templates; import org.openide.ErrorManager; import org.openide.awt.DynamicMenuContent; @@ -141,7 +143,7 @@ } NewFileWizard wd = new NewFileWizard( preselectedProject( context ) /* , null */ ); - + DataFolder preselectedFolder = preselectedFolder( context ); if ( preselectedFolder != null ) { wd.setTargetFolder( preselectedFolder ); @@ -274,8 +276,10 @@ menuItem.removeAll(); ActionListener menuListener = new PopupListener(); - - List lruList = OpenProjectList.getDefault().getTemplatesLRU( project ); + + // check the action context for recommmended/privileged templates.. + PrivilegedTemplates privs = getLookup().lookup(PrivilegedTemplates.class); + List lruList = OpenProjectList.getDefault().getTemplatesLRU( project, privs ); boolean itemAdded = false; for( Iterator it = lruList.iterator(); it.hasNext(); ) { DataObject template = (DataObject)it.next(); diff -r 027b9526757a -r 17953efeef2b projectuiapi/apichanges.xml --- a/projectuiapi/apichanges.xml Sun Mar 09 23:53:22 2008 -0700 +++ b/projectuiapi/apichanges.xml Mon Mar 17 15:47:56 2008 +0100 @@ -104,6 +104,22 @@ + + + + PrivilegedTemplates instance in global action context is preferred + + + + + + The previous scope of PrivilegedTemplates was the whole project. Now the selected Node (active context) can + also provide an instance in it's lookup and it will be used instead of the default one from project's lookup. + In this case the last used templates will not be considered. + + + + diff -r 027b9526757a -r 17953efeef2b projectuiapi/nbproject/project.properties --- a/projectuiapi/nbproject/project.properties Sun Mar 09 23:53:22 2008 -0700 +++ b/projectuiapi/nbproject/project.properties Mon Mar 17 15:47:56 2008 +0100 @@ -39,7 +39,7 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.5 -spec.version.base=1.27.0 +spec.version.base=1.28.0 is.autoload=true javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff -r 027b9526757a -r 17953efeef2b projectuiapi/src/org/netbeans/spi/project/ui/PrivilegedTemplates.java --- a/projectuiapi/src/org/netbeans/spi/project/ui/PrivilegedTemplates.java Sun Mar 09 23:53:22 2008 -0700 +++ b/projectuiapi/src/org/netbeans/spi/project/ui/PrivilegedTemplates.java Mon Mar 17 15:47:56 2008 +0100 @@ -46,6 +46,11 @@ * when making a new file. * An instance should be placed in {@link org.netbeans.api.project.Project#getLookup} * to affect the privileged list for that project. + * + *

+ * Since 1.28, the PrivilegedTemplates instance can also reside in active node's lookup + * and such instance will be used instead of the default one. + * *

* For more information about registering templates see overview of * {@link org.netbeans.spi.project.ui.templates.support} package.