Friday, February 25, 2005
Thursday, February 24, 2005
Help authoring in Eclipse?
I am currently writing online help for a set of Eclipse plugins and find that the whole TOC and F1-help context setup can get quite complex! Why is there no help authoring plugins for eclipse? If anybody knows of one, please let me know! While on this topic, what is a good DocBook authoring tool?
Mac-mini meeting TiVo?
TiVo shares jump on Apple speculation | CNET News.com
Now that would be cool! I just got a Mac mini with the sole purpose of it becoming the media hub in our family room. Moved all iTunes and iPhoto content to it and started to research the possibilities of recording TV with it too, making my TiVo box obsolete. Hook it all up to an Optoma H30 HDTV projector or something similar or better, and that would make for a very sweet next generation home "theater" indeed...
Oh yeah, for those looking for a digital (optical) audio-out solution for the Mac mini, consider the Edirol UA20. That's what I'm using because I happened to have one already for its MIDI capabilities. It has an optical out and it goes straight into our Yamaha home theater setup and it works great.
Now that would be cool! I just got a Mac mini with the sole purpose of it becoming the media hub in our family room. Moved all iTunes and iPhoto content to it and started to research the possibilities of recording TV with it too, making my TiVo box obsolete. Hook it all up to an Optoma H30 HDTV projector or something similar or better, and that would make for a very sweet next generation home "theater" indeed...
Oh yeah, for those looking for a digital (optical) audio-out solution for the Mac mini, consider the Edirol UA20. That's what I'm using because I happened to have one already for its MIDI capabilities. It has an optical out and it goes straight into our Yamaha home theater setup and it works great.
Tuesday, February 22, 2005
What is that monkey doing?
Do I dare ask what the monkey on this book cover is doing? :-) I guess it's related to the hands-on aspect of this book...
Friday, February 18, 2005
a bit premature? [onEclipse - Eclipse 3.1 M5 Released!]
I wish it was true: onEclipse - Eclipse 3.1 M5 Released! but I can't seem to find it anywhere yet... And when I checked this morning, the integration build was broken :-(
Sunday, February 13, 2005
Workspace-aware file dialog?
In my recent effort to create a search for unused property names, I had the need for a file dialog allowing a user to specify a properties file. However, I wanted the dialog to restrict its view to the workspace and to my surprise I could not find a built-in dialog that does that! The SWT FileDialog offers up the entire filesystem and knows nothing about the Eclipse workspace, and the ResourceSelectionDialog - which is workspace aware - shows two panes and checkboxes and does not look at all like the usual open file dialog...
I was looking for something that looks like the resource perspective's navigator view, but as a modal selection dialog. I could have sworn that I'd seen that used elsewhere in Eclipse, but I could not find it, and I had others ask me the same question, so I decided to look at how to do just that: embed (parts of) the Eclipse Navigator view in a file selection dialog, and it turned out to be relatively simple!
The key to doing this is the org.eclipse.ui.model.WorkbenchContentProvider, which turns out to be the real workhorse behind the navigator view. It provides all the knowledge about the workspace resources. With this content provider and the WorkbenchLabelProvider from the same package, writing this workspace aware file selection dialog was a snap!
Here's how to create a Dialog with an embedded resource navigator (not the complete code, which is here):
There are some additional bells and whistles, but that's basically it! The only other interesting part is the initFilters method, because this is where the built-in filters actually can not be used. The navigator filters remove the positive matches of the filter, whereas I wanted to only show files with a certain extension, and directories regardless. The following filter does the trick:
If you are still reading this, you're probably interested in the entire code. The code is available from the CVS repository for my metrics plugin (Didn't feel like creating an entire new sourceforge project for this). Create a repository entry for cvs.sourceforge.net, root folder /cvsroot/metrics, check out the biz.volantec.utils project. The fully qualified name of the file dialog is biz.volantec.utils.widgets.WSFileDialog
Please note that I'm doing this work on Eclipse 3.1M4 (on a Mac OSX 10.3.8) and I already know that some of this (the SearchJob) does not work on 3.0.1 or older. I need to find a public API to do the text searches, but I'm not there yet. The (unfortunately internal) API of the TextSearchEngine has changed between 3.0.1 and 3.1
I was looking for something that looks like the resource perspective's navigator view, but as a modal selection dialog. I could have sworn that I'd seen that used elsewhere in Eclipse, but I could not find it, and I had others ask me the same question, so I decided to look at how to do just that: embed (parts of) the Eclipse Navigator view in a file selection dialog, and it turned out to be relatively simple!
The key to doing this is the org.eclipse.ui.model.WorkbenchContentProvider, which turns out to be the real workhorse behind the navigator view. It provides all the knowledge about the workspace resources. With this content provider and the WorkbenchLabelProvider from the same package, writing this workspace aware file selection dialog was a snap!
Here's how to create a Dialog with an embedded resource navigator (not the complete code, which is here):
public class WSFileDialog extends Dialog {
private TreeViewer viewer;
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
getShell().setText(title);
TreeViewer viewer = createViewer(comp);
GridData data = new GridData(GridData.FILL_BOTH);
...
viewer.getControl().setLayoutData(data);
return comp;
}
protected TreeViewer createViewer(Composite parent) {
ResourceNavigator nav = new ResourceNavigator();
viewer = new TreeViewer(parent, selectionStyle |
SWT.H_SCROLL |
SWT.V_SCROLL |
SWT.BORDER);
viewer.setUseHashlookup(true);
initContentProvider(viewer);
initLabelProvider(viewer);
initFilters(viewer);
viewer.setInput(rootElement);
if (expand) {
viewer.expandToLevel(2);
}
return viewer;
}
protected void initContentProvider(TreeViewer viewer) {
viewer.setContentProvider(new WorkbenchContentProvider());
}
protected void initLabelProvider(TreeViewer viewer) {
viewer.setLabelProvider(
new DecoratingLabelProvider(
new WorkbenchLabelProvider(),
IDEWorkbenchPlugin.getDefault().getWorkbench()
.getDecoratorManager().getLabelDecorator()));
}
...
}
There are some additional bells and whistles, but that's basically it! The only other interesting part is the initFilters method, because this is where the built-in filters actually can not be used. The navigator filters remove the positive matches of the filter, whereas I wanted to only show files with a certain extension, and directories regardless. The following filter does the trick:
private class FilePatternFilter extends ViewerFilter {
public boolean select(Viewer viewer,
Object parentElement,
Object element) {
if (extensions == null || extensions.length == 0)
return true;
IResource resource = null;
if (element instanceof IResource) {
resource = (IResource) element;
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
resource = (IResource) adaptable
.getAdapter(IResource.class);
}
if (resource != null && !resource.isDerived()) {
if (resource.getType() != IResource.FILE) return true;
String extension = resource.getFileExtension();
if (extension == null) return true;
for (int i = 0; i < extensions.length;i++) {
if (extension.equalsIgnoreCase(extensions[i]))
return true;
}
}
return false;
}
}
If you are still reading this, you're probably interested in the entire code. The code is available from the CVS repository for my metrics plugin (Didn't feel like creating an entire new sourceforge project for this). Create a repository entry for cvs.sourceforge.net, root folder /cvsroot/metrics, check out the biz.volantec.utils project. The fully qualified name of the file dialog is biz.volantec.utils.widgets.WSFileDialog
Please note that I'm doing this work on Eclipse 3.1M4 (on a Mac OSX 10.3.8) and I already know that some of this (the SearchJob) does not work on 3.0.1 or older. I need to find a public API to do the text searches, but I'm not there yet. The (unfortunately internal) API of the TextSearchEngine has changed between 3.0.1 and 3.1
NLS Keys revisited
In the previous post I mentioned that the Eclipse NLS keys search page does exactly what I was looking for, but it turns out I was not exactly correct there. NLS Keys tries to be a little too smart, and really ties in to the "Externalize Strings" refactoring feature of Eclipse. It does not simply look for uses of the property names, but performs a search for uses of the accessor class using the Java Search Engine (as opposed to the text search engine) and some additional magic. What I found was that if you for example write a method that accepts property names as parameters and look them up in the method using the accessor class, the NLS Keys page will report them as unused! Example:
And somewhere else:
Then "prop1" and "prop2" will be wrongly reported as unused...
So back to plan A and write one myself...I simply want to report all property names that cannot be found anywhere else as literal strings, regardless of the use of any accessor class. The next series of posts will be about my experiences doing this.
public void showErrorDialog(String titleProp,
String messageProp) {
String title = Messages.getString(titleProp);
String message = Messages.getString(messageProp);
...
}
And somewhere else:
showErrorDialog("prop1", "prop2");
Then "prop1" and "prop2" will be wrongly reported as unused...
So back to plan A and write one myself...I simply want to report all property names that cannot be found anywhere else as literal strings, regardless of the use of any accessor class. The next series of posts will be about my experiences doing this.
Tuesday, February 08, 2005
Eclipse tip: NLS Keys
After spending the superbowl weekend writing a plugin to find unused properties in a properties file, I just found out that this feature already exists but is hidden quite efficiently... If you open the search dialog and hit the customize button, you'll see a dialog with one unchecked search page, named 'NLS Keys'. This page does exactly what I was trying to write a new plugin for last weekend....
A little background: When you write UI code that contains a lot of text that may have to get translated for internationalization purposes, eclipse offers the very useful source->externalize strings feature. Then you start to refactor and change lots of code, and in the end you find yourself with gigantic resource bundles with lots of obsolete property definitions, making your translation department very unhappy. This is where this search page comes in. You get the picture.
I may blog about my experiences writing this little plugin when I get some time anyways, as I learned a few neat tricks about the 3.0 concurrency feature (the Job API)
A little background: When you write UI code that contains a lot of text that may have to get translated for internationalization purposes, eclipse offers the very useful source->externalize strings feature. Then you start to refactor and change lots of code, and in the end you find yourself with gigantic resource bundles with lots of obsolete property definitions, making your translation department very unhappy. This is where this search page comes in. You get the picture.
I may blog about my experiences writing this little plugin when I get some time anyways, as I learned a few neat tricks about the 3.0 concurrency feature (the Job API)
Tuesday, February 01, 2005
Pattern share
A new pattern repository in Wiki form :Pattern Share This site collects all patterns from GOF, Fowler, Woolf and many others. Very cool!

