/** * Executes the module linked to this node. Does nothing for non-leaf nodes. */ @Override public void run() { if (moduleInfo == null) return; // no module to run if (moduleService != null) moduleService.run(moduleInfo, true); }
/** Builds the master list of available commands. */ private List<ModuleInfo> buildCommands(final ModuleService moduleService) { final List<ModuleInfo> list = new ArrayList<>(); list.addAll(moduleService.getModules()); Collections.sort(list); return list; }
private ModuleItem<?> getSingleInput(final Module module, final Class<?> type) { if (moduleService == null || convertService == null) return null; // Check the actual class first ModuleItem<?> item = moduleService.getSingleInput(module, type); if (item == null || !item.isAutoFill()) { // No match, so check look for classes that can be converted from the specified type final Collection<Class<?>> compatibleClasses = convertService.getCompatibleOutputClasses(type); item = moduleService.getSingleInput(module, compatibleClasses); } if (item == null || !item.isAutoFill()) return null; return item; }
/** <strong>This is not part of the public API. DO NOT USE!</strong> */ boolean handleShortcut(final String accelerator) { final Accelerator acc = Accelerator.create(accelerator); if (acc == null) return false; final ModuleInfo module = moduleService.getModuleForAccelerator(acc); // NB: ImageJ 1.x handles its own keyboard shortcuts. // We need to ignore legacy commands to avoid duplicate execution. // See: https://github.com/imagej/imagej1/issues/50 if (module == null || module instanceof LegacyCommandInfo) return false; moduleService.run(module, true); return true; }
public <C extends Command> Module executeCommand(final Class<C> cmdClass, final Map<String, Object> inputs) { final Module module = moduleService.createModule(cmdService.getCommand(cmdClass)); try { module.initialize(); } catch (final MethodCallException ex) { ex.printStackTrace(); } if (inputs != null) { inputs.forEach((k, v) -> { module.setInput(k, v); module.resolveInput(k); }); } cmdService.run(cmdClass, true, inputs); module.run(); final Future<Module> run = moduleService.run(module, true, inputs); try { run.get(); } catch (final InterruptedException ex) { ex.printStackTrace(); } catch (final ExecutionException ex) { ex.printStackTrace(); } return module; }
moduleService.getModules().stream() // .filter(info -> info.is("no-legacy")) // .collect(Collectors.toList()); moduleService.removeModules(noLegacyModules); moduleService.addModules(ij1Commands);
@Override protected String process(final String directive, final Map<String, Object> attrs, final String theRest) { for (final String k : attrs.keySet()) { assignAttribute(k == null ? "name" : k, attrs.get(k)); } moduleService.addModule(info()); // TODO how to handle duplicate names? return ""; }
@Override public void clear() { openWindows.clear(); moduleService.removeModules(windowModules.values()); windowModules.clear(); }
@Override public void run() { // mark inputChoice as resolved, then harvest script parameters (i.e. run) ModuleItem<?> inputModuleItem = moduleInfo.getInput(inputChoice); // TODO check if conversion needed? Module scriptModule = moduleService.createModule(moduleInfo); scriptModule.resolveInput(inputChoice); /* Create output Table and mark all outputs as resolved */ outputTable = new DefaultGenericTable(); @SuppressWarnings("rawtypes") List<Column> columns = new ArrayList<>(); for (String outputKey : scriptModule.getOutputs().keySet()) { columns.add(outputTable.appendColumn(outputKey)); scriptModule.resolveOutput(outputKey); } for (File file : inputFileList) { if(!processFile(scriptModule, inputModuleItem, file)) { log.warn("Terminating batch process."); break; // end for loop } } // case File // feed files into input // case Image (not needed if conversion works // open each file as image (warn on errors) and feed image into input }
/** Adds new commands to the module service. */ private void addCommands(final List<PluginInfo<Command>> plugins) { // extract commands from the list of plugins final List<CommandInfo> commands = new ArrayList<>(); for (final PluginInfo<Command> info : plugins) { final CommandInfo commandInfo = wrapAsCommand(info); commands.add(commandInfo); // record association between plugin info and derived command info commandMap.put(info, commandInfo); } // add extracted commands to the module service moduleService.addModules(commands); }
@Override protected String process(final String directive, final Map<String, Object> attrs, final String theRest) { for (final String k : attrs.keySet()) { assignAttribute(k == null ? "name" : k, attrs.get(k)); } moduleService.addModule(info()); // TODO how to handle duplicate names? return ""; }
@Override public void clear() { recentFiles.clear(); prefService.clear(RecentFileService.class, RECENT_FILES_KEY); // unregister the modules with the module service moduleService.removeModules(recentModules.values()); recentModules.clear(); }
/** Helper method of {@link #match(OpCandidate, Object[])}. */ private Module createModule(final OpCandidate candidate, final Object... args) { // create the module final Module module = moduleService.createModule(candidate.cInfo()); // unwrap the created op final Op op = OpUtils.unwrap(module, candidate.getRef()); // inject the op execution environment op.setEnvironment(candidate.ops()); // populate the inputs and return the module return assignInputs(module, args); }
/** Adds new commands to the module service. */ private void addCommands(final List<PluginInfo<Command>> plugins) { // extract commands from the list of plugins final List<CommandInfo> commands = new ArrayList<>(); for (final PluginInfo<Command> info : plugins) { final CommandInfo commandInfo = wrapAsCommand(info); commands.add(commandInfo); // record association between plugin info and derived command info commandMap.put(info, commandInfo); } // add extracted commands to the module service moduleService.addModules(commands); }
/** * Executes the module linked to this node. Does nothing for non-leaf nodes. */ @Override public void run() { if (moduleInfo == null) return; // no module to run if (moduleService != null) moduleService.run(moduleInfo, true); }
/** * Helper method to look up the name of singleton module inputs of a given * type. * * @param module Module to check for single input * @param type Type of single input to look for * @return If the given module has exactly one input of the specified type, * return that input's name. Otherwise null; */ protected String getSingleInput(final Module module, final Class<?> type) { if (moduleService == null) return null; final ModuleItem<?> item = moduleService.getSingleInput(module, type); if (item == null || !item.isAutoFill()) return null; return item.getName(); }
/** Initializes {@link #rootMenus}. */ private synchronized void initRootMenus() { if (rootMenus != null) return; final HashMap<String, ShadowMenu> map = new HashMap<>(); final List<ModuleInfo> allModules = moduleService.getModules(); addModules(allModules, map); rootMenus = map; }
@Override public void add(final String path) { final boolean present = recentModules.containsKey(path); // add path to recent files list if (present) recentFiles.remove(path); recentFiles.add(path); // persist the updated list saveList(); if (present) { // path already present; update linked module info final ModuleInfo info = recentModules.get(path); // TODO - update module weights info.update(eventService); } else { // new path; create linked module info final ModuleInfo info = createInfo(path); recentModules.put(path, info); // register the module with the module service moduleService.addModule(info); } }
/** Removes old commands from the module service. */ private void removeCommands(final List<PluginInfo<?>> plugins) { final List<CommandInfo> commands = getCommandsUnknown(plugins); for (final CommandInfo info : commands) { // clear association between plugin info and derived command info commandMap.remove(info); } // remove extracted commands from the module service moduleService.removeModules(commands); }