A New Eclipse Timesaver for Flex, Java, and [insert language here] Developers

Monday, June 21, 2010

CFML developers using CFEclipse (and  more recently ColdFusion Builder) have long enjoyed the benefits of Snippets and the Snip Tree View, a way to create customized, variable-driven chunks of code which you can drop into your source with a single keyboard combination. I wrote about them a long time ago, Matt Gifford recently wrote what has become the de facto guide to snippets, and lo many years back Mark Drew made this video which is still relevant today.

To add to the general awesomeness of snippets, you can share them amongst your computers or even other developers. This shows you how to do so with DropBox.

In my experience, once a developer becomes snippet-infected, they tend to bemoan their absence when editing other types of source code. Unfortunately, Snippet insertion never worked when editing other files like Flex, and even when it did work, you had to install the entire CFEclipse plugin which some developers don’t want to do. Until now.

Who’s the target audience?

Flex, Java, JavaScript, Groovy, Scala, [insert your language here] developers who use Eclipse and who do not have ColdFusion Builder installed.* It’s also important that you like to save time.

*ColdFusion Builder snippets should already work with other sources! Good job, CFB team.

How do I install it?

The Eclipse Update Site is at http://cfeclipse.org/snippets/update/. In Eclipse 3.5 and later, you’d use “Help – Install New Software”. Then click the “Add” Button. Then add that URL into the URL field. Follow through to the end.

What will this install into my Eclipse?

This will install a standalone Snippet Tree View and corresponding key binding into Eclipse. By default, the key binding is “Ctrl-Shift-I”. Note that this will be different from the binding mentioned in the above articles, although you can reassign it to whichever key combination you like. In FlashBuilder, I immediately reassigned mine to the familiar Ctrl-J sequence.

Who’s responsible for bringing such Joy unto the world?

We’d be remiss if we didn’t thank the CFEclipse founding fathers. Rob Rohan and Spike Milligan will most likely never know that the work they did still continues to improve the lives of developers around the world. Mark Drew has led CFEclipse for years and many credit him with helping make it a mature, stable platform on which to build CFML applications. And Robert Blackburn added the SnipEx support into the Snippet Tree View. Thanks to all you wonderful people!

For this release -- separating Snippets into their own plugin and refactoring so that they’d be useful for other languages on the Eclipse platform --  Denny Valliant (github) gets all the credit. Denny’s one of those guys you don’t hear much about, but he’s brought inestimable joy into developer lives through all the work he’s done on CFEclipse and other projects. Thank you, Denny.

What to do next?

  1. Install the Snippets Plugin
  2. Read one or more of the links above explaining how to use snippets.
  3. Open up the Snippet Tree View and add some snippets (don’t forget the “trigger text”!)
  4. Go into your editor and type the trigger text for one of the snippets you added. Hit Ctrl-Shift-I to insert the snippet
  5. Repeat Steps 3 and 4 and rejoice in all the time this will save you

5 comments:

K said...

Hi, this stand-alone version of the snippet Tree View is great, exactly what I was looking for.

I installed it into my Eclipse, but ran into the following problem:
- If I open Eclipse and the Snippet Tree View is visible or
- When I add the Snippet Tree view to my Perspective when there is no editor open in the Editor Area
the view doesn't initialize properly. The following error is raised:
java.lang.NullPointerException
at org.cfeclipse.cfml.snippets.properties.CFMLPropertyManager.getSnippetsPath(CFMLPropertyManager.java:103)
at org.cfeclipse.cfml.snippets.views.snips.SnipTreeView.(SnipTreeView.java:153)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
....

If i add the view to my perspective when there is an Editor open, it works just fine.

Any thoughts? I'm posting it here, because I cannot seem to find any other reference to this stand alone version of the Snippet Tree View, neither on the CFEclipse website/wiki/Google groups or anywhere else.

TIA,

K

Marc Esher said...

K,
I'll follow up with Denny and see if he has any thoughts on this.

thanks!

Denny said...

Ja, I know what's causing that I think. I'll check it out a bit later and holler when there's an update available.

Denny said...

Alrighty, looks like it's fixed in the latest version. Update and holler if anything goes sideways for ya!

K said...

Hi Denny,

Tnx for the quick fix. Although it does seem to work a bit better, I'm still getting the error if I open Eclipse and the Snippet Tree View is visible in the first perspective and there is an (text) editor open in the Editor Area.

Note: I'm saying "(test) editor", because if the open editor is a graphical editor (from GEF), I get the error as well, but if it's a text editor (from DLTK), then the Snippet Tree View instantiates just fine.

Besides this instantiation issue, I ran into two more things that I'd like to run by you (although I do not know if this is the proper place to do so. If not, please point me to the proper location).

Item 1: inside the view, the context menu on nodes coming from a snipex server do not work, until you have right-clicked a node that is locally stored. Right-clicking a snipex node afterwards then all of a sudden does pop up the context menu.

When you right-click the snipex node before having right-clicked a locally stored node, the following error appears in the log:
!ENTRY org.eclipse.ui 4 0 2010-11-01 09:19:39.840
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.ClassCastException: org.cfeclipse.snippet.snipex.SnipEx cannot be cast to java.io.File
at org.cfeclipse.cfml.snippets.views.snips.SnipTreeView.getSelectedFile(SnipTreeView.java:665)
at org.cfeclipse.cfml.snippets.views.snips.SnipTreeView.fillContextMenu(SnipTreeView.java:537)
at org.cfeclipse.cfml.snippets.views.snips.SnipTreeView.access$1(SnipTreeView.java:536)
at org.cfeclipse.cfml.snippets.views.snips.SnipTreeView$12.menuAboutToShow(SnipTreeView.java:524)
at org.eclipse.jface.action.MenuManager.fireAboutToShow(MenuManager.java:338)
...

Item 2: Once you have the context menu going on the snipex nodes, when you try to use one of the options from it (or click one of the buttons of the view's toolbar when a snipex node is selected), you also get the same ClassCast error as mentioned under Item 1 in the log and nothing happens.

Hope you can shed some light on this, or point me to the proper location to discuss these things.

TIA,

K