1 19 20 package org.netbeans.modules.debugger.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 28 import org.netbeans.api.debugger.DebuggerManager; 29 30 import org.netbeans.api.debugger.Watch; 31 import org.netbeans.modules.debugger.ui.actions.AddWatchAction; 32 import org.netbeans.modules.debugger.ui.WatchPanel; 33 import org.netbeans.spi.viewmodel.Models; 34 import org.netbeans.spi.viewmodel.TreeModel; 35 import org.netbeans.spi.viewmodel.NodeActionsProvider; 36 import org.netbeans.spi.viewmodel.ModelListener; 37 import org.netbeans.spi.viewmodel.UnknownTypeException; 38 import org.openide.DialogDisplayer; 39 import org.openide.util.NbBundle; 40 import org.openide.util.HelpCtx; 41 42 43 46 public class WatchesActionsProvider implements NodeActionsProvider { 47 48 private static final Action NEW_WATCH_ACTION = new AbstractAction 49 (NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_AddNew")) { 50 public void actionPerformed (ActionEvent e) { 51 ((AddWatchAction) AddWatchAction.findObject(AddWatchAction.class, true)).actionPerformed(null); 52 } 53 }; 54 private static final Action DELETE_ALL_ACTION = new AbstractAction 55 (NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_DeleteAll")) { 56 public void actionPerformed (ActionEvent e) { 57 DebuggerManager.getDebuggerManager ().removeAllWatches (); 58 } 59 }; 60 private static final Action DELETE_ACTION = Models.createAction ( 61 NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Delete"), 62 new Models.ActionPerformer () { 63 public boolean isEnabled (Object node) { 64 return true; 65 } 66 public void perform (Object [] nodes) { 67 int i, k = nodes.length; 68 for (i = 0; i < k; i++) 69 ((Watch) nodes [i]).remove (); 70 } 71 }, 72 Models.MULTISELECTION_TYPE_ANY 73 ); 74 static { 75 DELETE_ACTION.putValue ( 76 Action.ACCELERATOR_KEY, 77 KeyStroke.getKeyStroke ("DELETE") 78 ); 79 }; 80 private static final Action CUSTOMIZE_ACTION = Models.createAction ( 81 NbBundle.getBundle(WatchesActionsProvider.class).getString("CTL_WatchAction_Customize"), 82 new Models.ActionPerformer () { 83 public boolean isEnabled (Object node) { 84 return true; 85 } 86 public void perform (Object [] nodes) { 87 customize ((Watch) nodes [0]); 88 } 89 }, 90 Models.MULTISELECTION_TYPE_EXACTLY_ONE 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 Watch) 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 Watch) { 116 customize ((Watch) node); 117 return; 118 } 119 throw new UnknownTypeException (node); 120 } 121 122 public void addModelListener (ModelListener l) { 123 } 124 125 public void removeModelListener (ModelListener l) { 126 } 127 128 private static void customize (Watch w) { 129 130 WatchPanel wp = new WatchPanel(w.getExpression()); 131 JComponent panel = wp.getPanel(); 132 133 org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor( 134 panel, 135 NbBundle.getMessage(WatchesActionsProvider.class, "CTL_WatchDialog_Title", w.getExpression()) 137 ); 138 dd.setHelpCtx(new HelpCtx("debug.add.watch")); 139 Dialog dialog = DialogDisplayer.getDefault().createDialog(dd); 140 dialog.setVisible(true); 141 dialog.dispose(); 142 143 if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return; 144 w.setExpression(wp.getExpression()); 145 } 146 } 147 | Popular Tags |