1 19 20 package org.netbeans.lib.editor.codetemplates; 21 22 import javax.swing.JEditorPane ; 23 import javax.swing.text.Document ; 24 import javax.swing.text.JTextComponent ; 25 import javax.swing.text.PlainDocument ; 26 import org.netbeans.lib.editor.codetemplates.api.CodeTemplate; 27 import org.netbeans.lib.editor.codetemplates.api.CodeTemplateManager; 28 import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateInsertRequest; 29 import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateParameter; 30 import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateProcessor; 31 import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateProcessorFactory; 32 33 38 public class CTManagerOperationBridge { 39 40 private static final Document staticDoc = new PlainDocument (); 41 static { 42 staticDoc.putProperty("mimeType", "text/fake"); 43 } 44 45 private static final CodeTemplateManager staticManager 46 = CodeTemplateManagerOperation.getManager(staticDoc); 47 48 private static final JTextComponent staticComponent = new JEditorPane (); 49 static { 50 staticComponent.setDocument(staticDoc); 51 } 52 53 public static void test(String parametrizedText, CTProcessor processor) { 54 CodeTemplateApiPackageAccessor.get().getOperation(staticManager).testInstallProcessorFactory(new CTPFactory(processor)); 55 CodeTemplate template = staticManager.createTemporary(parametrizedText); 56 template.insert(staticComponent); 57 } 58 59 private static final class CTPFactory implements CodeTemplateProcessorFactory { 60 61 private CTProcessor processor; 62 63 CTPFactory(CTProcessor processor) { 64 this.processor = processor; 65 } 66 67 public CodeTemplateProcessor createProcessor(CodeTemplateInsertRequest request) { 68 assert (request != null); 69 processor.setRequest(request); 70 return processor; 71 } 72 73 } 74 } 75 | Popular Tags |