NOTICE! This is a static HTML version of a legacy ImageJ Trac ticket.

The ImageJ project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Ticket #555 (closed enhancement: fixed)

Opened 2011-06-01T15:28:08-05:00

Last modified 2011-06-07T17:26:10-05:00

Convention for how a plugin handles no image/view selected

Reported by: gharris Owned by: curtis
Priority: major Milestone: biweekly-2011: Jun-06 to Jun-17
Component: Plugin Framework Version:
Severity: serious Keywords:
Cc: Blocked By:
Blocking:

Description

If the plugin relies on there being a view selected, it may do this in its constructor:
final AbstractDatasetView view = getActiveDisplayView();
And then if no view exists, referencing view throws NullPointer exception.

Change History

comment:1 Changed 2011-06-01T15:36:29-05:00 by curtis

One solution could be to have a companion interface (similar to PreviewPlugin) called ConditionalPlugin with a "String checkConditions()" method that verifies the current program state is acceptable to execution. In the example above, this method would check if view!=null, returning null if so. If the conditions fail, the method returns a string error message explaining why the plugin cannot be executed. The plugin UI framework can then display a modal dialog box with the error message, if the conditions are not met.

comment:2 Changed 2011-06-01T16:13:54-05:00 by gharris

I like it (at least as the short-term.)
Ideally we will have an encoding of the conditions in such a way that the actions can be enabled/disabled based on selection...

comment:3 Changed 2011-06-07T17:26:10-05:00 by curtis

  • Status changed from new to closed
  • Resolution set to fixed

Rather than a companion interface, as of 14f53919701b09367691844cfe1cf9dd2202b9b9 it is possible for a plugin preprocessor to provide a message indicating a reason for cancelation. This message is propagated through the system. Specifically, at the PluginRunner level it becomes a warning-style StatusEvent that the Swing UI displays to the end user in a dialog box.

We will still need a solution in the long term to query a plugin for whether the current context is acceptable to execution.