KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > text > ManifestTextHover


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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 package org.eclipse.pde.internal.ui.editor.text;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.jdt.core.IJavaProject;
15 import org.eclipse.jdt.core.JavaCore;
16 import org.eclipse.jface.text.IRegion;
17 import org.eclipse.jface.text.ITextViewer;
18 import org.eclipse.pde.core.IBaseModel;
19 import org.eclipse.pde.core.IModel;
20 import org.eclipse.pde.internal.core.ICoreConstants;
21 import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
22 import org.eclipse.pde.internal.core.text.IDocumentRange;
23 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
24 import org.eclipse.pde.internal.ui.editor.PDESourcePage;
25 import org.eclipse.pde.internal.ui.util.PDEJavaHelperUI;
26
27 public class ManifestTextHover extends PDETextHover {
28
29     private PDESourcePage fSourcePage;
30     private IJavaProject fJP;
31     
32     public ManifestTextHover(PDESourcePage sourcePage) {
33         fSourcePage = sourcePage;
34         IProject project = ((PDEFormEditor)fSourcePage.getEditor()).getCommonProject();
35         fJP = JavaCore.create(project);
36     }
37     
38     public String JavaDoc getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
39         int offset = hoverRegion.getOffset();
40         IDocumentRange range = fSourcePage.getRangeElement(offset, false);
41         if (range instanceof IManifestHeader) {
42             IManifestHeader header = (IManifestHeader)range;
43             String JavaDoc headerName = header.getName();
44             if (offset >= header.getOffset() + headerName.length())
45                 return checkForTranslatable(header);
46             if (fJP != null)
47                 return PDEJavaHelperUI.getOSGIConstantJavaDoc(headerName, fJP);
48         }
49         return null;
50     }
51
52     private String JavaDoc checkForTranslatable(IManifestHeader header) {
53         String JavaDoc name = header.getName();
54         String JavaDoc value = header.getValue();
55         for (int i = 0; i < ICoreConstants.TRANSLATABLE_HEADERS.length; i++) {
56             if (name.equals(ICoreConstants.TRANSLATABLE_HEADERS[i]) &&
57                     value.startsWith("%")) { //$NON-NLS-1$
58
IBaseModel model = ((PDEFormEditor)fSourcePage.getEditor()).getAggregateModel();
59                 if (model instanceof IModel)
60                     return ((IModel)model).getResourceString(value);
61             }
62         }
63         return null;
64     }
65 }
66
Popular Tags