1 12 package org.eclipse.debug.internal.ui.actions; 13 14 15 import org.eclipse.debug.core.DebugEvent; 16 import org.eclipse.debug.core.DebugPlugin; 17 import org.eclipse.debug.core.IDebugEventSetListener; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.swt.widgets.Event; 20 import org.eclipse.swt.widgets.Shell; 21 import org.eclipse.ui.IActionDelegate2; 22 import org.eclipse.ui.IViewPart; 23 import org.eclipse.ui.IWorkbenchWindow; 24 25 public abstract class AbstractListenerActionDelegate extends AbstractDebugActionDelegate implements IDebugEventSetListener, IActionDelegate2 { 26 27 private boolean fDisposed = false; 28 29 33 public synchronized void dispose() { 34 super.dispose(); 35 DebugPlugin.getDefault().removeDebugEventListener(this); 36 fDisposed = true; 37 } 38 39 42 public void handleDebugEvents(final DebugEvent[] events) { 43 if (getWindow() == null || getAction() == null) { 44 return; 45 } 46 Shell shell= getWindow().getShell(); 47 if (shell == null || shell.isDisposed()) { 48 return; 49 } 50 synchronized (this) { 51 if (fDisposed) { 52 return; 53 } 54 } 55 for (int i = 0; i < events.length; i++) { 56 if (events[i].getSource() != null) { 57 doHandleDebugEvent(events[i]); 58 } 59 } 60 } 61 62 66 protected void doHandleDebugEvent(DebugEvent event) { 67 switch (event.getKind()) { 68 case DebugEvent.TERMINATE : 69 update(getAction(), getSelection()); 70 break; 71 case DebugEvent.RESUME : 72 if (!event.isEvaluation() || !((event.getDetail() & DebugEvent.EVALUATION_IMPLICIT) != 0)) { 73 update(getAction(), getSelection()); 74 } 75 break; 76 case DebugEvent.SUSPEND : 77 update(getAction(), getSelection()); 80 break; 81 case DebugEvent.CHANGE : 82 update(getAction(), getSelection()); 87 break; 88 } 89 } 90 91 94 public void init(IWorkbenchWindow window){ 95 super.init(window); 96 DebugPlugin.getDefault().addDebugEventListener(this); 97 } 98 99 102 public void init(IViewPart view) { 103 super.init(view); 104 DebugPlugin.getDefault().addDebugEventListener(this); 105 setWindow(view.getViewSite().getWorkbenchWindow()); 106 } 107 108 111 public void init(IAction action) { 112 } 113 114 117 public void runWithEvent(IAction action, Event event) { 118 run(action); 119 } 120 } 121 | Popular Tags |