Tabnine Logo
ModuleItem
Code IndexAdd Tabnine to your IDE (free)

How to use
ModuleItem
in
org.scijava.module

Best Java code snippets using org.scijava.module.ModuleItem (Showing top 20 results out of 315)

Refine searchRefine arrow

  • Module
  • ModuleInfo
origin: org.scijava/scijava-common

@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);
    }
  }
}
origin: org.scijava/scijava-common

/** 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();
}
origin: org.scijava/scijava-common

/** 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);
}
origin: org.scijava/scijava-common

  private String prefKey(final ModuleItem<?> item) {
    final String persistKey = item.getPersistKey();
    return persistKey == null || persistKey.isEmpty() ? //
      item.getName() : persistKey;
  }
}
origin: org.scijava/scijava-common

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";
}
origin: org.scijava/scijava-common

protected <T> void update(final ModuleItem<T> item, final T newValue) {
  final T oldValue = item.getValue(this);
  if (oldValue != newValue) {
    item.setValue(this, newValue);
    try {
      item.callback(this);
    }
    catch (final MethodCallException exc) {
      log.error(exc);
    }
  }
}
origin: org.scijava/scijava-common

/**
 * Gets the single unresolved {@link File} input parameter. If there is not
 * exactly one unresolved {@link File} input parameter, or if there are other
 * types of unresolved parameters, this method returns null.
 */
private ModuleItem<File> getFileInput(final Module module) {
  ModuleItem<File> result = null;
  for (final ModuleItem<?> input : module.getInfo().inputs()) {
    if (module.isInputResolved(input.getName())) continue;
    final Class<?> type = input.getType();
    if (!File.class.isAssignableFrom(type)) {
      // not a File parameter; abort
      return null;
    }
    if (result != null) {
      // second File parameter; abort
      return null;
    }
    @SuppressWarnings("unchecked")
    final ModuleItem<File> fileInput = (ModuleItem<File>) input;
    result = fileInput;
  }
  return result;
}
origin: org.scijava/scijava-common

@Override
public void process(final Module module) {
  if (uiService == null) return;
  final ModuleItem<File> fileInput = getFileInput(module);
  if (fileInput == null) return;
  final File file = fileInput.getValue(module);
  final String style = fileInput.getWidgetStyle();
  // show file chooser dialog box
  final File result = uiService.chooseFile(file, style);
  if (result == null) {
    cancel("");
    return;
  }
  fileInput.setValue(module, result);
  module.resolveInput(fileInput.getName());
}
origin: scijava/scijava-common

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());
}
origin: org.scijava/scijava-common

@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.");
    }
  }
}
origin: org.scijava/scijava-common

@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);
}
origin: org.scijava/scijava-common

@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);
  }
}
origin: org.scijava/scijava-common

  /** 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);
    }
  }
}
origin: org.scijava/scijava-common

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());
}
origin: net.imagej/imagej-common

@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);
}
origin: org.scijava/scijava-common

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;
}
origin: org.scijava/scijava-common

@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 (Gateway.class.isAssignableFrom(type)) {
      // input is a gateway
      @SuppressWarnings("unchecked")
      final ModuleItem<? extends Gateway> gatewayInput =
        (ModuleItem<? extends Gateway>) input;
      setGatewayValue(getContext(), module, gatewayInput);
    }
  }
}
origin: imagej/imagej-ops

/** 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());
}
origin: net.imagej/imagej-legacy

  @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());
    }
  }
}
origin: net.imagej/imagej-ui-swing

/**
 * Extract the Axis from the {@link Dataset}.
 * 
 * @param model A {@link WidgetModel}
 * @return The Axis of the {@link Dataset} or null if no {@link Dataset} was
 *         found.
 */
private TypedAxis[] extractAxis(final WidgetModel model) {
  final Module module = model.getModule();
  for (final ModuleItem<?> moduleItem : module.getInfo().inputs()) {
    if (TypedSpace.class.isAssignableFrom(moduleItem.getType())) {
      final TypedSpace<?> space = (TypedSpace<?>) moduleItem.getValue(module);
      final TypedAxis[] axis = new TypedAxis[space.numDimensions()];
      for (int i = 0; i < space.numDimensions(); i++) {
        axis[i] = space.axis(i);
      }
      return axis;
    }
  }
  return null;
}
org.scijava.moduleModuleItem

Javadoc

A ModuleItem represents metadata about one input or output of a module.

Most used methods

  • getName
  • getType
    Gets the type of the item.
  • getWidgetStyle
    Gets the preferred widget style to use when rendering the item in a user interface.
  • getValue
    Gets the item's current value with respect to the given module.
  • isRequired
    Gets whether the item value must be specified (i.e., no default).
  • getColumnCount
    Gets the preferred width of the input field in characters (if applicable).
  • getGenericType
    Gets the type of the item, including Java generic parameters. For many modules, this may be the same
  • getLabel
  • getVisibility
    Gets the visibility of the item.
  • setValue
    Sets the item's current value with respect to the given module.
  • get
  • getChoices
    Gets the list of possible values.
  • get,
  • getChoices,
  • getDefaultValue,
  • getDescription,
  • getIOType,
  • getMaximumValue,
  • getMinimumValue,
  • getPersistKey,
  • getSoftMaximum,
  • getSoftMinimum

Popular in Java

  • Reading from database using SQL prepared statement
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getSystemService (Context)
  • setContentView (Activity)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now