1 11 12 package org.eclipse.ant.internal.ui.editor.templates; 13 14 import org.eclipse.jface.text.BadLocationException; 15 import org.eclipse.jface.text.DocumentEvent; 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.jface.text.IRegion; 18 import org.eclipse.jface.text.templates.Template; 19 import org.eclipse.jface.text.templates.TemplateContext; 20 import org.eclipse.jface.text.templates.TemplateProposal; 21 import org.eclipse.swt.graphics.Image; 22 23 public class AntTemplateProposal extends TemplateProposal { 24 25 public AntTemplateProposal(Template template, TemplateContext context, IRegion region, Image image, int relevance) { 26 super(template, context, region, image, relevance); 27 } 28 29 32 public boolean validate(IDocument document, int offset, DocumentEvent event) { 33 try { 34 int replaceOffset= getReplaceOffset(); 35 if (offset >= replaceOffset) { 36 String content= document.get(replaceOffset, offset - replaceOffset); 37 if (content.length() == 0) { 38 return true; 39 } 40 if (content.charAt(0) == '<') { 41 content= content.substring(1); 42 } 43 return getTemplate().getName().toLowerCase().startsWith(content.toLowerCase()); 44 } 45 } catch (BadLocationException e) { 46 } 48 return false; 49 } 50 } 51 | Popular Tags |