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