01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.text;
11:
12: import org.eclipse.core.resources.IProject;
13: import org.eclipse.jdt.core.IJavaProject;
14: import org.eclipse.jdt.core.JavaCore;
15: import org.eclipse.jface.text.IRegion;
16: import org.eclipse.jface.text.ITextViewer;
17: import org.eclipse.pde.core.IBaseModel;
18: import org.eclipse.pde.core.IModel;
19: import org.eclipse.pde.internal.core.ICoreConstants;
20: import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
21: import org.eclipse.pde.internal.core.text.IDocumentRange;
22: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
23: import org.eclipse.pde.internal.ui.editor.PDESourcePage;
24: import org.eclipse.pde.internal.ui.util.PDEJavaHelperUI;
25:
26: public class ManifestTextHover extends PDETextHover {
27:
28: private PDESourcePage fSourcePage;
29: private IJavaProject fJP;
30:
31: public ManifestTextHover(PDESourcePage sourcePage) {
32: fSourcePage = sourcePage;
33: IProject project = ((PDEFormEditor) fSourcePage.getEditor())
34: .getCommonProject();
35: fJP = JavaCore.create(project);
36: }
37:
38: public String getHoverInfo(ITextViewer textViewer,
39: IRegion hoverRegion) {
40: int offset = hoverRegion.getOffset();
41: IDocumentRange range = fSourcePage.getRangeElement(offset,
42: false);
43: if (range instanceof IManifestHeader) {
44: IManifestHeader header = (IManifestHeader) range;
45: String headerName = header.getName();
46: if (offset >= header.getOffset() + headerName.length())
47: return checkForTranslatable(header);
48: if (fJP != null)
49: return PDEJavaHelperUI.getOSGIConstantJavaDoc(
50: headerName, fJP);
51: }
52: return null;
53: }
54:
55: private String checkForTranslatable(IManifestHeader header) {
56: String name = header.getName();
57: String value = header.getValue();
58: for (int i = 0; i < ICoreConstants.TRANSLATABLE_HEADERS.length; i++) {
59: if (name.equals(ICoreConstants.TRANSLATABLE_HEADERS[i])
60: && value.startsWith("%")) { //$NON-NLS-1$
61: IBaseModel model = ((PDEFormEditor) fSourcePage
62: .getEditor()).getAggregateModel();
63: if (model instanceof IModel)
64: return ((IModel) model).getResourceString(value);
65: }
66: }
67: return null;
68: }
69: }
|