use of org.eclipse.jface.text.DefaultInformationControl.IInformationPresenter in project mylyn.docs by eclipse.
the class InformationPresenterUtil method getHtmlInformationPresenter.
/**
* Get an information presenter to present the provided HTML content. The returned presenter is ready for displaying
* the information, all that is left to do is call {@link InformationPresenter#showInformation()}.
*
* @param viewer
* the viewer for which the information control should be created
* @param constraint
* the size constraint
* @param toolBarManager
* the tool bar manager, or null if there should be none
* @param htmlContent
* the HTML content to be displayed by the information presenter.
* @return the presenter
*/
public static InformationPresenter getHtmlInformationPresenter(ISourceViewer viewer, SizeConstraint constraint, final ToolBarManager toolBarManager, String htmlContent) {
Control control = viewer.getTextWidget();
InformationPresenter presenter = (InformationPresenter) control.getData(DATA_INFORMATION_PRESENTER);
// bug 270059: ensure that the size/positioning math works by specifying the offet of the
// current selection.
int offset = viewer.getSelectedRange().x;
IInformationControlCreator informationControlCreator;
if (presenter == null) {
informationControlCreator = new IInformationControlCreator() {
@SuppressWarnings("deprecation")
public IInformationControl createInformationControl(Shell shell) {
try {
// DefaultInformationControl(Shell parent, ToolBarManager toolBarManager, IInformationPresenter presenter);
return DefaultInformationControl.class.getConstructor(Shell.class, ToolBarManager.class, IInformationPresenter.class).newInstance(shell, toolBarManager, new HtmlTextPresenter());
} catch (NoSuchMethodException e) {
// no way with 3.3 to get V_SCROLL and a ToolBarManager
return new DefaultInformationControl(shell, SWT.RESIZE, SWT.V_SCROLL | SWT.H_SCROLL, new HtmlTextPresenter());
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
};
presenter = new InformationPresenter(informationControlCreator) {
@Override
public IInformationProvider getInformationProvider(String contentType) {
IInformationProvider informationProvider = super.getInformationProvider(contentType);
if (informationProvider == null) {
informationProvider = super.getInformationProvider(IDocument.DEFAULT_CONTENT_TYPE);
}
return informationProvider;
}
};
presenter.install(viewer);
presenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
// default values from AbstractInformationControlManager
presenter.setMargins(6, 6);
presenter.setOffset(offset);
presenter.install(viewer);
final InformationPresenter informationPresenter = presenter;
viewer.getTextWidget().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
try {
informationPresenter.uninstall();
} catch (Exception e2) {
}
informationPresenter.dispose();
}
});
control.setData(DATA_INFORMATION_PRESENTER, presenter);
control.setData(DATA_INFORMATION_CONTROL_CREATOR, informationControlCreator);
} else {
informationControlCreator = (IInformationControlCreator) control.getData(DATA_INFORMATION_CONTROL_CREATOR);
presenter.disposeInformationControl();
}
presenter.setSizeConstraints(constraint.horizontalWidthInChars, constraint.verticalWidthInChars, constraint.enforceAsMinimumSize, constraint.enforceAsMaximumSize);
InformationProvider informationProvider = new InformationProvider(new org.eclipse.jface.text.Region(offset, 0), htmlContent, informationControlCreator);
for (String contentType : FastMarkupPartitioner.ALL_CONTENT_TYPES) {
presenter.setInformationProvider(informationProvider, contentType);
}
presenter.setInformationProvider(informationProvider, IDocument.DEFAULT_CONTENT_TYPE);
return presenter;
}
Aggregations