| package org.eclipse.ui.examples.jobs.actions; |
| |
| import org.eclipse.core.runtime.OperationCanceledException; |
| import org.eclipse.core.runtime.Platform; |
| import org.eclipse.jface.action.IAction; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.ui.IWorkbenchWindow; |
| import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
| |
| /** |
| * Toggles the suspend/resume state of the job manager. |
| */ |
| public class SuspendJobManagerAction implements IWorkbenchWindowActionDelegate { |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) |
| */ |
| public void run(IAction action) { |
| try { |
| if (action.isChecked()) |
| Platform.getJobManager().suspend(); |
| else |
| Platform.getJobManager().resume(); |
| } catch (OperationCanceledException e) { |
| //thrown if the user cancels the attempt to suspend |
| e.printStackTrace(); |
| } |
| } |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) |
| */ |
| public void selectionChanged(IAction action, ISelection selection) { |
| //do nothing |
| } |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() |
| */ |
| public void dispose() { |
| //do nothing |
| } |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) |
| */ |
| public void init(IWorkbenchWindow window) { |
| //do nothing |
| } |
| } |