KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > browser > embedded > EmbeddedBrowserFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal.browser.embedded;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.help.browser.*;
15 import org.eclipse.help.internal.base.*;
16 import org.eclipse.help.ui.internal.*;
17 import org.eclipse.osgi.service.environment.*;
18 import org.eclipse.swt.*;
19 import org.eclipse.swt.browser.*;
20 import org.eclipse.swt.widgets.*;
21
22 public class EmbeddedBrowserFactory implements IBrowserFactory {
23     private boolean tested = false;
24
25     private boolean available = false;
26
27     /**
28      * Constructor.
29      */

30     public EmbeddedBrowserFactory() {
31         super();
32     }
33
34     /*
35      * @see IBrowserFactory#isAvailable()
36      */

37     public boolean isAvailable() {
38         if (BaseHelpSystem.getMode() == BaseHelpSystem.MODE_STANDALONE) {
39             try {
40                 if (HelpUIEventLoop.isRunning()) {
41                     Display.getDefault().syncExec(new Runnable JavaDoc() {
42                         public void run() {
43                             test();
44                         }
45                     });
46                 }
47             } catch (Exception JavaDoc e) {
48                 // just in case
49
}
50         } else {
51             test();
52         }
53         tested = true;
54         return available;
55     }
56
57     /**
58      * Must run on UI thread
59      *
60      * @return
61      */

62     private boolean test() {
63         if (!Constants.OS_WIN32.equalsIgnoreCase(Platform.getOS())
64                 && !Constants.OS_LINUX.equalsIgnoreCase(Platform.getOS())) {
65             return false;
66         }
67         if (!tested) {
68             tested = true;
69             Shell sh = new Shell();
70             try {
71                 new Browser(sh, SWT.NONE);
72                 available = true;
73             } catch (SWTError se) {
74                 if (se.code == SWT.ERROR_NO_HANDLES) {
75                     // Browser not implemented
76
available = false;
77                 } else {
78                     HelpUIPlugin
79                             .logError(
80                                     "An error occurred during creation of embedded help browser.", se); //$NON-NLS-1$
81
}
82             } catch (Exception JavaDoc e) {
83                 // Browser not implemented
84
}
85             if (sh != null && !sh.isDisposed())
86                 sh.dispose();
87         }
88         return available;
89     }
90
91     /*
92      * @see IBrowserFactory#createBrowser()
93      */

94     public IBrowser createBrowser() {
95         return new EmbeddedBrowserAdapter();
96     }
97 }
98
Popular Tags