Java Code Examples for org.eclipse.swt.widgets.Display.syncExec()

The following are Jave code examples for showing how to use syncExec() of the org.eclipse.swt.widgets.Display class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: neoscada   File: Application.java   Source Code and License Vote up 7 votes
@Override
public void stop ()
{
    if ( !PlatformUI.isWorkbenchRunning () )
    {
        return;
    }
    final IWorkbench workbench = PlatformUI.getWorkbench ();
    final Display display = workbench.getDisplay ();
    display.syncExec ( new Runnable () {
        @Override
        public void run ()
        {
            if ( !display.isDisposed () )
            {
                workbench.close ();
            }
        }
    } );
}
 
Example 2
Project: neoscada   File: Application.java   Source Code and License Vote up 6 votes
@Override
public void stop ()
{
    if ( !PlatformUI.isWorkbenchRunning () )
    {
        return;
    }
    final IWorkbench workbench = PlatformUI.getWorkbench ();
    final Display display = workbench.getDisplay ();
    display.syncExec ( new Runnable () {
        @Override
        public void run ()
        {
            if ( !display.isDisposed () )
            {
                workbench.close ();
            }
        }
    } );
}
 
Example 3
Project: convertigo-eclipse   File: ConvertigoPlugin.java   Source Code and License Vote up 6 votes
private static void messageBoxWithoutReturnCode(final String message, int options) {
	final Display display = getDisplay();
	
	Runnable runnable = new Runnable() {
		public void run() {
			try {
				messageBox(null, message, SWT.OK | SWT.ICON_INFORMATION);
			}
			catch (Exception e){
				ConvertigoPlugin.logException(e, "Error while trying to open message box");
			}
		};
	};
	
	if (display.getThread() != Thread.currentThread()) {
		display.asyncExec(runnable);		
	} else {
		display.syncExec(runnable);
	}
}
 
Example 4
Project: n4js   File: N4JSApplication.java   Source Code and License Vote up 5 votes
@Override
public void stop() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench == null)
		return;
	final Display display = workbench.getDisplay();
	display.syncExec(new Runnable() {
		@Override
		public void run() {
			if (!display.isDisposed())
				workbench.close();
		}
	});
}
 
Example 5
Project: neoscada   File: Application.java   Source Code and License Vote up 5 votes
public void stop() {
	if (!PlatformUI.isWorkbenchRunning())
		return;
	final IWorkbench workbench = PlatformUI.getWorkbench();
	final Display display = workbench.getDisplay();
	display.syncExec(new Runnable() {
		public void run() {
			if (!display.isDisposed())
				workbench.close();
		}
	});
}
 
Example 6
Project: gw4e.project   File: ExecutionContextSelectionUIPage.java   Source Code and License Vote up 5 votes
private void loadAncestor(IFile file) {
	Display display = Display.getCurrent();
	Runnable longJob = new Runnable() {
		public void run() {
			display.syncExec(new Runnable() {
				public void run() {
					ancestors = JDTManager.findAvailableExecutionContextAncestors(file);
				}
			});
			display.wake();
		}
	};
	BusyIndicator.showWhile(display, longJob);

}
 
Example 7
Project: gw4e.project   File: JUnitGW4ETestUIPage.java   Source Code and License Vote up 5 votes
/**
 * 
 */
private void loadVertices() {
	Display display = Display.getCurrent();
	Runnable longJob = new Runnable() {
		public void run() {
			display.syncExec(new Runnable() {
				public void run() {
					IFile ifile = ResourceManager.toIFile(selection);
					String modelFileName = null;

					try {
						modelFileName = ResourceManager.getAbsolutePath(ifile);
						context = GraphWalkerFacade.getContext(modelFileName);
						updateUI();
					} catch (Exception e) {
						ResourceManager.logException(e);
						JUnitGW4ETestUIPage.this.setErrorMessage(
								"Unable to load the graph model. See error logs in the Error View.");
						return;
					}

					comboReachedVertexViewer.setInput(_loadVertices(context));
				}
			});
			display.wake();
		}
	};
	BusyIndicator.showWhile(display, longJob);
}
 
Example 8
Project: gw4e.project   File: GeneratorChoiceComposite.java   Source Code and License Vote up 5 votes
private void loadAncestor(IFile file) {
	Display display = Display.getCurrent();
	Runnable longJob = new Runnable() {
		public void run() {
			display.syncExec(new Runnable() {
				public void run() {
					ancestors = JDTManager.findAvailableExecutionContextAncestors(file);
				}
			});
			display.wake();
		}
	};
	BusyIndicator.showWhile(display, longJob);
	 
}
 
Example 9
Project: gw4e.project   File: BuildPoliciesCheckboxTableViewer.java   Source Code and License Vote up 5 votes
/**
 * 
 */
public void loadBuildPolicies() {
	Display display = Display.getCurrent();
	Runnable longJob = new Runnable() {
		public void run() {
			display.syncExec(new Runnable() {
				public void run() {
					List<BuildPolicy> policies;
					try {
						if (file!=null) {
							policies = BuildPolicyManager.getBuildPolicies(file, false);
						} else {
							policies = new ArrayList<BuildPolicy>();
						}
					} catch (Exception e) {
						// DialogManager.displayErrorMessage(MessageUtil.getString("error"), e.getMessage(),e);
						// throw new RuntimeException(e);
						policies = new ArrayList<BuildPolicy>();
					}
					BuildPolicy[] input = policies.stream().filter(item -> !item.hasTimeDuratioStopCondition())
							.toArray(BuildPolicy[]::new);
					setInput(input);
				}
			});
			display.wake();
		}
	};
	BusyIndicator.showWhile(display, longJob);
}
 
Example 10
Project: Hydrograph   File: Application.java   Source Code and License Vote up 5 votes
public void stop() {
	if (!PlatformUI.isWorkbenchRunning())
		return;
	final IWorkbench workbench = PlatformUI.getWorkbench();
	final Display display = workbench.getDisplay();
	display.syncExec(new Runnable() {
		public void run() {
			if (!display.isDisposed())
				workbench.close();
		}
	});
}
 
Example 11
Project: Hydrograph   File: SaveJobFileBeforeRunDialog.java   Source Code and License Vote up 5 votes
private Image getSWTImage() {
	Shell shell = getShell();
	final Display display;
	if (shell == null || shell.isDisposed()) {
		shell = getParentShell();
	}
	if (shell == null || shell.isDisposed()) {
		display = Display.getCurrent();
		// The dialog should be always instantiated in UI thread.
		// However it was possible to instantiate it in other threads
		// (the code worked in most cases) so the assertion covers
		// only the failing scenario. See bug 107082 for details.
		Assert.isNotNull(display,
				"The dialog should be created in UI thread"); //$NON-NLS-1$
	} else {
		display = shell.getDisplay();
	}

	final Image[] image = new Image[1];
	display.syncExec(new Runnable() {
		public void run() {
			image[0] = display.getSystemImage(SWT.ICON_QUESTION);
		}
	});

	return image[0];

}
 
Example 12
Project: eZooKeeper   File: SwtThreadSafeDelegatingInvocationHandler.java   Source Code and License Vote up 4 votes
@Override
protected Object subInvoke(Object proxy, Method method, Object[] args) throws Throwable {

    Display currentDisplay = Display.getCurrent();
    Display widgetDisplay = null;

    Widget widget = getWidget();
    if (widget != null) {
        if (widget.isDisposed()) {
            // System.err.println("ERROR:  Invoking: " + method.getName() + " on Widget: " + widget +
            // " which is disposed.");
            return null;
        }
        widgetDisplay = widget.getDisplay();
    }

    if (currentDisplay == null && widgetDisplay == null) {
        // The current thread is not a UI thread but no widget display was provided so...
        return baseInvoke(proxy, method, args);
    }
    else if (currentDisplay != null && (widgetDisplay == null || currentDisplay == widgetDisplay)) {
        // Current thread is the widget's UI thread (or at least *a* UI thread).
        return baseInvoke(proxy, method, args);
    }
    else {
        // Current thread is not the widget's UI thread.

        IBaseInvokeRunnable runnable = createBaseInvokeRunnable(proxy, method, args);

        if (isAsync()) {
            widgetDisplay.asyncExec(runnable);
            return null;
        }

        widgetDisplay.syncExec(runnable);
        Throwable error = runnable.getError();
        if (error != null) {
            throw error;
        }
        return runnable.getResult();
    }
}
 
Example 13
Project: xcalendar   File: SwtUtils.java   Source Code and License Vote up 4 votes
public static void sync(@Nullable Display display, Runnable task) {
	if(display == null) display = getDisplay(); display.syncExec(task);
}
 
Example 14
Project: BiglyBT   File: ShellSlider.java   Source Code and License Vote up 4 votes
/**
 * Slide In
 *
 * @param shell
 * @param direction
 * @param endBounds
 */
public ShellSlider(final Shell shell, int direction, final Rectangle endBounds) {
	this.shell = shell;
	this.endBounds = endBounds;
	this.slideIn = true;
	this.direction = direction;

	if (shell == null || shell.isDisposed())
		return;

	Display display = shell.getDisplay();
	display.syncExec(new Runnable() {
		@Override
		public void run() {
			if (shell.isDisposed())
				return;

			switch (ShellSlider.this.direction) {
				case SWT.UP:
				default:
					shell.setLocation(endBounds.x, endBounds.y);
					Rectangle displayBounds = null;
					try {
						boolean ok = false;
						Monitor[] monitors = shell.getDisplay().getMonitors();
						for (int i = 0; i < monitors.length; i++) {
							Monitor monitor = monitors[i];
							displayBounds = monitor.getBounds();
							if (displayBounds.contains(endBounds.x, endBounds.y)) {
								ok = true;
								break;
							}
						}
						if (!ok) {
							displayBounds = shell.getMonitor().getBounds();
						}
					} catch (Throwable t) {
						displayBounds = shell.getDisplay().getBounds();
					}

					shellBounds = new Rectangle(endBounds.x, displayBounds.y
							+ displayBounds.height, endBounds.width, 0);
					break;
			}
			shell.setBounds(shellBounds);
			shell.setVisible(true);

			if (DEBUG)
				System.out.println("Slide In: " + shell.getText());
		}
	});
}