KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > UISynchronizationContext


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ui.internal.editors.text;
12
13 import org.eclipse.core.filebuffers.ISynchronizationContext;
14
15 import org.eclipse.swt.widgets.Display;
16
17 import org.eclipse.ui.IWorkbench;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.PlatformUI;
20
21 /**
22  * Synchronization context for file buffers whose documents are shown in the UI.
23  * The synchronization runnable is executed in the UI thread.
24  *
25  * @since 3.0
26  */

27 public class UISynchronizationContext implements ISynchronizationContext {
28
29     /*
30      * @see org.eclipse.core.filebuffers.ISynchronizationContext#run(java.lang.Runnable)
31      */

32     public void run(Runnable JavaDoc runnable) {
33         if (Display.getCurrent() != null) {
34             runnable.run();
35         } else {
36             IWorkbench workbench= PlatformUI.getWorkbench();
37             IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
38             if (windows != null && windows.length > 0) {
39                 Display display= windows[0].getShell().getDisplay();
40                 display.asyncExec(runnable);
41             } else {
42                 runnable.run();
43             }
44         }
45     }
46 }
47
Popular Tags