KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > templates > AntTemplateProposal


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /* (non-Javadoc)
30      * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
31      */

32     public boolean validate(IDocument document, int offset, DocumentEvent event) {
33         try {
34             int replaceOffset= getReplaceOffset();
35             if (offset >= replaceOffset) {
36                 String JavaDoc 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             // concurrent modification - ignore
47
}
48         return false;
49     }
50 }
51
Popular Tags