public static void main(String[] args) { final Display d = new Display(); final IStylingEngine styleingEngine = null; Realm.runWithDefault( SWTObservables.getRealm(d), new Runnable() { public void run() { Shell shell = new Shell(d); shell.setLayout(new FillLayout()); MailView view = new MailView(shell, null); IFolder folder = ((IAccount) new MailSessionFactoryImpl() .openSession("", "john", "doe") .getAccounts() .get(0)) .getFolders() .get(0); view.setMail(folder.getSession().getMails(folder, 0, 1).get(0)); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) { d.sleep(); } } } }); d.dispose(); }
@Override protected void createGUI(final MUIElement uiRoot) { Realm.runWithDefault( DisplayRealm.getRealm(display), new Runnable() { @Override public void run() { UIStartupTest.super.createGUI(uiRoot); } }); }
@Override public void testGetSecondPart_GetContext() { // need to wrap this since the renderer will try build the UI for the // part if it hasn't been built Realm.runWithDefault( DisplayRealm.getRealm(display), new Runnable() { @Override public void run() { UIStartupTest.super.testGetSecondPart_GetContext(); } }); }
/** * Launch the application * * @param args */ public static void main(String[] args) { Display display = new Display(); Realm.runWithDefault( SWTObservables.getRealm(display), new Runnable() { public void run() { try { PhoneBookUsingDetailCompositeEmpty window = new PhoneBookUsingDetailCompositeEmpty(); window.open(); } catch (Exception e) { e.printStackTrace(); } } }); }
@Override protected IEclipseContext createApplicationContext() { final IEclipseContext[] contexts = new IEclipseContext[1]; Realm.runWithDefault( DisplayRealm.getRealm(display), new Runnable() { @Override public void run() { contexts[0] = UIStartupTest.super.createApplicationContext(); contexts[0].set(IResourceUtilities.class.getName(), new ResourceUtility()); contexts[0].set( IStylingEngine.class.getName(), new IStylingEngine() { @Override public void style(Object widget) { // no-op } @Override public void setId(Object widget, String id) { // no-op } @Override public void setClassname(Object widget, String classname) { // no-op } @Override public CSSStyleDeclaration getStyle(Object widget) { // TODO Auto-generated method stub return null; } @Override public void setClassnameAndId(Object widget, String classname, String id) { // no-op } }); } }); return contexts[0]; }
@Override protected void runEventLoop(final Display display, final CountDownLatch ready) { ready.countDown(); Realm.runWithDefault( SWTObservables.getRealm(display), new Runnable() { @Override public void run() { while (!mShutDown) { try { if (!display.readAndDispatch()) { display.sleep(); } } catch (Throwable t) { setAsyncThrowable(t); } } } }); }
/** @param args */ public static void main(String[] args) { final Display display = new Display(); Realm.runWithDefault( SWTObservables.getRealm(display), new Runnable() { public void run() { Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final UI ui = new UI(shell); final Data data = new Data(); // Bind the UI to the Data. DataBindingContext dbc = new DataBindingContext(); dbc.bindValue( SWTObservables.observeText(ui.firstName, SWT.Modify), data.firstName, null, null); dbc.bindValue( SWTObservables.observeText(ui.lastName, SWT.Modify), data.lastName, null, null); // Construct the formatted name observable. FormattedName formattedName = new FormattedName(data.firstName, data.lastName); // Bind the formatted name Text to the formatted name // observable. dbc.bindValue( SWTObservables.observeText(ui.formattedName, SWT.None), formattedName, new UpdateValueStrategy(false, UpdateValueStrategy.POLICY_NEVER), null); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }); display.dispose(); }
public static void main(String[] args) { Display display = new Display(); // note that the "runWithDefault" will be done for you if you are using // the // Workbench as opposed to just JFace/SWT. Realm.runWithDefault( SWTObservables.getRealm(display), new Runnable() { public void run() { IWizard wizard = new SampleWizard(); WizardDialog dialog = new WizardDialog(null, wizard); dialog.open(); // The SWT event loop Display display = Display.getCurrent(); while (dialog.getShell() != null && !dialog.getShell().isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } }); }
public static void main(String[] args) { final Display display = new Display(); // Set up data binding. In an RCP application, the threading Realm // will be set for you automatically by the Workbench. In an SWT // application, you can do this once, wrapping your binding // method call. Realm.runWithDefault( DisplayRealm.getRealm(display), new Runnable() { @Override public void run() { ViewModel viewModel = new ViewModel(); Shell shell = new View(viewModel).createShell(); // The SWT event loop while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } }); }
public Object run(final MApplicationElement uiRoot, final IEclipseContext runContext) { final Display display; if (runContext.get(Display.class) != null) { display = runContext.get(Display.class); } else { display = Display.getDefault(); runContext.set(Display.class, display); } Realm.runWithDefault( SWTObservables.getRealm(display), new Runnable() { public void run() { initializeStyling(display, runContext); // Register an SWT resource handler runContext.set(IResourceUtilities.class.getName(), new ResourceUtility()); // set up the keybinding manager KeyBindingDispatcher dispatcher = (KeyBindingDispatcher) ContextInjectionFactory.make(KeyBindingDispatcher.class, runContext); runContext.set(KeyBindingDispatcher.class.getName(), dispatcher); keyListener = dispatcher.getKeyDownFilter(); display.addFilter(SWT.KeyDown, keyListener); display.addFilter(SWT.Traverse, keyListener); // Show the initial UI // Create a 'limbo' shell (used to host controls that shouldn't // be in the current layout) Shell limbo = getLimboShell(); runContext.set("limbo", limbo); // HACK!! we should loop until the display gets disposed... // ...then we listen for the last 'main' window to get disposed // and dispose the Display testShell = null; theApp = null; boolean spinOnce = true; if (uiRoot instanceof MApplication) { ShellActivationListener shellDialogListener = new ShellActivationListener((MApplication) uiRoot); display.addFilter(SWT.Activate, shellDialogListener); display.addFilter(SWT.Deactivate, shellDialogListener); spinOnce = false; // loop until the app closes theApp = (MApplication) uiRoot; // long startTime = System.currentTimeMillis(); MWindow selected = theApp.getSelectedElement(); if (selected == null) { for (MWindow window : theApp.getChildren()) { createGui(window); } } else { // render the selected one first createGui(selected); for (MWindow window : theApp.getChildren()) { if (selected != window) { createGui(window); } } } // long endTime = System.currentTimeMillis(); // System.out.println("Render: " + (endTime - startTime)); // tell the app context we are starting so the splash is // torn down IApplicationContext ac = appContext.get(IApplicationContext.class); if (ac != null) ac.applicationRunning(); } else if (uiRoot instanceof MUIElement) { if (uiRoot instanceof MWindow) { testShell = (Shell) createGui((MUIElement) uiRoot); } else { // Special handling for partial models (for testing...) testShell = new Shell(display, SWT.SHELL_TRIM); createGui((MUIElement) uiRoot, testShell, null); } } TestableObject testableObject = (TestableObject) runContext.get(TestableObject.class.getName()); if (testableObject instanceof E4Testable) { ((E4Testable) testableObject) .init(display, (IWorkbench) runContext.get(IWorkbench.class.getName())); } IEventLoopAdvisor advisor = runContext.getActiveLeaf().get(IEventLoopAdvisor.class); if (advisor == null) { advisor = new IEventLoopAdvisor() { public void eventLoopIdle(Display display) { display.sleep(); } public void eventLoopException(Throwable exception) { StatusReporter statusReporter = (StatusReporter) appContext.get(StatusReporter.class.getName()); if (statusReporter != null) { statusReporter.show(StatusReporter.ERROR, "Internal Error", exception); } else { if (logger != null) { logger.error(exception); } } } }; } // Spin the event loop until someone disposes the display while (((testShell != null && !testShell.isDisposed()) || (!theApp.getChildren().isEmpty() && someAreVisible(theApp.getChildren()))) && !display.isDisposed()) { try { if (!display.readAndDispatch()) { runContext.processWaiting(); if (spinOnce) return; advisor.eventLoopIdle(display); } } catch (ThreadDeath th) { throw th; } catch (Exception ex) { handle(ex, advisor); } catch (Error err) { handle(err, advisor); } } if (!spinOnce) { cleanUp(); } } private void handle(Throwable ex, IEventLoopAdvisor advisor) { try { advisor.eventLoopException(ex); } catch (Throwable t) { if (t instanceof ThreadDeath) { throw (ThreadDeath) t; } // couldn't handle the exception, print to console t.printStackTrace(); } } }); return IApplication.EXIT_OK; }