Skip to content

Commit 45ab6cf

Browse files
author
LeonYang5114
committed
Add empty option for not-required parameter in Widget
For command parameter that is not required but candidate options exist, DefaultWidgetModel gave no empty option to be chosen from, which force the user to use the potentially invalid values.
1 parent 032cb85 commit 45ab6cf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/org/scijava/widget/DefaultWidgetModel.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public DefaultWidgetModel(final Context context, final InputPanel<?, ?> inputPan
8383
this.module = module;
8484
this.item = item;
8585
this.objectPool = objectPool;
86+
if (!item.isRequired())
87+
this.objectPool.add(0, null);
8688
convertedObjects = new WeakHashMap<Object, Object>();
8789
}
8890

@@ -306,8 +308,10 @@ private Object ensureValidObject(final Object value) {
306308

307309
/** Ensures the value is on the given list. */
308310
private Object ensureValid(final Object value, final List<?> list) {
311+
if (value == null)
312+
return list.contains(null);
309313
for (final Object o : list) {
310-
if (o.equals(value)) return value; // value is valid
314+
if (value.equals(o)) return value; // value is valid
311315
// check if value was converted and cached
312316
final Object convertedValue = convertedObjects.get(o);
313317
if (convertedValue != null && value.equals(convertedValue)) {

0 commit comments

Comments
 (0)