Steps:
- Create a new NB Module
- Expand the Tree as follows in the projects view
-->Important files-->XML Layer--> -->Editors-->text-->x-java-->CodeTemplates-->Defaults - Right click on the file named org-netbeans-modules-editor-java-codetemplates.xml.
- Click Edit
- append the following line near the end of the file (before the </codetemplates> tag)
- Run the project,
- a new instance of netbeans will be started.
- Bring up the options dialog.
- Click on editor-->Code templates tab
- Select Java as the language
- Scroll down the list looking for suid
Viola, code template ready.
Another option is to use the code generator
- in the module create above right click on the module package and click new
- Optionally click other
- Select code generator in the Module development
- Provide a name
- in the mime type enter text/x-java
- Open the class that is generated and search for the getDisplayName method and replace the method content as return NbBundle.getMessage(SerialVersionUIDGenerator.class, "SerialVersionUIDGenerator.label");
- Now for the meat of the implementation. Search for the invoke method and add the following contents
Caret caret = textComp.getCaret();
int start = Math.min(caret.getDot(), caret.getMark());
StringBuilder builder = new StringBuilder("private static final long serialVersionUID = 1L;");
builder.append(System.getProperty("line.separator","\n"));
Document doc = textComp.getDocument();
try {
doc.insertString(start, builder.toString(), null);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}