Checklist for well-behaved sluice components
Check that your bean:
-
Does not crash when changing the source (by having addSourceView()
called) in runtime. This will happen many times during the life
of your bean.
-
Does not crash when data is not in the right format. There are two
cases for this:
-
The type of the table is not what was expected - You can reject the source,
go back to the initial state and throw NoSourceException for that.
-
Should accept missing values (that is, one or more values in a row can be
null). You CANNOT throw an exception in that case, you should handle that
within your code. The most common way to deal with this is to count the missing
values and ignore them. In the latest version DescriptiveView can
handle null values.
-
Does not assume that because it accepts only one source, its
addSourceView() method will be called only once. If an user
tries to set more than one link to your bean (and that will happen), then
addSourceView() will be called more than once. In this case throw
a TooManySourcesException exception to notify sieve you rejected
the link, but make sure your bean still works with the previous link
or links.
-
Resets to the initial state when unlinked. Unlinking may happen at
any time except when inside a method, except if that method spawns a thread,
in which case you need to be sure that the thread can handle that.
-
As a general rule, DO NOT throw an exception unless there is NOTHING the
bean can do to recover itself from the problem (an example when it is
not possible to recover is having a table of the wrong type as the source).
If your bean throws an exception, Sieve will catch the exception (there is
one case in which it won't, see next point) but chances are your bean will
not work correctly after that.
-
Under no circunstances throw an exception in the paint() method.
ALL EXCEPTIONS thrown by other methods called in paint() must be caught
and dealt with them properly. The reason for this is that paint() is called
from inside the Swing thread, not the sieve thread, and then it is not possible
to implement a safety net for the bean while it is repainting itself.