package ie.dcu.apps.ist.actions; import ie.dcu.swt.layout.LayoutFactory; import org.eclipse.swt.*; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; /** * Show a help dialog. * * @author Kevin McGuinness */ public class HelpAction extends AppAction { private HelpBox dialog; public HelpAction(ActionManager m) { super(m); } @Override public void run() { if (dialog == null) { dialog = new HelpBox(); } if (dialog.available()) { dialog.open(); } else { info("Help browser unavailable on this system"); } } /** * Help dialog box, just wraps a browser. */ private class HelpBox { private Shell shell; private Composite content; private Browser browser; public HelpBox() { createShell(); createContent(); } private void createShell() { shell = new Shell(window.getShell(), SWT.SHELL_TRIM); // Prevent the shell from disposing on close shell.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent evt) { evt.doit = false; close(); } }); // Use a fill layout shell.setLayout(new GridLayout()); // Set size and title shell.setSize(640, 480); shell.setText("Help"); } private void createContent() { // Create content pane content = new Composite(shell, SWT.BORDER); content.setLayout(new FillLayout()); content.setLayoutData(LayoutFactory.createGridData()); // Add browser widget try { browser = new Browser(content, SWT.NONE); } catch (SWTError e) { // Log warning and return log.warning("Browser unavailable: " + e.getMessage()); browser = null; return; } // Go to help home page home(); } public void home() { String urlString = string("helpURL"); if (urlString != null) { go(urlString); } else { browser.setText("Help file is unavailable."); } } public void go(String url) { browser.setUrl(url); } public boolean available() { return browser != null; } public void open() { shell.setVisible(true); } public void close() { shell.setVisible(false); } } }