Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support widget groups to resolve #310 #428

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/org/scijava/ItemVisibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public enum ItemVisibility {
* intended as a message to the user (e.g., in the input harvester panel)
* rather than an actual parameter to the module execution.
*/
MESSAGE

MESSAGE,

/**
* Indicates that the item's value defines the name of a widget group
* (e.g., in the input harvester panel) rather than an actual parameter
* to the module execution. Widget groups organize related input widgets.
* Group members are added to a group by providing a group parameter annotation
* having the common group name.
*/
GROUP
}
10 changes: 10 additions & 0 deletions src/main/java/org/scijava/command/CommandModuleItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ public String getCallback() {
public String getWidgetStyle() {
return getParameter().style();
}

@Override
public String getWidgetGroup() {
return getParameter().group();
}

@Override
public boolean isExpanded() {
return getParameter().expanded();
}

@Override
public T getMinimumValue() {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/scijava/module/AbstractModuleItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public String toString() {
sm.append("persistKey", getPersistKey());
sm.append("callback", getCallback());
sm.append("widgetStyle", getWidgetStyle());
sm.append("widgetGroup", getWidgetGroup());
sm.append("expanded", isExpanded());
sm.append("default", getDefaultValue());
sm.append("min", getMinimumValue());
sm.append("max", getMaximumValue());
Expand Down Expand Up @@ -231,6 +233,16 @@ public void callback(final Module module) throws MethodCallException {
public String getWidgetStyle() {
return null;
}

@Override
public String getWidgetGroup() {
return null;
}

@Override
public boolean isExpanded() {
return true;
}

@Override
public T getDefaultValue() {
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/scijava/module/DefaultMutableModuleItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class DefaultMutableModuleItem<T> extends AbstractModuleItem<T>
private String validater;
private String callback;
private String widgetStyle;
private String widgetGroup;
private boolean expanded;
private T defaultValue;
private T minimumValue;
private T maximumValue;
Expand Down Expand Up @@ -94,6 +96,8 @@ public DefaultMutableModuleItem(final ModuleInfo info, final String name,
validater = super.getValidater();
callback = super.getCallback();
widgetStyle = super.getWidgetStyle();
widgetGroup = super.getWidgetGroup();
expanded = super.isExpanded();
minimumValue = super.getMinimumValue();
maximumValue = super.getMaximumValue();
stepSize = super.getStepSize();
Expand Down Expand Up @@ -122,6 +126,8 @@ public DefaultMutableModuleItem(final ModuleInfo info,
validater = item.getValidater();
callback = item.getCallback();
widgetStyle = item.getWidgetStyle();
widgetGroup = item.getWidgetGroup();
expanded = item.isExpanded();
minimumValue = item.getMinimumValue();
maximumValue = item.getMaximumValue();
softMinimum = item.getSoftMinimum();
Expand Down Expand Up @@ -185,6 +191,16 @@ public void setCallback(final String callback) {
public void setWidgetStyle(final String widgetStyle) {
this.widgetStyle = widgetStyle;
}

@Override
public void setWidgetGroup(final String widgetGroup) {
this.widgetGroup = widgetGroup;
}

@Override
public void setExpanded(final boolean expanded) {
this.expanded = expanded;
}

@Override
public void setDefaultValue(final T defaultValue) {
Expand Down Expand Up @@ -288,6 +304,16 @@ public String getCallback() {
public String getWidgetStyle() {
return widgetStyle;
}

@Override
public String getWidgetGroup() {
return widgetGroup;
}

@Override
public boolean isExpanded() {
return expanded;
}

@Override
public T getDefaultValue() {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/scijava/module/ModuleItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ public interface ModuleItem<T> extends BasicDetails {
* interface.
*/
String getWidgetStyle();

/**
* Gets the name of the group the widget belongs to so it can be displayed within
* the group.
*/
String getWidgetGroup();

/** Returns the state of the widget group, expanded and visible or not expanded and hidden. */
boolean isExpanded();

/** Gets the default value. */
T getDefaultValue();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/scijava/module/MutableModuleItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public interface MutableModuleItem<T> extends ModuleItem<T> {
void setCallback(String callback);

void setWidgetStyle(String widgetStyle);

void setWidgetGroup(String widgetGroup);

void setExpanded(boolean expanded);

void setDefaultValue(T defaultValue);

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/scijava/plugin/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
* output, such as a "verbose" flag.</li>
* <li>MESSAGE: parameter value is intended as a message only, not editable by
* the user nor included as an input or output parameter.</li>
* <li>GROUP: parameter value specifies a widget group, not editable by
* the user nor included as an input or output parameter. Members are added
* to the group using the group parameter annotation.</li>
* </ul>
*/
ItemVisibility visibility() default ItemVisibility.NORMAL;
Expand Down Expand Up @@ -142,6 +145,15 @@
* </p>
*/
String style() default "";

/** Defines the widget group. */
String group() default "";

/**
* Defines the state of the widget group. When true the group is expanded and visible.
* Otherwise, group members are hidden.
* */
boolean expanded() default true;

/** Defines the minimum allowed value (numeric parameters only). */
String min() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ private <T> void assignAttribute(final DefaultMutableModuleItem<T> item,
else if (is(k, "softMin")) item.setSoftMinimum(as(v, item.getType()));
else if (is(k, "stepSize")) item.setStepSize(as(v, double.class));
else if (is(k, "style")) item.setWidgetStyle(as(v, String.class));
else if (is(k, "group")) item.setWidgetGroup(as(v, String.class));
else if (is(k, "expanded")) item.setExpanded(as(v, boolean.class));
else if (is(k, "visibility")) item.setVisibility(as(v, ItemVisibility.class));
else if (is(k, "value")) item.setDefaultValue(as(v, item.getType()));
else item.set(k, v.toString());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/scijava/widget/DefaultWidgetModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public String getWidgetLabel() {
public boolean isStyle(final String style) {
return WidgetStyle.isStyle(getItem(), style);
}

@Override
public String getGroup() {
return getItem().getWidgetGroup();
}

@Override
public Object getValue() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/scijava/widget/WidgetModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public interface WidgetModel extends Contextual {
* {@code style.equals(getItem().getWidgetStyle())}.
*/
boolean isStyle(String style);

/**
* Gets group that the widget belongs to.
*
* @return Group that the widget belongs to.
*/
String getGroup();

/**
* Gets the current value of the module input.
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/org/scijava/script/ScriptInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,18 @@ public void testParameters() {

final ModuleItem<?> log = info.getInput("log");
assertItem("log", LogService.class, null, ItemIO.INPUT, false, true, null,
null, null, null, null, null, null, null, noChoices, log);
null, null, null, null, null, null, null, null, noChoices, log);

final ModuleItem<?> sliderValue = info.getInput("sliderValue");
assertItem("sliderValue", int.class, "Slider Value", ItemIO.INPUT, true,
true, null, " slidEr,", 11, null, null, 5, 15, 3.0, noChoices, sliderValue);
true, null, " slidEr,", null, 11, null, null, 5, 15, 3.0, noChoices, sliderValue);
assertTrue("Case-insensitive trimmed style", WidgetStyle.isStyle(sliderValue, "slider"));

final ModuleItem<?> animal = info.getInput("animal");
final List<String> animalChoices = //
Arrays.asList("quick brown fox", "lazy dog");
assertItem("animal", String.class, null, ItemIO.INPUT, true, false,
null, null, null, null, null, null, null, null, animalChoices, animal);
null, null, null, null, null, null, null, null, null, animalChoices, animal);
assertEquals(animal.get("family"), "Carnivora"); // test custom attribute

final ModuleItem<?> notAutoFilled = info.getInput("notAutoFilled");
Expand All @@ -288,7 +288,7 @@ public void testParameters() {

final ModuleItem<?> buffer = info.getOutput("buffer");
assertItem("buffer", StringBuilder.class, null, ItemIO.BOTH, true, true,
null, null, null, null, null, null, null, null, noChoices, buffer);
null, null, null, null, null, null, null, null, null, noChoices, buffer);

int inputCount = 0;
final ModuleItem<?>[] inputs = { log, sliderValue, animal, notAutoFilled, msg, buffer };
Expand Down Expand Up @@ -367,7 +367,7 @@ private String id(final String path, final String script) {
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 String group, final Object value, final Object min, final Object max,
final Object softMin, final Object softMax, final Number stepSize,
final List<?> choices, final ModuleItem<?> item)
{
Expand All @@ -379,6 +379,7 @@ private void assertItem(final String name, final Class<?> type,
assertEquals(persist, item.isPersisted());
assertEquals(persistKey, item.getPersistKey());
assertEquals(style, item.getWidgetStyle());
assertEquals(group, item.getWidgetGroup());
assertEquals(value, item.getDefaultValue());
assertEquals(min, item.getMinimumValue());
assertEquals(max, item.getMaximumValue());
Expand Down