1 19 20 21 package org.netbeans.spi.project.ui.support; 22 23 import java.util.Arrays ; 24 import java.util.LinkedHashSet ; 25 import java.util.Set ; 26 import org.netbeans.spi.project.LookupMerger; 27 import org.netbeans.spi.project.ui.PrivilegedTemplates; 28 import org.netbeans.spi.project.ui.RecommendedTemplates; 29 import org.openide.util.Lookup; 30 31 36 public final class UILookupMergerSupport { 37 38 39 private UILookupMergerSupport() { 40 } 41 42 48 public static LookupMerger createRecommendedTemplatesMerger() { 49 return new RecommendedMerger(); 50 } 51 52 58 public static LookupMerger createPrivilegedTemplatesMerger() { 59 return new PrivilegedMerger(); 60 } 61 62 private static class PrivilegedMerger implements LookupMerger<PrivilegedTemplates> { 63 public Class <PrivilegedTemplates> getMergeableClass() { 64 return PrivilegedTemplates.class; 65 } 66 67 public PrivilegedTemplates merge(Lookup lookup) { 68 return new PrivilegedTemplatesImpl(lookup); 69 } 70 } 71 72 private static class RecommendedMerger implements LookupMerger<RecommendedTemplates> { 73 74 public Class <RecommendedTemplates> getMergeableClass() { 75 return RecommendedTemplates.class; 76 } 77 78 public RecommendedTemplates merge(Lookup lookup) { 79 return new RecommendedTemplatesImpl(lookup); 80 } 81 } 82 83 private static class PrivilegedTemplatesImpl implements PrivilegedTemplates { 84 85 private Lookup lkp; 86 87 public PrivilegedTemplatesImpl(Lookup lkp) { 88 this.lkp = lkp; 89 } 90 91 public String [] getPrivilegedTemplates() { 92 Set <String > templates = new LinkedHashSet <String >(); 93 for (PrivilegedTemplates pt : lkp.lookupAll(PrivilegedTemplates.class)) { 94 templates.addAll(Arrays.asList(pt.getPrivilegedTemplates())); 95 } 96 return templates.toArray(new String [templates.size()]); 97 } 98 } 99 100 private static class RecommendedTemplatesImpl implements RecommendedTemplates { 101 102 private Lookup lkp; 103 104 public RecommendedTemplatesImpl(Lookup lkp) { 105 this.lkp = lkp; 106 } 107 108 public String [] getRecommendedTypes() { 109 Set <String > templates = new LinkedHashSet <String >(); 110 for (RecommendedTemplates pt : lkp.lookupAll(RecommendedTemplates.class)) { 111 templates.addAll(Arrays.asList(pt.getRecommendedTypes())); 112 } 113 return templates.toArray(new String [templates.size()]); 114 } 115 116 } 117 118 119 } 120 | Popular Tags |