Saturday Mar 27, 2010

Extending the NetBeans IDE Debugger

The real message of the article "How to Make the NetBeans Platform Sensitive to Customers", which I recently wrote on NetBeans Zone, is that actions in applications on the NetBeans Platform can be sensitive to their business objects (also known as model objects). In the case of that article, the business object was "Customer", while in NetBeans IDE the business objects are "FileObject", "DataObject", "Node", among others.

One of these is org.netbeans.api.debugger.jpda.ObjectVariable, which enables you to create actions that are sensitive to object variables in the NetBeans IDE Debugger:

<folder name="Actions">
    <folder name="Build">
        <file name="org-demo-detector-java-ShowSelectedObjectVariables.instance">
            <attr name="delegate" methodvalue="org.openide.awt.Actions.inject"/>
            <attr name="displayName" bundlevalue=""/>
            <attr name="injectable" stringvalue=""/>
            <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.context"/>
            <attr name="noIconInMenu" boolvalue="false"/>
            <attr name="iconBase" stringvalue="org/demo/detector/java/customer.png"/>
            <attr name="selectionType" stringvalue="ANY"/>
            <attr name="type" stringvalue="org.netbeans.api.debugger.jpda.ObjectVariable"/>

From the bold lines above, especially, you can see that all the selected "org.netbeans.api.debugger.jpda.ObjectVariable" instances will be injected into my action class, which I defined as follows:

import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import org.netbeans.api.debugger.jpda.ObjectVariable;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;

public final class ShowSelectedObjectVariables implements ActionListener {

    private final List<ObjectVariable> context;

    public ShowSelectedObjectVariables(List<ObjectVariable> context) {
        this.context = context;

    public void actionPerformed(ActionEvent e) {
        DialogDescriptor dd = new DialogDescriptor(new UIPanel(context), "Selected Variables");
        Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);

The "UIPanel" that you see above receives the selected ObjectVariables, where they are placed into a text area, as shown below, thanks to this constructor in the panel:

UIPanel(List<ObjectVariable> context) {
    for (ObjectVariable objectVariable : context) {
        jTextArea1.append(objectVariable.getType() + 
                ": " + objectVariable.getValue()+"\\n");

To get the above to work, start the debugger in the IDE where you install the module. Then, when you select a row in the Variables window, the action will become enabled (the grumpy face button in the toolbar below) and when you invoke the action your new dialog will appear, showing the currently selected variables:

So, now you've made your first steps in extending the NetBeans IDE Debugger, more about which can be read here.


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« March 2010 »