X

Geertjan's Blog

  • March 27, 2010

Extending the NetBeans IDE Debugger

Geertjan Wielenga
Product Manager
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="org.demo.detector.java.Bundle#CTL_ShowSelectedObjectVariables"/>
<attr name="injectable" stringvalue="org.demo.detector.java.ShowSelectedObjectVariables"/>
<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"/>

</file>
</folder>
</folder>

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);
dlg.setVisible(true);
}
}

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) {
initComponents();
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.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services