All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scijava.module.DefaultMutableModuleItem Maven / Gradle / Ivy

Go to download

SciJava Common is a shared library for SciJava software. It provides a plugin framework, with an extensible mechanism for service discovery, backed by its own annotation processor, so that plugins can be loaded dynamically. It is used by downstream projects in the SciJava ecosystem, such as ImageJ and SCIFIO.

There is a newer version: 2.99.0
Show newest version
/*
 * #%L
 * SciJava Common shared library for SciJava software.
 * %%
 * Copyright (C) 2009 - 2016 Board of Regents of the University of
 * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
 * Institute of Molecular Cell Biology and Genetics.
 * %%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * #L%
 */

package org.scijava.module;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.scijava.ItemIO;
import org.scijava.ItemVisibility;

/**
 * Default {@link MutableModuleItem} implementation, for use with custom
 * {@link MutableModule} implementations.
 * 
 * @author Curtis Rueden
 */
public class DefaultMutableModuleItem extends AbstractModuleItem
	implements MutableModuleItem
{

	private final Class type;
	private final Type genericType;
	private ItemIO ioType;
	private ItemVisibility visibility;
	private boolean required;
	private boolean persisted;
	private String persistKey;
	private String initializer;
	private String callback;
	private String widgetStyle;
	private T defaultValue;
	private T minimumValue;
	private T maximumValue;
	private T softMinimum;
	private T softMaximum;
	private Number stepSize;
	private int columnCount;
	private final List choices = new ArrayList<>();
	private String name;
	private String label;
	private String description;

	public DefaultMutableModuleItem(final Module module, final String name,
		final Class type)
	{
		this(module.getInfo(), name, type);
	}

	public DefaultMutableModuleItem(final ModuleInfo info, final String name,
		final Class type)
	{
		super(info);
		this.name = name;
		this.type = type;
		genericType = type;
		ioType = super.getIOType();
		visibility = super.getVisibility();
		required = super.isRequired();
		persisted = super.isPersisted();
		persistKey = super.getPersistKey();
		initializer = super.getInitializer();
		callback = super.getCallback();
		widgetStyle = super.getWidgetStyle();
		minimumValue = super.getMinimumValue();
		maximumValue = super.getMaximumValue();
		stepSize = super.getStepSize();
		columnCount = super.getColumnCount();
		final List superChoices = super.getChoices();
		if (superChoices != null) choices.addAll(superChoices);
		label = super.getLabel();
		description = super.getDescription();
	}

	/** Creates a new module item with the same values as the given item. */
	public DefaultMutableModuleItem(final ModuleInfo info,
		final ModuleItem 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();
		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 itemChoices = item.getChoices();
		if (itemChoices != null) choices.addAll(itemChoices);
		label = item.getLabel();
		description = item.getDescription();
	}

	// -- MutableModuleItem methods --

	@Override
	public void setIOType(final ItemIO ioType) {
		this.ioType = ioType;
	}

	@Override
	public void setVisibility(final ItemVisibility visibility) {
		this.visibility = visibility;
	}

	@Override
	public void setRequired(final boolean required) {
		this.required = required;
	}

	@Override
	public void setPersisted(final boolean persisted) {
		this.persisted = persisted;
	}

	@Override
	public void setPersistKey(final String persistKey) {
		this.persistKey = persistKey;
	}

	@Override
	public void setInitializer(final String initializer) {
		this.initializer = initializer;
	}

	@Override
	public void setCallback(final String callback) {
		this.callback = callback;
	}

	@Override
	public void setWidgetStyle(final String widgetStyle) {
		this.widgetStyle = widgetStyle;
	}

	@Override
	public void setDefaultValue(final T defaultValue) {
		this.defaultValue = defaultValue;
	}

	@Override
	public void setMinimumValue(final T minimumValue) {
		this.minimumValue = minimumValue;
	}

	@Override
	public void setMaximumValue(final T maximumValue) {
		this.maximumValue = maximumValue;
	}

	@Override
	public void setSoftMinimum(final T softMinimum) {
		this.softMinimum = softMinimum;
	}

	@Override
	public void setSoftMaximum(final T softMaximum) {
		this.softMaximum = softMaximum;
	}

	@Override
	public void setStepSize(final Number stepSize) {
		this.stepSize = stepSize;
	}

	@Override
	public void setColumnCount(final int columnCount) {
		this.columnCount = columnCount;
	}

	@Override
	public void setChoices(final List choices) {
		this.choices.clear();
		this.choices.addAll(choices);
	}

	// -- ModuleItem methods --

	@Override
	public Class getType() {
		return type;
	}

	@Override
	public Type getGenericType() {
		return genericType;
	}

	@Override
	public ItemIO getIOType() {
		return ioType;
	}

	@Override
	public ItemVisibility getVisibility() {
		return visibility;
	}

	@Override
	public boolean isRequired() {
		return required;
	}

	@Override
	public boolean isPersisted() {
		return persisted;
	}

	@Override
	public String getPersistKey() {
		return persistKey;
	}

	@Override
	public String getInitializer() {
		return initializer;
	}

	@Override
	public String getCallback() {
		return callback;
	}

	@Override
	public String getWidgetStyle() {
		return widgetStyle;
	}

	@Override
	public T getDefaultValue() {
		return defaultValue;
	}

	@Override
	public T getMinimumValue() {
		return minimumValue;
	}

	@Override
	public T getMaximumValue() {
		return maximumValue;
	}

	@Override
	public T getSoftMinimum() {
		return softMinimum;
	}

	@Override
	public T getSoftMaximum() {
		return softMaximum;
	}

	@Override
	public Number getStepSize() {
		return stepSize;
	}

	@Override
	public int getColumnCount() {
		return columnCount;
	}

	@Override
	public List getChoices() {
		return Collections.unmodifiableList(choices);
	}

	// -- BasicDetails methods --

	@Override
	public String getLabel() {
		return label;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public void setLabel(final String label) {
		this.label = label;
	}

	@Override
	public void setDescription(final String description) {
		this.description = description;
	}

	// -- Named methods --

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(final String name) {
		this.name = name;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy