Skip to content

Commit fd8a932

Browse files
committed
Merge pull request #211 from scijava/widget-empty-choice
Add empty option for not-required parameter in Widget
2 parents cddd255 + 45ab6cf commit fd8a932

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
@@ -87,6 +87,8 @@ public DefaultWidgetModel(final Context context, final InputPanel<?, ?> inputPan
8787
this.module = module;
8888
this.item = item;
8989
this.objectPool = objectPool;
90+
if (!item.isRequired())
91+
this.objectPool.add(0, null);
9092
convertedObjects = new WeakHashMap<Object, Object>();
9193

9294
if (item.getValue(module) == null) {
@@ -315,8 +317,10 @@ private Object ensureValidObject(final Object value) {
315317

316318
/** Ensures the value is on the given list. */
317319
private Object ensureValid(final Object value, final List<?> list) {
320+
if (value == null)
321+
return list.contains(null);
318322
for (final Object o : list) {
319-
if (o.equals(value)) return value; // value is valid
323+
if (value.equals(o)) return value; // value is valid
320324
// check if value was converted and cached
321325
final Object convertedValue = convertedObjects.get(o);
322326
if (convertedValue != null && value.equals(convertedValue)) {

0 commit comments

Comments
 (0)