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 |
} |