KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
15 import org.eclipse.ant.internal.ui.editor.text.XMLTextHover;
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.IRegion;
19 import org.eclipse.jface.text.ITextHover;
20 import org.eclipse.jface.text.ITextViewer;
21 import org.eclipse.jface.text.templates.TemplateContextType;
22 import org.eclipse.jface.text.templates.TemplateVariableResolver;
23
24 public class AntTemplateVariableTextHover implements ITextHover {
25
26     public AntTemplateVariableTextHover() {
27     }
28
29     /* (non-Javadoc)
30      * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
31      */

32     public String JavaDoc getHoverInfo(ITextViewer textViewer, IRegion subject) {
33         try {
34             IDocument doc= textViewer.getDocument();
35             int offset= subject.getOffset();
36             if (offset >= 2 && "${".equals(doc.get(offset-2, 2))) { //$NON-NLS-1$
37
String JavaDoc varName= doc.get(offset, subject.getLength());
38                 TemplateContextType contextType= AntTemplateAccess.getDefault().getContextTypeRegistry().getContextType(TaskContextType.TASK_CONTEXT_TYPE);
39                 if (contextType != null) {
40                     Iterator JavaDoc iter= contextType.resolvers();
41                     while (iter.hasNext()) {
42                         TemplateVariableResolver var= (TemplateVariableResolver) iter.next();
43                         if (varName.equals(var.getType())) {
44                             return var.getDescription();
45                         }
46                     }
47                 }
48             }
49         } catch (BadLocationException e) {
50         }
51         return null;
52     }
53
54     /* (non-Javadoc)
55      * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int)
56      */

57     public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
58         if (textViewer != null) {
59             return XMLTextHover.getRegion(textViewer, offset);
60         }
61         return null;
62     }
63 }
64
Popular Tags