This is based on the existing tutorial. That tutorial, lets you get started with the NetBeans Plugin-Development, by creating a Conditionally Enabled (see CookieAction), without using any Wizard and that too smoothly.
Now, you're ready for transformation. So, lets get started then!
public final class SayCheez extends CallableSystemAction {
@Override
protected int mode() {
//throw new UnsupportedOperationException("Not supported yet.");
return CookieAction.MODE_EXACTLY_ONE;
}
@Override
protected Class<?>[] cookieClasses() {
//throw new UnsupportedOperationException("Not supported yet.");
return new Class[]{EditorCookie.class};
}
@Override
public String getName() {
//throw new UnsupportedOperationException("Not supported yet.");
return NbBundle.getMessage(SayCheez.class, "CTL_SayCheez");
}
// Newly Added
@Override
protected void initialize() {
super.initialize();
// see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
putValue("noIconInMenu", Boolean.TRUE);
}
@Override
public HelpCtx getHelpCtx() {
//throw new UnsupportedOperationException("Not supported yet.");
return HelpCtx.DEFAULT_HELP;
}
@Override
protected String iconResource() {
//Replace org/nvarun/tat with your path/to/icon
//see attachments to download icon24.png
return "org/nvarun/tat/icon24.png";
}
// Newly Added
@Override
protected boolean asynchronous() {
return false;
}
@Override
public void performAction() {
EditorCookie editorCookie = activatedNodes[0].getLookup().lookup(EditorCookie.class);
//throw new UnsupportedOperationException("Not supported yet.");
String msg = "I'm plugged in!";
NotifyDescriptor d = new NotifyDescriptor.Message(msg,
NotifyDescriptor.INFORMATION_MESSAGE);
DialogDisplayer.getDefault().notify(d);
}
<folder name="Shortcuts">
<file name="O-F3.shadow">
<attr name="originalFile" stringvalue="Actions/Tools/org-nvarun-tat-SayCheez.instance"/>
</file>
</folder>
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//package {$your-package};
/**
*
* @author Varun Nischal (nvarun@NetBeans.org)
*/
public class SayCheez extends CallableSystemAction {
@Override
public void performAction() {
//throw new UnsupportedOperationException("Not supported yet.");
String msg = "I'm plugged in!";
NotifyDescriptor d = new NotifyDescriptor.Message(msg,
NotifyDescriptor.INFORMATION_MESSAGE);
DialogDisplayer.getDefault().notify(d);
}
@Override
public String getName() {
//throw new UnsupportedOperationException("Not supported yet.");
return NbBundle.getMessage(SayCheez.class, "CTL_SayCheez");
}
@Override
public HelpCtx getHelpCtx() {
//throw new UnsupportedOperationException("Not supported yet.");
return HelpCtx.DEFAULT_HELP;
}
// Newly Added
@Override
protected void initialize() {
super.initialize();
// see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
putValue("noIconInMenu", Boolean.TRUE);
}
@Override
protected String iconResource() {
//Replace org/nvarun/tat with your path/to/icon
//see attachments to download icon24.png
return "org/nvarun/tat/icon24.png";
}
// Newly Added
@Override
protected boolean asynchronous() {
return false;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
<folder name="Actions">
<folder name="Tools">
<file name="org-nvarun-tat-SayCheez.instance"/>
</folder>
</folder>
<folder name="Menu">
<folder name="Tools">
<file name="org-nvarun-tat-SayCheez.shadow">
<attr name="originalFile" stringvalue="Actions/Tools/org-nvarun-tat-SayCheez.instance"/>
<attr name="position" intvalue="150"/>
</file>
<file name="org-nvarun-tat-separatorAfter.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="175"/>
</file>
<file name="org-nvarun-tat-separatorBefore.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="125"/>
</file>
</folder>
</folder>
<folder name="Toolbars">
<folder name="Build">
<file name="org-nvarun-tat-SayCheez.shadow">
<attr name="originalFile" stringvalue="Actions/Tools/org-nvarun-tat-SayCheez.instance"/>
<attr name="position" intvalue="325"/>
</file>
</folder>
</folder>
<!-- Add Shortcut Keys here -->
<folder name="Shortcuts">
<file name="O-F3.shadow">
<attr name="originalFile" stringvalue="Actions/Tools/org-nvarun-tat-SayCheez.instance"/>
</file>
</folder>
</filesystem>
Thanks for following, enjoy and have fun!
| icon24.png | ![]() |
1908 bytes |