Skip to content

Persistence of enum choices in Commands #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stefanhahmann opened this issue Oct 12, 2023 · 6 comments · May be fixed by scijava/scijava-ui-swing#87
Open

Persistence of enum choices in Commands #471

stefanhahmann opened this issue Oct 12, 2023 · 6 comments · May be fixed by scijava/scijava-ui-swing#87

Comments

@stefanhahmann
Copy link
Contributor

stefanhahmann commented Oct 12, 2023

With 664b3ab and 61e98d7 it was made possible to use enums with custom labels in scijava commands

However, currently enums with custom labels are not persisted, i.e. if the user makes some settings using an enum with custom labels in a dialog, closes this dialog and comes back to this dialog, the selected value would fall back to the default parameter instead of the last selected parameter, which users may consider a bug, since this behavior would be different to other parameter types.

@imagejan
Copy link
Member

imagejan commented Sep 27, 2024

I think this issue is general for enums (i.e. not only enums with custom labels).

Looking at MoBIE's OpenCollectionTableCommand.DataRoot:
https://github.com/mobie/mobie-viewer-fiji/blob/18700b576efcc9574a9395598939bbf354f970e7/src/main/java/org/embl/mobie/command/open/OpenCollectionTableCommand.java#L49-L53

... non-default values seem to be correctly persisted to preference storage:

#@ PrefService ps
#@ ConvertService cs

import org.embl.mobie.command.open.OpenCollectionTableCommand
import org.embl.mobie.command.open.OpenCollectionTableCommand.DataRoot

stringValue = ps.get(OpenCollectionTableCommand.class, "dataRoot")

println(stringValue)  // e.g. UseTableFolder

converted = cs.convert(stringValue, DataRoot.class)

println(converted)  // e.g. UseTableFolder
println(converted.class)  // class org.embl.mobie.command.open.OpenCollectionTableCommand$DataRoot

However, the command dialog still falls back to default value every time.

Hence I think the issue is somewhere in the command module processing, not in the preferences.

@ctrueden would you have a best guess where to dig next?

@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/scijava-persist-not-working-for-enums/99827/7

@imagejan
Copy link
Member

imagejan commented Mar 27, 2025

I noticed that persisted enum values are actually harvested just fine: as long as you don't touch the dropdown widget, the persisted value is kept. It's just the UI that isn't updated to reflect the persisted value 🤦

Consider this Groovy script:

#@ org.scijava.ItemIO itemio

println itemio

When you run it, the dialog will always show the first enum value, INPUT:

Image

However, if you choose an alternative value (e.g. BOTH), press OK, and re-run the script, this time without changing in the dropdown (that again shows INPUT), the correct, persisted value (i.e. BOTH) will be printed.

That means this issue actually belongs to scijava-ui-swing 🚀 .

(NB: This didn't work in older Fiji installation of mine that had scijava-common-2.94.2, so the persisting behavior must have changed between that version and scijava-common-2.99.0)

@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/scijava-persist-not-working-for-enums/99827/9

@tischi
Copy link
Contributor

tischi commented Apr 16, 2025

Hi @imagejan and @ctrueden, are those changes already shipped with Fiji? I think I observed some strange behaviour related to the persistence of enums. I would investigate more if you tell me that those changes are already in place.

@tischi
Copy link
Contributor

tischi commented Apr 16, 2025

I am sorry 😬 !

I did not carefully read @imagejan's above post.
In fact it seems that he exactly found what I found.
I also saw now that the PR has not been merged yet.

tl;dr please simply ignore all my comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants