1 11 package org.eclipse.debug.internal.ui.actions; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.core.runtime.jobs.Job; 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.debug.core.model.IDropToFrame; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.viewers.ISelection; 21 22 25 public class DropToFrameActionDelegate extends AbstractListenerActionDelegate { 26 27 class UpdateJob extends Job { 28 IAction fAction; 29 ISelection fSelection; 30 31 UpdateJob() { 32 super("Update Action Enablement"); } 34 35 void setAction(IAction action) { 36 fAction = action; 37 } 38 void setSelection(ISelection selection) { 39 fSelection = selection; 40 } 41 42 protected IStatus run(IProgressMonitor monitor) { 43 DropToFrameActionDelegate.super.update(fAction, fSelection); 44 return Status.OK_STATUS; 45 } 46 47 } 48 49 private UpdateJob fUpdateJob = new UpdateJob(); 50 51 public DropToFrameActionDelegate() { 52 super(); 53 fUpdateJob.setSystem(true); 54 } 55 56 60 protected void doAction(Object element) throws DebugException { 61 if (element instanceof IDropToFrame) { 62 IDropToFrame dropToFrame= (IDropToFrame) element; 63 if (dropToFrame.canDropToFrame()) { 64 dropToFrame.dropToFrame(); 65 } 66 } 67 } 68 69 72 protected boolean isRunInBackground() { 73 return true; 74 } 75 76 80 protected boolean isEnabledFor(Object element) { 81 return element instanceof IDropToFrame && ((IDropToFrame) element).canDropToFrame(); 82 } 83 84 protected void update(IAction action, ISelection selection) { 85 fUpdateJob.setAction(action); 86 fUpdateJob.setSelection(selection); 87 fUpdateJob.schedule(); 88 } 89 } 90 | Popular Tags |