Skip to content

Improve ObjectService with names for objects #371

Closed
@imagejan

Description

@imagejan

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:

@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, and
  • Map<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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions