From 1949891258de0c7b6399919c6542572a769b8718 Mon Sep 17 00:00:00 2001
From: Karl Duderstadt
Date: Wed, 28 Jul 2021 14:16:37 +0200
Subject: [PATCH 1/5] Add widget group option to Parameter annotations and
implementations
---
.../java/org/scijava/command/CommandModuleItem.java | 5 +++++
.../java/org/scijava/module/AbstractModuleItem.java | 6 ++++++
.../org/scijava/module/DefaultMutableModuleItem.java | 8 ++++++++
src/main/java/org/scijava/module/ModuleItem.java | 6 ++++++
src/main/java/org/scijava/plugin/Parameter.java | 3 +++
.../java/org/scijava/widget/DefaultWidgetModel.java | 5 +++++
src/main/java/org/scijava/widget/WidgetModel.java | 5 +++++
src/test/java/org/scijava/script/ScriptInfoTest.java | 11 ++++++-----
8 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/scijava/command/CommandModuleItem.java b/src/main/java/org/scijava/command/CommandModuleItem.java
index 7be4d3e9f..478f62b68 100644
--- a/src/main/java/org/scijava/command/CommandModuleItem.java
+++ b/src/main/java/org/scijava/command/CommandModuleItem.java
@@ -134,6 +134,11 @@ public String getCallback() {
public String getWidgetStyle() {
return getParameter().style();
}
+
+ @Override
+ public String getWidgetGroup() {
+ return getParameter().group();
+ }
@Override
public T getMinimumValue() {
diff --git a/src/main/java/org/scijava/module/AbstractModuleItem.java b/src/main/java/org/scijava/module/AbstractModuleItem.java
index da260b12a..d9ae1fb1d 100644
--- a/src/main/java/org/scijava/module/AbstractModuleItem.java
+++ b/src/main/java/org/scijava/module/AbstractModuleItem.java
@@ -74,6 +74,7 @@ public String toString() {
sm.append("persistKey", getPersistKey());
sm.append("callback", getCallback());
sm.append("widgetStyle", getWidgetStyle());
+ sm.append("widgetGroup", getWidgetGroup());
sm.append("default", getDefaultValue());
sm.append("min", getMinimumValue());
sm.append("max", getMaximumValue());
@@ -231,6 +232,11 @@ public void callback(final Module module) throws MethodCallException {
public String getWidgetStyle() {
return null;
}
+
+ @Override
+ public String getWidgetGroup() {
+ return null;
+ }
@Override
public T getDefaultValue() {
diff --git a/src/main/java/org/scijava/module/DefaultMutableModuleItem.java b/src/main/java/org/scijava/module/DefaultMutableModuleItem.java
index 4c8354d14..4cf794256 100644
--- a/src/main/java/org/scijava/module/DefaultMutableModuleItem.java
+++ b/src/main/java/org/scijava/module/DefaultMutableModuleItem.java
@@ -59,6 +59,7 @@ public class DefaultMutableModuleItem extends AbstractModuleItem
private String validater;
private String callback;
private String widgetStyle;
+ private String widgetGroup;
private T defaultValue;
private T minimumValue;
private T maximumValue;
@@ -94,6 +95,7 @@ public DefaultMutableModuleItem(final ModuleInfo info, final String name,
validater = super.getValidater();
callback = super.getCallback();
widgetStyle = super.getWidgetStyle();
+ widgetGroup = super.getWidgetGroup();
minimumValue = super.getMinimumValue();
maximumValue = super.getMaximumValue();
stepSize = super.getStepSize();
@@ -122,6 +124,7 @@ public DefaultMutableModuleItem(final ModuleInfo info,
validater = item.getValidater();
callback = item.getCallback();
widgetStyle = item.getWidgetStyle();
+ widgetGroup = item.getWidgetGroup();
minimumValue = item.getMinimumValue();
maximumValue = item.getMaximumValue();
softMinimum = item.getSoftMinimum();
@@ -288,6 +291,11 @@ public String getCallback() {
public String getWidgetStyle() {
return widgetStyle;
}
+
+ @Override
+ public String getWidgetGroup() {
+ return widgetGroup;
+ }
@Override
public T getDefaultValue() {
diff --git a/src/main/java/org/scijava/module/ModuleItem.java b/src/main/java/org/scijava/module/ModuleItem.java
index 4abd391ea..bfe24a535 100644
--- a/src/main/java/org/scijava/module/ModuleItem.java
+++ b/src/main/java/org/scijava/module/ModuleItem.java
@@ -153,6 +153,12 @@ public interface ModuleItem 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();
/** Gets the default value. */
T getDefaultValue();
diff --git a/src/main/java/org/scijava/plugin/Parameter.java b/src/main/java/org/scijava/plugin/Parameter.java
index ac24dd5e6..bc06919f3 100644
--- a/src/main/java/org/scijava/plugin/Parameter.java
+++ b/src/main/java/org/scijava/plugin/Parameter.java
@@ -142,6 +142,9 @@
*
*/
String style() default "";
+
+ /** Defines the widget group. */
+ String group() default "";
/** Defines the minimum allowed value (numeric parameters only). */
String min() default "";
diff --git a/src/main/java/org/scijava/widget/DefaultWidgetModel.java b/src/main/java/org/scijava/widget/DefaultWidgetModel.java
index 1a768d5d7..f08c1d1bf 100644
--- a/src/main/java/org/scijava/widget/DefaultWidgetModel.java
+++ b/src/main/java/org/scijava/widget/DefaultWidgetModel.java
@@ -131,6 +131,11 @@ public String getWidgetLabel() {
public boolean isStyle(final String style) {
return WidgetStyle.isStyle(getItem(), style);
}
+
+ @Override
+ public boolean isGroup(final String group) {
+ return getItem().getWidgetGroup().equals(group);
+ }
@Override
public Object getValue() {
diff --git a/src/main/java/org/scijava/widget/WidgetModel.java b/src/main/java/org/scijava/widget/WidgetModel.java
index 80f033de0..0d0c2d52d 100644
--- a/src/main/java/org/scijava/widget/WidgetModel.java
+++ b/src/main/java/org/scijava/widget/WidgetModel.java
@@ -80,6 +80,11 @@ public interface WidgetModel extends Contextual {
* {@code style.equals(getItem().getWidgetStyle())}.
*/
boolean isStyle(String style);
+
+ /**
+ * Gets whether the widget is part of the group.
+ */
+ boolean isGroup(String group);
/**
* Gets the current value of the module input.
diff --git a/src/test/java/org/scijava/script/ScriptInfoTest.java b/src/test/java/org/scijava/script/ScriptInfoTest.java
index 678996628..f1a4b0f61 100644
--- a/src/test/java/org/scijava/script/ScriptInfoTest.java
+++ b/src/test/java/org/scijava/script/ScriptInfoTest.java
@@ -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 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");
@@ -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 };
@@ -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)
{
@@ -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());
From 2e9c729b974baeb15720a1da7f8fa47051202d5d Mon Sep 17 00:00:00 2001
From: Karl Duderstadt
Date: Fri, 30 Jul 2021 19:49:52 +0200
Subject: [PATCH 2/5] Add GROUP ItemVisibility option for specifying widget
group names
---
src/main/java/org/scijava/ItemVisibility.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/scijava/ItemVisibility.java b/src/main/java/org/scijava/ItemVisibility.java
index 749e91ae3..6f8691aa3 100644
--- a/src/main/java/org/scijava/ItemVisibility.java
+++ b/src/main/java/org/scijava/ItemVisibility.java
@@ -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
}
From cdca0e52136ad9103e7c33b92a866b452ea46b45 Mon Sep 17 00:00:00 2001
From: Karl Duderstadt
Date: Fri, 30 Jul 2021 20:30:39 +0200
Subject: [PATCH 3/5] Add expanded annotation to Parameter and related
implementations
---
.../org/scijava/command/CommandModuleItem.java | 5 +++++
.../org/scijava/module/AbstractModuleItem.java | 6 ++++++
.../module/DefaultMutableModuleItem.java | 18 ++++++++++++++++++
.../java/org/scijava/module/ModuleItem.java | 3 +++
.../org/scijava/module/MutableModuleItem.java | 4 ++++
.../java/org/scijava/plugin/Parameter.java | 9 +++++++++
6 files changed, 45 insertions(+)
diff --git a/src/main/java/org/scijava/command/CommandModuleItem.java b/src/main/java/org/scijava/command/CommandModuleItem.java
index 478f62b68..4210921f7 100644
--- a/src/main/java/org/scijava/command/CommandModuleItem.java
+++ b/src/main/java/org/scijava/command/CommandModuleItem.java
@@ -139,6 +139,11 @@ public String getWidgetStyle() {
public String getWidgetGroup() {
return getParameter().group();
}
+
+ @Override
+ public boolean isExpanded() {
+ return getParameter().expanded();
+ }
@Override
public T getMinimumValue() {
diff --git a/src/main/java/org/scijava/module/AbstractModuleItem.java b/src/main/java/org/scijava/module/AbstractModuleItem.java
index d9ae1fb1d..de98530a9 100644
--- a/src/main/java/org/scijava/module/AbstractModuleItem.java
+++ b/src/main/java/org/scijava/module/AbstractModuleItem.java
@@ -75,6 +75,7 @@ public String toString() {
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());
@@ -237,6 +238,11 @@ public String getWidgetStyle() {
public String getWidgetGroup() {
return null;
}
+
+ @Override
+ public boolean isExpanded() {
+ return true;
+ }
@Override
public T getDefaultValue() {
diff --git a/src/main/java/org/scijava/module/DefaultMutableModuleItem.java b/src/main/java/org/scijava/module/DefaultMutableModuleItem.java
index 4cf794256..5619b5b81 100644
--- a/src/main/java/org/scijava/module/DefaultMutableModuleItem.java
+++ b/src/main/java/org/scijava/module/DefaultMutableModuleItem.java
@@ -60,6 +60,7 @@ public class DefaultMutableModuleItem extends AbstractModuleItem
private String callback;
private String widgetStyle;
private String widgetGroup;
+ private boolean expanded;
private T defaultValue;
private T minimumValue;
private T maximumValue;
@@ -96,6 +97,7 @@ public DefaultMutableModuleItem(final ModuleInfo info, final String name,
callback = super.getCallback();
widgetStyle = super.getWidgetStyle();
widgetGroup = super.getWidgetGroup();
+ expanded = super.isExpanded();
minimumValue = super.getMinimumValue();
maximumValue = super.getMaximumValue();
stepSize = super.getStepSize();
@@ -125,6 +127,7 @@ public DefaultMutableModuleItem(final ModuleInfo info,
callback = item.getCallback();
widgetStyle = item.getWidgetStyle();
widgetGroup = item.getWidgetGroup();
+ expanded = item.isExpanded();
minimumValue = item.getMinimumValue();
maximumValue = item.getMaximumValue();
softMinimum = item.getSoftMinimum();
@@ -188,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) {
@@ -296,6 +309,11 @@ public String getWidgetStyle() {
public String getWidgetGroup() {
return widgetGroup;
}
+
+ @Override
+ public boolean isExpanded() {
+ return expanded;
+ }
@Override
public T getDefaultValue() {
diff --git a/src/main/java/org/scijava/module/ModuleItem.java b/src/main/java/org/scijava/module/ModuleItem.java
index bfe24a535..c9ca93191 100644
--- a/src/main/java/org/scijava/module/ModuleItem.java
+++ b/src/main/java/org/scijava/module/ModuleItem.java
@@ -159,6 +159,9 @@ public interface ModuleItem extends BasicDetails {
* 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();
diff --git a/src/main/java/org/scijava/module/MutableModuleItem.java b/src/main/java/org/scijava/module/MutableModuleItem.java
index 58c146a81..36381fb4c 100644
--- a/src/main/java/org/scijava/module/MutableModuleItem.java
+++ b/src/main/java/org/scijava/module/MutableModuleItem.java
@@ -61,6 +61,10 @@ public interface MutableModuleItem extends ModuleItem {
void setCallback(String callback);
void setWidgetStyle(String widgetStyle);
+
+ void setWidgetGroup(String widgetGroup);
+
+ void setExpanded(boolean expanded);
void setDefaultValue(T defaultValue);
diff --git a/src/main/java/org/scijava/plugin/Parameter.java b/src/main/java/org/scijava/plugin/Parameter.java
index bc06919f3..6c110f5fe 100644
--- a/src/main/java/org/scijava/plugin/Parameter.java
+++ b/src/main/java/org/scijava/plugin/Parameter.java
@@ -92,6 +92,9 @@
* output, such as a "verbose" flag.
* MESSAGE: parameter value is intended as a message only, not editable by
* the user nor included as an input or output parameter.
+ * 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.
*
*/
ItemVisibility visibility() default ItemVisibility.NORMAL;
@@ -145,6 +148,12 @@
/** 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 "";
From 76db52db6b74164392e4fabd7ca2ec801c7cf385 Mon Sep 17 00:00:00 2001
From: Karl Duderstadt
Date: Tue, 3 Aug 2021 22:08:10 +0200
Subject: [PATCH 4/5] WidgetModel: change to getGroup from isGroup, more
appropriate
---
src/main/java/org/scijava/widget/DefaultWidgetModel.java | 4 ++--
src/main/java/org/scijava/widget/WidgetModel.java | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/scijava/widget/DefaultWidgetModel.java b/src/main/java/org/scijava/widget/DefaultWidgetModel.java
index f08c1d1bf..452e189fc 100644
--- a/src/main/java/org/scijava/widget/DefaultWidgetModel.java
+++ b/src/main/java/org/scijava/widget/DefaultWidgetModel.java
@@ -133,8 +133,8 @@ public boolean isStyle(final String style) {
}
@Override
- public boolean isGroup(final String group) {
- return getItem().getWidgetGroup().equals(group);
+ public String getGroup() {
+ return getItem().getWidgetGroup();
}
@Override
diff --git a/src/main/java/org/scijava/widget/WidgetModel.java b/src/main/java/org/scijava/widget/WidgetModel.java
index 0d0c2d52d..fc85d633b 100644
--- a/src/main/java/org/scijava/widget/WidgetModel.java
+++ b/src/main/java/org/scijava/widget/WidgetModel.java
@@ -82,9 +82,11 @@ public interface WidgetModel extends Contextual {
boolean isStyle(String style);
/**
- * Gets whether the widget is part of the group.
+ * Gets group that the widget belongs to.
+ *
+ * @return Group that the widget belongs to.
*/
- boolean isGroup(String group);
+ String getGroup();
/**
* Gets the current value of the module input.
From c238cbb3e3edd1bf86317bcaf331ad2f37eff60b Mon Sep 17 00:00:00 2001
From: Karl Duderstadt
Date: Tue, 3 Aug 2021 22:11:03 +0200
Subject: [PATCH 5/5] ParameterScriptProcessor: parse attributes group and
expanded
---
.../org/scijava/script/process/ParameterScriptProcessor.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/main/java/org/scijava/script/process/ParameterScriptProcessor.java b/src/main/java/org/scijava/script/process/ParameterScriptProcessor.java
index 0ed4d7212..b9028e6c0 100644
--- a/src/main/java/org/scijava/script/process/ParameterScriptProcessor.java
+++ b/src/main/java/org/scijava/script/process/ParameterScriptProcessor.java
@@ -277,6 +277,8 @@ private void assignAttribute(final DefaultMutableModuleItem 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());