下面列出了org.eclipse.ui.part.PageBookView#org.eclipse.ui.progress.UIJob 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Update the shown name with the server stop/stopping state.
*/
private void updateName(int serverState) {
final String computedName;
if (serverState == IServer.STATE_STARTING) {
computedName = Messages.getString("SERVER_STARTING_TEMPLATE", unprefixedName);
} else if (serverState == IServer.STATE_STOPPING) {
computedName = Messages.getString("SERVER_STOPPING_TEMPLATE", unprefixedName);
} else if (serverState == IServer.STATE_STOPPED) {
computedName = Messages.getString("SERVER_STOPPED_TEMPLATE", unprefixedName);
} else {
computedName = unprefixedName;
}
UIJob nameUpdateJob = new UIJob("Update server name") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
LocalAppEngineConsole.this.setName(computedName);
return Status.OK_STATUS;
}
};
nameUpdateJob.setSystem(true);
nameUpdateJob.schedule();
}
/**
* Displays the given file in an editor using the Java perspective.
* If something goes wrong, this method has no effect.
*
* @param file The file to display.
* @param workbench The workbench.
*/
public static void displayInEditor(IFile file, IWorkbench workbench) {
new UIJob("Display in editor") {
@Override
public IStatus runInUIThread(IProgressMonitor m) {
try {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IDE.openEditor(window.getActivePage(), file);
workbench.showPerspective("org.eclipse.jdt.ui.JavaPerspective", window);
return Status.OK_STATUS;
}
catch (NullPointerException | WorkbenchException e) {
return Status.CANCEL_STATUS;
}
}
}.schedule();
}
/**
* Tests bug https://jira.int.sys.net/browse/AIG-931.
*
* @throws Exception
* the exception
*/
@Test
public void testBugAig931() throws Exception {
final String partialModel = "package p catalog T for grammar com.avaloq.tools.ddk.check.Check { error \"X\" for ";
final String[] expectedContextTypeProposals = {"EObject - org.eclipse.emf.ecore", "JvmType - org.eclipse.xtext.common.types"};
new UIJob("compute completion proposals") {
@SuppressWarnings("restriction")
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
try {
completionsExist(newBuilder().append(partialModel).computeCompletionProposals(), expectedContextTypeProposals);
// CHECKSTYLE:OFF
} catch (Exception e) {
// CHECKSTYLE:ON
return new Status(Status.ERROR, "com.avaloq.tools.ddk.check.ui.test", 1, e.getMessage(), e);
}
return Status.OK_STATUS;
}
};
}
/**
* Opens the editor for the given spec (needs access to the UI thus has to
* run as a UI job)
*/
private void openEditorInUIThread(final Spec spec) {
// with parsing done, we are ready to open the spec editor
final UIJob uiJob = new UIJob("NewSpecWizardEditorOpener") {
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
// create parameters for the handler
final HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put(OpenSpecHandler.PARAM_SPEC, spec.getName());
// runs the command
UIHelper.runCommand(OpenSpecHandler.COMMAND_ID, parameters);
return Status.OK_STATUS;
}
};
uiJob.schedule();
}
public void start(BundleContext context) throws Exception
{
super.start(context);
plugin = this;
changedColor = new Color(null, 255, 200, 200);
addedColor = new Color(null, 255, 255, 200);
deletedColor = new Color(null, 240, 240, 255);
if (Display.getCurrent() != null && ExecutionStatisticsCollector.promptUser()) { // Display is null during unit test execution.
final UIJob j = new UIJob(Display.getCurrent(), "TLA+ execution statistics approval.") {
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
new ExecutionStatisticsDialog(false, PlatformUI.createDisplay().getActiveShell()).open();
return Status.OK_STATUS;
}
};
j.schedule(5 * 60 * 1000L);
}
}
private void registerExampleDropAdapter() {
UIJob registerJob = new UIJob(Display.getDefault(), "Registering example drop adapter.") {
{
setPriority(Job.SHORT);
setSystem(true);
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.addWindowListener(workbenchListener);
IWorkbenchWindow[] workbenchWindows = workbench
.getWorkbenchWindows();
for (IWorkbenchWindow window : workbenchWindows) {
workbenchListener.hookWindow(window);
}
return Status.OK_STATUS;
}
};
registerJob.schedule();
}
protected void schedulePerspectiveSwitchJob(final String perspectiveID) {
Job switchJob = new UIJob(DebugUIPlugin.getStandardDisplay(), "Perspective Switch Job") { //$NON-NLS-1$
public IStatus runInUIThread(IProgressMonitor monitor) {
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
if (window != null && !(isCurrentPerspective(window, perspectiveID))) {
switchToPerspective(window, perspectiveID);
}
// Force the debug view to open
if (window != null) {
try {
window.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SIMULATION_VIEW_ID);
} catch (PartInitException e) {
e.printStackTrace();
}
}
return Status.OK_STATUS;
}
};
switchJob.setSystem(true);
switchJob.setPriority(Job.INTERACTIVE);
switchJob.setRule(AsynchronousSchedulingRuleFactory.getDefault().newSerialPerObjectRule(this));
switchJob.schedule();
}
public Object execute(ExecutionEvent event) throws ExecutionException
{
UIJob job = new UIJob("Open Theme Preferences") //$NON-NLS-1$
{
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
final PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(UIUtils.getActiveShell(),
ThemePreferencePage.ID, null, null);
dialog.open();
return Status.OK_STATUS;
}
};
job.setPriority(Job.INTERACTIVE);
job.setRule(PopupSchedulingRule.INSTANCE);
job.schedule();
return null;
}
@Override
public boolean performFinish()
{
final String targetPath = this.page.getSourcePath();
final String fileName = this.page.getPagePath();
pageName = this.page.getPageName();
Job menuJob = new UIJob("")
{
public IStatus runInUIThread(IProgressMonitor monitor)
{
try {
doFinish(targetPath, fileName, monitor);
} catch (CoreException e) {
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
menuJob.schedule(300L);
return true;
}
private static void showErrorMessage(final String title, final String message, final Throwable exception)
{
if (Display.getCurrent() == null || exception != null)
{
UIJob job = new UIJob(message)
{
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
if (exception == null)
{
showErrorDialog(title, message);
return Status.OK_STATUS;
}
return new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID, null, exception);
}
};
job.setPriority(Job.INTERACTIVE);
job.setUser(true);
job.schedule();
}
else
{
showErrorDialog(title, message);
}
}
private void resetPerspective(final IWorkbenchPage page)
{
UIJob job = new UIJob("Resetting Studio perspective...") //$NON-NLS-1$
{
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
if (MessageDialog.openQuestion(UIUtils.getActiveShell(),
com.aptana.ui.Messages.UIPlugin_ResetPerspective_Title,
com.aptana.ui.Messages.UIPlugin_ResetPerspective_Description))
{
page.resetPerspective();
}
return Status.OK_STATUS;
}
};
EclipseUtil.setSystemForJob(job);
job.setPriority(Job.INTERACTIVE);
job.schedule();
}
private Composite createBrowserArea(Composite parent) {
GridLayout gridLayout = new GridLayout(1, false);
parent.setLayout(gridLayout);
GridData gd_displayArea = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
parent.setLayoutData(gd_displayArea);
tabFolder = new CTabFolder(parent, SWT.TOP|SWT.MULTI|SWT.FLAT);
tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
UIJob job = new UIJob(Display.getDefault(),"refresh browser") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
refreshTabContent();
return Status.OK_STATUS;
}
/** (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#shouldRun()
*/
@Override
public boolean shouldRun() {
return !tabFolder.isDisposed();
}
};
job.schedule();
return parent;
}
/**
* Remove the editor from askReparse and if it's the last one, do the find.
*/
private void doFindIfLast() {
synchronized (lock) {
askReparse.remove(editToReparse);
if (askReparse.size() > 0) {
return; //not the last one (we'll only do the find when all are reparsed.
}
}
/**
* Create an ui job to actually make the find.
*/
UIJob job = new UIJob("Find") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
try {
findDefinitionsAndOpen(true);
} catch (Throwable e) {
Log.log(e);
}
return Status.OK_STATUS;
}
};
job.setPriority(Job.INTERACTIVE);
job.schedule();
}
@Override
public void initialize() {
//need to do this asynchronously, or it has no effect
new UIJob("Show/Hide Column") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
showColumn(fPreemptColumn, PyHoverPreferencesPage.getCombineHoverInfo());
showColumn(fModifierColumn, !PyHoverPreferencesPage.getCombineHoverInfo());
fModifierFieldLabel.setEnabled(!fCombineHovers.getSelection());
return Status.OK_STATUS;
}
}.schedule();
doInit(true);
}
private static void show(Image image, String title, String text) {
UIJob job = new UIJob("Open popup") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
Display display = getDisplay();
if (display == null || display.isDisposed())
return Status.CANCEL_STATUS;
Notifier.notify(
image,
title != null ? title : "?",
text != null ? text : "?",
NotifierTheme.YELLOW_THEME);
return Status.OK_STATUS;
}
};
job.schedule();
}
private void scheduleClosingDialogAfterOpen(final CloseAction closeAction) {
dialogCloser = new UIJob("dialog closer") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (dialog.getShell() != null && dialog.getShell().isVisible()) {
closeDialog(closeAction);
} else {
schedule(100);
}
return Status.OK_STATUS;
}
};
dialogCloser.schedule();
}
/**
* Opens the specified url in a Web browser instance in a UI thread.
*
* @param urlPath the URL to display
* @param browserId if an instance of a browser with the same id is already opened, it will be
* returned instead of creating a new one. Passing null will create a new instance with a
* generated id.
* @param name a name displayed on the tab of the internal browser
* @param tooltip the text for a tooltip on the <code>name</code> of the internal browser
*/
public static void openInBrowserInUiThread(final String urlPath, final String browserId,
final String name, final String tooltip) {
final IWorkbench workbench = PlatformUI.getWorkbench();
Job launchBrowserJob = new UIJob(workbench.getDisplay(), name) {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
return openInBrowser(workbench, urlPath, browserId, name, tooltip);
}
};
launchBrowserJob.schedule();
}
@Override
public void execute(String newWorkingDir) {
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot()
.findContainersForLocation(getWorkingDirPath().append(path));
if (c != null && c.length > 0) {
for (int i = 0; i < c.length; i++) {
UIJob job = new RefreshContainerJob(c[i].getParent(), true);
job.schedule();
}
}
}
@Override
public void execute(String newWorkingDir) {
try {
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot()
.findContainersForLocation(new Path(newWorkingDir));
if (c != null && c.length > 0) {
for (int i = 0; i < c.length; i++) {
UIJob job = new RefreshContainerJob(c[i], false);
job.schedule();
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
@Override
public void execute(String newWorkingDir) {
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot()
.findContainersForLocation(new Path(getWorkingDir()).append(path).removeLastSegments(1));
if (c != null && c.length > 0) {
for (int i = 0; i < c.length; i++) {
UIJob job = new RefreshContainerJob(c[i], true);
job.schedule();
}
}
}
@Override
public void componentChanged(final ITraceControlComponent component) {
if (fTreeViewer.getTree().isDisposed()) {
return;
}
UIJob myJob = new UIJob("Refresh") { //$NON-NLS-1$
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (fTreeViewer.getTree().isDisposed()) {
return Status.OK_STATUS;
}
fTreeViewer.refresh(component);
// Change selection needed
final ISelection sel = fTreeViewer.getSelection();
fTreeViewer.setSelection(null);
fTreeViewer.setSelection(sel);
// Show component that was changed
fTreeViewer.reveal(component);
return Status.OK_STATUS;
}
};
myJob.setUser(false);
myJob.setSystem(true);
myJob.schedule();
}
/**
* Sets the selected components in the tree
* @param components - array of components to select
*/
public void setSelection(ITraceControlComponent[] components) {
final StructuredSelection selection = new StructuredSelection(components);
UIJob myJob = new UIJob("Select") { //$NON-NLS-1$
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
fTreeViewer.setSelection(selection);
return Status.OK_STATUS;
}
};
myJob.setUser(false);
myJob.schedule();
}
/**
* Displays a yes/no dialog of a specified type with a specified title,a specified message, and a
* specified default value, then blocks until the user responds or interrupts the dialog.
*
* @param type the dialog type, specified by one of the int constants in {@link MessageDialog}
* @param title the specified title
* @param message the specified message
* @param defaultIsYes
* {@link true} if the specified default value is <i>yes</i>, false if the specified default
* value is <i>no</i>
* @return
* {@code true} if the user responded <i>yes</i>, {@code false} if the user responded
* <i>no</i>, or the value of {@code defaultValueIsYes} if the user interrupts the dialog
*/
public boolean userAnsweredYes(
final int type, final String title, final String message, final boolean defaultIsYes) {
final int defaultPosition = defaultIsYes ? YesOrNo.YES.ordinal() : YesOrNo.NO.ordinal();
if (Display.getCurrent() == null) {
// This is not a UI thread. Schedule a UI job to call displayDialogAndGetAnswer, and block
// this thread until the UI job is complete.
final Semaphore barrier = new Semaphore(0);
final AtomicBoolean responseContainer = new AtomicBoolean();
UIJob dialogJob =
new UIJob("background-initiated question dialog"){
@Override public IStatus runInUIThread(IProgressMonitor monitor) {
boolean result = displayDialogAndGetAnswer(type, title, message, defaultPosition);
responseContainer.set(result);
barrier.release();
return Status.OK_STATUS;
}
};
dialogJob.schedule();
try {
barrier.acquire();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return defaultIsYes;
}
return responseContainer.get();
} else {
// This is the UI thread. Simply call displayDialogAndGetAnswer in this thread.
// (Scheduling a UIJob and blocking until it completes would result in deadlock.)
return displayDialogAndGetAnswer(type, title, message, defaultPosition);
}
}
public static void runInUI(final String title, final int scheduleTime, final Consumer<IProgressMonitor> run) {
final UIJob job = new UIJob(title) {
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
run.accept(monitor);
return Status.OK_STATUS;
}
};
job.schedule(scheduleTime);
}
/**
* Schedules a message dialog to be displayed safely in the UI thread
*
* @param runnable
* Something that gets run if the message dialog return code is Window.OK
* @param runnableCondition
* The return code from SafeMessageDialogRunnable.openMessageDialog() that would trigger
* SafeMessageDialogRunnable.run()
*/
public static void showMessageDialogFromBgThread(final SafeMessageDialogRunnable runnable,
final int runnableCondition)
{
UIJob job = new UIJob("Modal Message Dialog Job") //$NON-NLS-1$
{
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
// If the system dialog is shown, then the active shell would be null
if (Display.getDefault().getActiveShell() == null)
{
if (!monitor.isCanceled())
{
schedule(1000);
}
}
else if (!monitor.isCanceled())
{
if (runnable.openMessageDialog() == runnableCondition)
{
try
{
runnable.run();
}
catch (Exception e)
{
IdeLog.logError(UIPlugin.getDefault(), e);
}
}
}
return Status.OK_STATUS;
}
};
EclipseUtil.setSystemForJob(job);
job.schedule();
}
public static boolean showPromptDialog(final String title, final String message)
{
if (Display.getCurrent() == null)
{
UIJob job = new UIJob(title)
{
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
if (showPromptDialogUI(title, message))
{
return Status.OK_STATUS;
}
return Status.CANCEL_STATUS;
}
};
job.setPriority(Job.INTERACTIVE);
job.setUser(true);
job.schedule();
try
{
job.join();
}
catch (InterruptedException e)
{
}
return job.getResult() == Status.OK_STATUS;
}
else
{
return showPromptDialogUI(title, message);
}
}
public void start(BundleContext context) throws Exception
{
super.start(context);
plugin = this;
// Update occurrence colors
listenForThemeChanges();
// Activate indexing
// FIXME Why can't we just have the indexing plugin load lazily on-demand?
IndexPlugin.getDefault();
differentiator = new FilenameDifferentiator();
differentiator.schedule();
// FIXME initialize spelling preferences lazily
spellingPreferences = new SpellingPreferences();
new UIJob("adding part listener") //$NON-NLS-1$
{
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
addPartListener();
return Status.OK_STATUS;
}
}.schedule();
}
/**
* Installs this target. I.e. adds all required listeners.
*/
private void install() {
if (fInstalled)
return;
StyledText text = fTextViewer.getTextWidget();
if (text == null)
return;
text.addMouseListener(this);
text.addFocusListener(this);
fTextViewer.addTextListener(this);
ISelectionProvider selectionProvider = fTextViewer.getSelectionProvider();
if (selectionProvider != null)
selectionProvider.addSelectionChangedListener(this);
if (fTextViewer instanceof ITextViewerExtension)
((ITextViewerExtension) fTextViewer).prependVerifyKeyListener(this);
else
text.addVerifyKeyListener(this);
keyAssistDialog = new KeyAssistDialog(this.fEdit);
fInstalled = true;
//Wait a bit until showing the key assist dialog
new UIJob("") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
synchronized (lock) {
if (fInstalled && keyAssistDialog != null) {
keyAssistDialog.open(OfflineActionTarget.this.fEdit.getOfflineActionDescriptions(),
OfflineActionTarget.this);
}
}
return Status.OK_STATUS;
}
}.schedule(700);
}
/**
* Actually executes this action.
*
* Checks preconditions... if
*/
@Override
public void run(final IAction action) {
// Select from text editor
request = null; //clear the cache from previous runs
ps = PySelectionFromEditor.createPySelectionFromEditor(getTextEditor());
RefactoringRequest req;
try {
req = getRefactoringRequest();
} catch (MisconfigurationException e2) {
Log.log(e2);
return;
}
IPyRefactoring pyRefactoring = AbstractPyRefactoring.getPyRefactoring();
if (areRefactorPreconditionsOK(req, pyRefactoring) == false) {
return;
}
UIJob job = new UIJob("Performing: " + this.getClass().getName()) {
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
try {
Operation o = new Operation(action);
o.execute(monitor);
} catch (Exception e) {
Log.log(e);
}
return Status.OK_STATUS;
}
};
job.setSystem(true);
job.schedule();
}
public void open() {
// Must cache here, since editor context is not available in menu from popup shell:
openDialogBinding = getOpenDialogBinding();
Shell workbenchShell = editor.getSite().getShell();
final Display display = workbenchShell.getDisplay();
popup = new Shell(workbenchShell, SWT.ON_TOP | SWT.NO_TRIM | SWT.TOOL);
popupLayout = new GridLayout(2, false);
popupLayout.marginWidth = 1;
popupLayout.marginHeight = 1;
popupLayout.marginLeft = 4;
popupLayout.horizontalSpacing = 0;
popup.setLayout(popupLayout);
createContent(popup);
updatePopupLocation();
new PopupVisibilityManager().start();
// Leave linked mode when popup loses focus
// (except when focus goes back to workbench window or menu is open):
popup.addShellListener(new ShellAdapter() {
@Override
public void shellDeactivated(ShellEvent e) {
if (iSMenuUp)
return;
final Shell editorShell = editor.getSite().getShell();
display.asyncExec(new Runnable() {
// post to UI thread since editor shell only gets activated after popup has lost focus
@Override
public void run() {
Shell activeShell = display.getActiveShell();
if (activeShell != editorShell) {
controller.cancelLinkedMode();
}
}
});
}
});
if (!MAC) { // carbon and cocoa draw their own border...
popup.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent pe) {
pe.gc.drawPolygon(getPolygon(true));
}
});
}
UIJob delayJob = new UIJob(display, "Delayed RenameInformationPopup") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
delayJobFinished = true;
if (popup != null && !popup.isDisposed()) {
updateVisibility();
}
return Status.OK_STATUS;
}
};
delayJob.setSystem(true);
delayJob.setPriority(Job.INTERACTIVE);
delayJob.schedule(POPUP_VISIBILITY_DELAY);
}