001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.ui.actions;
043:
044: import java.awt.Window;
045: import java.util.*;
046: import java.beans.*;
047: import javax.swing.*;
048: import java.awt.event.*;
049: import java.util.Set;
050: import java.util.TreeSet;
051:
052: import org.openide.awt.Mnemonics;
053: import org.openide.util.HelpCtx;
054: import org.openide.util.NbBundle;
055:
056: import org.netbeans.api.debugger.*;
057: import org.netbeans.api.debugger.Breakpoint.*;
058: import org.netbeans.spi.debugger.ui.BreakpointType;
059: import org.netbeans.spi.debugger.ui.Controller;
060:
061: /**
062: * New Breakpint Dialog panel.
063: *
064: * @author Jan Jacura
065: */
066: // <RAVE>
067: // Make the class implement HelpCtx.Provider to be able to get Help for it
068: // public class AddBreakpointPanel extends javax.swing.JPanel {
069: // ====
070: public class AddBreakpointPanel extends javax.swing.JPanel implements
071: HelpCtx.Provider {
072: // </RAVE>
073:
074: public static final String PROP_TYPE = "type";
075:
076: private static Object lastSelectedCategory;
077:
078: // variables ...............................................................
079:
080: private boolean doNotRefresh = false;
081: /** List of cathegories. */
082: private Set cathegories = new TreeSet();
083: /** Types in currently selected cathegory. */
084: private ArrayList types = new ArrayList();
085: /** Currently selected type. */
086: private BreakpointType type;
087: private JComponent customizer;
088:
089: private javax.swing.JLabel jLabel1;
090: private javax.swing.JLabel jLabel2;
091: private javax.swing.JComboBox cbCathegory;
092: private javax.swing.JComboBox cbEvents;
093: private javax.swing.JPanel pEvent;
094: /** <CODE>HelpCtx</CODE> of the selected breakpoint type's customizer */
095: private HelpCtx helpCtx;
096: private List<? extends BreakpointType> breakpointTypes;
097:
098: // init ....................................................................
099:
100: /** Creates new form AddBreakpointPanel */
101: public AddBreakpointPanel() {
102: breakpointTypes = DebuggerManager.getDebuggerManager().lookup(
103: null, BreakpointType.class);
104: String def = null;
105: for (BreakpointType bt : breakpointTypes) {
106: String dn = bt.getCategoryDisplayName();
107: if (!cathegories.contains(dn)) {
108: cathegories.add(dn);
109: }
110: if (bt.isDefault())
111: def = dn;
112: }
113: cbCathegory = new javax.swing.JComboBox(cathegories.toArray());
114:
115: initComponents();
116: if (def != null) {
117: cbCathegory.setSelectedItem(def);
118: selectCathegory(def);
119: } else if (breakpointTypes.size() > 0) {
120: if (lastSelectedCategory != null
121: && cathegories.contains(lastSelectedCategory)) {
122: cbCathegory.setSelectedItem(lastSelectedCategory);
123: } else {
124: cbCathegory.setSelectedIndex(0);
125: }
126: selectCathegory((String) cbCathegory.getSelectedItem());
127: }
128: }
129:
130: // public interface ........................................................
131:
132: public BreakpointType getType() {
133: return type;
134: }
135:
136: public Controller getController() {
137: return (Controller) customizer;
138: }
139:
140: // other methods ...........................................................
141:
142: private void initComponents() {
143: getAccessibleContext().setAccessibleDescription(
144: NbBundle.getBundle(AddBreakpointPanel.class).getString(
145: "ACSD_AddBreakpointPanel")); // NOI18N
146: setLayout(new java.awt.GridBagLayout());
147: java.awt.GridBagConstraints gridBagConstraints1;
148:
149: if (cathegories.size() > 1) {
150: jLabel1 = new javax.swing.JLabel();
151: Mnemonics.setLocalizedText(jLabel1, NbBundle.getBundle(
152: AddBreakpointPanel.class).getString(
153: "CTL_Breakpoint_cathegory")); // NOI18N
154: gridBagConstraints1 = new java.awt.GridBagConstraints();
155: gridBagConstraints1.gridwidth = 2;
156: gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0,
157: 0);
158: add(jLabel1, gridBagConstraints1);
159:
160: cbCathegory
161: .addActionListener(new java.awt.event.ActionListener() {
162: public void actionPerformed(
163: java.awt.event.ActionEvent evt) {
164: cbCathegoryActionPerformed(evt);
165: }
166: });
167: cbCathegory
168: .getAccessibleContext()
169: .setAccessibleDescription(
170: NbBundle
171: .getBundle(AddBreakpointPanel.class)
172: .getString(
173: "ACSD_CTL_Breakpoint_cathegory")); // NOI18N
174: jLabel1.setLabelFor(cbCathegory);
175: gridBagConstraints1 = new java.awt.GridBagConstraints();
176: gridBagConstraints1.gridwidth = 2;
177: gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0,
178: 0);
179: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
180: add(cbCathegory, gridBagConstraints1);
181: }
182:
183: jLabel2 = new javax.swing.JLabel();
184: Mnemonics.setLocalizedText(jLabel2, NbBundle.getBundle(
185: AddBreakpointPanel.class).getString(
186: "CTL_Breakpoint_type")); // NOI18N
187: gridBagConstraints1 = new java.awt.GridBagConstraints();
188: gridBagConstraints1.gridwidth = 2;
189: gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 0);
190: add(jLabel2, gridBagConstraints1);
191:
192: cbEvents = new javax.swing.JComboBox();
193: cbEvents.addActionListener(new java.awt.event.ActionListener() {
194: public void actionPerformed(java.awt.event.ActionEvent evt) {
195: cbEventsActionPerformed();
196: }
197: });
198: cbEvents.getAccessibleContext().setAccessibleDescription(
199: NbBundle.getBundle(AddBreakpointPanel.class).getString(
200: "ACSD_CTL_Breakpoint_type")); // NOI18N
201: cbEvents.setMaximumRowCount(12);
202: gridBagConstraints1 = new java.awt.GridBagConstraints();
203: gridBagConstraints1.gridwidth = 0;
204: gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 12);
205: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
206: add(cbEvents, gridBagConstraints1);
207: jLabel2.setLabelFor(cbEvents);
208: pEvent = new javax.swing.JPanel();
209: pEvent.setLayout(new java.awt.BorderLayout());
210: gridBagConstraints1 = new java.awt.GridBagConstraints();
211: gridBagConstraints1.gridwidth = 0;
212: gridBagConstraints1.insets = new java.awt.Insets(9, 9, 0, 9);
213: gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
214: gridBagConstraints1.weightx = 1.0;
215: gridBagConstraints1.weighty = 1.0;
216: add(pEvent, gridBagConstraints1);
217: }
218:
219: private void cbEventsActionPerformed() {
220: // Add your handling code here:
221: if (doNotRefresh)
222: return;
223: SwingUtilities.invokeLater(new Runnable() {
224: public void run() {
225: boolean pv = cbEvents.isPopupVisible();
226: int j = cbEvents.getSelectedIndex();
227: if (j < 0)
228: return;
229: update((BreakpointType) types.get(j));
230: if (pv)
231: SwingUtilities.invokeLater(new Runnable() {
232: public void run() {
233: cbEvents.setPopupVisible(true);
234: }
235: });
236: //cbEvents.setPopupVisible (true);
237: }
238: });
239: }
240:
241: private void cbCathegoryActionPerformed(
242: java.awt.event.ActionEvent evt) {
243: // Add your handling code here:
244: if (doNotRefresh)
245: return;
246: String c = (String) cbCathegory.getSelectedItem();
247: if (c == null)
248: return;
249: selectCathegory(c);
250: }
251:
252: private void selectCathegory(String c) {
253: lastSelectedCategory = c;
254: doNotRefresh = true;
255: cbEvents.removeAllItems();
256: types = new ArrayList();
257: int defIndex = 0;
258: for (BreakpointType bt : breakpointTypes) {
259: if (!bt.getCategoryDisplayName().equals(c))
260: continue;
261: cbEvents.addItem(bt.getTypeDisplayName());
262: types.add(bt);
263: if (bt.isDefault())
264: defIndex = cbEvents.getItemCount() - 1;
265: }
266: doNotRefresh = false;
267: if (defIndex < cbEvents.getItemCount())
268: cbEvents.setSelectedIndex(defIndex);
269: }
270:
271: /**
272: * Returns <CODE>HelpCtx</CODE> of the selected breakpoint type's customizer.
273: * It is used in {@link AddBreakpointAction.AddBreakpointDialogManager}.
274: */
275: // <RAVE>
276: // Make getHelpCtx() method public to correctly implement HelpCtx.Provider
277: // HelpCtx getHelpCtx() {
278: // ====
279: public HelpCtx getHelpCtx() {
280: // </RAVE>
281: return helpCtx;
282: }
283:
284: private void update(BreakpointType t) {
285: if (type == t)
286: return;
287: pEvent.removeAll();
288: DebuggerManager d = DebuggerManager.getDebuggerManager();
289: BreakpointType old = type;
290: type = t;
291: customizer = type.getCustomizer();
292: if (customizer == null)
293: return;
294:
295: //Set HelpCtx. This method must be called _before_ the customizer
296: //is added to some container, otherwise HelpCtx.findHelp(...) would
297: //query also the customizer's parents.
298: // <RAVE>
299: // The help IDs for the customizer panels have to be different from the
300: // values returned by getHelpCtx() because they provide different help
301: // in the 'Add Breakpoint' dialog and when invoked in the 'Breakpoints' view
302: // helpCtx = HelpCtx.findHelp (customizer);
303: // ====
304: String hid = (String) customizer
305: .getClientProperty("HelpID_AddBreakpointPanel"); // NOI18N
306: if (hid != null) {
307: helpCtx = new HelpCtx(hid);
308: } else {
309: helpCtx = HelpCtx.findHelp(customizer);
310: }
311: // </RAVE>
312:
313: pEvent.add(customizer, "Center"); // NOI18N
314: pEvent.getAccessibleContext().setAccessibleDescription(
315: customizer.getAccessibleContext()
316: .getAccessibleDescription());
317: customizer.getAccessibleContext().setAccessibleName(
318: pEvent.getAccessibleContext().getAccessibleName());
319: revalidate();
320: Window w = SwingUtilities.windowForComponent(this);
321: if (w == null)
322: return;
323: w.pack();
324: firePropertyChange(PROP_TYPE, old, type);
325: }
326: }
|