1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import java.awt.event.ActionEvent ; 23 import java.util.Vector ; 24 import javax.swing.Action ; 25 26 import org.netbeans.api.debugger.DebuggerEngine; 27 import org.netbeans.api.debugger.DebuggerManager; 28 import org.netbeans.spi.debugger.ContextProvider; 29 import org.netbeans.api.debugger.jpda.JPDADebugger; 30 import org.netbeans.api.debugger.jpda.JPDAThread; 31 import org.netbeans.api.debugger.jpda.JPDAThreadGroup; 32 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge; 33 import org.netbeans.modules.debugger.jpda.ui.SourcePath; 34 import org.netbeans.spi.viewmodel.NodeActionsProvider; 35 import org.netbeans.spi.viewmodel.ModelListener; 36 import org.netbeans.spi.viewmodel.UnknownTypeException; 37 import org.netbeans.spi.viewmodel.Models; 38 import org.netbeans.spi.viewmodel.TreeModel; 39 import org.openide.util.NbBundle; 40 41 42 45 public class ThreadsActionsProvider implements NodeActionsProvider { 46 47 private Action MAKE_CURRENT_ACTION = Models.createAction ( 48 NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_MakeCurrent_Label"), 49 new Models.ActionPerformer () { 50 public boolean isEnabled (Object node) { 51 if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread; 52 return debugger.getCurrentThread () != node; 53 } 54 55 public void perform (Object [] nodes) { 56 if (nodes[0] instanceof MonitorModel.ThreadWithBordel) nodes[0] = ((MonitorModel.ThreadWithBordel) nodes[0]).originalThread; 57 ((JPDAThread) nodes [0]).makeCurrent (); 58 } 59 }, 60 Models.MULTISELECTION_TYPE_EXACTLY_ONE 61 ); 62 63 private static Action GO_TO_SOURCE_ACTION = Models.createAction ( 64 NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_GoToSource_Label"), 65 new Models.ActionPerformer () { 66 public boolean isEnabled (Object node) { 67 if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread; 68 return isGoToSourceSupported ((JPDAThread) node); 69 } 70 71 public void perform (Object [] nodes) { 72 if (nodes[0] instanceof MonitorModel.ThreadWithBordel) nodes[0] = ((MonitorModel.ThreadWithBordel) nodes[0]).originalThread; 73 String language = DebuggerManager.getDebuggerManager (). 74 getCurrentSession ().getCurrentLanguage (); 75 SourcePath sp = (SourcePath) DebuggerManager. 76 getDebuggerManager ().getCurrentEngine ().lookupFirst 77 (null, SourcePath.class); 78 sp.showSource ((JPDAThread) nodes [0], language); 79 } 80 }, 81 Models.MULTISELECTION_TYPE_EXACTLY_ONE 82 ); 83 84 private Action SUSPEND_ACTION = Models.createAction ( 85 NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_Suspend_Label"), 86 new Models.ActionPerformer () { 87 public boolean isEnabled (Object node) { 88 if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread; 89 if (node instanceof JPDAThread) 90 return !((JPDAThread) node).isSuspended (); 91 else 92 return true; 93 } 94 95 public void perform (Object [] nodes) { 96 int i, k = nodes.length; 97 for (i = 0; i < k; i++) { 98 Object node = (nodes[i] instanceof MonitorModel.ThreadWithBordel) ? 99 ((MonitorModel.ThreadWithBordel) nodes[i]).originalThread : nodes[i]; 100 if (node instanceof JPDAThread) 101 ((JPDAThread) node).suspend (); 102 else 103 ((JPDAThreadGroup) node).suspend (); 104 } 105 } 106 }, 107 Models.MULTISELECTION_TYPE_ALL 108 ); 109 110 private Action RESUME_ACTION = Models.createAction ( 111 NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_Resume_Label"), 112 new Models.ActionPerformer () { 113 public boolean isEnabled (Object node) { 114 if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread; 115 if (node instanceof JPDAThread) 116 return ((JPDAThread) node).isSuspended (); 117 else 118 return true; 119 } 120 121 public void perform (Object [] nodes) { 122 int i, k = nodes.length; 123 for (i = 0; i < k; i++) { 124 Object node = (nodes[i] instanceof MonitorModel.ThreadWithBordel) ? 125 ((MonitorModel.ThreadWithBordel) nodes[i]).originalThread : nodes[i]; 126 if (node instanceof JPDAThread) 127 ((JPDAThread) node).resume (); 128 else 129 ((JPDAThreadGroup) node).resume (); 130 } 131 } 132 }, 133 Models.MULTISELECTION_TYPE_ALL 134 ); 135 136 private Action INTERRUPT_ACTION = Models.createAction ( 137 NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_Interrupt_Label"), 138 new Models.ActionPerformer () { 139 public boolean isEnabled (Object node) { 140 if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread; 141 if (node instanceof JPDAThread) 142 return !((JPDAThread) node).isSuspended (); 143 else 144 return false; 145 } 146 147 public void perform (Object [] nodes) { 148 int i, k = nodes.length; 149 for (i = 0; i < k; i++) { 150 Object node = (nodes[i] instanceof MonitorModel.ThreadWithBordel) ? 151 ((MonitorModel.ThreadWithBordel) nodes[i]).originalThread : nodes[i]; 152 if (node instanceof JPDAThread) { 153 ((JPDAThread) node).interrupt(); 154 } 155 } 156 } 157 }, 158 Models.MULTISELECTION_TYPE_ALL 159 ); 160 161 private JPDADebugger debugger; 162 163 164 public ThreadsActionsProvider (ContextProvider lookupProvider) { 165 debugger = (JPDADebugger) lookupProvider. 166 lookupFirst (null, JPDADebugger.class); 167 } 168 169 public Action [] getActions (Object node) throws UnknownTypeException { 170 if (node == TreeModel.ROOT) 171 return new Action [0]; 172 if (node instanceof JPDAThreadGroup) { 173 return new Action [] { 174 RESUME_ACTION, 175 SUSPEND_ACTION, 176 }; 177 } else 178 if (node instanceof JPDAThread) { 179 JPDAThread t = (JPDAThread) node; 180 boolean suspended = t.isSuspended (); 181 Action a = null; 182 if (suspended) 183 a = RESUME_ACTION; 184 else 185 a = SUSPEND_ACTION; 186 return new Action [] { 187 MAKE_CURRENT_ACTION, 188 a, 189 INTERRUPT_ACTION, 190 GO_TO_SOURCE_ACTION, 191 }; 192 } else 193 throw new UnknownTypeException (node); 194 } 195 196 public void performDefaultAction (Object node) throws UnknownTypeException { 197 if (node == TreeModel.ROOT) 198 return; 199 if (node instanceof JPDAThread) 200 ((JPDAThread) node).makeCurrent (); 201 else 202 if (node instanceof JPDAThreadGroup) 203 return; 204 else 205 throw new UnknownTypeException (node); 206 } 207 208 212 public void addModelListener (ModelListener l) { 213 } 214 215 219 public void removeModelListener (ModelListener l) { 220 } 221 222 private static boolean isGoToSourceSupported (JPDAThread t) { 223 String language = DebuggerManager.getDebuggerManager (). 224 getCurrentSession ().getCurrentLanguage (); 225 if (!t.isSuspended ()) 226 return false; 227 String className = t.getClassName (); 228 SourcePath sp = (SourcePath) DebuggerManager. 229 getDebuggerManager ().getCurrentEngine ().lookupFirst 230 (null, SourcePath.class); 231 return sp.sourceAvailable (t, language, true); 232 } 233 } 234 | Popular Tags |