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

The following examples show how to use org.eclipse.swt.widgets.Display#syncExec() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EclipseUIUtils.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Shows then returns with the view with the given unique view part identifier. May return with {@code null} if the
 * view cannot be found.
 *
 * @param id
 *            the unique ID of the view part to show.
 * @return the view part or {@code null} if the view part cannot be shown.
 */
public static IViewPart showView(final String id) {
	checkNotNull(id, "Provided view ID was null.");

	final AtomicReference<IViewPart> result = new AtomicReference<>();
	final Display display = PlatformUI.getWorkbench().getDisplay();
	display.syncExec(() -> {
		try {
			result.set(getActivePage().showView(id));
		} catch (PartInitException e) {
			final String message = "Error occurred while initializing view with ID: '" + id + "'.";
			LOGGER.error(message, e);
			throw new RuntimeException(message, e);
		}
	});

	return result.get();
}
 
Example 2
Source File: ParseSpecHandler.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * @deprecated
 */
protected void saveDirtyEditors()
{
    Display display = UIHelper.getCurrentDisplay(); 
    display.syncExec(new Runnable() {
        public void run()
        {
            IWorkbenchWindow[] windows = Activator.getDefault().getWorkbench().getWorkbenchWindows();
            for (int i = 0; i < windows.length; i++)
            {
                IWorkbenchPage[] pages = windows[i].getPages();
                for (int j = 0; j < pages.length; j++)
                    pages[j].saveAllEditors(false);
            }
        }
    });
}
 
Example 3
Source File: AcquireLockUi.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static void aquireAndRun(Identifiable identifiable, ILockHandler lockhandler){
	Display display = Display.getDefault();
	LockResponse result = LocalLockServiceHolder.get().acquireLock(identifiable);
	if (result.isOk()) {
		
		display.syncExec(new Runnable() {
			@Override
			public void run(){
				lockhandler.lockAcquired();
			}
		});
		LocalLockServiceHolder.get().releaseLock(identifiable);
	} else {
		
		display.syncExec(new Runnable() {
			@Override
			public void run(){
				lockhandler.lockFailed();
				LockResponseHelper.showInfo(result, identifiable, logger);
			}
		});
	}
}
 
Example 4
Source File: DebuggerTestUtils.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This method can be used to switch to a given perspective
 * @param perspectiveId the id of the perspective that should be activated.
 * @return the exception raised or null.
 */
public void switchToPerspective(final String perspectiveId) {
    final IWorkbench workBench = PydevPlugin.getDefault().getWorkbench();
    Display display = workBench.getDisplay();

    // Make sure to run the UI thread.
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            IWorkbenchWindow window = workBench.getActiveWorkbenchWindow();
            try {
                workBench.showPerspective(perspectiveId, window);
            } catch (WorkbenchException e) {
                failException = e;
            }
        }
    });
}
 
Example 5
Source File: Application.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
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
Source File: Application.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@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 7
Source File: ContentAssistant.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * showAssist
 * 
 * @param showStyle
 */
protected void showAssist(final int showStyle)
{
	final Display d = fContentAssistSubjectControlAdapter.getControl().getDisplay();
	if (d != null)
	{
		try
		{
			d.syncExec(new Runnable()
			{
				public void run()
				{
					Control c = d.getFocusControl();
					if (c == null)
					{
						return;
					}

					if (showStyle == SHOW_PROPOSALS)
					{
						fProposalPopup.showProposals(true);
					}
					else if (showStyle == SHOW_CONTEXT_INFO && fContextInfoPopup != null)
					{
						fContextInfoPopup.showContextProposals(true);
					}
					// }
				}
			});
		}
		catch (SWTError e)
		{
		}
	}
}
 
Example 8
Source File: EclipseSWTSynchronizer.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private void exec(Runnable runnable, boolean async) {
  try {
    Display display = getDisplay();

    /*
     * this will not work, although the chance is really small, it is
     * possible that the device is disposed after this check and before
     * the a(sync)Exec call
     */
    // if (display.isDisposed())
    // return;

    if (async) display.asyncExec(runnable);
    else display.syncExec(runnable);

  } catch (SWTException e) {

    if (PlatformUI.getWorkbench().isClosing()) {
      log.warn(
          "could not execute runnable " + runnable + ", UI thread is not available",
          new StackTrace());
    } else {
      log.error(
          "could not execute runnable "
              + runnable
              + ", workbench display was disposed before workbench shutdown",
          e);
    }
  }
}
 
Example 9
Source File: DialogWithToggle.java    From eclipse-explorer with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get an <code>Image</code> from the provide SWT image constant.
 *
 * @param imageID
 *            the SWT image constant
 * @return image the image
 */
private Image getSWTImage(final int imageID) {
    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() {
        @Override
        public void run() {
            image[0] = display.getSystemImage(imageID);
        }
    });
    
    return image[0];
    
}
 
Example 10
Source File: RepositoriesView.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void refresh(Object object, boolean refreshRepositoriesFolders) {
	final Object finalObject = object;
          final boolean finalRefreshReposFolders = refreshRepositoriesFolders;
	Display display = getViewer().getControl().getDisplay();
	display.syncExec(new Runnable() {
		public void run() {
			RepositoriesView.this.refreshViewer(finalObject, finalRefreshReposFolders);
		}
	});
}
 
Example 11
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void run(final Runnable r) {
	final Display d = getDisplay();
	if (d != null && !d.isDisposed()) {
		if (d.getThread() == Thread.currentThread()) {
			r.run();
		} else {
			d.syncExec(r);
		}
	} else {
		r.run();
	}
}
 
Example 12
Source File: OpenBrowserUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens the given url in the browser as choosen in the preferences.
 * 
 * @param url the URL
 * @param display the display
 * @since 3.6
 */
public static void open(final URL url, Display display) {
	display.syncExec(new Runnable() {
		public void run() {
			internalOpen(url, false);
		}
	});
}
 
Example 13
Source File: Application.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void stop() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench == null) {
		return;
	}
	final Display display = workbench.getDisplay();
	display.syncExec(new Runnable() {
		public void run() {
			if (!display.isDisposed()) {
				workbench.close();
			}
		}
	});
}
 
Example 14
Source File: Application.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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 15
Source File: UserDialog.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Fire this message
 */
public boolean open(){
	final Display display = Display.getDefault();
	UserDialogRunnable runnable = new UserDialogRunnable(display);
	display.syncExec(runnable);
	return runnable.getResult();
}
 
Example 16
Source File: Application.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void stop() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench == null)
		return;
	final Display display = workbench.getDisplay();
	display.syncExec(new Runnable() {
		public void run() {
			if (!display.isDisposed())
				workbench.close();
		}
	});
}
 
Example 17
Source File: UIUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Processes UI input and does not return while there are things to do on the UI thread. I.e., when this method
 * returns, there is no more work to do on the UI thread <em>at this time</em>. This method may be invoked from any
 * thread.
 * <p>
 * Moved here from <code>AbstractPluginUITest#waitForUiThread()</code>.
 */
public static void waitForUiThread() {
	final Display display = getDisplay();
	display.syncExec(() -> {
		if (!display.isDisposed()) {
			while (display.readAndDispatch()) {
				// wait while there might be something to process.
			}
			display.update();
		}
	});
}
 
Example 18
Source File: ExamplesApplication.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void stop() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench == null) {
		return;
	}
	final Display display = workbench.getDisplay();
	display.syncExec(() -> {
		if (!display.isDisposed()) {
			workbench.close();
		}
	});
}
 
Example 19
Source File: AppEngineConfigWizardPageTestWorkbench.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void testCreateLaunchAndDebugGoogleAppProject() throws Exception {

        final Display display = Display.getDefault();
        final Boolean[] executed = new Boolean[] { false };
        display.syncExec(new Runnable() {

            @Override
            public void run() {
                final Shell shell = new Shell(display);
                shell.setLayout(new FillLayout());
                Composite pageContainer = new Composite(shell, 0);
                AppEngineWizard appEngineWizard = new AppEngineWizard();
                appEngineWizard.setContainer(new IWizardContainer() {

                    @Override
                    public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                            throws InvocationTargetException, InterruptedException {
                        runnable.run(new NullProgressMonitor());
                    }

                    @Override
                    public void updateWindowTitle() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public void updateTitleBar() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public void updateMessage() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public void updateButtons() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public void showPage(IWizardPage page) {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public Shell getShell() {
                        throw new RuntimeException("Not implemented");
                    }

                    @Override
                    public IWizardPage getCurrentPage() {
                        return null;
                    }
                });

                appEngineWizard.init(PlatformUI.getWorkbench(), new StructuredSelection());
                appEngineWizard.addPages();
                appEngineWizard.createPageControls(pageContainer);

                IWizardPage[] pages = appEngineWizard.getPages();
                NewProjectNameAndLocationWizardPage nameAndLocation = (NewProjectNameAndLocationWizardPage) pages[0];
                AppEngineConfigWizardPage appEnginePage = (AppEngineConfigWizardPage) pages[1];

                assertFalse(nameAndLocation.isPageComplete());
                nameAndLocation.setProjectName("AppEngineTest");
                assertTrue(nameAndLocation.isPageComplete());

                assertFalse(appEnginePage.isPageComplete());
                appEnginePage.setAppEngineLocationFieldValue(TestDependent.GOOGLE_APP_ENGINE_LOCATION
                        + "invalid_path_xxx");
                assertFalse(appEnginePage.isPageComplete());
                appEnginePage.setAppEngineLocationFieldValue(TestDependent.GOOGLE_APP_ENGINE_LOCATION);
                assertTrue(appEnginePage.isPageComplete());

                assertTrue(appEngineWizard.performFinish());

                IProject createdProject = appEngineWizard.getCreatedProject();
                PythonNature nature = PythonNature.getPythonNature(createdProject);
                Map<String, String> expected = new HashMap<String, String>();
                expected.put(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE, new File(
                        TestDependent.GOOGLE_APP_ENGINE_LOCATION).getAbsolutePath());
                IPythonPathNature pythonPathNature = nature.getPythonPathNature();
                try {
                    assertEquals(expected, pythonPathNature.getVariableSubstitution());

                    String projectExternalSourcePath = pythonPathNature.getProjectExternalSourcePath(false);
                    assertTrue(projectExternalSourcePath.indexOf(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE) != -1);
                    projectExternalSourcePath = pythonPathNature.getProjectExternalSourcePath(true);
                    assertTrue(projectExternalSourcePath.indexOf(AppEngineConstants.GOOGLE_APP_ENGINE_VARIABLE) == -1);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

                //                goToManual();

                executed[0] = true;
            }
        });
        assertTrue(executed[0]);
    }
 
Example 20
Source File: Activator.java    From ermaster-b with Apache License 2.0 3 votes vote down vote up
public static GraphicalViewer createGraphicalViewer(final ERDiagram diagram) {
	Display display = PlatformUI.getWorkbench().getDisplay();

	GraphicalViewerCreator runnable = new GraphicalViewerCreator(display,
			diagram);

	display.syncExec(runnable);

	return runnable.viewer;
}