<div dir="ltr">Hi Adrian,<div><br></div><div><div>> Doesn't that allow doing what Felix would like to do, by populating</div><div>> the combobox through such an initialiser ?</div></div><div><br></div><div>I think what Felix wants is to set a parameter's "choices" attribute -- i.e., the values that will appear in the input harvester UI's dropdown list box.</div><div><br></div><div>It can be done with a DynamicCommand, but right now it only works from an initializer, not from a callback. So if you want to populate the choice once from, say, the active Dataset, it works. But if you want to update the choices e.g. every time the user moves a numerical slider, it will not work because the UI will not update.</div><div><br></div><div>See also:</div><div>* <a href="https://github.com/scijava/scijava-common/issues/180">https://github.com/scijava/scijava-common/issues/180</a><br></div><div><div>* <a href="https://github.com/scijava/scijava-common/issues/181">https://github.com/scijava/scijava-common/issues/181</a><br></div></div><div><br></div><div><div>> Are the parameters populated/initialised in the order they appear? In</div><div>> particular, is the initialisation done serially or can there be</div><div>> parallel execution of initialisers ?</div></div><div><br></div><div>Initialization is currently implemented serially [1].</div><div><br></div><div><div>> I have parameters a, b, c whose initialisation depend on a common</div><div>> calculation (depending on the image gotten through a previous</div><div>> @Parameter ImagePlus imp): can I do this calculation in the</div><div>> initialiser for the first parameter a, and then in the initialisers of</div><div>> b and c rely on the fact that the calculation was already done ?</div></div><div><br></div><div>Perhaps simplest at the moment would be to give your command a global initializer -- i.e., set the initializer method in the @Plugin annotation itself, rather than on specific parameters. The ImagePlus will be populated by a preprocessor _before_ the initialize method is called, so when your global initializer gets called you will already have access to the ImagePlus.</div><div><br></div><div>But again, scijava/scijava-common#181 is very relevant here.</div><div><br></div><div>Regards,</div><div>Curtis</div><div><br></div><div>[1] <a href="https://github.com/scijava/scijava-common/blob/scijava-common-2.42.2/src/main/java/org/scijava/module/AbstractModule.java#L75-L88">https://github.com/scijava/scijava-common/blob/scijava-common-2.42.2/src/main/java/org/scijava/module/AbstractModule.java#L75-L88</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 21, 2015 at 6:18 AM, Adrian Daerr <span dir="ltr"><<a href="mailto:adrian.daerr@univ-paris-diderot.fr" target="_blank">adrian.daerr@univ-paris-diderot.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Curtis, Felix, Jan, and others,<br>
<br>
In the CommandWithPreview tutorial example[*] that Curtis sent to<br>
the list a few weeks back, there is a @Parameter which is<br>
initialised to a value depending on the initialisation of another<br>
parameter:<br>
<br>
@Parameter private ImagePlus imp;<br>
<br>
@Parameter(persist = false, initializer = "initTitle") private String title;<br>
<br>
/** Initializes the {@link #title} parameter. */<br>
protected void initTitle() {<br>
        title = initialTitle = imp.getTitle();<br>
}<br>
<br>
[*]<br>
<a href="https://github.com/imagej/imagej-tutorials/blob/master/commands-with-preview/src/main/java/CommandWithPreview.java" rel="noreferrer" target="_blank">https://github.com/imagej/imagej-tutorials/blob/master/commands-with-preview/src/main/java/CommandWithPreview.java</a><br>
<br>
Doesn't that allow doing what Felix would like to do, by<br>
populating the combobox through such an initialiser ?<br>
<br>
Are the parameters populated/initialised in the order they<br>
appear? In particular, is the initialisation done serially or can<br>
there be parallel execution of initialisers ? I ask because I<br>
have parameters a, b, c whose initialisation depend on a common<br>
calculation (depending on the image gotten through a previous<br>
@Parameter ImagePlus imp): can I do this calculation in the<br>
initialiser for the first parameter a, and then in the<br>
initialisers of b and c rely on the fact that the calculation was<br>
already done ?<br>
<br>
cheers,<br>
Adrian<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
On Thu, 20 Aug 2015 17:13:11 -0500<br>
 Curtis Rueden <<a href="mailto:ctrueden@wisc.edu" target="_blank">ctrueden@wisc.edu</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Felix, Jan and everyone,<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I couldn’t find any hint that it is possible to update the choices of<br>
a parameter (declared with the annotator) in a callback that for<br>
another parameter.<br>
</blockquote>
<br>
It is possible to dynamically adjust parameters from Java code [1]. You can<br>
also dynamically add and remove parameters. Such commands extend the<br>
DynamicCommand class.<br>
<br>
There are many examples currently in the imagej-plugins-commands project;<br>
e.g.:<br>
<a href="https://github.com/imagej/imagej-plugins-commands/blob/imagej-plugins-commands-0.5.1/src/main/java/net/imagej/plugins/commands/restructure/AddAxis.java" rel="noreferrer" target="_blank">https://github.com/imagej/imagej-plugins-commands/blob/imagej-plugins-commands-0.5.1/src/main/java/net/imagej/plugins/commands/restructure/AddAxis.java</a><br>
<br>
However, a couple of notes:<br>
<br>
- This pattern makes the command less reusable from other contexts, because<br>
some contexts require a priori knowledge about the number and types of<br>
input and output parameters.<br>
<br>
- The user interface currently does not properly refresh the input<br>
harvester dialog if changes are made to parameters from a callback. So<br>
while you can technically do things like change the choices array of a<br>
multiple-choice input, the user will not actually see it.<br>
<br>
- What does work currently is to determine the multiple-choice values at<br>
initialization time, based on the values of parameters which have already<br>
been populated earlier, such as an active dataset. This is what many of the<br>
DynamicCommand implementations in imagej-plugins-commands do.<br>
<br>
Really, there are _five_ different classes of commands here:<br>
<br>
1) Totally fixed, with inputs and outputs known in advance.<br>
2) Updates parameter attributes (such as choices—but not # or type of<br>
inputs/outputs) once during initialization.<br>
3) Updates parameter number and type (i.e., adding/removing inputs/outputs)<br>
once during initialization.<br>
4) Updates parameter attributes repeatedly e.g. during callbacks.<br>
5) Updates parameter number and type repeatedly e.g. during callbacks.<br>
<br>
Of these, type #1 is most desirable for a variety of reasons. Failing that,<br>
types #2 and #3 can be done right now using DynamicCommand and it works<br>
properly from the ImageJ UI—but not from other contexts like CellProfiler,<br>
KNIME, etc. Types #4 and #5 can also be coded but will not work properly<br>
from the UI in ImageJ because the input harvester is not rebuilt on<br>
callbacks.<br>
<br>
See also:<br>
* <a href="https://github.com/scijava/scijava-common/issues/42" rel="noreferrer" target="_blank">https://github.com/scijava/scijava-common/issues/42</a><br>
* <a href="https://github.com/scijava/scijava-common/issues/43" rel="noreferrer" target="_blank">https://github.com/scijava/scijava-common/issues/43</a><br>
* <a href="https://github.com/CellProfiler/CellProfiler/issues/647" rel="noreferrer" target="_blank">https://github.com/CellProfiler/CellProfiler/issues/647</a><br>
<br>
Regards,<br>
Curtis<br>
<br>
[1] Dynamically updating parameters from scripts would be a different<br>
story. No plans to do that any time soon...<br>
<br>
On Thu, Aug 20, 2015 at 6:50 AM, Jan Eglinger <<a href="mailto:jan.eglinger@gmail.com" target="_blank">jan.eglinger@gmail.com</a>><br>
wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Felix and all,<br>
<br>
On 20.08.2015 10:06, MEYENHOFER Felix wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I couldn’t find any hint that it is possible to update the choices of a<br>
parameter (declared with the annotator) in a callback that for another<br>
parameter. For example; I have a file chooser and once a file hase been<br>
chosen, I want to read some file metadata and then update the choices of<br>
the combobox that allows to select the images series.<br>
Since I could not figure a way to do it, I wanted to ask here if it is<br>
possible at all?<br>
<br>
<br>
</blockquote>
I think dynamic adjustment of parameters isn't possible currently, but I<br>
agree that it would be a great thing to have.<br>
<br>
I know quite some use cases where either a DialogListener or a series of<br>
subsequent dialogs are used in ImageJ 1.x plugins to adjust parameter<br>
choice to previously harvested input.<br>
<br>
Furthermore, is it possible to get a directory chooser instead of a file<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
chooser in the configuration dialog of a command using the @Parameter<br>
annotation?<br>
<br>
<br>
</blockquote>
Yes, by using the<br>
    style = "directory"<br>
attribute. See *Templates > Python > Process Folder* in the script editor,<br>
and this related discussion:<br>
  <a href="https://github.com/imagej/imagej-legacy/pull/114" rel="noreferrer" target="_blank">https://github.com/imagej/imagej-legacy/pull/114</a><br>
<br>
Best,<br>
Jan<br>
<br>
<br>
_______________________________________________<br>
ImageJ-devel mailing list<br>
<a href="mailto:ImageJ-devel@imagej.net" target="_blank">ImageJ-devel@imagej.net</a><br>
<a href="http://imagej.net/mailman/listinfo/imagej-devel" rel="noreferrer" target="_blank">http://imagej.net/mailman/listinfo/imagej-devel</a><br>
<br>
</blockquote></blockquote>
<br></div></div><span class="HOEnZb"><font color="#888888">
-- <br>
<a href="http://www.msc.univ-paris-diderot.fr/~daerr/" rel="noreferrer" target="_blank">http://www.msc.univ-paris-diderot.fr/~daerr/</a><br>
</font></span></blockquote></div><br></div>