1 19 20 package org.netbeans.modules.debugger.ui.models; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.AbstractAction ; 24 import javax.swing.Action ; 25 import javax.swing.KeyStroke ; 26 27 import org.netbeans.api.debugger.Breakpoint; 28 import org.netbeans.api.debugger.DebuggerManager; 29 import org.netbeans.modules.debugger.ui.actions.AddBreakpointAction; 30 import org.netbeans.spi.viewmodel.Models; 31 import org.netbeans.spi.viewmodel.TreeModel; 32 import org.netbeans.spi.viewmodel.NodeActionsProvider; 33 import org.netbeans.spi.viewmodel.ModelListener; 34 import org.netbeans.spi.viewmodel.UnknownTypeException; 35 import org.openide.DialogDisplayer; 36 import org.openide.NotifyDescriptor; 37 import org.openide.util.NbBundle; 38 import org.openide.util.RequestProcessor; 39 40 41 44 public class BreakpointsActionsProvider implements NodeActionsProvider { 45 46 47 private static final Action NEW_BREEAKPOINT_ACTION = new AbstractAction 48 (NbBundle.getBundle (BreakpointsActionsProvider.class).getString 49 ("CTL_BreakpointAction_New_Label")) { 50 public void actionPerformed (ActionEvent e) { 51 new AddBreakpointAction ().actionPerformed (null); 52 } 53 }; 54 private static final Action ENABLE_ALL_ACTION = new AbstractAction 55 (NbBundle.getBundle (BreakpointsActionsProvider.class).getString 56 ("CTL_BreakpointAction_EnableAll_Label")) { 57 public boolean isEnabled () { 58 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 59 Breakpoint[] bs = dm.getBreakpoints (); 60 int i, k = bs.length; 61 for (i = 0; i < k; i++) { 62 if (!bs[i].isEnabled()) { 63 return true; 64 } 65 } 66 return false; 67 } 68 public void actionPerformed (ActionEvent e) { 69 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 70 Breakpoint[] bs = dm.getBreakpoints (); 71 int i, k = bs.length; 72 for (i = 0; i < k; i++) 73 bs [i].enable (); 74 } 75 }; 76 private static final Action DISABLE_ALL_ACTION = new AbstractAction 77 (NbBundle.getBundle (BreakpointsActionsProvider.class).getString 78 ("CTL_BreakpointAction_DisableAll_Label")) { 79 public boolean isEnabled () { 80 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 81 Breakpoint[] bs = dm.getBreakpoints (); 82 int i, k = bs.length; 83 for (i = 0; i < k; i++) { 84 if (bs[i].isEnabled()) { 85 return true; 86 } 87 } 88 return false; 89 } 90 public void actionPerformed (ActionEvent e) { 91 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 92 Breakpoint[] bs = dm.getBreakpoints (); 93 int i, k = bs.length; 94 for (i = 0; i < k; i++) 95 bs [i].disable (); 96 } 97 }; 98 private static final Action DELETE_ALL_ACTION = new AbstractAction 99 (NbBundle.getBundle (BreakpointsActionsProvider.class).getString 100 ("CTL_BreakpointAction_DeleteAll_Label")) { 101 public boolean isEnabled () { 102 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 103 Breakpoint[] bs = dm.getBreakpoints (); 104 return bs.length > 0; 105 } 106 public void actionPerformed (ActionEvent e) { 107 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 108 Breakpoint[] bs = dm.getBreakpoints (); 109 int i, k = bs.length; 110 for (i = 0; i < k; i++) 111 dm.removeBreakpoint (bs [i]); 112 } 113 }; 114 private static final Action ENABLE_ACTION = Models.createAction ( 115 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 116 ("CTL_BreakpointAction_Enable_Label"), 117 new Models.ActionPerformer () { 118 public boolean isEnabled (Object node) { 119 return true; 120 } 121 public void perform (Object [] nodes) { 122 int i, k = nodes.length; 123 for (i = 0; i < k; i++) 124 ((Breakpoint) nodes [i]).enable (); 125 } 126 }, 127 Models.MULTISELECTION_TYPE_ANY 128 ); 129 private static final Action DISABLE_ACTION = Models.createAction ( 130 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 131 ("CTL_BreakpointAction_Disable_Label"), 132 new Models.ActionPerformer () { 133 public boolean isEnabled (Object node) { 134 return true; 135 } 136 public void perform (Object [] nodes) { 137 int i, k = nodes.length; 138 for (i = 0; i < k; i++) 139 ((Breakpoint) nodes [i]).disable (); 140 } 141 }, 142 Models.MULTISELECTION_TYPE_ANY 143 ); 144 private static final Action DELETE_ACTION = Models.createAction ( 145 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 146 ("CTL_BreakpointAction_Delete_Label"), 147 new Models.ActionPerformer () { 148 public boolean isEnabled (Object node) { 149 return true; 150 } 151 public void perform (final Object [] nodes) { 152 RequestProcessor.getDefault().post(new Runnable () { 153 public void run() { 154 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 155 int i, k = nodes.length; 156 for (i = 0; i < k; i++) 157 dm.removeBreakpoint ((Breakpoint) nodes [i]); 158 } 159 }); 160 } 161 }, 162 Models.MULTISELECTION_TYPE_ANY 163 ); 164 static { 165 DELETE_ACTION.putValue ( 166 Action.ACCELERATOR_KEY, 167 KeyStroke.getKeyStroke ("DELETE") 168 ); 169 }; 170 private static final Action SET_GROUP_NAME_ACTION = Models.createAction ( 171 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 172 ("CTL_BreakpointAction_SetGroupName_Label"), 173 new Models.ActionPerformer () { 174 public boolean isEnabled (Object node) { 175 return true; 176 } 177 public void perform (Object [] nodes) { 178 setGroupName (nodes); 179 } 180 }, 181 Models.MULTISELECTION_TYPE_ALL 182 ); 183 private static final Action DELETE_ALL_ACTION_S = Models.createAction ( 184 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 185 ("CTL_BreakpointAction_DeleteAll_Label"), 186 new Models.ActionPerformer () { 187 public boolean isEnabled (Object node) { 188 return true; 189 } 190 public void perform (Object [] nodes) { 191 String groupName = (String ) nodes [0]; 192 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 193 Breakpoint[] bs = dm.getBreakpoints (); 194 int i, k = bs.length; 195 for (i = 0; i < k; i++) 196 if (bs [i].getGroupName ().equals (groupName)) 197 dm.removeBreakpoint (bs [i]); 198 } 199 }, 200 Models.MULTISELECTION_TYPE_EXACTLY_ONE 201 ); 202 private static final Action ENABLE_ALL_ACTION_S = Models.createAction ( 203 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 204 ("CTL_BreakpointAction_EnableAll_Label"), 205 new Models.ActionPerformer () { 206 public boolean isEnabled (Object node) { 207 String groupName = (String ) node; 208 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 209 Breakpoint[] bs = dm.getBreakpoints (); 210 int i, k = bs.length; 211 for (i = 0; i < k; i++) { 212 if (bs [i].getGroupName ().equals (groupName)) { 213 if (!bs[i].isEnabled()) { 214 return true; 215 } 216 } 217 } 218 return false; 219 } 220 public void perform (Object [] nodes) { 221 String groupName = (String ) nodes [0]; 222 Breakpoint[] bs = DebuggerManager.getDebuggerManager (). 223 getBreakpoints (); 224 int i, k = bs.length; 225 for (i = 0; i < k; i++) 226 if (bs [i].getGroupName ().equals (groupName)) 227 bs [i].enable (); 228 } 229 }, 230 Models.MULTISELECTION_TYPE_EXACTLY_ONE 231 ); 232 private static final Action DISABLE_ALL_ACTION_S = Models.createAction ( 233 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 234 ("CTL_BreakpointAction_DisableAll_Label"), 235 new Models.ActionPerformer () { 236 public boolean isEnabled (Object node) { 237 String groupName = (String ) node; 238 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 239 Breakpoint[] bs = dm.getBreakpoints (); 240 int i, k = bs.length; 241 for (i = 0; i < k; i++) { 242 if (bs [i].getGroupName ().equals (groupName)) { 243 if (bs[i].isEnabled()) { 244 return true; 245 } 246 } 247 } 248 return false; 249 } 250 public void perform (Object [] nodes) { 251 String groupName = (String ) nodes [0]; 252 Breakpoint[] bs = DebuggerManager.getDebuggerManager (). 253 getBreakpoints (); 254 int i, k = bs.length; 255 for (i = 0; i < k; i++) 256 if (bs [i].getGroupName ().equals (groupName)) 257 bs [i].disable (); 258 } 259 }, 260 Models.MULTISELECTION_TYPE_EXACTLY_ONE 261 ); 262 263 264 266 267 public Action [] getActions (Object node) throws UnknownTypeException { 268 if (node == TreeModel.ROOT) 269 return new Action [] { 270 NEW_BREEAKPOINT_ACTION, 271 null, 272 ENABLE_ALL_ACTION, 273 DISABLE_ALL_ACTION, 274 DELETE_ALL_ACTION, 275 null 276 }; 277 if (node instanceof String ) 278 return new Action [] { 279 SET_GROUP_NAME_ACTION, 280 null, 281 ENABLE_ALL_ACTION_S, 282 DISABLE_ALL_ACTION_S, 283 DELETE_ALL_ACTION_S, 284 null 285 }; 286 if (node instanceof Breakpoint) 287 if (((Breakpoint) node).isEnabled ()) 288 return new Action [] { 289 DISABLE_ACTION, 290 DELETE_ACTION, 291 SET_GROUP_NAME_ACTION, 292 null, 293 NEW_BREEAKPOINT_ACTION, 294 null, 295 ENABLE_ALL_ACTION, 296 DISABLE_ALL_ACTION, 297 DELETE_ALL_ACTION, 298 null 299 }; 300 else 301 return new Action [] { 302 ENABLE_ACTION, 303 DELETE_ACTION, 304 SET_GROUP_NAME_ACTION, 305 null, 306 NEW_BREEAKPOINT_ACTION, 307 null, 308 ENABLE_ALL_ACTION, 309 DISABLE_ALL_ACTION, 310 DELETE_ALL_ACTION, 311 null 312 }; 313 throw new UnknownTypeException (node); 314 } 315 316 public void performDefaultAction (Object node) throws UnknownTypeException { 317 if (node == TreeModel.ROOT) 318 return; 319 if (node instanceof String ) 320 return; 321 if (node instanceof Breakpoint) 322 return; 323 throw new UnknownTypeException (node); 324 } 325 326 public void addModelListener (ModelListener l) { 327 } 329 330 public void removeModelListener (ModelListener l) { 331 } 333 334 341 private static void setGroupName (Object [] nodes) { 342 NotifyDescriptor.InputLine descriptor = new NotifyDescriptor.InputLine ( 343 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 344 ("CTL_BreakpointAction_GroupDialog_NameLabel"), 345 NbBundle.getBundle (BreakpointsActionsProvider.class).getString 346 ("CTL_BreakpointAction_GroupDialog_Title") 347 ); 348 if (DialogDisplayer.getDefault ().notify (descriptor) == 349 NotifyDescriptor.OK_OPTION 350 ) { 351 if (nodes [0] instanceof String ) { 352 String oldName = (String ) nodes [0]; 353 Breakpoint[] bs = DebuggerManager.getDebuggerManager (). 354 getBreakpoints (); 355 int j, jj = bs.length; 356 for (j = 0; j < jj; j++) 357 if ( ((Breakpoint) bs [j]).getGroupName (). 358 equals (oldName) 359 ) 360 ((Breakpoint) bs [j]).setGroupName ( 361 descriptor.getInputText () 362 ); 363 return; 364 } 365 int i, k = nodes.length; 366 for (i = 0; i < k; i++) 367 ((Breakpoint) nodes [i]).setGroupName ( 368 descriptor.getInputText () 369 ); 370 } 372 } 373 } 374 | Popular Tags |