/** * Hook the given Listener to the Mac OS X application Quit menu and the IActions to the About and * Preferences menus. * * @param display The Display to use. * @param quitListener The listener to invoke when the Quit menu is invoked. * @param aboutAction The action to run when the About menu is invoked. * @param preferencesAction The action to run when the Preferences menu is invoked. */ public void hookApplicationMenu( Display display, Listener quitListener, IAction aboutAction, IAction preferencesAction) { // This is our callbackObject whose 'actionProc' method will be called when the About or // Preferences menuItem is invoked. MenuHookObject target = new MenuHookObject(aboutAction, preferencesAction); try { // Initialize the menuItems. initialize(target); } catch (Exception e) { throw new IllegalStateException(e); } // Connect the quit/exit menu. if (!display.isDisposed()) { display.addListener(SWT.Close, quitListener); } // Schedule disposal of callback object display.disposeExec( new Runnable() { public void run() { invoke(proc3Args, "dispose"); } }); }
public Main(String args[]) { // must be before display is created (on Macs at least) Display.setAppName("BrailleZephyr"); Display display = Display.getDefault(); // needed to catch Quit (Command-Q) on Macs display.addListener(SWT.Close, new CloseHandler()); shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("BrailleZephyr"); shell.addShellListener(new ShellHandler()); bzStyledText = new BZStyledText(shell); bzFile = new BZFile(bzStyledText); bzSettings = new BZSettings(bzStyledText); new BZMenu(bzStyledText, bzFile, bzSettings); // assume any argument is a file to open if (args.length > 0) bzFile.openFile(args[0]); shell.open(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); display.dispose(); }
private static void installColorUpdater(final Display display) { display.addListener( SWT.Settings, new Listener() { @Override public void handleEvent(Event event) { cacheColors(display); } }); }
// @Override public Object startX(IApplicationContext context) throws Exception { final Display display = PlatformUI.createDisplay(); final TakariWorkbenchAdvisor advisor = new TakariWorkbenchAdvisor(); display.addListener(SWT.OpenDocument, advisor.getOpenDocumentHandler()); // FIXME: Check unhandled arguments for a pom.xml file and treat like an // OpenDocument for (String arg : (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS)) { File f = new File(arg); if (f.exists()) { if ("pom.xml".equals(f.getName())) { Event e = new Event(); e.text = arg; advisor.getOpenDocumentHandler().handleEvent(e); } else if (f.isDirectory() && (f = new File(f, "pom.xml")).exists()) { Event e = new Event(); e.text = f.getPath(); advisor.getOpenDocumentHandler().handleEvent(e); } } } try { int returnCode = PlatformUI.createAndRunWorkbench(display, advisor); if (returnCode == PlatformUI.RETURN_RESTART) { return IApplication.EXIT_RESTART; } return IApplication.EXIT_OK; } finally { Location loc = Platform.getInstanceLocation(); if (loc != null) { loc.release(); } display.dispose(); } }
/* * (non-Javadoc) * * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext context) */ @Override public Object start(IApplicationContext appContext) throws Exception { // Display display = createDisplay(); // processor must be created before we start event loop // DelayedEventsProcessor processor = new DelayedEventsProcessor(display); final Display display = PlatformUI.createDisplay(); final TakariWorkbenchAdvisor advisor = new TakariWorkbenchAdvisor(); display.addListener(SWT.OpenDocument, advisor.getOpenDocumentHandler()); // FIXME: Check unhandled arguments for a pom.xml file and treat like an // OpenDocument for (String arg : (String[]) appContext.getArguments().get(IApplicationContext.APPLICATION_ARGS)) { File f = new File(arg); if (f.exists()) { if ("pom.xml".equals(f.getName())) { Event e = new Event(); e.text = arg; advisor.getOpenDocumentHandler().handleEvent(e); } else if (f.isDirectory() && (f = new File(f, "pom.xml")).exists()) { Event e = new Event(); e.text = f.getPath(); advisor.getOpenDocumentHandler().handleEvent(e); } } } try { // look and see if there's a splash shell we can parent off of Shell shell = WorkbenchPlugin.getSplashShell(display); if (shell != null) { // should should set the icon and message for this shell to be the // same as the chooser dialog - this will be the guy that lives in // the task bar and without these calls you'd have the default icon // with no message. shell.setText(ChooseWorkspaceDialog.getWindowTitle()); shell.setImages(Window.getDefaultImages()); } Object instanceLocationCheck = checkInstanceLocation(shell, appContext.getArguments()); if (instanceLocationCheck != null) { WorkbenchPlugin.unsetSplashShell(display); appContext.applicationRunning(); return instanceLocationCheck; } // create the workbench with this advisor and run it until it exits // N.B. createWorkbench remembers the advisor, and also registers // the workbench globally so that all UI plug-ins can find it using // PlatformUI.getWorkbench() or AbstractUIPlugin.getWorkbench() // int returnCode = PlatformUI.createAndRunWorkbench(display, new // TakariWorkbenchAdvisor(processor)); int returnCode = PlatformUI.createAndRunWorkbench(display, advisor); // the workbench doesn't support relaunch yet (bug 61809) so // for now restart is used, and exit data properties are checked // here to substitute in the relaunch return code if needed if (returnCode != PlatformUI.RETURN_RESTART) { return EXIT_OK; } // if the exit code property has been set to the relaunch code, then // return that code now, otherwise this is a normal restart return EXIT_RELAUNCH.equals(Integer.getInteger(PROP_EXIT_CODE)) ? EXIT_RELAUNCH : EXIT_RESTART; } finally { if (display != null) { display.dispose(); } Location instanceLoc = Platform.getInstanceLocation(); if (instanceLoc != null) { instanceLoc.release(); } } }
/** * Constructor. * * @param display display used as a source of event */ public DelayedEventsProcessor(Display display) { display.addListener(SWT.OpenDocument, this); }