-
Notifications
You must be signed in to change notification settings - Fork 54
Description
The ObjectService can be used quite flexibly to keep track of registered objects of any kind. To improve user experience, it would be useful to be able to specify names/identifiers for registered objects, though.
For example, the DefaultWidgetModel currently displays choice labels that are generated from each object's toString method:
scijava-common/src/main/java/org/scijava/widget/DefaultWidgetModel.java
Lines 225 to 233 in 06aa06d
| @Override | |
| public String[] getChoices() { | |
| final List<?> choicesList = item.getChoices(); | |
| final String[] choices = new String[choicesList.size()]; | |
| for (int i = 0; i < choices.length; i++) { | |
| choices[i] = choicesList.get(i).toString(); | |
| } | |
| return choices; | |
| } |
We could improve this by checking for the object's name via getName if the object implements org.scijava.Named. However, many objects we might want to register in practice don't implement this interface, e.g. RealTransform (from imglib2) or BdvHandle (from bigdataviewer) (@NicoKiaru, @tischi), Node (from sciview) (@kephale), or SpotCollection (from TrackMate).
To allow for more flexibility here, I'd like to suggest adding new API to ObjectService:
void addObject(Object object, String name)allowing to add an object with a specified name, andMap<String, Object> getObjectMap()retrieving a map of names and objects.
In addition, we could change addObject(Object object) to automatically try getName and fall back to toString if no name is provided explicitly.
I vaguely remember that naming objects was mentioned in some discussion somewhere (maybe @ctrueden can recall better).
If that's a feasible change, we would most likely also need to change/improve the underlying ObjectIndex implementation.