Java Code Examples for org.eclipse.jface.internal.text.html.HTMLPrinter#insertPageProlog()

The following examples show how to use org.eclipse.jface.internal.text.html.HTMLPrinter#insertPageProlog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultEObjectHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected XtextBrowserInformationControlInput getHoverInfo(EObject element, IRegion hoverRegion,
		XtextBrowserInformationControlInput previous) {
	String html = getHoverInfoAsHtml(element);
	if (html != null) {
		StringBuffer buffer = new StringBuffer(html);
		ColorRegistry registry = JFaceResources.getColorRegistry();
		RGB fgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
		RGB bgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
		if (fgRGB != null && bgRGB != null) {
			HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, getStyleSheet());
		} else {
			HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
		}
		HTMLPrinter.addPageEpilog(buffer);
		html = buffer.toString();
		return new XtextBrowserInformationControlInput(previous, element, html, labelProvider);
	}
	return null;
}
 
Example 2
Source File: NLSStringHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String toHtml(String header, String string, String errorString, boolean addPreFormatted) {
	StringBuffer buffer= new StringBuffer();
	HTMLPrinter.addSmallHeader(buffer, header);

	if (string != null) {
		if (addPreFormatted) {
			HTMLPrinter.addParagraph(buffer, ""); //$NON-NLS-1$
			HTMLPrinter.addPreFormatted(buffer, HTMLPrinter.convertToHTMLContent(string));
		} else {
			HTMLPrinter.addParagraph(buffer, string);
		}
		if (errorString != null) {
			HTMLPrinter.addParagraph(buffer, errorString);
		}
	} else {
		HTMLPrinter.addParagraph(buffer, JavaHoverMessages.NLSStringHover_NLSStringHover_missingKeyWarning);
	}

	HTMLPrinter.insertPageProlog(buffer, 0);
	HTMLPrinter.addPageEpilog(buffer);
	return buffer.toString();
}
 
Example 3
Source File: XbaseHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected XtextBrowserInformationControlInput getHoverInfo(EObject element, IRegion hoverRegion,
		XtextBrowserInformationControlInput previous) {
	//TODO remove this check when the typesystem works without a java project
	if (isValidationDisabled(element))
		return null;
	EObject objectToView = getObjectToView(element);
	if(objectToView == null || objectToView.eIsProxy())
		return null;
	String html = getHoverInfoAsHtml(element, objectToView, hoverRegion);
	if (html != null) {
		StringBuffer buffer = new StringBuffer(html);
		ColorRegistry registry = JFaceResources.getColorRegistry();
		RGB fgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
		RGB bgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
		if (fgRGB != null && bgRGB != null) {
			HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, getStyleSheet());
		} else {
			HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
		}
		HTMLPrinter.addPageEpilog(buffer);
		html = buffer.toString();
		IJavaElement javaElement = null;
		if (objectToView != element && objectToView instanceof JvmIdentifiableElement) {
			javaElement = javaElementFinder.findElementFor((JvmIdentifiableElement) objectToView);
		}
		return new XbaseInformationControlInput(previous, objectToView, javaElement, html, labelProvider);
	}
	return null;
}
 
Example 4
Source File: HTMLTypeScriptPrinter.java    From typescript.java with MIT License 5 votes vote down vote up
public static void endPage(StringBuffer buffer, ITextViewer textViewer) {
	ITheme theme = null;
	if (textViewer != null) {
		TMPresentationReconciler reconciler = getTMPresentationReconciler(textViewer);
		if (reconciler != null) {
			theme = (ITheme) reconciler.getTokenProvider();
		}
		if (theme == null) {
			theme = TMUIPlugin.getThemeManager().getDefaultTheme();
		}
	}
	HTMLPrinter.insertPageProlog(buffer, 0, colorInfoForeground, colorInfoBackround,
			HTMLTypeScriptPrinter.getStyleSheet() + (theme != null ? theme.toCSSStyleSheet() : ""));
	HTMLPrinter.addPageEpilog(buffer);
}
 
Example 5
Source File: AbstractJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
	if (getProposalInfo() != null) {
		String info= getProposalInfo().getInfo(monitor);
		if (info != null && info.length() > 0) {
			StringBuffer buffer= new StringBuffer();
			HTMLPrinter.insertPageProlog(buffer, 0, getCSSStyles());

			buffer.append(info);

			IJavaElement element= null;
			try {
				element= getProposalInfo().getJavaElement();
				if (element instanceof IMember) {
					String base= JavaDocLocations.getBaseURL(element, ((IMember) element).isBinary());
					if (base != null) {
						int endHeadIdx= buffer.indexOf("</head>"); //$NON-NLS-1$
						buffer.insert(endHeadIdx, "\n<base href='" + base + "'>\n"); //$NON-NLS-1$ //$NON-NLS-2$
					}
				}
			} catch (JavaModelException e) {
				JavaPlugin.log(e);
			}

			HTMLPrinter.addPageEpilog(buffer);
			info= buffer.toString();

			return new JavadocBrowserInformationControlInput(null, element, info, 0);
		}
	}
	return null;
}
 
Example 6
Source File: AbstractDocumentationHover.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Computes the hover info and returns a {@link DocumentationBrowserInformationControlInput} for it.
 * 
 * @param element
 *            the resolved element
 * @param useHTMLTags
 * @param previousInput
 *            the previous input, or <code>null</code>
 * @param editorPart
 *            (can be <code>null</code>)
 * @param hoverRegion
 * @return the HTML hover info for the given element(s) or <code>null</code> if no information is available
 */
@SuppressWarnings("unused")
protected DocumentationBrowserInformationControlInput getHoverInfo(Object element, boolean useHTMLTags,
		DocumentationBrowserInformationControlInput previousInput, IEditorPart editorPart, IRegion hoverRegion)
{
	if (element == null)
	{
		return null;
	}
	StringBuffer buffer = new StringBuffer();
	String base = null;

	int leadingImageWidth = 0;
	setHeader(getHeader(element, editorPart, hoverRegion), buffer, useHTMLTags);
	setDocumentation(getDocumentation(element, editorPart, hoverRegion), buffer, useHTMLTags);
	if (buffer.length() > 0)
	{
		if (useHTMLTags)
		{
			Color borderColor = getBorderColor();
			Color bgColor = getBackgroundColor();
			Color fgColor = getForegroundColor();

			String borderColorHex = (borderColor != null) ? getHexColor(borderColor.getRGB())
					: DEFAULT_BORDER_COLOR;
			RGB bgRGB = (bgColor != null) ? bgColor.getRGB() : null;
			RGB fgRGB = (fgColor != null) ? fgColor.getRGB() : null;

			// We need to set the border color before we call insertPageProlog on the style-sheet
			String styleSheet = getStyleSheet();
			styleSheet = styleSheet.replaceAll(BORDER_COLOR_CSS_TEXT, borderColorHex);
			HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, styleSheet);
			if (base != null)
			{
				int endHeadIdx = buffer.indexOf("</head>"); //$NON-NLS-1$
				buffer.insert(endHeadIdx, "\n<base href='" + base + "'>\n"); //$NON-NLS-1$ //$NON-NLS-2$
			}
			HTMLPrinter.addPageEpilog(buffer);
		}
		return new DocumentationBrowserInformationControlInput(previousInput, element, buffer.toString(),
				leadingImageWidth, hoverRegion);
	}
	return null;
}