Community
Participate
Working Groups
Build ID: eclipse-SDK-3.2.2-win32.zip Steps To Reproduce: The attached are derivation work because of restrictive access to private classes. The attached file is provided to provide a means where customers can access the source so that the EPL is upheld, and perhaps encourage the powers that be loosen restrictions so the class can be subclassed. More information:
Created attachment 61279 [details] derived from HTMLPrinter
Created attachment 61280 [details] dervied from Strings.java
I'm marking this as WONTFIX because - we don't make that particular class API as a whole, rather we would make BrowserInformationControl (bug 218482) and/or HTML2TextReader (bug 241896). - this bug contains two different proposed APIs from different components.
@Ed: you recently expressed the wish for HTMLPrinter to be API. As per comment 2, could you please elaborate why you need it in a way that BrowserInformationControl or HTML2TextReader don't help? I imagine if there are decent reasons, we can reopen this issue.
Here is what each project is doing. EMF and Oomph do this: protected void computeInformation() { MouseEvent hoverEvent = getHoverEvent(); Event event = new Event(); event.x = hoverEvent.x; event.y = hoverEvent.y; if (shouldCreateToolTip(event)) { StringBuffer buffer = new StringBuffer(text); String styleSheet = getStyleSheet(); FontData fontData = JFaceResources.getFontRegistry().getFontData(getSymbolicFont())[0]; styleSheet = HTMLPrinter.convertTopLevelFont(styleSheet, fontData); HTMLPrinter.insertPageProlog(buffer, 0, foregroundColor == null ? null : foregroundColor.getRGB(), backgroundColor == null ? null : backgroundColor.getRGB(), styleSheet); HTMLPrinter.addPageEpilog(buffer); final String html = buffer.toString(); setInformation (new BrowserInformationControlInput(null) { @Override public String getHtml() { return html; } @Override public String getInputName() { return ""; } @Override public Object getInputElement() { return text; } }, currentCell.getBounds()); currentCell = null; } else { setInformation(null, null); } } JDT does this: protected void doSetInput(Object input) { String javadocHtml; if (input instanceof String) { javadocHtml= (String) input; } else { StringBuffer buffer= new StringBuffer(); HTMLPrinter.insertPageProlog(buffer, 0, null, fBackgroundColorRGB, fgStyleSheet); HTMLPrinter.addPageEpilog(buffer); javadocHtml= buffer.toString(); } fOriginalInput= javadocHtml; if (fInputSelectionProvider != null) { IJavaElement inputElement= getOrignalInput(); StructuredSelection selection= inputElement == null ? StructuredSelection.EMPTY : new StructuredSelection(inputElement); fInputSelectionProvider.setSelection(selection); } if (fOpenBrowserAction != null) fOpenBrowserAction.setEnabled(input != null); if (fIsUsingBrowserWidget) { if (javadocHtml != null && javadocHtml.length() > 0) { boolean RTL= (getSite().getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0; if (RTL) { StringBuffer buffer= new StringBuffer(javadocHtml); HTMLPrinter.insertStyles(buffer, new String[] { "direction:rtl" } ); //$NON-NLS-1$ javadocHtml= buffer.toString(); } } fBrowser.setText(javadocHtml); } else { fPresentation.clear(); Rectangle size= fText.getClientArea(); try { javadocHtml= fPresenter.updatePresentation(fText, javadocHtml, fPresentation, size.width, size.height); } catch (IllegalArgumentException ex) { // the javadoc might no longer be valid return; } fText.setText(javadocHtml); TextPresentation.applyTextPresentation(fPresentation, fText); } } and this: 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; } Xtext does this: 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; } The methods HTMLPrinter do the job. I think adding static methods to some class that is not internal would suffice, leaving the internal class where it is would suffice.
I would also like to see the static methods of HTMLPrinter as API. We also use them in SAP's ABAP Development Tools