1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionEvent ; 24 import java.util.*; 25 import javax.swing.*; 26 import javax.swing.KeyStroke ; 27 import org.netbeans.api.debugger.DebuggerManager; 28 29 import org.netbeans.api.debugger.jpda.JPDAWatch; 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.netbeans.modules.debugger.jpda.ui.WatchPanel; 36 import org.openide.util.NbBundle; 37 import org.openide.util.HelpCtx; 38 import org.openide.DialogDisplayer; 39 40 41 44 public class WatchesActionsProvider implements NodeActionsProvider { 45 46 47 private static final Action NEW_WATCH_ACTION = new AbstractAction 48 (NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_AddNew")) { 49 public void actionPerformed (ActionEvent e) { 50 newWatch (); 51 } 52 }; 53 private static final Action DELETE_ALL_ACTION = new AbstractAction 54 (NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_DeleteAll")) { 55 public void actionPerformed (ActionEvent e) { 56 DebuggerManager.getDebuggerManager ().removeAllWatches (); 57 } 58 }; 59 private static final Action DELETE_ACTION = Models.createAction ( 60 NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Delete"), 61 new Models.ActionPerformer () { 62 public boolean isEnabled (Object node) { 63 return true; 64 } 65 public void perform (Object [] nodes) { 66 int i, k = nodes.length; 67 for (i = 0; i < k; i++) 68 ((JPDAWatch) nodes [i]).remove (); 69 } 70 }, 71 Models.MULTISELECTION_TYPE_ANY 72 ); 73 static { 74 DELETE_ACTION.putValue ( 75 Action.ACCELERATOR_KEY, 76 KeyStroke.getKeyStroke ("DELETE") 77 ); 78 }; 79 private static final Action CUSTOMIZE_ACTION = Models.createAction ( 80 NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Customize"), 81 new Models.ActionPerformer () { 82 public boolean isEnabled (Object node) { 83 return true; 84 } 85 public void perform (Object [] nodes) { 86 customize ((JPDAWatch) nodes [0]); 87 } 88 }, 89 Models.MULTISELECTION_TYPE_EXACTLY_ONE 90 ); 91 92 93 public Action[] getActions (Object node) throws UnknownTypeException { 94 if (node == TreeModel.ROOT) 95 return new Action [] { 96 NEW_WATCH_ACTION, 97 null, 98 DELETE_ALL_ACTION 99 }; 100 if (node instanceof JPDAWatch) 101 return new Action [] { 102 NEW_WATCH_ACTION, 103 null, 104 DELETE_ACTION, 105 DELETE_ALL_ACTION, 106 null, 107 CUSTOMIZE_ACTION 108 }; 109 throw new UnknownTypeException (node); 110 } 111 112 public void performDefaultAction (Object node) throws UnknownTypeException { 113 if (node == TreeModel.ROOT) 114 return; 115 if (node instanceof JPDAWatch) { 116 return; 117 } 118 throw new UnknownTypeException (node); 119 } 120 121 public void addModelListener (ModelListener l) { 122 } 123 124 public void removeModelListener (ModelListener l) { 125 } 126 127 private static void customize (JPDAWatch w) { 128 WatchPanel wp = new WatchPanel (w.getExpression ()); 129 JComponent panel = wp.getPanel (); 130 131 ResourceBundle bundle = NbBundle.getBundle (WatchesActionsProvider.class); 132 org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor ( 133 panel, 134 java.text.MessageFormat.format(bundle.getString("CTL_Edit_Watch_Dialog_Title"), new Object [] { w.getExpression() }) 136 ); 137 dd.setHelpCtx (new HelpCtx ("debug.customize.watch")); 138 Dialog dialog = DialogDisplayer.getDefault ().createDialog (dd); 139 dialog.setVisible (true); 140 dialog.dispose (); 141 142 if (dd.getValue () != org.openide.DialogDescriptor.OK_OPTION) return; 143 if (panel.getClientProperty("WatchCanceled") != null) return ; w.setExpression (wp.getExpression ()); 145 } 146 147 private static void newWatch () { 148 WatchPanel wp = new WatchPanel (""); 149 JComponent panel = wp.getPanel (); 150 151 ResourceBundle bundle = NbBundle.getBundle (WatchesActionsProvider.class); 152 org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor ( 153 panel, 154 bundle.getString ("CTL_New_Watch_Dialog_Title") ); 156 dd.setHelpCtx (new HelpCtx ("debug.new.watch")); 157 Dialog dialog = DialogDisplayer.getDefault ().createDialog (dd); 158 dialog.setVisible (true); 159 dialog.dispose (); 160 161 if (dd.getValue () != org.openide.DialogDescriptor.OK_OPTION) return; 162 if (panel.getClientProperty("WatchCanceled") != null) return ; DebuggerManager.getDebuggerManager ().createWatch (wp.getExpression ()); 164 } 165 } 166 | Popular Tags |