Archive
Font handling in SWT
The Eclipse SWT framework is a great framework. It is fast, tidy and free. Unfortunately the documentation seems to lack a bit. Here secrets are unleashed! The code shows two things:
- How to see all fonts available to your SWT program
- how to load a font such as a *.ttf font!
When you load your font, you specify the file name of the file (e.g. *.ttf or *.fon or whatever). After loading the font, you must specify the font name. You can use getFontList() for this, and use a specific name or null for a full font list.
Equipping SWT applications with content assistants
Creating an HTML editor
The concept of content assistants is related to a specific implementation of JFace text viewers, the classorg.eclipse.jface.text.source.SourceViewer. Instances of this class are used throughout the Eclipse workbench to implement the various editors. However, SourceViewers are not restricted to the Eclipse workbench but may be used in any application that builds upon the SWT and JFace JARs. This article demonstrates the implementation of content assistants in the context of an Eclipse editor plug-in, and gives some hints on how to use content assistants with "naked" SourceViewers.
Let's implement a simple HTML editor. Here a content assistant can be very helpful. For example, a content assistant could generate typical HTML structures such as tables or links, or could wrap selected text areas into style tags.
Eclipse Databinding + Validation + Decoration
How do I open an editor on something that is not a file?
Since 3.3 you can use the new EFS support to open an text editor on a file store that's backed by any kind of EFS using IDE.openEditorOnFileStore(IWorkbenchPage, IFileStore).
Most editors will accept as input either an IFileEditorInput or an IStorageEditorInput. The former can be used only for opening files in the workspace, but the latter can be used to open a stream of bytes from anywhere. If you want to open a file on a database object, remote file, or other data source, IStorage is the way to go. The only downside is that this is a read-only input type, so you can use it only for viewing a file, not editing it. To use this approach, implement IStorage so that it returns the bytes for the file you want to display. Here is an IStorage that returns the contents of a string:

