scijava-common
scijava-common copied to clipboard
Default to required=false and persist=false for inputs with ItemVisibility.MESSAGE
When using a message parameter:
@Parameter(visibility=ItemVisibility.MESSAGE)
String message = "Some informative message";
it would help to have required=false and persist=false by default, as this is almost always what you want. Otherwise, you'll have to provide this parameter when e.g. running from command line.
Suggested by @xulman.
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/bonej-fractal-dimension-and-ij-robot-how-to-automatically-press-ok-on-dialog-box/39459/8
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/display-text-label-with-script-parameters/10772/12
Just reviving this thread after having a potential solution to my use case.
The problem I faced was not with inputs required or not, but rather with messages and buttons that are here to give some info to the user. The problem is that if all inputs are programmatically given, the messages still show up:

What I've done is a PreProcessor Plugin that looks at all inputs. If the only unresolved inputs have a 'message' visibility type, then I resolve them, and they don't show up.
I put this in a repo of mine, but I think it makes sense in scijava common.
import org.scijava.ItemVisibility;
import org.scijava.log.LogService;
import org.scijava.module.Module;
import org.scijava.module.ModuleItem;
import org.scijava.module.process.AbstractPreprocessorPlugin;
import org.scijava.module.process.PreprocessorPlugin;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.widget.InputHarvester;
/**
* Scijava processor that resolves all inputs with MESSAGE {@link ItemVisibility},
* if they are the only ones remaining, before the InputHarvester kicks in
*/
@Plugin(type = PreprocessorPlugin.class, priority = InputHarvester.PRIORITY+1) // We want it to kick in before the swing input harvester
public class MessageResolverProcessor extends AbstractPreprocessorPlugin {
int unresolvedInputsExceptMessageCount = 0;
int messagesCount = 0;
@Parameter
LogService logger;
@Override
public void process(Module module) {
if (module.getInfo()==null) {
logger.warn("null getInfo for module "+module);
return;
}
module.getInputs().forEach((name, input) -> {
ModuleItem<?> inputKind = module.getInfo().getInput(name);
if (inputKind == null) {
logger.warn("null input "+name+" for module "+module);
return; // avoid doing anything
}
ItemVisibility visibility = inputKind.getVisibility();
if (visibility==null) {
logger.warn("null visibility for input "+name+" for module "+module);
return; // avoid doing anything
}
if (visibility.equals(ItemVisibility.MESSAGE)) {
messagesCount++;
} else {
if (!module.isInputResolved(name)) unresolvedInputsExceptMessageCount++;
}
});
if (messagesCount > 0) {
if (unresolvedInputsExceptMessageCount == 0) {
// No need for null check, it's been done before
module.getInputs().forEach((name, input) -> {
if (module.getInfo().getInput(name).getVisibility().equals(ItemVisibility.MESSAGE)) {
module.resolveInput(name);
}
});
}
}
}
}