/** * Adds an output. Intended to be called from overridden * {@link #parseParameters()} methods. */ protected void registerOutput(final ModuleItem<?> output) { outputMap.put(output.getName(), output); outputList.add(output); }
/** * Adds an input. Intended to be called from overridden * {@link #parseParameters()} methods. */ protected void registerInput(final ModuleItem<?> input) { inputMap.put(input.getName(), input); inputList.add(input); }
@Override public String getWidgetLabel() { // Do this dynamically. Don't cache this result. // Some controls change their labels at runtime. final String label = item.getLabel(); if (label != null && !label.isEmpty()) return label; final String name = item.getName(); return name.substring(0, 1).toUpperCase() + name.substring(1); }
private String prefKey(final ModuleItem<?> item) { final String persistKey = item.getPersistKey(); return persistKey == null || persistKey.isEmpty() ? // item.getName() : persistKey; } }
private String defaultName(final ModuleItem<?> item) { final String label = item.getLabel(); if (label != null && !label.isEmpty()) return label; final String name = item.getName(); if (name != null && !name.isEmpty()) return name; return "Unnamed"; }
@Override public void addInput(final ModuleItem<?> input) { inputMap().put(input.getName(), input); inputList().add(input); }
@Override public void removeOutput(final ModuleItem<?> output) { outputMap().remove(output.getName()); outputList().remove(output); } }
@Override public void addOutput(final ModuleItem<?> output) { outputMap().put(output.getName(), output); outputList().add(output); }
@Override public void removeInput(final ModuleItem<?> input) { inputMap().remove(input.getName()); inputList().remove(input); }
private Map<String, Object> createMap(final Iterable<ModuleItem<?>> items, final boolean outputMap) { final Map<String, Object> map = new HashMap<>(); for (final ModuleItem<?> item : items) { final String name = item.getName(); final Object value = outputMap ? getOutput(name) : getInput(name); map.put(name, value); } return map; }
private ModuleItem<?> getInputItem(final String name) { for (final ModuleItem<?> item : getInfo().inputs()) { if (item.getName().equals(name)) return item; } return null; } }
protected void updateInput(final ModuleItem<?> item) { final ModuleItem<Display<?>> displayItem = asDisplay(item); if (displayItem != null) updateDisplay(displayItem); else { log.warn("Input '" + item.getName() + "' (" + item.getClass().getName() + ") is not supported"); } }
/** Does any needed processing, after input values have been harvested. */ @SuppressWarnings("unused") default void processResults(final InputPanel<P, W> inputPanel, final Module module) throws ModuleException { final Iterable<ModuleItem<?>> inputs = module.getInfo().inputs(); for (final ModuleItem<?> item : inputs) { final String name = item.getName(); module.resolveInput(name); } } }
private <S extends Service> void setServiceValue(final Context context, final Module module, final ModuleItem<S> input) { final S service = context.getService(input.getType()); input.setValue(module, service); module.resolveInput(input.getName()); }
private void resetState() { // NB: Clear "resolved" status of all inputs. // Otherwise, no inputs are harvested on next run. for (final ModuleItem<?> input : getInfo().inputs()) { unresolveInput(input.getName()); } // NB: Clear "canceled" status. // Otherwise, the command cannot run again. uncancel(); } }
@SuppressWarnings("unchecked") @Override public <I> void fillInput(Module module, ModuleItem<?> moduleItem, I inputObject) { BatchInputProvider<File> handler = (BatchInputProvider<File>) getHandler(new BatchInput(File.class, moduleItem)); if (handler == null) { log.error("No handler found for input: " + moduleItem.getName()); return; } handler.populateInput(module, moduleItem, (File) inputObject); }
private <T> void assignDefaultValue(final Module module, final ModuleItem<T> item) { if (module.isInputResolved(item.getName())) return; final T nullValue = Types.nullValue(item.getType()); if (!Objects.equals(item.getValue(module), nullValue)) return; final T defaultValue = moduleService.getDefaultValue(item); if (defaultValue == null) return; item.setValue(module, defaultValue); }
@Override public void process(final Module module) { for (final ModuleItem<?> input : module.getInfo().inputs()) { if (input.isRequired() && input.getValue(module) == null) { cancel("'" + input.getName() + "' is required but unset."); } } }
/** Loads the value of the given module item from persistent storage. */ private <T> void loadValue(final Module module, final ModuleItem<T> item) { // skip input that has already been resolved if (module.isInputResolved(item.getName())) return; final T prefValue = moduleService.load(item); final Class<T> type = item.getType(); final T defaultValue = item.getValue(module); final T value = getBestValue(prefValue, defaultValue, type); item.setValue(module, value); }
@Override public void process(final Module module) { if (displayService == null) return; for (final ModuleItem<?> outputItem : module.getInfo().outputs()) { if (module.isOutputResolved(outputItem.getName())) continue; final Object value = outputItem.getValue(module); final String name = defaultName(outputItem); final boolean resolved = handleOutput(name, value); if (resolved) module.resolveOutput(name); } }