1 11 package org.eclipse.debug.internal.ui.actions; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.debug.core.DebugEvent; 16 import org.eclipse.debug.core.DebugPlugin; 17 import org.eclipse.debug.core.model.IWatchExpression; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.jface.viewers.ISelection; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.ui.IObjectActionDelegate; 22 import org.eclipse.ui.IWorkbenchPart; 23 24 27 public class EnableWatchExpressionAction implements IObjectActionDelegate { 28 29 private ISelection fSelection; 30 protected boolean fEnable= true; 31 32 35 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 36 } 37 38 41 public void run(IAction action) { 42 if (fSelection instanceof IStructuredSelection) { 43 Iterator iter= ((IStructuredSelection) fSelection).iterator(); 44 IWatchExpression expression; 45 while (iter.hasNext()) { 46 expression= ((IWatchExpression) iter.next()); 47 expression.setEnabled(fEnable); 48 fireWatchExpressionChanged(expression); 49 } 50 } else if (fSelection instanceof IWatchExpression) { 51 IWatchExpression expression= ((IWatchExpression) fSelection); 52 expression.setEnabled(fEnable); 53 fireWatchExpressionChanged(expression); 54 } 55 } 56 57 60 private void fireWatchExpressionChanged(IWatchExpression expression) { 61 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(expression, DebugEvent.CHANGE)}); 62 } 63 64 67 public void selectionChanged(IAction action, ISelection selection) { 68 fSelection= selection; 69 if (fSelection instanceof IStructuredSelection) { 70 boolean enabled= false; 71 Iterator iter= ((IStructuredSelection) selection).iterator(); 72 while (iter.hasNext()) { 73 IWatchExpression expression = (IWatchExpression) iter.next(); 74 if (expression.isEnabled() != fEnable) { 75 enabled= true; 76 break; 77 } 78 } 79 action.setEnabled(enabled); 80 } else if (fSelection instanceof IWatchExpression) { 81 action.setEnabled(((IWatchExpression) fSelection).isEnabled() != fEnable); 82 } else { 83 action.setEnabled(false); 84 } 85 } 86 87 } 88 | Popular Tags |