1 11 package org.eclipse.debug.internal.ui.views.expression; 12 13 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.debug.core.DebugEvent; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.IExpressionsListener; 20 import org.eclipse.debug.core.ILaunch; 21 import org.eclipse.debug.core.model.IDebugElement; 22 import org.eclipse.debug.core.model.IDebugTarget; 23 import org.eclipse.debug.core.model.IExpression; 24 import org.eclipse.debug.core.model.IWatchExpression; 25 import org.eclipse.debug.internal.ui.views.variables.VariablesViewEventHandler; 26 import org.eclipse.debug.ui.AbstractDebugView; 27 import org.eclipse.debug.ui.DebugUITools; 28 import org.eclipse.jface.viewers.IContentProvider; 29 import org.eclipse.jface.viewers.ISelection; 30 import org.eclipse.jface.viewers.IStructuredSelection; 31 import org.eclipse.jface.viewers.StructuredSelection; 32 33 36 public class ExpressionViewEventHandler extends VariablesViewEventHandler implements IExpressionsListener { 37 38 43 protected void doHandleTerminateEvent(DebugEvent event) { 44 super.doHandleTerminateEvent(event); 45 if (event.getSource() instanceof IDebugTarget) { 46 IExpression[] expressions = DebugPlugin.getDefault().getExpressionManager().getExpressions(); 47 IAdaptable object = DebugUITools.getDebugContext(); 48 IDebugElement context= null; 49 if (object instanceof IDebugElement) { 50 context= (IDebugElement) object; 51 } else if (object instanceof ILaunch) { 52 context= ((ILaunch) object).getDebugTarget(); 53 } 54 for (int i = 0; i < expressions.length; i++) { 55 IExpression expression = expressions[i]; 56 if (expression instanceof IWatchExpression) { 57 ((IWatchExpression)expression).setExpressionContext(context); 58 } 59 } 60 } 61 } 62 63 68 public ExpressionViewEventHandler(AbstractDebugView view) { 69 super(view); 70 DebugPlugin plugin= DebugPlugin.getDefault(); 71 plugin.getExpressionManager().addExpressionListener(this); 72 } 73 74 77 public void dispose() { 78 DebugPlugin plugin= DebugPlugin.getDefault(); 79 plugin.getExpressionManager().removeExpressionListener(this); 80 super.dispose(); 81 } 82 83 86 public void expressionsAdded(final IExpression[] expressions) { 87 Runnable r = new Runnable () { 88 public void run() { 89 if (isAvailable()) { 90 getTreeViewer().refresh(); 91 if (expressions.length > 0) { 92 ISelection selection = new StructuredSelection(expressions[0]); 93 getTreeViewer().setSelection(selection, true); 94 } 95 } 96 } 97 }; 98 getView().asyncExec(r); 99 } 100 101 104 public void expressionsRemoved(final IExpression[] expressions) { 105 Runnable r = new Runnable () { 106 public void run() { 107 if (isAvailable()) { 108 getTreeViewer().getControl().setRedraw(false); 109 for (int i = 0; i < expressions.length; i++) { 110 IExpression expression = expressions[i]; 111 remove(expression); 112 IContentProvider provider= getTreeViewer().getContentProvider(); 113 if (provider instanceof RemoteExpressionsContentProvider) { 114 RemoteExpressionsContentProvider expressionProvider= (RemoteExpressionsContentProvider) provider; 115 List decendants = expressionProvider.getCachedDecendants(expression); 116 decendants.add(expression); 117 expressionProvider.removeCache(decendants.toArray()); 119 IExpression[] allExpressions= DebugPlugin.getDefault().getExpressionManager().getExpressions(); 120 if (allExpressions.length > 0) { 121 getTreeViewer().setSelection(new StructuredSelection(allExpressions[0]), true); 122 } 123 } 124 } 125 getTreeViewer().getControl().setRedraw(true); 126 } 127 } 128 }; 129 getView().asyncExec(r); 130 } 131 132 135 public void expressionsChanged(final IExpression[] expressions) { 136 Runnable r = new Runnable () { 137 public void run() { 138 if (isAvailable()) { 139 getTreeViewer().getControl().setRedraw(false); 140 for (int i = 0; i < expressions.length; i++) { 141 IExpression expression = expressions[i]; 142 refresh(expression); 143 IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection(); 145 if (selection.size() == 1 && selection.getFirstElement().equals(expression)) { 146 getVariablesView().populateDetailPane(); 147 } 148 } 149 getTreeViewer().getControl().setRedraw(true); 150 } 151 } 152 }; 153 getView().asyncExec(r); 154 } 155 156 159 protected void doHandleResumeEvent(DebugEvent event) { 160 } 161 164 protected void doHandleChangeEvent(DebugEvent event) { 165 if (event.getSource() instanceof IExpression) { 166 refresh(event.getSource()); 167 getVariablesView().populateDetailPane(); 168 } else { 169 super.doHandleChangeEvent(event); 170 } 171 } 172 173 protected boolean isFiltered(DebugEvent event) { 174 return false; 176 } 177 178 179 180 } 181 | Popular Tags |