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 26 import org.netbeans.api.debugger.DebuggerManager; 27 import org.netbeans.api.debugger.Session; 28 import org.netbeans.spi.viewmodel.Models; 29 import org.netbeans.spi.viewmodel.TreeModel; 30 import org.netbeans.spi.viewmodel.NodeActionsProvider; 31 import org.netbeans.spi.viewmodel.ModelListener; 32 import org.netbeans.spi.viewmodel.UnknownTypeException; 33 import org.openide.util.NbBundle; 34 35 36 39 public class SessionsActionsProvider implements NodeActionsProvider { 40 41 private static final Action FINISH_ALL_ACTION = new AbstractAction 42 (NbBundle.getBundle(SessionsActionsProvider.class).getString("CTL_SessionAction_FinishAll_Label")) { 43 public void actionPerformed (ActionEvent e) { 44 Session[] ss = DebuggerManager.getDebuggerManager (). 45 getSessions (); 46 int i, k = ss.length; 47 for (i = 0; i < k; i++) 48 ss [i].kill (); 49 } 50 }; 51 private Action MAKE_CURRENT_ACTION = Models.createAction ( 52 NbBundle.getBundle(SessionsActionsProvider.class).getString("CTL_SessionAction_MakeCurrent_Label"), new Models.ActionPerformer () { 53 public boolean isEnabled (Object node) { 54 return DebuggerManager.getDebuggerManager (). 55 getCurrentSession () != node; 56 } 57 58 public void perform (Object [] nodes) { 59 DebuggerManager.getDebuggerManager ().setCurrentSession ( 60 (Session) nodes [0] 61 ); 62 } 63 }, 64 Models.MULTISELECTION_TYPE_EXACTLY_ONE 65 ); 66 private static final Action FINISH_ACTION = Models.createAction ( 67 NbBundle.getBundle(SessionsActionsProvider.class).getString("CTL_SessionAction_Finish_Label"), 68 new Models.ActionPerformer () { 69 public boolean isEnabled (Object node) { 70 return true; 71 } 72 public void perform (Object [] nodes) { 73 int i, k = nodes.length; 74 for (i = 0; i < k; i++) 75 ((Session) nodes [i]).kill (); 76 } 77 }, 78 Models.MULTISELECTION_TYPE_ANY 79 ); 80 81 public Action [] getActions (Object node) throws UnknownTypeException { 82 if (node == TreeModel.ROOT) 83 return new Action [] { 84 FINISH_ALL_ACTION 85 }; 86 if (node instanceof Session) 87 return new Action [] { 88 MAKE_CURRENT_ACTION, 89 FINISH_ACTION, 90 null, 91 FINISH_ALL_ACTION 92 }; 93 throw new UnknownTypeException (node); 94 } 95 96 public void performDefaultAction (Object node) throws UnknownTypeException { 97 if (node == TreeModel.ROOT) 98 return; 99 if (node instanceof Session) { 100 if (DebuggerManager.getDebuggerManager ().getCurrentSession () == 101 node 102 ) return; 103 DebuggerManager.getDebuggerManager ().setCurrentSession ( 104 (Session) node 105 ); 106 return; 107 } 108 throw new UnknownTypeException (node); 109 } 110 111 public void addModelListener (ModelListener l) { 112 } 113 114 public void removeModelListener (ModelListener l) { 115 } 116 } 117 | Popular Tags |