This tutorial is based on an existing tutorial. That tutorial, lets you get started with the NetBeans Plugin-Development, as easily as possible.
Now, you're ready for plugin-development. So, lets get started then!
We won't be using any Wizard, as said before. So, follow these steps to create your Action;
Now, we will extend SayCheez by CallableSystemAction, and you would be prompted by NetBeans, to implement all abstract methods. Press Alt-Insert, let the IDE implement them.
So, you can see the following structure of SayCheez.java;
import org.openide.util.HelpCtx;
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.");
}
@Override
public String getName() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public HelpCtx getHelpCtx() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Do following changes in these methods;
@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;
}
You must be wondering what to do with, NbBundle.getMessage(SayCheez.class, "CTL_SayCheez"); No need to worry, when you first created this project, a file called Bundle.properties gets created into {$your-package}, where SayCheez.java is present. Just add the following line into properties file, and continue coding!
CTL_SayCheez=Say Cheez... # You may change the content on the right side of this assignment operator.
@Override
protected void initialize() {
super.initialize();
// see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
putValue("noIconInMenu", Boolean.TRUE);
}
//Added
@Override
protected boolean asynchronous() {
return false;
}
@Override
protected String iconResource() {
//Replace org/nvarun/tat with your path/to/icon
return "org/nvarun/tat/icon24.png";
}
//see attachments to download icon24.png
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);
}
// Newly Added
@Override
protected boolean asynchronous() {
return false;
}
}
<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>
Thank you!
| icon24.png | ![]() |
1908 bytes |