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.awt.event.ActionListener ; 25 import javax.swing.Action ; 26 import javax.swing.JButton ; 27 import javax.swing.JComponent ; 28 29 import org.netbeans.api.debugger.Breakpoint; 30 import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint; 31 import org.netbeans.api.debugger.jpda.ExceptionBreakpoint; 32 import org.netbeans.api.debugger.jpda.FieldBreakpoint; 33 import org.netbeans.api.debugger.jpda.JPDABreakpoint; 34 import org.netbeans.api.debugger.jpda.LineBreakpoint; 35 import org.netbeans.api.debugger.jpda.MethodBreakpoint; 36 import org.netbeans.api.debugger.jpda.ThreadBreakpoint; 37 import org.netbeans.spi.viewmodel.NodeActionsProvider; 38 import org.netbeans.spi.viewmodel.ModelListener; 39 import org.netbeans.spi.viewmodel.UnknownTypeException; 40 import org.netbeans.spi.viewmodel.Models; 41 42 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge; 43 import org.netbeans.modules.debugger.jpda.ui.breakpoints.*; 44 import org.netbeans.spi.debugger.ui.Controller; 45 import org.netbeans.spi.viewmodel.NodeActionsProviderFilter; 46 47 import org.openide.DialogDescriptor; 48 import org.openide.DialogDisplayer; 49 import org.openide.util.HelpCtx; 50 import org.openide.util.NbBundle; 51 52 53 56 public class BreakpointsActionsProvider implements NodeActionsProviderFilter { 57 58 private static final Action GO_TO_SOURCE_ACTION = Models.createAction ( 59 loc("CTL_Breakpoint_GoToSource_Label"), new Models.ActionPerformer () { 61 public boolean isEnabled (Object node) { 62 return true; 63 } 64 public void perform (Object [] nodes) { 65 goToSource ((LineBreakpoint) nodes [0]); 66 } 67 }, 68 Models.MULTISELECTION_TYPE_EXACTLY_ONE 69 ); 70 private static final Action CUSTOMIZE_ACTION = Models.createAction ( 71 loc("CTL_Breakpoint_Customize_Label"), new Models.ActionPerformer () { 73 public boolean isEnabled (Object node) { 74 return true; 75 } 76 public void perform (Object [] nodes) { 77 customize ((Breakpoint) nodes [0]); 78 } 79 }, 80 Models.MULTISELECTION_TYPE_EXACTLY_ONE 81 ); 82 83 private static String loc(String key) { 84 return NbBundle.getBundle(BreakpointsActionsProvider.class).getString(key); 85 } 86 87 public Action [] getActions (NodeActionsProvider original, Object node) 88 throws UnknownTypeException { 89 if (!(node instanceof JPDABreakpoint)) 90 return original.getActions (node); 91 92 Action [] oas = original.getActions (node); 93 if (node instanceof LineBreakpoint) { 94 Action [] as = new Action [oas.length + 3]; 95 as [0] = GO_TO_SOURCE_ACTION; 96 as [1] = null; 97 System.arraycopy (oas, 0, as, 2, oas.length); 98 as [as.length - 1] = CUSTOMIZE_ACTION; 99 return as; 100 } 101 Action [] as = new Action [oas.length + 1]; 102 System.arraycopy (oas, 0, as, 0, oas.length); 103 as [as.length - 1] = CUSTOMIZE_ACTION; 104 return as; 105 } 106 107 public void performDefaultAction (NodeActionsProvider original, Object node) throws UnknownTypeException { 108 if (node instanceof LineBreakpoint) 109 goToSource ((LineBreakpoint) node); 110 else 111 if (node instanceof JPDABreakpoint) 112 customize ((Breakpoint) node); 113 else 114 original.performDefaultAction (node); 115 } 116 117 public void addModelListener (ModelListener l) { 118 } 119 120 public void removeModelListener (ModelListener l) { 121 } 122 123 public static void customize (Breakpoint b) { 124 JComponent c = null; 125 if (b instanceof LineBreakpoint) 126 c = new LineBreakpointPanel ((LineBreakpoint) b); 127 else 128 if (b instanceof FieldBreakpoint) 129 c = new FieldBreakpointPanel ((FieldBreakpoint) b); 130 else 131 if (b instanceof ClassLoadUnloadBreakpoint) 132 c = new ClassBreakpointPanel ((ClassLoadUnloadBreakpoint) b); 133 else 134 if (b instanceof MethodBreakpoint) 135 c = new MethodBreakpointPanel ((MethodBreakpoint) b); 136 else 137 if (b instanceof ThreadBreakpoint) 138 c = new ThreadBreakpointPanel ((ThreadBreakpoint) b); 139 else 140 if (b instanceof ExceptionBreakpoint) 141 c = new ExceptionBreakpointPanel ((ExceptionBreakpoint) b); 142 143 c.getAccessibleContext().setAccessibleDescription( 144 NbBundle.getMessage(BreakpointsActionsProvider.class, "ACSD_Breakpoint_Customizer_Dialog")); HelpCtx helpCtx = HelpCtx.findHelp (c); 146 if (helpCtx == null) { 147 helpCtx = new HelpCtx ("debug.add.breakpoint"); } 149 final Controller[] cPtr = new Controller[] { (Controller) c }; 150 final DialogDescriptor[] descriptorPtr = new DialogDescriptor[1]; 151 final Dialog [] dialogPtr = new Dialog [1]; 152 ActionListener buttonsActionListener = new ActionListener () { 153 public void actionPerformed(ActionEvent ev) { 154 if (descriptorPtr[0].getValue() == DialogDescriptor.OK_OPTION) { 155 boolean ok = cPtr[0].ok(); 156 if (ok) { 157 dialogPtr[0].setVisible(false); 158 } 159 } else { 160 dialogPtr[0].setVisible(false); 161 } 162 } 163 }; 164 DialogDescriptor descriptor = new DialogDescriptor ( 165 c, 166 NbBundle.getMessage ( 167 BreakpointsActionsProvider.class, 168 "CTL_Breakpoint_Customizer_Title" ), 170 true, 171 DialogDescriptor.OK_CANCEL_OPTION, 172 DialogDescriptor.OK_OPTION, 173 DialogDescriptor.DEFAULT_ALIGN, 174 helpCtx, 175 buttonsActionListener 176 ); 177 descriptor.setClosingOptions(new Object [] {}); 178 Dialog d = DialogDisplayer.getDefault ().createDialog (descriptor); 179 d.pack (); 180 descriptorPtr[0] = descriptor; 181 dialogPtr[0] = d; 182 d.setVisible (true); 183 } 184 185 private static void goToSource (LineBreakpoint b) { 186 EditorContextBridge.showSource (b, null); 187 } 188 } 189 | Popular Tags |