List of usage examples for org.eclipse.jface.operation ModalContext isModalContextThread
public static boolean isModalContextThread(Thread thread)
From source file:org.eclipse.egit.ui.internal.branch.LaunchFinder.java
License:Open Source License
/** * If there is a running launch covering at least one project from the given * repositories, return the first such launch configuration. * * @param repositories/*from www .j a v a2 s . co m*/ * to determine projects to be checked whether they are used in * running launches * @param monitor * for progress reporting and cancellation * @return the {@link ILaunchConfiguration}, or {@code null} if none found. */ @Nullable public static ILaunchConfiguration getRunningLaunchConfiguration(final Collection<Repository> repositories, IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, 1); final ILaunchConfiguration[] result = { null }; IRunnableWithProgress operation = new IRunnableWithProgress() { @Override public void run(IProgressMonitor m) throws InvocationTargetException, InterruptedException { Set<IProject> projects = new HashSet<>(); for (Repository repository : repositories) { projects.addAll(Arrays.asList(ProjectUtil.getProjects(repository))); } result[0] = findLaunch(projects, m); } }; try { if (ModalContext.isModalContextThread(Thread.currentThread())) { operation.run(progress); } else { ModalContext.run(operation, true, progress, PlatformUI.getWorkbench().getDisplay()); } } catch (InvocationTargetException e) { // ignore } catch (InterruptedException e) { // ignore } return result[0]; }
From source file:org.eclipse.gmf.runtime.common.ui.util.UIModificationValidator.java
License:Open Source License
public IStatus validateEdit(IFile[] files) { Shell shell = listener == null ? null : listener.getShell(); RunnableWithStatus r = new RunnableWithStatus(files, shell); Display display = DisplayUtils.getDisplay(); ISyncExecHelper syncExecHelper = org.eclipse.gmf.runtime.common.core.command.FileModificationValidator.SyncExecHelper .getInstance();/* w w w. jav a 2 s .c om*/ if (ModalContext.isModalContextThread(Thread.currentThread())) { Runnable safeRunnable = syncExecHelper.safeRunnable(r); if (safeRunnable != null) { display.syncExec(safeRunnable); } else { r.run(); } } else { if (display == null) { r.setShell(null); } r.run(); } return r.getResult(); }