The very first template is probably nop, which stands for Naked Objects Property. This basically creates a property with its setter and (annotated with @MemberOrder) getter. The problem is that I like to keep fields separated from setters and getters, so a template was not the best solution (at least not for me). The nop templates was then replaced with the ready-made ALT+INS, Add Property...
This opens a form that lets you specify the property name, type, and tweak the rest of the generated code a little bit.
And so much for the first template, as all I still need to do is to manually add the @MemberOrder annotation on the getter (but the autocompletion feature is of great help, as a simple @Mem followed by CTRL+space is normally enough).
To create a new code template you have to click on the Tools menu, select the Options item, and when the form opens click on the Code templates tab:
A click on the New button, some clickety clackety and a click on the OK button and there you have it: a brand new template all for you. The templates I've created so far:
- noft (Naked Objects Factory Transient)
/** Creates a new transient ${Type} */
public ${Type} new${Type}(){
${Type} ${instance} = newTransientInstance(${Type}.class);
return ${instance};
}
- noidicon (Naked Objects Identification Icon)
/** The name of the icon that represents the object */
public String iconName(){
return "${iconName}";
}
- noidtitle (Naked Objects Identification Title)
/** A description of the object */Note the use of the reserved ${cursor} property that positions the cursor where you are supposed to add your custom code.
public String title(){
TitleBuffer buf = new TitleBuffer();
// TODO add properties
${cursor}
return buf.toString();
}
- nopval (Naked Objects Property Validation)
/** Validation for property ${property} */Last but not least
public String validate${Property}(${Type} ${value}){
if ((${value} == null)) {
return null;
}
// TODO implement imperative rule
${cursor}
return null;
}
- nopval (Naked Objects Property Validation)
/** Find all ${TypePlural} */
@Exploration
public List<${Type}> findAll${TypePlural}(){
return allInstances(${Type}.class);
}
I'm sure I can do better than this, e.g. there should be a way to automatically fix imports without the need for me to hit SHIFT+CTRL+I - which, anyway, is not all that work, moreover I'm more than used to combine it with ALT+SHIFT+F to format code and CTRL+S to save whenever I type something.
As with all code templates, use the Tab key to switch from a variable to the next one and hit Enter when you're done.
Maybe more on this will follow.
1 comment:
That is very nice. Please post if you tweak it more.
Post a Comment