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

The following examples show how to use org.eclipse.swt.widgets.Display#syncExec() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: n4js   File: EclipseUIUtils.java    License: 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 Project: tlaplus   File: ParseSpecHandler.java    License: 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
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 Project: Pydev   File: DebuggerTestUtils.java    License: 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
@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 6
Source Project: n4js   File: UIUtils.java    License: 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 7
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 8
/**
 * Fire this message
 */
public boolean open(){
	final Display display = Display.getDefault();
	UserDialogRunnable runnable = new UserDialogRunnable(display);
	display.syncExec(runnable);
	return runnable.getResult();
}
 
Example 9
Source Project: neoscada   File: Application.java    License: 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 10
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
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 12
/**
 * 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
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 14
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 15
/**
 * 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 16
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 17
/**
 * 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 18
@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 19
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 Project: ermaster-b   File: Activator.java    License: 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;
}