Skip to content
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

ImageJ2Options: add log level selection #137

Merged
merged 4 commits into from
Jan 1, 2017
Merged

Conversation

stelfrich
Copy link
Member

Add selection of the SciJava log level to the ImageJ2 options dialog.

Known issues:

  • Doesn't set the drop down's default value to the currently active log level. Is there a possibility to access the generated widget from an initialize() method?
  • Could LogService.WARN, etc, be implemented as an enum?

@@ -80,10 +80,20 @@
description = "<html>Whether to use ImageJ2's file I/O mechanism when "
+ "opening files.<br>Image files will be opened using the SCIFIO library "
+ "(SCientific Image<br>Format Input and Output), which provides truly "
+ "extensible support for<br>reading and writing image file formats.",
+ "extensible support for<br>reading and writing image file formats.</html>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that closing tag really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With HTML5 it is optional. Shall I remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that HTML is the bastardized Java version, which Swing uses for rich text formatting. AFAIK, you absolutely do not need the closing tag. And in any case: adding it here is unrelated to the stated purpose of your commit.

@ctrueden
Copy link
Member

Is there a possibility to access the generated widget from an initialize() method?

Yes, although you shouldn't need to access the widget. Just give the field an initializer method in its @Parameter declaration, then change the value of that field to match what the LogService reports.

Could LogService.WARN, etc, be implemented as an enum?

Not without breaking backwards API compatibility in SciJava Common. I guess we could do this for SJC3. But what would be the advantage? I guess as things stand, when you call LogService.getLevel() you'll have to convert the int back into the level using case logic, which is unfortunate...

@stelfrich stelfrich force-pushed the log-level-in-ij2-options branch from de4895c to 243739c Compare March 23, 2016 19:19
@stelfrich
Copy link
Member Author

Just give the field an initializer method in its @Parameter declaration, then change the value of that field to match what the LogService reports.

That does not set the selection of the combo box. That's why I was asking about the widget. Should the selection of the combo box be set according to the value of the annotated field?

when you call LogService.getLevel() you'll have to convert the int back into the level using case logic, which is unfortunate...

Exactly...

@ctrueden
Copy link
Member

Should the selection of the combo box be set according to the value of the annotated field?

Yes, that is what is supposed to happen. The initial value of the field should determine the initially selected item of the combo box, according to the equals method.

/**
* Parses a log level from a {@code int}
*
* FIXME Could be removed if log level is defined as enumeration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark this as TODO rather than FIXME. From the ImageJ coding style page:

  • For code (or lack thereof) that is considered wrong or broken, and in need of repair, we add a "FIXME" comment with the relevant developer's initials, to serve as a reminder to address it as soon as time allows.
  • When additional work is needed somewhere, but not urgently, we add a "TODO" comment marking it.

@stelfrich
Copy link
Member Author

The initial value of the field should determine the initially selected item of the combo box.

That does not work for me.

Some additional insights, @ctrueden

  • initialize() sets logLevel field properly; when SwingChoiceWidget.set(WidgetModel) is called, the module of WidgetModel has logLevel == ERROR no matter what initialize() has done beforehand

Shall I open a new issue?

@stelfrich stelfrich force-pushed the log-level-in-ij2-options branch from 4dcc348 to d96d028 Compare March 23, 2016 20:36
@ctrueden
Copy link
Member

I just tried to debug into this and could not reproduce. It then occurred to me what the problem is: the parameter value was persisted by the SaveInputsPreprocessor and is being restored the same every time by the LoadInputsPreprocessor (which runs after the InitPreprocessor). Please add persist = false to the logLevel parameter, and I bet you the problem will disappear for you.

@ctrueden
Copy link
Member

We could add a hack that the SaveInputsPreprocessor ignores inputs that have an initializer callback. I'm not sure if that would break any code anywhere, but it would prevent others from stumbling over this in the future (I think I have stumbled over it at least twice before, in my dim memory).

@stelfrich
Copy link
Member Author

and I bet you the problem will disappear for you.

It did 👏 Thanks, @ctrueden!

We could add a hack that the SaveInputsPreprocessor ignores inputs that have an initializer callback.

I would appreciate that hack since debugging such issues repeatedly is a pain (I thought the issue was somewhere with the DefaultValuePreprocessor because ERROR is the first choice and might be the fallback). This doesn't seem to be an urgent issue, so I could give it a shot next week?

@ctrueden
Copy link
Member

I could give it a shot next week?

Sure. Here is where you would add the following code:

// NB: Do not persist values which are computed via an initializer.
if (item.getInitializer() != null && !item.getInitializer().isEmpty()) return;

Again: this breaks the (theoretical) use case where a command uses the initializer to specify the initial initial value (i.e.: the initial value the first time the command ever runs), but then wants to prefer the last-chosen value of the user for the initial value upon subsequent executions. I am not sure whether that is a big deal. But without this hack, you can have the behavior work either way, by setting persist=false or not.

stelfrich added a commit to stelfrich/scijava-common that referenced this pull request Mar 24, 2016
Disable the persisting of a ModuleItems if an initialize() method is set
and is not empty. This way, initialize() can overwrite the value of a
ModuleItem even if persist=true is assumed implicitly.

See:
* imagej/imagej-legacy#137 (comment)
@stelfrich
Copy link
Member Author

Sure. Here is where you would add the following code

Feel free to do it yourself the next time (if it is just one line). I think writing that comment has taken you longer than actually integrating that line 😄

@ctrueden
Copy link
Member

Feel free to do it yourself the next time (if it is just one line). I think writing that comment has taken you longer than actually integrating that line 😄

Nope, I didn't test it. And untested code is nonworking code. Besides: I am trying to train you. Training always takes longer than doing it yourself. But hopefully not globally over all time.

@@ -90,9 +90,10 @@
@Parameter(
label = "SciJava log level",
description = "<html>Log level for SciJava</html",
initializer = "initializeLogLevel",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add persist = false just for clarity here (even though scijava/scijava-common#236 will probably merge soon).

@ctrueden
Copy link
Member

ctrueden commented Jul 1, 2016

@stelfrich Can you take a couple of minutes to clean up these commits as mentioned in my earlier comments? Then we can merge it!

@stelfrich
Copy link
Member Author

Thanks for the comments @ctrueden. I took the liberty to reformat both @Parameter annotations after realizing that they first one was not formatted according to the code style (or was it?). I have reformatted with Eclipse Mars and the current version of the ImageJ preferences.

@stelfrich stelfrich force-pushed the log-level-in-ij2-options branch from f252ed6 to 7cd2af8 Compare July 2, 2016 16:29
stelfrich added a commit to stelfrich/scijava-common that referenced this pull request Aug 8, 2016
Disable the persisting of a ModuleItems if an initialize() method is set
and is not empty. This way, initialize() can overwrite the value of a
ModuleItem even if persist=true is assumed implicitly.

See:
* imagej/imagej-legacy#137 (comment)
@ctrueden ctrueden force-pushed the log-level-in-ij2-options branch from 7cd2af8 to be07ac0 Compare January 1, 2017 16:23
@ctrueden
Copy link
Member

ctrueden commented Jan 1, 2017

I finally found time to rewrite/clean these commits. Merging. Thanks again @stelfrich!

@ctrueden ctrueden merged commit 3fbc4ad into master Jan 1, 2017
@ctrueden ctrueden deleted the log-level-in-ij2-options branch January 1, 2017 16:24
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 this pull request may close these issues.

2 participants