Java Code Examples for org.eclipse.ui.progress.UIJob#schedule()

The following examples show how to use org.eclipse.ui.progress.UIJob#schedule() . 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: LocalAppEngineConsole.java    From google-cloud-eclipse with Apache License 2.0 8 votes vote down vote up
/**
 * 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();
}
 
Example 2
Source File: PerspectiveChangeResetListener.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: NewSpecHandler.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example 4
Source File: TLCUIActivator.java    From tlaplus with MIT License 6 votes vote down vote up
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);
}
  }
 
Example 5
Source File: BrowserViewPart.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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;

}
 
Example 6
Source File: PyGoToDefinition.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 7
Source File: ExampleDropSupportRegistrar.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
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();
}
 
Example 8
Source File: OptInDialogTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 9
Source File: UIUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
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);
	}
}
 
Example 10
Source File: UIUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 11
Source File: PyRefactorAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 12
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: BackgroundInitiatedYesNoDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 14
Source File: ControlView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 15
Source File: ControlView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@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();
}
 
Example 16
Source File: DelCommandInterpreter.java    From typescript.java with MIT License 5 votes vote down vote up
@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();
		}
	}
}
 
Example 17
Source File: RdCommandInterpreter.java    From typescript.java with MIT License 5 votes vote down vote up
@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();
		}
	}
}
 
Example 18
Source File: RenameInformationPopup.java    From typescript.java with MIT License 4 votes vote down vote up
public void open() {
		// Must cache here, since editor context is not available in menu from popup shell:
		fOpenDialogBinding= getOpenDialogBinding();

		Shell workbenchShell= fEditor.getSite().getShell();
		final Display display= workbenchShell.getDisplay();

		fPopup= new Shell(workbenchShell, SWT.ON_TOP | SWT.NO_TRIM | SWT.TOOL);
		fPopupLayout= new GridLayout(3, false);
		fPopupLayout.marginWidth= 1;
		fPopupLayout.marginHeight= 1;
		fPopupLayout.marginLeft= 4;
		fPopupLayout.horizontalSpacing= 0;
		fPopup.setLayout(fPopupLayout);

		createContent(fPopup);
		updatePopupLocation(true);
		new PopupVisibilityManager().start();

		// Leave linked mode when popup loses focus
		// (except when focus goes back to workbench window or menu is open):
		fPopup.addShellListener(new ShellAdapter() {
			@Override
			public void shellDeactivated(ShellEvent e) {
				if (fIsMenuUp)
					return;

				final Shell editorShell= fEditor.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) {
							fRenameLinkedMode.cancel();
						}
					}
				});
			}
		});

		if (! MAC) { // carbon and cocoa draw their own border...
			fPopup.addPaintListener(new PaintListener() {
				@Override
				public void paintControl(PaintEvent pe) {
					pe.gc.drawPolygon(getPolygon(true));
				}
			});
		}

//		fPopup.moveBelow(null); // make sure hovers are on top of the info popup
// XXX workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=170774
//		fPopup.moveBelow(workbenchShell.getShells()[0]);

		UIJob delayJob= new UIJob(display, RefactoringMessages.RenameInformationPopup_delayJobName) {
			@Override
			public IStatus runInUIThread(IProgressMonitor monitor) {
				fDelayJobFinished= true;
				if (fPopup != null && ! fPopup.isDisposed()) {
					updateVisibility();
				}
				return Status.OK_STATUS;
			}
		};
		delayJob.setSystem(true);
		delayJob.setPriority(Job.INTERACTIVE);
		delayJob.schedule(POPUP_VISIBILITY_DELAY);
	}
 
Example 19
Source File: RenameRefactoringPopup.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
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);
}
 
Example 20
Source File: RenameInformationPopup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void open() {
		// Must cache here, since editor context is not available in menu from popup shell:
		fOpenDialogBinding= getOpenDialogBinding();

		Shell workbenchShell= fEditor.getSite().getShell();
		final Display display= workbenchShell.getDisplay();

		fPopup= new Shell(workbenchShell, SWT.ON_TOP | SWT.NO_TRIM | SWT.TOOL);
		fPopupLayout= new GridLayout(2, false);
		fPopupLayout.marginWidth= 1;
		fPopupLayout.marginHeight= 1;
		fPopupLayout.marginLeft= 4;
		fPopupLayout.horizontalSpacing= 0;
		fPopup.setLayout(fPopupLayout);

		createContent(fPopup);
		updatePopupLocation(true);
		new PopupVisibilityManager().start();

		// Leave linked mode when popup loses focus
		// (except when focus goes back to workbench window or menu is open):
		fPopup.addShellListener(new ShellAdapter() {
			@Override
			public void shellDeactivated(ShellEvent e) {
				if (fIsMenuUp)
					return;

				final Shell editorShell= fEditor.getSite().getShell();
				display.asyncExec(new Runnable() {
					// post to UI thread since editor shell only gets activated after popup has lost focus
					public void run() {
						Shell activeShell= display.getActiveShell();
						if (activeShell != editorShell) {
							fRenameLinkedMode.cancel();
						}
					}
				});
			}
		});

		if (! MAC) { // carbon and cocoa draw their own border...
			fPopup.addPaintListener(new PaintListener() {
				public void paintControl(PaintEvent pe) {
					pe.gc.drawPolygon(getPolygon(true));
				}
			});
		}

//		fPopup.moveBelow(null); // make sure hovers are on top of the info popup
// XXX workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=170774
//		fPopup.moveBelow(workbenchShell.getShells()[0]);

		UIJob delayJob= new UIJob(display, ReorgMessages.RenameInformationPopup_delayJobName) {
			@Override
			public IStatus runInUIThread(IProgressMonitor monitor) {
				fDelayJobFinished= true;
				if (fPopup != null && ! fPopup.isDisposed()) {
					updateVisibility();
				}
				return Status.OK_STATUS;
			}
		};
		delayJob.setSystem(true);
		delayJob.setPriority(Job.INTERACTIVE);
		delayJob.schedule(POPUP_VISIBILITY_DELAY);
	}