public class SlideSetPluginLoader extends Object
SlideSetPluginLoader
maintains an index of available
SlideSetPlugin
s and manages command execution.
The same methods are used to run both SlideSetPlugins
and general ImageJ plugins; the few differences between them
are described below. A single instance is shared by other
Slide Set components and can be used repeatedly to run different
commands. Command execution proceeds in four phases:
Context
, ImageJ
,
DatasetService
) or Slide Set components (ex:
SlideSetLog
, DataTypeIDService
) that should be
filled without consulting the user. For the remaining inputs,
two lists are requested from DataTypeIDService
:
ColumnBoundReader
s that can produce a cast-compatible
type from the input SlideSet table; and
ElementReader
types that can produce a cast-compatible
type from a constant value.
PluginInputPicker
is then used to select the readers or constant values to use.
In Slide Set core, PluginInputPicker
is implemented by
PluginInputMatcherFrame
,
which prompts the user to select the desired inputs, although
custom implementations are also possible, including schemes for
automated selection. If a constant value is specified for an
input parameter, it is used to instantiate a
"constant" ColumnBoundReader
.
SlideSet
table in which to save them. For each output, a list of
ElementWriter
s with "processed" types cast-compatible
with the output type is requested from DataTypeIDService
.
These lists are passed to an instance of PluginOutputPicker
to determine which ElementWriter
should be used,
or if the output value should be discarded. In Slide Set core,
PluginOutputPicker
is implemented by
PluginOutputMatcherFrame
,
which uses a dialog box to prompt the user for choices,
although, as with PluginInputPicker
, custom
implementations are possible, including schemes for automated selection.
PluginOutputPicker
also provides selections for columns
from the input table that should be copied into the output table.
Given the selected ElementWriter
s,
SlideSetPluginLoader
than requests a SlideSet
table from DataTypeIDService
containing columns using
DataElement
classes and MIME types matching those writers.
The writers are then wrapped in ColumnBoundWriter
instances
which can be used to write data without interacting with the
table directly. Columns for the data selected for copying from
the input table are appended to the results table.
ColumnBoundReader
s, and the
plugin's run()
method is invoked. Once the method returns, the
plugin output parameters are recorded by the selected
ColumnBoundWriter
s. Each plugin run occurs in sequence
using one instance of the plugin class on a single thread,
though multithreading may be implemented in future versions.
An important consequence of this is that plugin output parameter
values from the previous run are retained when the subsequent
run begins. Therefore, initialization of output parameters should
occur at the beginning of the run()
method, rather than
in the constructor.
Modifier and Type | Field and Description |
---|---|
private org.scijava.command.CommandService |
cs |
private DataTypeIDService |
dtid |
private HelpLoader |
hl |
private net.imagej.ImageJ |
ij |
private SlideSetLog |
log |
(package private) List<org.scijava.command.CommandInfo> |
plugins |
Constructor and Description |
---|
SlideSetPluginLoader(net.imagej.ImageJ context,
DataTypeIDService dtid,
SlideSetLog log,
HelpLoader hl) |
Modifier and Type | Method and Description |
---|---|
private void |
addColumnsForParentFields(ArrayList<Integer> includedFields,
SlideSet parent,
SlideSet results)
Add columns to the results table for included fields from
the input table
|
private void |
fillServices(org.scijava.module.Module module,
Iterable<org.scijava.module.ModuleItem<?>> inputs)
Prefill service inputs
|
private int |
getNumResults(Map<String,Object> outputs)
Checks to make sure that all results are either length 1
(i.e.
|
List<org.scijava.command.CommandInfo> |
getPluginInfo()
Get a list of available
SlideSetPlugin s |
ArrayList<String> |
getPluginMenuPaths()
Get a list of the plugin paths, i.e.
|
private ArrayList<ColumnBoundReader> |
getReaders(Iterable<org.scijava.module.ModuleItem<?>> inputs,
SlideSet data,
PluginInputPicker pip,
String docPath,
CommandTemplate ct)
Create a list of
ColumnBoundReader s for each input |
private ArrayList<org.scijava.module.ModuleItem<?>> |
getUnfilledInputs(org.scijava.module.Module module,
Iterable<org.scijava.module.ModuleItem<?>> inputs)
Get a list of inputs that have not been filled
|
private void |
getWriters(ArrayList<org.scijava.module.ModuleItem<?>> outputs,
boolean reduce,
PluginOutputPicker pop,
ArrayList<ColumnBoundWriter> writers,
SlideSet resultsTable,
String[] parentLabels,
ArrayList<Integer> parentFields,
ArrayList<String> linkDir,
ArrayList<String> linkPre,
ArrayList<String> linkExt,
CommandTemplate ct)
Prepare for plugin results be creating a results table
and appropriate
ColumnBoundWriter s to write the
results to it |
private List<org.scijava.command.CommandInfo> |
loadPlugins()
Because the
CommandService is persnickety
when launched through Fiji, we'll do this manually. |
private Object |
reduce(Object output,
int index)
Get element
result from an output Object
which may or may not be an array or a List . |
private Class<?> |
reduceClass(Class<?> c)
If a class is an array or a
List , returns the class of the
array or list element. |
void |
refreshList()
Redo the search for plugins
|
SlideSet |
runPlugin(org.scijava.command.CommandInfo plugin,
SlideSet data,
PluginInputPicker pip,
PluginOutputPicker pop)
Run a
SlideSetPlugin |
SlideSet |
runPlugin(String className,
SlideSet data,
PluginInputPicker pip,
PluginOutputPicker pop)
Run a
SlideSetPlugin |
private void |
saveResults(org.scijava.module.Module m,
ArrayList<org.scijava.module.ModuleItem<?>> outputs,
boolean reduce,
ArrayList<ColumnBoundWriter> writers,
ArrayList<Integer> parentFields,
SlideSet resultsTable,
SlideSet parentTable,
int parentRow)
Save results from a command execution
|
private void |
setupFileLinkColumns(SlideSet table,
ArrayList<String> linkDir,
ArrayList<String> linkPre,
ArrayList<String> linkExt)
Generate default path links as needed
|
private final DataTypeIDService dtid
private final SlideSetLog log
private final net.imagej.ImageJ ij
private final org.scijava.command.CommandService cs
private final HelpLoader hl
List<org.scijava.command.CommandInfo> plugins
public SlideSetPluginLoader(net.imagej.ImageJ context, DataTypeIDService dtid, SlideSetLog log, HelpLoader hl)
public SlideSet runPlugin(String className, SlideSet data, PluginInputPicker pip, PluginOutputPicker pop) throws SlideSetException
SlideSetPlugin
className
- Class name specifying the command to rundata
- A SlideSet
list of data to be made available as inputs for the pluginSlideSet
list of resultsSlideSetException
public SlideSet runPlugin(org.scijava.command.CommandInfo plugin, SlideSet data, PluginInputPicker pip, PluginOutputPicker pop) throws SlideSetException
SlideSetPlugin
plugin
- CommandInfo
of the plugin to rundata
- A SlideSet
list of data to be made available as inputs for the pluginSlideSet
list of resultsSlideSetException
public List<org.scijava.command.CommandInfo> getPluginInfo()
SlideSetPlugin
spublic ArrayList<String> getPluginMenuPaths()
public void refreshList()
private void fillServices(org.scijava.module.Module module, Iterable<org.scijava.module.ModuleItem<?>> inputs) throws SlideSetException
SlideSetException
private ArrayList<org.scijava.module.ModuleItem<?>> getUnfilledInputs(org.scijava.module.Module module, Iterable<org.scijava.module.ModuleItem<?>> inputs)
private ArrayList<ColumnBoundReader> getReaders(Iterable<org.scijava.module.ModuleItem<?>> inputs, SlideSet data, PluginInputPicker pip, String docPath, CommandTemplate ct) throws SlideSetException
ColumnBoundReader
s for each inputinputs
- The list if inputs which need readersdata
- The table from which inputs should be drawnpip
- UI module to allow user selection of inputsdocPath
- Path for the relevant documentation, or null
if there is noneSlideSetException
PluginInputPicker
private void getWriters(ArrayList<org.scijava.module.ModuleItem<?>> outputs, boolean reduce, PluginOutputPicker pop, ArrayList<ColumnBoundWriter> writers, SlideSet resultsTable, String[] parentLabels, ArrayList<Integer> parentFields, ArrayList<String> linkDir, ArrayList<String> linkPre, ArrayList<String> linkExt, CommandTemplate ct) throws SlideSetException
ColumnBoundWriter
s to write the
results to itoutputs
- List of plugin outputs that might need
to be written to the output table. If the user
chooses to discard an output, it will be removed
from the list.reduce
- Should array outputs be split into
their individual elements?pop
- UI module to allow user specification of
output handling.writers
- List to be filled with ColumnBoundWriters
for the results that will be savedresultsTable
- Empty SlideSet
table that will be
configured to store the resultsparentLabels
- List of labels for the fields from the input table
that the user may choose to copy to the output tableparentFields
- List to be filled with the users
choices for which fields from the input table to be
copied to the results tablelinkDir
- List to be filled with default link path
to use, for results that use FileLinkElement
slinkPre
- List to be filled with file name root to use,
for results that use FileLinkElement
slinkExt
- List to be filled with file extensions
to use, for results that use FileLinkElement
sSlideSetException
PluginOutputPicker
private void addColumnsForParentFields(ArrayList<Integer> includedFields, SlideSet parent, SlideSet results) throws SlideSetException
includedFields
- List if indeces of fields to includeparent
- Input tableresults
- Results table that will be modifiedSlideSetException
private void setupFileLinkColumns(SlideSet table, ArrayList<String> linkDir, ArrayList<String> linkPre, ArrayList<String> linkExt) throws SlideSetException
SlideSetException
private void saveResults(org.scijava.module.Module m, ArrayList<org.scijava.module.ModuleItem<?>> outputs, boolean reduce, ArrayList<ColumnBoundWriter> writers, ArrayList<Integer> parentFields, SlideSet resultsTable, SlideSet parentTable, int parentRow) throws SlideSetException
SlideSetException
private int getNumResults(Map<String,Object> outputs)
List
s, or arrays or
List
s of length 1) or length N, where N is
some constant value. For example, three results with lengths
{1, 5, 5} or {3, 3, 3} are acceptable, but results with
lengths {3, 5, 5} are not.private Object reduce(Object output, int index)
result
from an output Object
which may or may not be an array or a List
.
If the output is not an array or a List
, or
is shorter than the requested index, returns
the first (or only) element.private Class<?> reduceClass(Class<?> c)
List
, returns the class of the
array or list element.private List<org.scijava.command.CommandInfo> loadPlugins()
CommandService
is persnickety
when launched through Fiji, we'll do this manually.Copyright © 2023. All rights reserved.