File Size Decorator

Implements a new label decorator that shows the size of each file in the Navigator and Package views. The decorator can be turned on and off in the preferences menu, and can be configured to use kilo-units of 1024 or 1000 bytes. The names of the units (single, kilo, mega, giga) and the format of the whole string can be configured, and also whether the size appears in front of or after the filename.

This is the first version publicly released version. It has been used and tested by me and the other folks at klomp.org. As well as a useful plugin, the source can also serve as an example on building label decorators or preference pages. Some interesting possible features that could serve as an excercise or as future extensions are:

Usage

To use the plugin, go to the preferences dialog (Window->Preferences). First turn on the decorator, from the Workbench->Label Decorations page. (Note: if you are using CVS, you can turn on the CVS label decorator as well from there. I find it quite handy.) When you press "Apply" or "OK", you immediately see the size of each file in any visible Navigator or Package views.

To change the kilo unit (1000 or 1024 bytes), the format, the names of the units or whether the information is prefixed or suffixed on the file name, go back to the preferences dialog. Go to the File Size Decorator preference page and change at will. If you have a directory browsing view visible behind the preferences dialog, you can preview your settings by pressing the Apply button.

Restrictions

Eclipse has its own abstraction of files in a workspace. Unfortunately, this abstraction doesn't include many attributes of a file. To retrieve the size of a file, the eclipse IFile object is first asked for its corresponding java.io.File, which can return the size of a file. This only works if there is a corresponding java.io.File, so it doesn't work when a file is derived or not real in some other sense. Perhaps eclipse will support a virtual file system in the future to directly work with remote files. In those cases, this decorator won't show a size. It also won't show the size of a directory.



Thanks to Vincent Partington for the cascading style sheet that's used on this page.
Copyright (C) 2003 Erwin Bolwidt <erwin@klomp.org>, Last Updated: 14 Jan 2003.