Sunday, July 20, 2008

Open Command Prompt or Windows Explorer in Eclipse

One of the features I miss in Eclipse is an ability to open Windows Explorer and Command Prompt (like CMD Here) on the current file or folder.
So I decided to implement it myself and here it is.
I gave it a huge name, since I hope to add there some more plugins that I miss, but currently it contains only the above features.


Update: Since this post was written back in 2008, the plugin had some updates. See tarlog-plugins tagged posts.

Recommended Reading

1. Eclipse Rich Client Platform (2nd Edition)
2. Swt/Jface in Action: GUI Design with Eclipse 3.0
3. EMF: Eclipse Modeling Framework (2nd Edition)
4. Effective Java

Saturday, July 19, 2008

Plugin Spy in Eclipse

Did you ever try to implement plugin in Eclipse? If you didn't you can probably skip this post.
But if you did you know that Eclipse PDE is very nice. It provides you a lot of neat wizards that help you to start. However, you often experience a situation, when you want to write a feature that is "almost like that feature that already exists, but...". So what you're lacking is the code of "that feature", so you be able to look on code and do the same. But how the hell can you find this code?
Yes eclipse is open source and yes it comes with all the sources. But it has dozens and dozens of plugins and it can be exhausting to find the relevant plugin.

And here comes the "Plugin Spy", which was added in Eclipse 3.4. Just click Alt+Shift+F1 on the proper place in the workbench and it will show you a lot of useful information. It may be still not easy to find "that feature", but at least it gives you the directions where to start.

Saturday, July 5, 2008

How to cause the IE to open specific application based on mime type

In general IE opens files based on their extensions. So when you try to access let's say http://localhost/myapp/helloWord.csv, it will open excel.

This is good, but now good enough, since the content on the web usually is not defined by file extensions, but by a content-type header. Especially in REST, when a resource can have different representations and we want same URL for resource:
http://localhost/myapp/helloWord should return HTML, http://localhost/myapp/helloWord?alt=application/atom+xml should return atom, http://localhost/myapp/helloWord?alt=text/csv should return csv and so on.
So what will happen if we ask for CSV in this way and server returned content-type=text/csv? The IE will not know how to handle such response and it will ask the user. However, we expect it to understand that this is CSV file and it should be opened by Excel. Right?

So there are two solutions for this problem:

1. Teach IE that mime text/csv should be mapped to the .csv file. This can be done in registry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Mime\Database\Content Type\text/csv]

By the way in this way you can map and mime to any extensions. Most of the mime already predefined, but some (like CSV) are missing.

2. Send Content-Disposition header.
If the response contains Content-Disposition: attachment; filename=HelloWorld.csv, it will cause the IE to open Excel. It happens since this header actually means that the response should be saved as HelloWorld.csv file.

Let's compare these two solutions:
First solution is better, when you cannot change the response. The response arrives, it doesn't contain Content-Disposition header, but it contains the proper mime type. So the mapping is done at client and this is fine.

The second solution is better, when you can change the server. It's obviously better to add additional header instead of changing registry of each client.