Help system in pure e4 application [message #1699736] |
Fri, 26 June 2015 05:43  |
Eclipse User |
|
|
|
The eclipse help system is still bound to the old workbench and cannot be used in a pure e4 application. For the purpose of an rcp app we just needed a way to display the help application in a separate browser. This is easy to accomplish in a pure e4 app. Here is how:
I startet with a pure e4 rcp app based on the features org.eclipse.e4.rcp, o.e.emf.common and o.e.emf.ecore.
In order to use the help app I had to add the following bundles:
org.eclipse.help
org.eclipse.help.webapp
org.eclipse.help.base
org.apache.lucene.analysis
org.apache.lucene.core
org.eclipse.core.net
org.eclipse.equinox.security
org.eclipse.equinox.security.macosx (for macosx only)
javax.servlet
javax.servlet.jsp
javax.el
org.eclipse.equinox.http.registry
org.eclipse.equinox.jsp.jasper.registry
org.eclipse.equinox.jsp.jasper
org.apache.jasper.glassfish
org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.servlet
org.eclipse.jetty.continuation
org.eclipse.jetty.http
org.eclipse.jetty.io
org.eclipse.jetty.security
org.eclipse.jetty.server
org.eclipse.jetty.servlet
org.eclipse.jetty.util
None of these have dependencies to org.eclipse.ui or any other 3.x stuff.
The Help Contents menu item is handled by the following:
package ch.arenae.anm.handler;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.server.WebappManager;
public class HelpContentsHandler {
@Execute
public void execute() throws Exception {
BaseHelpSystem.ensureWebappRunning();
String helpURL = "http://" //$NON-NLS-1$
+ WebappManager.getHost() + ":" //$NON-NLS-1$
+ WebappManager.getPort() + "/help/index.jsp"; //$NON-NLS-1$
BaseHelpSystem.getHelpBrowser(true).displayURL(helpURL);
}
}
For us, this is enough. But I think it could be easily enhanced to open a specific topic.
HTH
Peter
|
|
|
|
|
|
|
|
|
Re: Help system in pure e4 application [message #1827514 is a reply to message #1699736] |
Sat, 16 May 2020 07:36  |
Eclipse User |
|
|
|
For those who are looking for more details, I have done the following:
@PostConstruct
public void createControls(Composite parent, MApplication app) {
this.app = app;
parent.setLayout(new GridLayout(2, false));
// start help webapp server (we don't stop it). Note that it runs in a thread of the application JVM.
if (server == null) try {
server = new JettyHelpServer();
server.start("help");
this.baseUrl = "http://" + server.getHost() + ":" + server.getPort() + "/help/";
} catch (Exception e1) {
server = null;
return;
}
// ok ? create browser
browser = new Browser(parent, SWT.NONE);
browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
app.getContext().set(HelpPart.class, this);
....
}
This starts the help server and opens up a browser in a part where my help will display. Of course, this is layed out in my e4xmi file (in a singleton partstack that gets hidden when the user closes the help).
Then later I do:
public static void trackHelp(MApplication app) {
app.getContext().runAndTrack(new RunAndTrack() {
boolean init = true;
@Override
public boolean changed(IEclipseContext context) {
String helpId = (String) context.get(helpIdKey);
if (helpId == null && !init) return false;
init = false;
HelpPart helpPart = app.getContext().get(HelpPart.class);
if (helpPart != null && helpId != null) { // the tracker doesn't start the help system up!
IContext ctx = HelpSystem.getContext(helpId);
if (ctx.getRelatedTopics()[0] != null)
helpPart.browser.setUrl(helpPart.baseUrl + "nftopic" + ctx.getRelatedTopics()[0].getHref());
// here you can use:
// - nftopic for a wide display with no navigation (in particular not the document index)
// - topic for a not so wide display because of the presence of a left navigation panel into the document index
// Usually, we should use nftopic here because you can call the static help for the whole document
// Note also that topic has display anomalies that do not make this a palatable choice
}
return true; // This RAT doesn't stop unless we send a null
}
});
which is a RunAndTrack attached to the application where I can post the topic I wish to display. I have also added a Display filter that can automatically scan controls that get focus and read a context help id that it posts to the RunAndTrack.
private org.eclipse.swt.widgets.Listener listener = event -> {
String helpId = getHelpId(event.widget);
if (helpId != null) app.getContext().set(helpIdKey, helpId);
};
This lets me mimic the e3 help system rather closely.
The only dependency I have here on "old" code is the JettyHelpServer dependency (and everything that it draws behind it such as lucene etc.) I have no attachments to the old PlatformUI.
[Updated on: Tue, 19 May 2020 11:50] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05066 seconds