Can @Parameter(choices = ?) annotation be filled automatically

I am trying to use the @Parameter annotation in a Java plugin and getting stuck in the way the choices attribute is used. I know that I can create a String array manually with the choices. But in my case it is about all open non-image window names. The user should finally be able to choose from a list of all e.g. table window names. Is there a possibility to fill in table names programatically in the choices attribute such as:


String[] nonimageWindowNames = WindowManager.getNonImageTitles();

@Parameter(label = "Results table", required = false, choices = nonimageWindowNames)
private String chosenWindowName;

Problem is that this kind of fill seems not supported and I currently see no way in how to convert the array in a format that is accepted by the choices attribute.

Any hints?

3 Likes

We faced the same problem with @tischi. There are some strong restrictions to the choices field because it is located within a java Annotation. Here’s the way I understand it: this field needs to be set when the jvm starts and cannot be changed.

If you need more flexibility in the fields of a command, you need to use something slightly more complicated (a DynamicCommand I think). Maybe @frauzufall or @imagejan can give you pointers.

4 Likes

I think I recently wrote something similar to what you are looking for. This command creates a list of non image windows. It was written to allow for conversion from an IJ1 table to a MarsTable. That is a type of generic scijava table we use with mars, but the command should be easily adapted for other purposes.

Let me know if this helps or I missed your question. Based on a suggestion from @imagejan the ability to update the table list dynamically based on other dialog inputs is now also possible as well and I could provide examples of that.

3 Likes

Thanks for your reply @karlduderstadt.

To be honest, I don’t fully understand the code yet, but I will have a look at it and see if I can make sense of it relation to my issue.

Thanks, @karlduderstadt, for sharing this great illustrative example! If you think any of the MarsTable functionality would be useful for other projects as well, pull requests to scijava-table are always welcome :slightly_smiling_face:

Would it help if instead of using a String parameter and trying to update it with the list of table names, we improve the possibilities to retrieve a ResultsTable directly?

Currently, the following returns the active ResultsTable only:

@Parameter
private ResultsTable rt;

This is due to the ResultsTablePreprocessor providing the single active ResultsTable.

How about if this:

@Parameter (autoFill=false)
private ResultsTable rt;

… would instead offer a dropdown choice for all open ResultsTable instances, similar for how it currently works with ImagePlus and Dataset?

Adding a widget to imagej-legacy should be relatively straight-forward, and I’d be willing to put some effort into it during the ongoing Fiji Hackathon days.

1 Like

Hi @imagejan

That sound great.

I just stumbled over that challenge but it is not at all urgent or desperately needed in my case.
However, I think it might be generally cool to have dropdown options for non-image windows.