NetBeans IDE 7.3: How to extend the context menu of the members and hierarchy view?
Today i will show you how to extend the context menu of the newly redesigned members and hierarchy view in NetBeans IDE 7.3.
Plugin your action at the following extension points
Navigator/Actions/Members/text/x-java Navigator/Actions/Hierarchy/text/x-java
and get the TreePathHandle from the Node’s lookup. Easy isn’t it? Please note that these extension points are new in NB IDE 7.3 – see the issues [1] and [2].
This allows the integration of current/future actions which react on
TreePathHandle like
- toggle method breakpoint (when a method is selected)
- toggle class breakpoint (when a class is selected)
- run/debug main method (when a class with a main method is selected)
- run/debug test (when a class with testmethods is selected or when a testmethod is selected)
- add as profiling root (when a method is selected)
- integration of my own “Copy FQN” plugin (i will blog about it next time)
But now a more concrete example:
package de.markiewb.netbeans.sample.extendMembersAndHierarchyView;
import java.util.ArrayList;
import java.util.List;
import static javax.swing.Action.NAME;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import org.netbeans.api.java.source.TreePathHandle;
import org.openide.awt.*;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CookieAction;
import org.openide.util.actions.Presenter;
@ActionID(category = "Edit", id = "de.markiewb.netbeans.sample.extendMembersAndHierarchyView.SampleAction")
@ActionRegistration(displayName = "SampleAction")
@ActionReferences({
@ActionReference(path = "Navigator/Actions/Members/text/x-java", position = 1150),
@ActionReference(path = "Navigator/Actions/Hierarchy/text/x-java", position = 1150)
})
public final class SampleAction extends CookieAction implements Presenter.Popup {
public SampleAction() {
putValue(NAME, "Hello TreePathHandle(s)");
}
@Override
public String getName() {
return "Hello TreePathHandle(s)";
}
@Override
public JMenuItem getPopupPresenter() {
return new JMenuItem(this);
}
@Override
public HelpCtx getHelpCtx() {
return null;
}
@Override
protected boolean enable(Node[] activatedNodes) {
//.. use tph from lookup in node
for (Node node : activatedNodes) {
if (null != node.getLookup().lookup(TreePathHandle.class)) {
return true;
};
}
return false;
}
@Override
protected int mode() {
return CookieAction.MODE_ALL;
}
@Override
protected Class[] cookieClasses() {
return new Class[]{Node.class};
}
@Override
protected void performAction(Node[] nodes) {
List<TreePathHandle> treePathHandles = new ArrayList<TreePathHandle>();
for (Node node : nodes) {
treePathHandles.add(node.getLookup().lookup(TreePathHandle.class));
}
//show all treePathHandles
JOptionPane.showMessageDialog(null, "Hello\n" + treePathHandles);
}
}
The result:
The full sample project is available at [3]
[1] http://netbeans.org/bugzilla/show_bug.cgi?id=220057
[2] http://netbeans.org/bugzilla/show_bug.cgi?id=224499
[3] https://github.com/markiewb/nb-api-samples/tree/master/ExtendMembersAndHierarchyView
[4] http://wiki.netbeans.org/DevFaqAddActionToMembersOrHierarchyView
Leave a Reply Cancel reply
Recent Posts
- NetBeans platform development with JRebel even more simplified
- NetBeans IDE: Additional hints plugin to simplify the work with String literals
- NetBeans IDE: Improved documents tabs in nightly builds
- NetBeans IDE: Custom hints
- NetBeans IDE: Verification of plugins and update center URLs for non-verified plugins
Twitter Updates
- RT @jvanzyl: Hell just froze over. Igor (m2e lead) just fired up IDEA. 8 hours ago
- RT @blouerat: Java 9's javac will drop support for Java 1.4 and older source code. openjdk.java.net/jeps/182 3 days ago
- RT @shelajev: Wow, saw a demo of the incoming new #jrebel core, now with class hierarchy reloading functionality. #epic #geekout_ee 4 days ago
- #JEE7 & #GlassFish 4.0 & #NetBeans 7.3.1 now available: bit.ly/16e9CJX 6 days ago
- RT @mojavelinux: #CDI 1.1 is available. Check out what's new & noteworthy, summarized by @plmuir in.relation.to/Bloggers/CDI11… 1 week ago
Tags
Archives
- May 2013 (1)
- March 2013 (2)
- February 2013 (2)
- January 2013 (4)
- December 2012 (3)
- November 2012 (2)
- October 2012 (1)
- September 2012 (2)
- August 2012 (2)
- May 2012 (4)
- April 2012 (2)
- March 2012 (1)
- February 2012 (2)
- January 2012 (1)
- December 2011 (1)
- July 2011 (2)
- June 2011 (1)
- May 2011 (3)
- February 2011 (1)
- November 2010 (1)
- September 2010 (4)
- August 2010 (2)
- June 2010 (2)
- May 2010 (1)
- March 2010 (3)
- January 2010 (2)
- December 2009 (3)
- November 2009 (3)
Blogroll
Blog Stats
- 25,234 hits

Recent Comments