Archive for July, 2006

Maybe I’m just easily entertained…

Monday, July 31st, 2006

I use web tools for all my XML editing needs (which, frankly, are many). One feature that I really love is the way that code complete works based on the current contents of the document. If I’ve embedded a <description> element inside a <resource> element, the next time I’m in a <resource> element and hit CTRL-space, one of the options is <description>. All this without a DTD or schema defined. How cool is that?

Toys in the Attic

Tuesday, July 25th, 2006

When you delete a file in Eclipse, it is deleted from the CVS repository when you commit the change (by committing the folder). But CVS doesn’t destroy the file, it puts it in the ‘attic’. If you ever need to get that file back, you can.

From the context menu for a directory or package, select “Team > Restore from Repository…”. You’ll see:

On the “Restore from Repository” dialog, select the resource and version (you get a preview) and click “Finish” to load the file into your workspace. Once you have the file in your workspace, you still need to commit it to put it back into the respository.

Installing Eclipse

Thursday, July 20th, 2006

I decided to update the screen cam that demonstrates how to download and install Eclipse (I made the old one before the Eclipse 3.2 release). The new version replaces the old version, so the old link still works. I’ve decided to tinker with the screen size a little with this one; I changed my resolution to 800×600 to make sure that everything is easy to see. Of course, after playing in that resolution for a while, I can’t help but think about how huge 800×600 seemed 15 or so years ago and how small it feels now.

But anyways…

I’ve been helping Matt answer a few questions sent to webmaster@eclipse.org concerning installation of the Eclipse SDK. The answer is almost always the same: download the ZIP file and decompress it using the software of your choice; then locate and double-click the “eclipse.exe” icon. Webmaster is probably not the right target for these sorts of questions (the newsgroups are a much better place to go), and we always try to provide a comment to that effect.

I’ve always loved the simplicity of installing Eclipse: no weird entries in the registry or files strewn about the place. But I understand how some folks can be confused by the lack of a proper installer. This is changing as some organizations are now offering distributions of Eclipse. I wrote about Yoxos a little while back. nexB offers EasyEclipse which provides numerous configurations of Eclipse, complete with double-clickable installers.

Loosely coupled but tightly integrated

Thursday, July 13th, 2006

I was never happy with how tightly coupled my image viewer is to the resources API. It seems to me that an image viewer is a pretty handy, general-purpose thing. The initial implementation can display images contained in files. But images come from other places. Items in an auction have images; so do the results of queries against Flickr.

I reworked the plug-in to make it exploit the Eclipse adapter mechanism. The adapter mechanism is one of those handy things that makes it possible to build plug-ins that work really well together but know nothing about each other. Strange? You bet. But very powerful.

The basic idea is that I want my image viewer to display an image for the selected thing. Whatever it is. So it registers a selection listener with the workbench selection service; the selection listener is notified whenever a selection occurs in a table, tree, editor, whatever. The image viewer looks at the selection and tries to determine how to display an image for it. To do this, it attempts to adapt the selected thing into an instance of the ImageProvider type (ImageProvider is a class that I’ve provided). It then asks the ImageProvider for the image. If the selected thing cannot be adapted to the appropriate type, the whole process is aborted (so the image viewer displays the last thing that was selected that could provide an image).

To insulate my image viewer from having any knowledge of the resources API, I created a separate plug-in which provides an extension to the org.eclipse.core.runtime.adapters extension point. This extension contributes a factory that knows how to adapt objects that implement org.eclipse.core.resources.IFile into an ImageProvider. This new plug-in knows about both the image viewer plug-in and the resources plug-in, but these other plug-ins each knows nothing about the other.

Adding support to display images for other types of objects is pretty easy: I just have to add another extension to org.eclipse.core.runtime.adapters and we’re off to the races. No changes are required to the image viewer to display this new type of thing.

If you’re curious about how all this works import this project set. If you just want to use the image viewer, you can get the plug-ins here. Just drop the contents of this ZIP file into your “plugins” directory (I’ll get around to building an update site someday).

Debugging JSPs using Eclipse WebTools

Tuesday, July 11th, 2006

As a general rule, I don’t like to have too much Java code in Java ServerPages (JSP) files. In fact, I’d prefer to have no Java code at all in a JSP. I have two basic reasons (and a collection of less basic reasons)… First, Java code in a JSP tends to be used to provide business logic; business logic doesn’t belong in the view layer and should instead by tucked somewhere behind a servlet. Second, JSPs are intended to be modified by content editors who–despite being wizards with HTML, JavaScript, AJAX, and whatnot–are blissfully unknowledgeable about Java (you don’t want these people to have the opportunity to change your Java code). That discussion aside, let’s just say that you have a very good reason to have a bunch of Java code in your JSP…

Before you can debug JSPs, you need to install the Eclipse WebTools. You can do this through the Callisto Update Site (click here to what a demonstration), or you can just download an all-in-one (Eclipse + everything you need for web development) here.

With WebTools installed, you can add one or more breakpoints by opening an editor on the JSP file, and double-clicking in the left-hand column. A breakpoint icon will appear as shown below.

Now, you need only start the server in debug mode. You can do this by right-clicking in the JSP editor or on the JSP file in the package explorer and selecting “Debug As > Debug on Server”, or by clicking the “Start in Debug Mode” icon (little picture of a bug) on the “Servers” view (shown below).

When execution reaches the breakpoint, Eclipse will drop you into the Debug perspective where you can hop, skip, jump, and inspect variables to your heart’s content.

Planes, trains,and automobiles…

Thursday, July 6th, 2006

One of the things I really enjoy about traveling in Europe is the train system. They have a vibrant train system; something that we’re missing in North America.

This week, I’ve been in Europe, attending both ECOOP and Java Forum Stuttgart. Unfortunately, the “Eclipse Bistro” I assembled for ECOOP didn’t go off quite as well as I had hoped: we were scheduled opposite a handful of other events (some of which started earlier) and there was no actual advertising done by the conference to let folks know we were even there. Still, we managed to attract a good number of people for the event and had an excellent (albeit somewhat quieter than expected) event.

Java Forum Stuttgart was an entirely different experience. The place is packed and totally hopping. My talk was very well attended and–judging from the questions asked at the end–pretty well received. I quipped to Bjorn recently that I am starting to get a little tired of presenting my Eclipse RCP talk, but I think I spoke too soon: I really do love the topic, and I tweak the presentation almost every time I deliver it. It’s a pretty fun talk (IMHO).

Since I know that Gunnar loves the pictures, here’s one of the folks attending my talk (at least many of them, I couldn’t get an angle that got everybody in).

Apologies to Gunnar. I was thinking of him when I originally typed the named “Gunther”; I was talking with a gentleman named Gunther today and that–combined with a spot of jetlag–has me bewildered.

Since I started on the topic of trains, here’s a picture of the train I wanted to get on.

Unfortunately, this one wasn’t going where I wanted to go, so I instead got on the IC which was still pretty cool (even after the conductor shooed me out of first class–oops). I learned two valuable lessons while on the train: don’t try to write code on a train (I got so absorbed in what I was doing, that I almost missed my stop) and buy a first class ticket (better air conditioning).

Totally customized Eclipse Experience, anyone?

Tuesday, July 4th, 2006

Bjorn mentioned the Yoxos “Eclipse on Demand” service in his blog a few days ago. The good people at Innoopract are proud of this service. For good reason.

Today, I decided that I wanted a PHP development environment. I went to the “Eclipse on Demand” site. Here’s what it looks like:

The browser looks a lot like Eclipse itself (it’s amazing what you can do with AJAX). I entered “php” in the filter text which exposed two different PHP options (1). For no particular reason, I chose PHPeclipse (2). Yoxos automatically figured out the other parts I needed to make PHPeclipse work (3). Finally, I hit the “Download now” button (4). At this point, it assembled all the components together into a single download and provided me with a link to a single “ZIP” file which I downloaded, decompressed, and ran.

As expected, it works like a charm.

Disconnect between the model and view

Sunday, July 2nd, 2006

One of the things that I implemented with the Sudoku game was a disconnect between the model and the view. I provided a representation of a Sudoku game that knows nothing of user interface. It knows about cells and boxes and numbers; it also knows if any given cell is considered valid. It knows nothing about what colour should be used to draw a cell, how thick the lines should be, or anything else that has anything to do with drawing.

To help with the drawing part, and to avoid having to continually recompute position information for individual cells, I introduced the notion of a CellDrawer that does know about colours, and line thickness, and such. It also knows–in absolute coordinates–where to draw the cell. This class is part of the user interface code.

I set up the Sudoku board so that it can be observed. Interested parties, like a user interface, can register event listeners that are triggered when a change occurs on the board. I use the listeners consistently. When the user clicks on the board or types a key, the user interface translates that operation into a command that’s passed to the Sudoko board. The command is along the lines of “set the value of the cell at position (5,4) to 7″ (position is the relative position of a cell, not a screen co-ordinate). The board makes the necessary modifications and fires an event to inform interested parties of the change. The user interface is one of the interested parties, and when it receives the event it redraws the board. I could have done this a lot simpler: when the user clicks or types a key, change the board and then get the user interface to redraw. Why not just do this? Why all the extra event stuff?

Well… Chris answered this question pretty well. In a few minutes on a plane, Chris added an ECF component to the game: he made the Sudoku game multi-player. He did it without interacting with the user interface, he just worked directly with the model. When the remote user makes a change, a message is sent. When that message is received, the model is modified which causes an event to be triggered resulting in the user interface updating. Pretty cool. And, a fine example of extending a system in a way that the original author had never considered.

I use the event in other places as well. The solver included with the implementation modify the model which then triggers an update of the user interface. The solvers know nothing about the user interface.

At some point, I’ll probably add a couple more views to the game. An obvious view might show some statistics: how many cells are left, how long as the game been going, how many times has a particular cell been changed, etc. This view will also just register itself to receive changed events from the board and update itself whenever those events are triggered. My main user interface will not have to know anything about this new view and so will be totally decoupled; but it will appear to the user to be tightly integrated. Very cool.

This relationship is described by the Observer Pattern. It’s used extensively throughout the Eclipse code (including SWT) and all over the place in Java. Heck, we even used it in (wait for it, Denis…) Smalltalk! It’s a pretty powerful mechanism that may require a little bit of work up front, but sure makes building applications a lot easier.

31,755 and counting

Saturday, July 1st, 2006

So far there have been 31,755 downloads of the Eclipse SDK 3.2 and 3,066 downloads of the Platform Runtime Binaries. This seems like a lot to me considering that it is the first weekend in July (first officialish weekend of summer in the northern hemisphere) and the start of a long holiday weekend in North America. Both Canada and the United States are celebrating the births of our respective nations this weekend with fireworks and excessive alcohol consumption. Apparently, we need to add downloading Eclipse to that list.

Consumption of the screen cams is pretty high as well, with 1,608 views of the “Installing Eclipse” demo. Now that the Callisto release is real, this demo is a little out of date (it shows how to obtain a release candidate build); I should have updated it on Friday, but with all the local Eclipse committers in the office, I was a little distracted (embarassingly, I was so distracted I even forgot to get out my camera). I’ll try to do something about it this week.

If you haven’t yet experienced Callisto, there’s still time. Experience Callisto.

You are currently browsing the Eclipse hints, tips, and random musings weblog archives for July, 2006.

  • Pages

  • Archives

  • Categories