@Override public void process(final Module module) { // assign singleton ResultsTable to single ResultsTable input final String resultsTableInput = getSingleInput(module, ResultsTable.class); if (resultsTableInput != null) { final ResultsTable resultsTable = ResultsTable.getResultsTable(); if (resultsTable == null) return; module.setInput(resultsTableInput, resultsTable); module.resolveInput(resultsTableInput); } } }
@Override public void process(final Module module) { if (logService == null || moduleService == null) return; final ModuleItem<?> loggerInput = moduleService.getSingleInput(module, Logger.class); if (loggerInput == null || !loggerInput.isAutoFill()) return; String loggerName = loggerInput.getLabel(); if(loggerName == null || loggerName.isEmpty()) loggerName = module.getDelegateObject().getClass().getSimpleName(); Logger logger = logService.subLogger(loggerName); final String name = loggerInput.getName(); module.setInput(name, logger); module.resolveInput(name); }
@Override public void process(final Module module) { if (logService == null || moduleService == null) return; final ModuleItem<?> loggerInput = moduleService.getSingleInput(module, Logger.class); if (loggerInput == null || !loggerInput.isAutoFill()) return; String loggerName = loggerInput.getLabel(); if(loggerName == null || loggerName.isEmpty()) loggerName = module.getDelegateObject().getClass().getSimpleName(); Logger logger = logService.subLogger(loggerName); final String name = loggerInput.getName(); module.setInput(name, logger); module.resolveInput(name); }
@Override public void process(final Module module) { if (uiService == null) return; // no UI service available final UserInterface ui = uiService.getDefaultUI(); if (ui == null) return; // no default UI for (final ModuleItem<?> input : module.getInfo().inputs()) { if (!input.isAutoFill()) continue; // cannot auto-fill this input final Class<?> type = input.getType(); if (type.isAssignableFrom(ui.getClass())) { // input is a compatible UI final String name = input.getName(); module.setInput(name, ui); module.resolveInput(name); } } }
@Override public void process(final Module module) { if (uiService == null) return; // no UI service available final UserInterface ui = uiService.getDefaultUI(); if (ui == null) return; // no default UI for (final ModuleItem<?> input : module.getInfo().inputs()) { if (!input.isAutoFill()) continue; // cannot auto-fill this input final Class<?> type = input.getType(); if (type.isAssignableFrom(ui.getClass())) { // input is a compatible UI final String name = input.getName(); module.setInput(name, ui); module.resolveInput(name); } } }
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; }
@Override public void process(final Module module) { // add Overlay from imp to single Overlay input final String overlayInput = getSingleInput(module, Overlay.class); if (overlayInput != null) { // TODO: Change this to a LegacyService API call? final ImagePlus imp = WindowManager.getCurrentImage(); if (imp == null) return; Overlay ovl = imp.getOverlay(); if (ovl == null) return; module.setInput(overlayInput, ovl); module.resolveInput(overlayInput); } } }
@Override public void setValue(final Module module, final T value) { if (isInput()) module.setInput(getName(), value); if (isOutput()) module.setOutput(getName(), value); }
@Override public void setValue(final Module module, final T value) { if (isInput()) module.setInput(getName(), value); if (isOutput()) module.setOutput(getName(), value); }
/** Helper method of {@link #assignInputs}. */ private void assign(final Module module, final Object arg, final ModuleItem<?> item) { if (arg != null) { final Type type = item.getGenericType(); final Object value = convert(arg, type); module.setInput(item.getName(), value); } module.resolveInput(item.getName()); }
@Override public void setValue(final Object value) { final String name = item.getName(); if (Objects.equals(item.getValue(module), value)) return; // no change // Check if a converted value is present Object convertedInput = convertedObjects.get(value); if (convertedInput != null && Objects.equals(item.getValue(module), convertedInput)) { return; // no change } // Pass the value through the convertService convertedInput = convertService.convert(value, item.getType()); // If we get a different (converted) value back, cache it weakly. if (convertedInput != value) { convertedObjects.put(value, convertedInput); } module.setInput(name, convertedInput); if (initialized) { threadService.queue(() -> { callback(); inputPanel.refresh(); // must be on AWT thread? module.preview(); }); } }
@Override public void setValue(final Object value) { final String name = item.getName(); if (Objects.equals(item.getValue(module), value)) return; // no change // Check if a converted value is present Object convertedInput = convertedObjects.get(value); if (convertedInput != null && Objects.equals(item.getValue(module), convertedInput)) { return; // no change } // Pass the value through the convertService convertedInput = convertService.convert(value, item.getType()); // If we get a different (converted) value back, cache it weakly. if (convertedInput != value) { convertedObjects.put(value, convertedInput); } module.setInput(name, convertedInput); if (initialized) { threadService.queue(() -> { callback(); inputPanel.refresh(); // must be on AWT thread? module.preview(); }); } }
@Override public void process(final Module module) { for (final ModuleItem<?> input : module.getInfo().inputs()) { if (!input.isAutoFill()) continue; // cannot auto-fill this input final Class<?> type = input.getType(); if (Service.class.isAssignableFrom(type)) { // input is a service @SuppressWarnings("unchecked") final ModuleItem<? extends Service> serviceInput = (ModuleItem<? extends Service>) input; setServiceValue(getContext(), module, serviceInput); } if (type.isAssignableFrom(getContext().getClass())) { // input is a compatible context final String name = input.getName(); module.setInput(name, getContext()); module.resolveInput(name); } } }
@Override public void process(final Module module) { for (final ModuleItem<?> input : module.getInfo().inputs()) { if (!input.isAutoFill()) continue; // cannot auto-fill this input final Class<?> type = input.getType(); if (Service.class.isAssignableFrom(type)) { // input is a service @SuppressWarnings("unchecked") final ModuleItem<? extends Service> serviceInput = (ModuleItem<? extends Service>) input; setServiceValue(getContext(), module, serviceInput); } if (type.isAssignableFrom(getContext().getClass())) { // input is a compatible context final String name = input.getName(); module.setInput(name, getContext()); module.resolveInput(name); } } }
@Override public void process(final Module module) { // look for single inputs that can be populated final ModuleItem<?> singleInput = getSingleInput(module, inputType); if (singleInput == null) return; // populate the value of the single input Object value = getValue(); if (value == null) return; String itemName = singleInput.getName(); value = convertService.convert(value, singleInput.getType()); module.setInput(itemName, value); module.resolveInput(itemName); }
@Override public void process(final Module module) { if (displayService == null || moduleService == null) return; final ModuleItem<?> displayInput = moduleService.getSingleInput(module, Display.class); if (displayInput == null || !displayInput.isAutoFill()) return; @SuppressWarnings("unchecked") final Class<? extends Display<?>> displayType = (Class<? extends Display<?>>) displayInput.getType(); final Display<?> activeDisplay = displayService.getActiveDisplay(displayType); if (activeDisplay == null) return; final String name = displayInput.getName(); module.setInput(name, activeDisplay); module.resolveInput(name); }
@Override public void process(final Module module) { if (displayService == null || moduleService == null) return; final ModuleItem<?> displayInput = moduleService.getSingleInput(module, Display.class); if (displayInput == null || !displayInput.isAutoFill()) return; @SuppressWarnings("unchecked") final Class<? extends Display<?>> displayType = (Class<? extends Display<?>>) displayInput.getType(); final Display<?> activeDisplay = displayService.getActiveDisplay(displayType); if (activeDisplay == null) return; final String name = displayInput.getName(); module.setInput(name, activeDisplay); module.resolveInput(name); }
@Override public void process(final Module module) { // assign singleton RoiManager to single RoiManager input final ModuleItem<RoiManager> roiManagerInput = moduleService.getSingleInput( module, RoiManager.class); if (roiManagerInput != null) { RoiManager roiManager; if (roiManagerInput.isRequired()) { roiManager = RoiManager.getRoiManager(); } else { roiManager = RoiManager.getInstance(); } if (roiManager == null) return; module.setInput(roiManagerInput.getName(), roiManager); module.resolveInput(roiManagerInput.getName()); } } }
@Override public void process(final Module module) { for (final ModuleItem<?> input : module.getInfo().inputs()) { if (Stuff.class.isAssignableFrom(input.getType())) { module.setInput(input.getName(), new Stuff()); module.resolveInput(input.getName()); } } }
@Override public void process(final Module module) { if (legacyService == null) return; final IJ1Helper ij1Helper = legacyService.getIJ1Helper(); if (ij1Helper == null) return; if (!ij1Helper.isMacro()) return; for (final ModuleItem<?> input : module.getInfo().inputs()) { final String name = input.getName(); final String value = ij1Helper.getMacroParameter(name); if (value == null) { // no macro parameter value provided continue; } final Class<?> type = input.getType(); if (!convertService.supports(value, type)) { // cannot convert macro value into the input's actual type continue; } final Object converted = convertService.convert(value, type); module.setInput(name, converted); module.resolveInput(name); } }