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 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.
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;
}
}

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;
}
}
Labels:
guidelines,
jface,
wizards
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.
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?
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();
}
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();
}
Labels:
gef
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

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:
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
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 -@
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.
, 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
Subscribe to:
Posts (Atom)