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