Feb 19, 2008

EMF Packing changes in 2.4

EMF has changed the packaging in 2.4. You need to download an additional jar for docs and source for EMF and XSD. While this might be a good news for those who are bundling EMF in RCP apps, not for the early adopters of WTP. If you are an early adopter, then probably you may want to do vote for the all-in-one package for the milestone builds.

Related:
How does EMF finds the right parser?
Converting EMF Resource to Platform Resource (IFile)
EMF Packing changes in 2.4
Using EMF with XML Catalog

Feb 18, 2008

Handy util method for WizardPages

Consider this familiar New Java class wizard.


It has to keep track of the status of the source folder, package, enclosing type, name, ... When ever there is a change in these fields, the WizardPage's status has to be updated. The algorithm goes like this: find the most severe status and update the wizard page with that status. This is a very common operation can be applied to any WizardPage. So I've written a helper method which I usually use it in almost all of the WizardPage I create. Let me know if it can be improved

public static void applyStatus(WizardPage page, IStatus[] statuses) {

IStatus severeStatus = statuses[0];
for (IStatus status : statuses) {
severeStatus = severeStatus.getSeverity() >= status.getSeverity() ? severeStatus : status;
}

String message = severeStatus.getMessage();
switch (severeStatus.getSeverity()) {
case IStatus.OK:
page.setMessage(null, IMessageProvider.NONE);
page.setErrorMessage(null);
break;
case IStatus.WARNING:
page.setMessage(message, IMessageProvider.WARNING);
page.setErrorMessage(null);
break;
case IStatus.INFO:
page.setMessage(message, IMessageProvider.INFORMATION);
page.setErrorMessage(null);
break;
default:
if (message.length() == 0) {
message = null;
}
page.setMessage(null);
page.setErrorMessage(message);
break;
}
}

Feb 15, 2008

Using EMF with XML Catalog

When you try to load an XML document using EMF, you might have noticed that the XML Catalog is not respected and might throw parse exceptions. First I thought I had made a mistake in extending org.eclipse.wst.xml.core.catalogContributions and was debugging that. Only after a while I realized that the XML Catalog is contributed by WTP and EMF is not depending on that. So there is no way for EMF to know the existence of such catalog. I found a quick solution using some internal classes. I'm not sure whether its the best, but it works (at least for my requirement)

The idea is when EMF fails to resolve when loading an XML we should get the WTP Catalog and try to resolve with that:


loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl() {

@Override
public synchronized XMLDefaultHandler getDefaultHandler(XMLResource resource, XMLLoad xmlLoad, XMLHelper helper, Map options) {
return
new SAXXMLHandler(resource, helper, options)
{
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
InputSource result;
try {
result = super.resolveEntity(publicId, systemId);
}catch(SAXException e) {
try {
ICatalog catalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
String resolvePublic = catalog.resolvePublic(publicId, systemId).substring(5);
InputStream inputStream = getURIConverter().createInputStream(URI.createFileURI(resolvePublic));
result = new InputSource(inputStream);
result.setPublicId(publicId);
result.setSystemId(systemId);
return result;
} catch (Exception exception) {
throw new SAXException(exception);
}
}
return result;
}
};

}

});

There are many cases where this code will fail (like if you had added the catalog entry by uri/systemId) and there might be a much better way of doing that without using any internal classes. Till I find that, I'm going to live with this hack.

Feb 14, 2008

FullScreen mode in SWT/RCP Application

If you didn't know the Eclipse Summer of Code gave us a nice addition - Full Screen mode for SWT (From Eclipse 3.4 only. Won't work with 3.3 or earlier). No tricky API, just a getter/setter. Shell.setFullScreen(true) Go play!

Related:
How to add TrayItem in Eclipse RCP application?
How to add a status bar in an RCP app?

Eclipse Forum India 2008

This year's Eclipse Forum India is happening in Bangalore on 8-11 April. Its now open for registrations. There is a "very early bird" price, which closes Feb 15th (Yes, its tomorrow) In case you miss it, the "normal" early bird prices are open till March 14th.

I had mixed experience after attending last year's EFI. The workshop was definitely nice and few other sessions as well. But the rest of the sessions were simply not that great and not useful. I decided not to attend this year (Esp, I with just 3 sessions on Eclipse). May be I'll wait for the feedback of this year and decide for EFI 2009 :-)

Related:
Eclipse Forum India 2007 - First Impressions ...
Eclipse Forum India - Day 2
Eclipse Forum India - Day 3

Feb 13, 2008

Using ConnectionDragCreationTool in GEF

Connection creation tools in the palette are nice. But the only problem with those is that it would require three mouse clicks from the user. Click the connection creation tool in the palette; the click the source edit part and then finally click the target edit part.

How good if we can simplify this further? Like just drag-n-drop an edit part into another should create a connection between them. Implementing this feature might be much easier than you think. Override the getDragTracker in your source edit part and return the ConnectionDragCreationTool :-)

@Override
public DragTracker getDragTracker(Request request) {
return new ConnectionDragCreationTool();
}

Remember this will be applicable only if your edit parts are not moveable. If they have to be movable in your application, then drag-n-drop should change their position - not create a connection!

[Update]
You cannot select the source edit part, if you use the ConnectionDragCreationTool. The fix is simple:

@Override
public DragTracker getDragTracker(Request request) {
getViewer().select(this);
return new ConnectionDragCreationTool();
}

Feb 12, 2008

Eclipse Search

It was during 2007 Eclipse Awards I guess. When I Googled for Eclipse Awards, I ended up with more results on horse racing than our Eclipse Awards. (Its much better now, that the result I wanted is at least in the first page) I thought how good, if we can filter out only "our" eclipse related results. Soon after that I created a custom search engine, which does that filtering. After that, I always search with that. Recently Google introduced Labels and Refinements to the Custom Search Engine. I tried adding few labels and it works nicely. For example, if I want to search for Cheat Sheet, I get a whole lot of results. All of them are relevant.



I can filter them with the labels, so I can see what blogs are available, the source code, the documentation or even the images that are related to Cheat Sheets.



I've added many of the sites and blogs (Thanks to Planet Eclipse, I can find them in one place) to this search engine, in case your favorite site/blog doesn't appear in the results, I might have missed it out. Let me know, I'll add them.

You can try out the Eclipse Search and find yourself the usefulness of it

Feb 11, 2008

Eclipse Icons - follow up post

Follow up 1:
Ben had a nice script for fetching all the icons from the cvs. I'm adding it here:

#!/bin/sh

CVSROOT=:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse
export CVSROOT

mkdir -p eclipse
cd eclipse
cvs -q co org.eclipse.debug.ui/icons
cvs -q co org.eclipse.pde.ui/icons
cvs -q co org.eclipse.jdt.ui/icons
cvs -q co org.eclipse.vcm.ui/icons
cvs -q co org.eclipse.team.ui/icons
cvs -q co org.eclipse.ant.ui/icons
cvs -q co org.eclipse.help.ui/icons
cvs -q co org.eclipse.ui/icons
cvs -q co org.eclipse.ui.views/icons
cvs -q co org.eclipse.ui.console/icons
cd ..
rm -f ~/public_html/eclipse-icons.zip
find eclipse -name "*.gif" -print | zip ~/public_html/eclipse-icons.zip -@

Follow up 2:
I remember Ben having a HTML page which lists all the icons. But due to bandwidth issues, he moved it to a zipped set of icons. Now that is also gone from the page. I've a back up of those icons. So if you want the complete set of icons, instead of the most commonly used ones, download them here.

Follow up 3:
Phillipus left a comment in the post saying how to access the icons from other plugins without bundling them in your plugin:

AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ui", "$nl$/icons/full/etool16/import_wiz.gif");

This is cool but raises an interesting question. What happens during an Eclipse upgrade? Will they be retained in the same name? Or rather a straight question: Are these icons part of API? I didn't know the answer. So posting the question here. Those who know please throw some light on this.

Related:

Eclipse Icons - original post
Searching for Eclipse - source, blogs, images ...
Accessing CVS of Eclipse.org

Feb 8, 2008

Eclipse icons

Explaining an action or describing an object with fewer words is tough. Showing them as 16x16 icons is even more tougher. Eclipse has a wonderful collection of icons. The best part of it - the whole set is consistent in sizing, coloring and styling. (I personally feel that icons like the filter , jar library , plugins are brilliantly done). You can reuse them in many places in your own plugins/RCP Application as well. AFAIK, these icons are under Eclipse Public License and so you should not be falling into any legal trap for using these (don't take my word, I'm not a lawyer :-).

Many common images (undo, redo, file, folder, cut, copy) are available thru the org.eclipse.ui.ISharedImages interface. You can get them with IWorkbench:

Image folderImg = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);

For other common items (refresh, filter, collapse all, expand all), finding the images inside the plugins jars will be a tough task. So here are some images that you can reuse in your plugins:

Add, Delete :
Collapse All/Expand All:
Navigation:
Window operations:
Run & Debug:
Import & Export:
Date & Time:
Editor Operations:
Vertical & Horizontal:
Flat & Hierarchical:
Misc: Eclipse , Config & , Console , Font Help , Lock , Stop , Properties , Search & , Tip/Quick Fix , Sort , Task & , Sync & , Pulldown Menu, Binary , Bookmark , Category

Let me know if I've missed any commonly used icon. I'll add it to this list. The complete set of above icons can be downloaded from here.

Related:
Eclipse Icons - follow up post
Searching for Eclipse - source, blogs, images ...
Accessing CVS of Eclipse.org

All WTP early adopters, please stand up

If you are an early adopter of WTP like me, probably you would have gone thru the pain of downloading & installing all the prerequisites of WTP, that too for every milestone build. Of course, EPP has downloads for the milestone builds, but those are not enough. If you compare the versions, JEE version doesn't have source, which I quite often refer for how-tos or as sample implementations of an extension point) and the RCP version doesn't have JST. Recently I found that there is a bug already opened for providing all-in-one version for milestone builds, but its not been done because the PMC is not sure of how many people need it. If you are one of the guys who are in need of such build, do vote here.

Rest of us can download the EPP's Milestone builds here.



Feb 6, 2008

Feature based configuration of an RCP application

For a RCP application, I started with plugins based product configuration. When I reached a point where I need to provide software updates thru an update site, I needed a feature based product configuration. I thought should be as simple as selecting the features check box and adding the feature. But I spent around two whole days googling and debugging to bring it up and running. I think everyone would have gone thru the phase. I thought I'll write a blog entry on the issues, but I was lazy to draft such a long post. Yesterday Jan Kohnert sent a nice mail on his experience to the news group. Instead of copy-pasting the whole thing here, I present the information with little modifications. Thanks Jan.

  • Open your product file and select features in the Overview tab:


  • In the Configuration tab, click "New Feature...", and create the new feature:

  • In the newly created feature, go to the included features tab and add "org.eclipse.rcp" feature:
  • Go to the plugins tab and add your product's plugins
  • RCP feature has most of the plugins that you would require. However if you use anything other plugins (core.resources, ui.forms, etc), you need to add those plugins to the feature:
At this point you should be successfully running your RCP application. If you are not interesting in providing support for Software Updates for your app, you should be fine with this.

Ideally, even for software updates, this should work fine. However, if you try to create an update site and try running software update, you will be hitting the java.lang.SecurityException: "Invalid signature file digest for Manifest main attributes". To get rid of that, remove the RCP feature from the included features list of your feature and add the plugins in RCP feature to your feature. Thanks to PDE team, copy-pasting works in the plugins tab of Feature Editor :-)



While going thru the update stuff, I realized that the update will not function as expected if we launch it from the IDE (Not sure of why). So I have to export the product and run from the disk, which means I can't debug and step thru the code :-( To know what happens during the update, I start the application with -debug options and add these lines in the .options file:

org.eclipse.update.core/debug=true
org.eclipse.update.core/debug/warning=true
org.eclipse.update.core/debug/parsing=true
org.eclipse.update.core/debug/install=true
org.eclipse.update.core/debug/configuration=true
org.eclipse.update.core/debug/type=true
org.eclipse.update.core/debug/web=true
org.eclipse.update.core/debug/installhandler=true
org.eclipse.update.core/debug/reconciler=true


Click here for more info on the .options

Feb 5, 2008

Eclipse on Mac OS Leopard

In case you are experiencing frequent crashes of Eclipse on Mac OS Leopard, here is the simple solution: update your SWT plugins from the latest stream build. Looks like it still has few issues, so make sure to back up the originals before replacing (Does Time Machine help?). More details are available here.

PS: I'm a happy Tiger user still searching for solid reasons to spend for $129 upgrade

How to prevent multiple instances of an RCP Application?

The Eclipse IDE does this by obtaining lock on a file in the workspace. However, this method allows you to run multiple instances of the same IDE, each of them in a separate workspace.

In an RCP Application, if you follow the file lock mechanism, you need to get a lock on a well known file (like C:\Program Files\My App\instance.lock). Alternatively you can also prevent multiple instances by creating a server socket on some port (this method might alert Virus scanners/Firewalls)

There is no technique that is specific to RCP application, that is used to achieve this. You can use any Java application technique. You can Google around for more Java solutions and apply them in your RCP applicaiton.

Feb 4, 2008

How to automatically update my RCP Application?

Updating a RCP application might be different from updating Eclipse IDE. In Eclipse IDE, the update *usually* triggered by the user and he is allowed to select the updates he wants to install and cancel it at any time. But in RCP application, the situation might be different. You might have a requirement that you should be always running the latest version. In this case, the application update need not be triggered by the user, rather it can be triggered automatically during startup (like Gchat) and/or periodically by a job.

To enable such updates, you need to specify the update site in your feature:


In your Application's startup code, add this:

ProgressMonitorDialog dialog = new ProgressMonitorDialog(new Shell(display, SWT.NONE));
dialog.run(false, false, new IRunnableWithProgress() {

public void run(IProgressMonitor monitor) {
UpdateCommand command = new UpdateCommand("in.cypal.studio.wsdlEditor", "false");
command.run(monitor);
}
});

The comman.run() method returns a boolean value indicating whether an update happened or not. Depending on that you can decide whether to proceed normally or to force a restart by returning IApplication.EXIT_RESTART from the start method of your Application.