So, soweit klappt jetzt alles. Die Hilfe meldet sich und die Hilfe beendet sich MIT all dem ganzen restlichen Kram im Hintergrund. *freu*
Ich hab mal die DefaultHelpUI mal zur Seite gelassen und in der BaseHelpSystem eine Methode gefunden, die auch meine Help aufruft. Hier mal der Code zum ausprobieren und freuen fuer die Communitiy.
Java Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
| package com.xyz.help.bootstrap;
import java.io.File;
@SuppressWarnings("restriction")
public class XYZHelpApplication implements IApplication,
IExecutableExtension {
private static final String APPLICATION_LOCK_FILE = ".applicationlock"; //$NON-NLS-1$
private static final int STATE_EXITING = 0;
private static final int STATE_RUNNING = 1;
private static final int STATE_RESTARTING = 2;
private static int status = STATE_RUNNING;
private File metadata;
private FileLock lock;
/*
* (non-Javadoc)
*
* @seeorg.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.
* IApplicationContext)
*/
public synchronized Object start(IApplicationContext context)
throws Exception {
if (status == STATE_RESTARTING) {
return EXIT_RESTART;
}
metadata = new File(Platform.getLocation().toFile(), ".metadata/"); //$NON-NLS-1$
if (!metadata.exists() || !metadata.isDirectory()) {
metadata.mkdirs();
}
if (!BaseHelpSystem.ensureWebappRunning()) {
System.out.println(NLS.bind(
HelpBaseResources.HelpApplication_couldNotStart, Platform
.getLogFileLocation().toOSString()));
return EXIT_OK;
}
if (status == STATE_RESTARTING) {
return EXIT_RESTART;
}
writeHostAndPort();
obtainLock();
// try running UI loop if possible
runUI();
// run a headless loop;
while (status == STATE_RUNNING) {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
break;
}
}
releaseLock();
if (status == STATE_RESTARTING) {
return EXIT_RESTART;
}
return EXIT_OK;
}
private void runUI() throws BundleException {
// TODO Auto-generated method stub
if (BaseHelpSystem.MODE_STANDALONE == BaseHelpSystem.getMode()) {
// UI loop may be sleeping if no SWT browser is up
try {
wakeupUI();
} catch (BundleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
XYZHelpUIEventLoop.run();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.equinox.app.IApplication#stop()
*/
public void stop() {
stopHelp();
// wait until start has finished
synchronized (this) {
}
;
}
/**
* Causes help service to stop and exit
*/
public static void stopHelp() {
status = STATE_EXITING;
if (BaseHelpSystem.MODE_STANDALONE == BaseHelpSystem.getMode()) {
// UI loop may be sleeping if no SWT browser is up
try {
wakeupUI();
} catch (BundleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private static void wakeupUI() throws BundleException {
// TODO Auto-generated method stub
XYZHelpUIEventLoop.wakeup();
// invoke("wakeup");
}
/**
* Causes help service to exit and start again
*/
public static void restartHelp() {
if (status != STATE_EXITING) {
status = STATE_RESTARTING;
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org
* .eclipse.core.runtime.IConfigurationElement, java.lang.String,
* java.lang.Object)
*/
@SuppressWarnings("unchecked")
public void setInitializationData(IConfigurationElement configElement,
String propertyName, Object data) {
String value = (String) ((Map) data).get("mode"); //$NON-NLS-1$
if ("infocenter".equalsIgnoreCase(value)) { //$NON-NLS-1$
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
} else if ("standalone".equalsIgnoreCase(value)) { //$NON-NLS-1$
BaseHelpSystem.setMode(BaseHelpSystem.MODE_STANDALONE);
}
}
private void writeHostAndPort() throws IOException {
Properties p = new Properties();
p.put("host", WebappManager.getHost()); //$NON-NLS-1$
p.put("port", "" + WebappManager.getPort()); //$NON-NLS-1$ //$NON-NLS-2$
File hostPortFile = new File(metadata, ".connection"); //$NON-NLS-1$
hostPortFile.deleteOnExit();
FileOutputStream out = null;
try {
out = new FileOutputStream(hostPortFile);
p.store(out, null);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException ioe2) {
}
}
}
}
private void obtainLock() {
File lockFile = new File(metadata, APPLICATION_LOCK_FILE);
try {
RandomAccessFile raf = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$
lock = raf.getChannel().lock();
} catch (IOException ioe) {
lock = null;
}
}
private void releaseLock() {
if (lock != null) {
try {
lock.channel().close();
} catch (IOException ioe) {
}
}
}
public static boolean isRunning() {
return status == STATE_RUNNING;
}
} |
Java Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| package com.xyz.help.bootstrap;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.server.WebappManager;
import org.eclipse.swt.widgets.Display;
@SuppressWarnings("restriction")
public class XYZHelpUIEventLoop {
/**
* Indicates whether run had a chance to execute and display got created
*/
private static boolean started = false;
/**
* Indicates whether it is still running
*/
private static boolean running = false;
private static Display display;
/**
* Called by base in stand-alone help since it cannot run event loop
*/
public static void run() {
try {
if (display == null)
display = Display.getCurrent();
if (display == null)
display = new Display();
} finally {
started = true;
}
try {
running = true;
///////////////////////////////////////////////////Aenderung-Start///////////////////////////////////////////////////////////////////////////////////////
XYZEmbeddedBrowserAdapter xyzEmbeddedBrowserAdapter = new XYZEmbeddedBrowserAdapter();
BaseHelpSystem.getInstance().setBrowserInstance(xyzoEmbeddedBrowserAdapter);
try {
BaseHelpSystem.getHelpBrowser(true).displayURL(getBaseURL() + "index.jsp");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
///////////////////////////////////////////////////Aenderung-Ende////////////////////////////////////////////////////////////////////////////////////////
while (XYZHelpApplication.isRunning()) {
try {
if (!display.readAndDispatch()) {
display.sleep();
}
} catch (Throwable t) {
HelpBasePlugin.logError(t.getMessage(), t);
}
}
display.dispose();
display = null;
} finally {
running = false;
}
}
public static void wakeup() {
Display d = display;
if (d != null)
try {
d.wake();
} catch (Exception e) {
}
}
/**
* Blocks until the loop is started (Display created)
*/
public static void waitFor() {
while (!started && XYZHelpApplication.isRunning()) {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
}
}
}
/**
* @return Returns if loop is running.
*/
public static boolean isRunning() {
return running;
}
private static String getBaseURL() {
return "http://" //$NON-NLS-1$
+ WebappManager.getHost() + ":" //$NON-NLS-1$
+ WebappManager.getPort() + "/help/"; //$NON-NLS-1$
}
} |
Java Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
| package com.xyz.help.bootstrap;
import org.eclipse.help.ui.internal.browser.embedded.EmbeddedBrowser;
import org.eclipse.help.ui.internal.browser.embedded.EmbeddedBrowserAdapter;
import org.eclipse.swt.widgets.Display;
@SuppressWarnings("restriction")
public class XYZEmbeddedBrowserAdapter extends EmbeddedBrowserAdapter {
private EmbeddedBrowser browser;
// Thread to use in workbench mode on Windows
private UIThread2 secondThread;
class UIThread2 extends Thread {
Display d;
boolean runEventLoop = true;
public UIThread2() {
super();
setDaemon(true);
setName("Help Browser UI"); //$NON-NLS-1$
}
public void run() {
d = new Display();
while (runEventLoop) {
if (!d.readAndDispatch()) {
d.sleep();
}
}
d.dispose();
}
public Display getDisplay() {
while (d == null && isAlive()) {
try {
sleep(40);
} catch (InterruptedException ie) {
}
}
return d;
}
public void dispose() {
runEventLoop = false;
}
}
/**
* Adapter constructor.
*/
public XYZEmbeddedBrowserAdapter() {
}
public Display getBrowserDisplay() {
return Display.getDefault();
}
public void browserClosed() {
browser=null;
if(secondThread!=null){
secondThread.dispose();
secondThread = null;
}
///////////////////////////////////////////////////Aenderung-Start///////////////////////////////////////////////////////////////////////////////////////
XYZHelpApplication.stopHelp();
///////////////////////////////////////////////////Aenderung-Ende///////////////////////////////////////////////////////////////////////////////////////
}
/*
* @see IBrowser#displayURL(String)
*/
public synchronized void displayURL(final String url) {
close();
if (getBrowserDisplay() == Display.getCurrent()) {
uiDisplayURL(url);
} else {
getBrowserDisplay().asyncExec(new Runnable() {
public void run() {
uiDisplayURL(url);
}
});
}
}
/**
* Must be run on UI thread
*
* @param url
*/
private void uiDisplayURL(final String url) {
getBrowser().displayUrl(url);
}
/*
* @see IBrowser#close()
*/
public synchronized void close() {
if (getBrowserDisplay() == Display.getCurrent()) {
uiClose();
} else {
getBrowserDisplay().syncExec(new Runnable() {
public void run() {
uiClose();
}
});
}
}
/*
* Must be run on UI thread
*/
private void uiClose() {
if (browser != null && !browser.isDisposed()){
browser.close();
}
if(secondThread!=null){
secondThread.dispose();
secondThread=null;
}
}
/**
*
*/
private EmbeddedBrowser getBrowser() {
if (browser == null || browser.isDisposed()) {
browser = new EmbeddedBrowser();
browser.addCloseListener(this);
}
return browser;
}
/*
* @see IBrowser#isCloseSupported()
*/
public boolean isCloseSupported() {
return true;
}
/*
* @see IBrowser#isSetLocationSupported()
*/
public boolean isSetLocationSupported() {
return true;
}
/*
* @see IBrowser#isSetSizeSupported()
*/
public boolean isSetSizeSupported() {
return true;
}
/*
* @see IBrowser#setLocation(int, int)
*/
public synchronized void setLocation(final int x, final int y) {
if (getBrowserDisplay() == Display.getCurrent()) {
uiSetLocation(x, y);
} else {
getBrowserDisplay().asyncExec(new Runnable() {
public void run() {
uiSetLocation(x, y);
}
});
}
}
/*
* Must be run on UI thread
*/
private void uiSetLocation(int x, int y) {
getBrowser().setLocation(x, y);
}
/*
* @see IBrowser#setSize(int, int)
*/
public synchronized void setSize(final int width, final int height) {
if (getBrowserDisplay() == Display.getCurrent()) {
uiSetSize(width, height);
} else {
getBrowserDisplay().asyncExec(new Runnable() {
public void run() {
uiSetSize(width, height);
}
});
}
}
/*
* Must be run on UI thread
*/
private void uiSetSize(int width, int height) {
getBrowser().setSize(width, height);
}
} |
Fuer jeden Verbesserungsvorschlag bin ich jederzeit Ohr!