/** * As {@link #paramString(Iterable, ModuleItem, String)} with a toggle to control * if inputs are types only or include the names. */ private static String paramString(final Iterable<ModuleItem<?>> items, final ModuleItem<?> special, final String delim, final boolean typeOnly) { final StringBuilder sb = new StringBuilder(); boolean first = true; for (final ModuleItem<?> item : items) { if (first) first = false; else sb.append(delim); sb.append("\n"); if (item == special) sb.append("==>"); // highlight special item sb.append("\t\t"); sb.append(item.getType().getSimpleName()); if (!typeOnly){ sb.append(" " + item.getName()); if (!item.isRequired()) sb.append("?"); } } return sb.toString(); } }
/** Helper method of {@link #match(OpCandidate, Object[])}. */ private boolean canAssign(final OpCandidate candidate, final Object arg, final ModuleItem<?> item) { if (arg == null) { if (item.isRequired()) { candidate.setStatus(StatusCode.REQUIRED_ARG_IS_NULL, null, item); return false; } return true; } final Type type = item.getGenericType(); if (!canConvert(arg, type)) { candidate.setStatus(StatusCode.CANNOT_CONVERT, arg.getClass().getName() + " => " + type, item); return false; } return true; }
/** * Determines if the candidate has some arguments missing. * <p> * Helper method of {@link #filterMatches(List)}. * </p> */ private boolean missArgs(final OpCandidate candidate) { int i = 0; for (final ModuleItem<?> item : candidate.inputs()) { if (candidate.getArgs()[i++] == null && item.isRequired()) { candidate.setStatus(StatusCode.REQUIRED_ARG_IS_NULL, null, item); return true; } } return false; }
@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."); } } }
@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."); } } }
for (final ModuleItem<?> item : candidate.inputs()) { inputCount++; if (item.isRequired()) requiredCount++; int argIndex = 0, paddedIndex = 0, optionalIndex = 0; for (final ModuleItem<?> item : candidate.inputs()) { if (!item.isRequired() && optionalIndex++ >= optionalsToFill) {
args.append(className); for (final ModuleItem<?> input : info.inputs()) { if (!input.isRequired()) {
@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()); } } }
private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel, final Module module, final ModuleItem<T> item) throws ModuleException { final String name = item.getName(); final boolean resolved = module.isInputResolved(name); if (resolved) return null; // skip resolved inputs final Class<T> type = item.getType(); final WidgetModel model = widgetService.createModel(inputPanel, module, item, getObjects(type)); final Class<W> widgetType = inputPanel.getWidgetComponentType(); final InputWidget<?, ?> widget = widgetService.create(model); if (widget == null) { log.debug("No widget found for input: " + model.getItem().getName()); } if (widget != null && widget.getComponentType() == widgetType) { @SuppressWarnings("unchecked") final InputWidget<?, W> typedWidget = (InputWidget<?, W>) widget; inputPanel.addWidget(typedWidget); return model; } if (item.isRequired()) { throw new ModuleException("A " + type.getSimpleName() + " is required but none exist."); } // item is not required; we can skip it return null; }
private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel, final Module module, final ModuleItem<T> item) throws ModuleException { final String name = item.getName(); final boolean resolved = module.isInputResolved(name); if (resolved) return null; // skip resolved inputs final Class<T> type = item.getType(); final WidgetModel model = widgetService.createModel(inputPanel, module, item, getObjects(type)); final Class<W> widgetType = inputPanel.getWidgetComponentType(); final InputWidget<?, ?> widget = widgetService.create(model); if (widget == null) { log.debug("No widget found for input: " + model.getItem().getName()); } if (widget != null && widget.getComponentType() == widgetType) { @SuppressWarnings("unchecked") final InputWidget<?, W> typedWidget = (InputWidget<?, W>) widget; inputPanel.addWidget(typedWidget); return model; } if (item.isRequired()) { throw new ModuleException("A " + type.getSimpleName() + " is required but none exist."); } // item is not required; we can skip it return null; }
int requiredCount = 0, inputCount = 0; for (final ModuleItem<?> input : info.inputs()) { if (input.isRequired()) requiredCount++; inputCount++;
/** Creates a new module item with the same values as the given item. */ public DefaultMutableModuleItem(final ModuleInfo info, final ModuleItem<T> item) { super(info); name = item.getName(); type = item.getType(); genericType = item.getGenericType(); ioType = item.getIOType(); visibility = item.getVisibility(); required = item.isRequired(); persisted = item.isPersisted(); persistKey = item.getPersistKey(); initializer = item.getInitializer(); validater = item.getValidater(); callback = item.getCallback(); widgetStyle = item.getWidgetStyle(); minimumValue = item.getMinimumValue(); maximumValue = item.getMaximumValue(); softMinimum = item.getSoftMinimum(); softMaximum = item.getSoftMaximum(); stepSize = item.getStepSize(); columnCount = item.getColumnCount(); final List<T> itemChoices = item.getChoices(); if (itemChoices != null) choices.addAll(itemChoices); label = item.getLabel(); description = item.getDescription(); }
/** Creates a new module item with the same values as the given item. */ public DefaultMutableModuleItem(final ModuleInfo info, final ModuleItem<T> item) { super(info); name = item.getName(); type = item.getType(); genericType = item.getGenericType(); ioType = item.getIOType(); visibility = item.getVisibility(); required = item.isRequired(); persisted = item.isPersisted(); persistKey = item.getPersistKey(); initializer = item.getInitializer(); validater = item.getValidater(); callback = item.getCallback(); widgetStyle = item.getWidgetStyle(); minimumValue = item.getMinimumValue(); maximumValue = item.getMaximumValue(); softMinimum = item.getSoftMinimum(); softMaximum = item.getSoftMaximum(); stepSize = item.getStepSize(); columnCount = item.getColumnCount(); final List<T> itemChoices = item.getChoices(); if (itemChoices != null) choices.addAll(itemChoices); label = item.getLabel(); description = item.getDescription(); }
private void assertItem(final String name, final Class<?> type, final String label, final ItemIO ioType, final boolean required, final boolean persist, final String persistKey, final String style, final Object value, final Object min, final Object max, final Object softMin, final Object softMax, final Number stepSize, final List<?> choices, final ModuleItem<?> item) { assertEquals(name, item.getName()); assertSame(type, item.getType()); assertEquals(label, item.getLabel()); assertSame(ioType, item.getIOType()); assertEquals(required, item.isRequired()); assertEquals(persist, item.isPersisted()); assertEquals(persistKey, item.getPersistKey()); assertEquals(style, item.getWidgetStyle()); assertEquals(value, item.getDefaultValue()); assertEquals(min, item.getMinimumValue()); assertEquals(max, item.getMaximumValue()); assertEquals(softMin, item.getSoftMinimum()); assertEquals(softMax, item.getSoftMaximum()); assertEquals(stepSize, item.getStepSize()); assertEquals(choices, item.getChoices()); }