1 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 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 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 checkForTranslatable(IManifestHeader header) { 53 String name = header.getName(); 54 String 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("%")) { 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 |