Adding small, powerful extensions to the IDE can be part of any normal development process. For example, you're a web developer. You're creating JSP pages. You need to add some bold tags around bits of text and are getting tired of typing them in manually. Why not create a module that will insert those tags around a selected piece of text for you?
- Create a new module project. (File > New Project, then choose Module Project from the NetBeans Plug-in Modules category.) Name the project "JSPTags" and click Next and Finish.
- Right-click the JSPTags node, choose New > File/Folder. In the NetBeans Module Development category, choose Action. Click Next.
- Choose "Conditionally Enabled". In the Cookie Classes drop-down list, choose "EditorCookie". (Do not choose "EditCookie"; choose "EditorCookie"!) Click Next. Uncheck "Global Menu Item". Check "Editor Context Menu Item". Choose "text/x-jsp" from the drop-down list. Click Next.
- Type "AddBoldAction" in Class Name and "Surround with Bold" in Display Name. Click Finish.
- Declare a dependency on "Editor Library", in the module's Project Properties dialog box (use the Libraries panel). Now remove the line generated in the performAction method and replace it with the following three:
JTextComponent editor = Registry.getMostActiveComponent();
String selection = editor.getSelectedText();
editor.replaceSelection("<b>" + selection + "</b>");
- Right-click the module and choose Install/Reload in Development IDE.
- Now, in your JSP page, select some text with your mouse, right-click and choose "Surround with Bold". And... now you magically have bold tags around the selected text!
This procedure is so trivial, it is so easy to do, that it (as well as many small modules like it) can be created while you're in the middle of some development cycle, as a small diversion that is useful at the sme time. Hurray for NetBeans module development.