This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 122942
Collapse All | Expand All

(-)a/projectui/src/org/netbeans/modules/project/ui/OpenProjectList.java (-20 / +26 lines)
Lines 775-782 Link Here
775
775
776
               
776
               
777
    // Used from NewFile action        
777
    // Used from NewFile action        
778
    public List<DataObject> getTemplatesLRU( Project project ) {
778
    public List<DataObject> getTemplatesLRU( Project project,  PrivilegedTemplates priv ) {
779
        List<FileObject> pLRU = getTemplateNamesLRU( project );
779
        List<FileObject> pLRU = getTemplateNamesLRU( project,  priv );
780
        List<DataObject> templates = new ArrayList<DataObject>();
780
        List<DataObject> templates = new ArrayList<DataObject>();
781
        FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
781
        FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
782
        for( Iterator<FileObject> it = pLRU.iterator(); it.hasNext(); ) {
782
        for( Iterator<FileObject> it = pLRU.iterator(); it.hasNext(); ) {
Lines 1013-1019 Link Here
1013
        }
1013
        }
1014
    }
1014
    }
1015
        
1015
        
1016
    private ArrayList<FileObject> getTemplateNamesLRU( Project project ) {
1016
    private ArrayList<FileObject> getTemplateNamesLRU( Project project, PrivilegedTemplates priv ) {
1017
        // First take recently used templates and try to find those which
1017
        // First take recently used templates and try to find those which
1018
        // are supported by the project.
1018
        // are supported by the project.
1019
        
1019
        
Lines 1021-1045 Link Here
1021
        
1021
        
1022
        RecommendedTemplates rt = project.getLookup().lookup( RecommendedTemplates.class );
1022
        RecommendedTemplates rt = project.getLookup().lookup( RecommendedTemplates.class );
1023
        String rtNames[] = rt == null ? new String[0] : rt.getRecommendedTypes();
1023
        String rtNames[] = rt == null ? new String[0] : rt.getRecommendedTypes();
1024
        PrivilegedTemplates pt = project.getLookup().lookup( PrivilegedTemplates.class );
1024
        PrivilegedTemplates pt = priv != null ? priv : project.getLookup().lookup( PrivilegedTemplates.class );
1025
        String ptNames[] = pt == null ? null : pt.getPrivilegedTemplates();
1025
        String ptNames[] = pt == null ? null : pt.getPrivilegedTemplates();        
1026
        ArrayList<String> privilegedTemplates = new ArrayList<String>( Arrays.asList( pt == null ? new String[0]: ptNames ) );
1026
        ArrayList<String> privilegedTemplates = new ArrayList<String>( Arrays.asList( pt == null ? new String[0]: ptNames ) );
1027
        FileSystem sfs = Repository.getDefault().getDefaultFileSystem();            
1027
        FileSystem sfs = Repository.getDefault().getDefaultFileSystem();            
1028
                
1028
        
1029
        synchronized (this) {
1029
        if (priv == null) {
1030
            Iterator<String> it = getRecentTemplates().iterator();
1030
            // when the privileged templates are part of the active lookup,
1031
            for( int i = 0; i < NUM_TEMPLATES && it.hasNext(); i++ ) {
1031
            // do not mix them with the recent templates, but use only the privileged ones.
1032
                String templateName = it.next();
1032
            // eg. on Webservices node, one is not interested in a recent "jsp" file template..
1033
                FileObject fo = sfs.findResource( templateName );
1033
            
1034
                if ( fo == null ) {
1034
            synchronized (this) {
1035
                    it.remove(); // Does not exists remove
1035
                Iterator<String> it = getRecentTemplates().iterator();
1036
                }
1036
                for( int i = 0; i < NUM_TEMPLATES && it.hasNext(); i++ ) {
1037
                else if ( isRecommended( project, fo ) ) {
1037
                    String templateName = it.next();
1038
                    result.add( fo );
1038
                    FileObject fo = sfs.findResource( templateName );
1039
                    privilegedTemplates.remove( templateName ); // Not to have it twice
1039
                    if ( fo == null ) {
1040
                }
1040
                        it.remove(); // Does not exists remove
1041
                else {
1041
                    }
1042
                    continue;
1042
                    else if ( isRecommended( project, fo ) ) {
1043
                        result.add( fo );
1044
                        privilegedTemplates.remove( templateName ); // Not to have it twice
1045
                    }
1046
                    else {
1047
                        continue;
1048
                    }
1043
                }
1049
                }
1044
            }
1050
            }
1045
        }
1051
        }
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java (-3 / +7 lines)
Lines 61-66 Link Here
61
import org.netbeans.modules.project.ui.NoProjectNew;
61
import org.netbeans.modules.project.ui.NoProjectNew;
62
import org.netbeans.modules.project.ui.OpenProjectList;
62
import org.netbeans.modules.project.ui.OpenProjectList;
63
import org.netbeans.modules.project.ui.ProjectUtilities;
63
import org.netbeans.modules.project.ui.ProjectUtilities;
64
import org.netbeans.spi.project.ui.PrivilegedTemplates;
65
import org.netbeans.spi.project.ui.RecommendedTemplates;
64
import org.netbeans.spi.project.ui.templates.support.Templates;
66
import org.netbeans.spi.project.ui.templates.support.Templates;
65
import org.openide.ErrorManager;
67
import org.openide.ErrorManager;
66
import org.openide.awt.DynamicMenuContent;
68
import org.openide.awt.DynamicMenuContent;
Lines 141-147 Link Here
141
        }
143
        }
142
144
143
        NewFileWizard wd = new NewFileWizard( preselectedProject( context ) /* , null */ );
145
        NewFileWizard wd = new NewFileWizard( preselectedProject( context ) /* , null */ );
144
146
        
145
        DataFolder preselectedFolder = preselectedFolder( context );
147
        DataFolder preselectedFolder = preselectedFolder( context );
146
        if ( preselectedFolder != null ) {
148
        if ( preselectedFolder != null ) {
147
            wd.setTargetFolder( preselectedFolder );
149
            wd.setTargetFolder( preselectedFolder );
Lines 274-281 Link Here
274
        menuItem.removeAll();
276
        menuItem.removeAll();
275
277
276
        ActionListener menuListener = new PopupListener();
278
        ActionListener menuListener = new PopupListener();
277
279
        
278
        List lruList = OpenProjectList.getDefault().getTemplatesLRU( project );
280
        // check the action context for recommmended/privileged templates..
281
        PrivilegedTemplates privs = getLookup().lookup(PrivilegedTemplates.class);
282
        List lruList = OpenProjectList.getDefault().getTemplatesLRU( project, privs );
279
        boolean itemAdded = false;
283
        boolean itemAdded = false;
280
        for( Iterator it = lruList.iterator(); it.hasNext(); ) {
284
        for( Iterator it = lruList.iterator(); it.hasNext(); ) {
281
            DataObject template = (DataObject)it.next();
285
            DataObject template = (DataObject)it.next();
(-)a/projectuiapi/apichanges.xml (+16 lines)
Lines 104-109 Link Here
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
105
106
    <changes>
106
    <changes>
107
        
108
        <change id="folder-based-privileged-templates">
109
            <api name="general"/>
110
            <summary>PrivilegedTemplates instance in global action context is preferred</summary>
111
            <version major="1" minor="28"/>
112
            <date day="21" month="3" year="2008"/>
113
            <author login="mkleint"/>
114
            <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
115
            <description>
116
                The previous scope of PrivilegedTemplates was the whole project. Now the selected Node (active context) can
117
                also provide an instance in it's lookup and it will be used instead of the default one from project's lookup.
118
                In this case the last used templates will not be considered.
119
            </description>
120
            <class package="org.netbeans.spi.project.ui" name="PrivilegedTemplates"/>
121
            <issue number="122942"/>
122
        </change>
107
        
123
        
108
        <change id="observe-opening-closing">
124
        <change id="observe-opening-closing">
109
            <api name="general"/>
125
            <api name="general"/>
(-)a/projectuiapi/nbproject/project.properties (-1 / +1 lines)
Lines 39-45 Link Here
39
39
40
javac.compilerargs=-Xlint -Xlint:-serial
40
javac.compilerargs=-Xlint -Xlint:-serial
41
javac.source=1.5
41
javac.source=1.5
42
spec.version.base=1.27.0
42
spec.version.base=1.28.0
43
is.autoload=true
43
is.autoload=true
44
javadoc.arch=${basedir}/arch.xml
44
javadoc.arch=${basedir}/arch.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
45
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/projectuiapi/src/org/netbeans/spi/project/ui/PrivilegedTemplates.java (+5 lines)
Lines 46-51 Link Here
46
 * when making a new file.
46
 * when making a new file.
47
 * An instance should be placed in {@link org.netbeans.api.project.Project#getLookup}
47
 * An instance should be placed in {@link org.netbeans.api.project.Project#getLookup}
48
 * to affect the privileged list for that project.
48
 * to affect the privileged list for that project.
49
 * 
50
 * <p>
51
 * Since 1.28, the PrivilegedTemplates instance can also reside in active node's lookup
52
 * and such instance will be used instead of the default one.
53
 * 
49
 * <p>
54
 * <p>
50
 * For more information about registering templates see overview of
55
 * For more information about registering templates see overview of
51
 * {@link org.netbeans.spi.project.ui.templates.support} package.
56
 * {@link org.netbeans.spi.project.ui.templates.support} package.

Return to bug 122942