1 19 20 package org.netbeans.lib.editor.codetemplates.api; 21 22 import java.util.Collection ; 23 import javax.swing.event.ChangeListener ; 24 import javax.swing.text.Document ; 25 import org.netbeans.lib.editor.codetemplates.CodeTemplateApiPackageAccessor; 26 import org.netbeans.lib.editor.codetemplates.CodeTemplateManagerOperation; 27 import org.netbeans.lib.editor.codetemplates.CodeTemplateSpiPackageAccessor; 28 import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateProcessor; 29 30 37 public final class CodeTemplateManager { 38 39 static { 40 CodeTemplateApiPackageAccessor.register(new ApiAccessor()); 41 } 42 43 48 public static CodeTemplateManager get(Document doc) { 49 return CodeTemplateManagerOperation.getManager(doc); 50 } 51 52 private CodeTemplateManagerOperation operation; 53 54 private CodeTemplateManager(CodeTemplateManagerOperation operation) { 55 this.operation = operation; 56 } 57 58 65 public Collection getCodeTemplates() { 66 waitLoaded(); return operation.getCodeTemplates(); 68 } 69 70 76 public CodeTemplate createTemporary(String parametrizedText) { 77 return new CodeTemplate(operation, "", "", parametrizedText, null); } 79 80 88 public boolean isLoaded() { 89 return operation.isLoaded(); 90 } 91 92 97 public void waitLoaded() { 98 operation.waitLoaded(); 99 } 100 101 116 public void registerLoadedListener(ChangeListener listener) { 117 operation.registerLoadedListener(listener); 118 } 119 120 CodeTemplateManagerOperation getOperation() { 121 return operation; 122 } 123 124 private static final class ApiAccessor extends CodeTemplateApiPackageAccessor { 125 126 public CodeTemplateManager createCodeTemplateManager(CodeTemplateManagerOperation operation) { 127 return new CodeTemplateManager(operation); 128 } 129 130 public CodeTemplateManagerOperation getOperation(CodeTemplateManager manager) { 131 return manager.getOperation(); 132 } 133 134 public CodeTemplateManagerOperation getOperation(CodeTemplate codeTemplate) { 135 return codeTemplate.getOperation(); 136 } 137 138 public CodeTemplate createCodeTemplate( 139 CodeTemplateManagerOperation managerOperation, 140 String abbreviation, String description, String parametrizedText) { 141 return new CodeTemplate(managerOperation, abbreviation, description, parametrizedText, null); 142 } 143 144 } 145 146 } 147 | Popular Tags |