Templates in Eclipse


I am loving Eclipse more and more every time I use. This IDE just rocks. Yes, it has it's quirks, but it still beats XCode hands down ..... no competition whatsoever. With Eclipse, your productivity soars. Anyway enough ranting, here is a tip on making your life easy with Templates........ saving keystrokes = more productivity = "More Fun" (TM) (Mike Schrag recently trademarked the "No Fun" statement on the wolips mailing list, so I had better trademark "More Fun" before he grabs it ;-)

Eclipse allows you to define templates for commonly used constructs. Think of templates as shorthand where you can very easily and quickly insert a standard piece of code, html of whatever with a couple of key strokes.

For example, now that we are in Eclipse, we often want to enter the generic webobject tag

<webobject name = "someName"></webobject>

Now what a pain if you have to type that every time!

OK, so select the Window/Preferences menu, and as shown on the left of the screenshot below, navigate to HTML Templates.

Click New and define the template as shown below. Click in the place you want the cursor to be after the automatic insertion of a template and click the Insert Variable button and select cursor.

Now head back to a WOComponent in the HTML editor view and type wo and then ctrl-space for auto-completion .... and presto!!

The Java preferences also has Templates where you can define things like "logd" for those pesky if (log.isDebugEnabled()) log.debug(""); statements, logi for log.info, etc. etc.






Mike Schrag had the following useful additional info:

I can't recall if i posted my sop template here before, but I love this one:
name = sop
context = java
System.out.println("${enclosing_type}.${enclosing_method}: ${cursor}");

(note there's a newline after that)
So when you just want a quick debug line, you do sop<complete> and it will make a 
System.out.println("TheClassYourAreIn.theMethodYouAreIn: <cursor>

I also have
name = attr
context = java
System.out.println("${enclosing_type}.${enclosing_method}: ${name} = " + ${name});

this is similar except you often want to just print out a variable or method, so this one automatically drops into into editing a templated variable and it changes in both places as you type (so it prints out the name of what you are printing as you type it -- like cmd-2 r).

Kieran also mentioned a shortcut for the <webobject> tag ... If you're using wonder, you can also turn on the inline binding parser in Wonder with:

ognl.helperFunctions=true
ognl.inlineBindings=true

(well that turns on inline bindings AND helpers, but both are cool) which gives you <wo name = "Whatever"></wo> which saves hundreds of virtual trees as well as things like <wo:if condition = "$whatever">...</wo>.

ms

Posted: Fri - March 2, 2007 at 09:27 PM        


Published by