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

Default to required=false and persist=false for inputs with ItemVisibility.MESSAGE #299

Open
imagejan opened this issue Sep 22, 2017 · 3 comments

Comments

@imagejan
Copy link
Member

imagejan commented Sep 22, 2017

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.

@imagesc-bot
Copy link

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

@imagesc-bot
Copy link

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

@NicoKiaru
Copy link
Contributor

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:

image

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);
                    }
                });
            }
        }

    }
}

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

No branches or pull requests

3 participants