1 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 30 public EmbeddedBrowserFactory() { 31 super(); 32 } 33 34 37 public boolean isAvailable() { 38 if (BaseHelpSystem.getMode() == BaseHelpSystem.MODE_STANDALONE) { 39 try { 40 if (HelpUIEventLoop.isRunning()) { 41 Display.getDefault().syncExec(new Runnable () { 42 public void run() { 43 test(); 44 } 45 }); 46 } 47 } catch (Exception e) { 48 } 50 } else { 51 test(); 52 } 53 tested = true; 54 return available; 55 } 56 57 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 available = false; 77 } else { 78 HelpUIPlugin 79 .logError( 80 "An error occurred during creation of embedded help browser.", se); } 82 } catch (Exception e) { 83 } 85 if (sh != null && !sh.isDisposed()) 86 sh.dispose(); 87 } 88 return available; 89 } 90 91 94 public IBrowser createBrowser() { 95 return new EmbeddedBrowserAdapter(); 96 } 97 } 98 | Popular Tags |