Speed up your development using Templates in Domino Designer

Eclipse provides a bevy of features which are available to us via Domino Designer. One of them is Templates. It allows us to insert commonly used code and easily customize them. So in your Java editor when you type while (and no space after that) then hit Ctrl+Space to bring up content assist it shows you sample code to iterate with enumeration, iterator or condition.

while content assist

These suggestions come from Templates. You can find them by in your Domino Designer by going to menu “File > Preferences” and in section “Java > Editor > Templates”.

Templates

You can also add your own templates. For guys like us working in Lotus Notes/Domino one of the common tasks is to loop over documents in a collection or view. So lets create one for it.

Click on “New” button in Templates Preference window. Enter the details with Name as while, Context as Java statements & Description as iterate with document collection. For pattern use the below code:

Document nextDoc = null;
${d:var(lotus.domino.Document)} = ${dc:var(lotus.domino.DocumentCollection)}.getFirstDocument();
while (${d} != null) {
	nextDoc = ${dc}.getNextDocument(${d});
	${cursor}
	${d}.recycle();
	${d} = nextDoc;
}

while - iterate with document collection

It may look complicated at first but it’s fairly simple. I declare and use variables d of type lotus.domino.Document and dc of type lotus.domino.DocumentCollection. When this pattern is inserted in code then the variables d and dc would be replaced by respective variables declared in actual code.

So now if you type while (and no space after that) then hit Ctrl+Space then content assist would show up a new option of while – iterate with document collection.

while - iterate with document collection content assist

Choose our while option and voila! Your code is done.

If you want to iterate all documents in view it can be done with a little modification and it would look like this:

Document nextDoc = null;
${d:var(lotus.domino.Document)} = ${v:var(lotus.domino.View)}.getFirstDocument();
while (${d} != null) {
	nextDoc = ${v}.getNextDocument(${d});
	${cursor}
	${d}.recycle();
	${d} = nextDoc;
}

As of now Templates in Domino Designer do not support JavaScript. If you want to learn more about Templates in Eclipse I recommend reading this article on IBM developerWorks.

Share:

3 thoughts on “Speed up your development using Templates in Domino Designer

    1. Naveen Maurya Post author

      Thanks Paul. Yes I agree if we need to move to new PC we need to export and backup our preferences, but if we need to share just the templates then we can just export those individual templates. In the Templates Preferences window we can select our custom templates and click on “Export…” button. This would export them to XML file :)

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>