Using the Eclipse templates

The latest release of Naked Objects (version 4) provides a set of templates for quickly adding snippets to your domain classes, from properties and collections to title and dependencies.

To set up Eclipse so these are available you need to import the template files that are included in the distribution. In both the Ant and Maven based distributions they can be found the following directory:

resources
|-- ide
|   `-- eclipse
|       |-- launch
|       `-- templates
|           |-- jmock2-templates.xml
|           |-- junit4-templates.xml
|           `-- nakedobjects-templates.xml

Open up Eclipse’s preferences dialog (Windows/Preferences) and navigate to JavaEditorTemplate. Click the Import button, browse to the templates directory, select the nakedobjects-templates.xml file and press OK. A series of templates will be added prefixed with no such as noa, nolnop etc. Press OK to commit the changes and you are ready to use them.

For example, to insert a property type nop in the editor window within the class declations and press ctrl-space to bring up the available templates.

List of all available templates

Each template has a brief description and the template result is shown in the box next to the list. Selecting the template inserts the code into your file at the cursor replacing the template name that you typed.

Template insert

It also highlights the parts that you can change. So in this example, when we type Purchase, tab, Date, tab, and date we end up with a complete property declaration for a Date value that will display with the label Date as we can see below.

The edited result

The other files each provide a couple of templates for building Junit version 4 tests and using JMock.

The available Naked Objects templates are:-

noa Action
noacho Action argument N choices
noadef Action argument defaults
noadis Action disabling
noahid Action hiding
noaval Action validation
noc-1m Collection (1:m bidir parent)
noc-mmc Collection (m:m bidir child)
noc-mmp Collection (m:m bidir parent)
nocdis Collection disabling
nochid Collection hiding
nocl Collection (list)
nocmod Collection modify
nocs Collection (set)
nocval Collection validation
nod Dependencies region
nods Dependencies – injected service
nofp Factory – new instance (persistent)
noft Factory – new instance (transient)
noid Identification region
noidicon Identification – icon
noidtitle Identification – title
nol Lifecycle region
nolc Lifecycle – create
noll Lifecycle – load
nolp Lifecycle – persist
nolr Lifecycle – remove
nolu Lifecycle – update
nop Property
nop-11c Property (1:1 bidir child)
nop-11p Property (1:1 bidir parent)
nop-m1 Property (m:1 bidir child)
nopcho Property choices
nopdef Property defaults
nopdis Property disabling
nophid Property hiding
nopmod Property modify
nopval Property validation
nosa Search for all
nosafil Search for all matching
nosffil Search for first matching
nosufil Search for unique matching
noval Object-level validation


No Comment

No comments yet

Leave a reply