Skip to content

Commit aeccb57

Browse files
committed
Add support for enums as multiple choice items
Thanks to Christian Dietz for reminding me.
1 parent 577a7d9 commit aeccb57

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/main/java/org/scijava/command/CommandModuleItem.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,14 @@ public int getColumnCount() {
155155

156156
@Override
157157
public List<T> getChoices() {
158-
final ArrayList<T> choices = new ArrayList<T>();
158+
final String[] choices = getParameter().choices();
159+
if (choices.length == 0) return super.getChoices();
160+
161+
final ArrayList<T> choiceList = new ArrayList<T>();
159162
for (final String choice : getParameter().choices()) {
160-
choices.add(tValue(choice));
163+
choiceList.add(tValue(choice));
161164
}
162-
return choices;
165+
return choiceList;
163166
}
164167

165168
// -- BasicDetails methods --

src/main/java/org/scijava/module/AbstractModuleItem.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package org.scijava.module;
3333

3434
import java.lang.reflect.Type;
35+
import java.util.Arrays;
3536
import java.util.List;
3637

3738
import org.scijava.AbstractBasicDetails;
@@ -258,7 +259,8 @@ public int getColumnCount() {
258259

259260
@Override
260261
public List<T> getChoices() {
261-
return null;
262+
final T[] choices = getType().getEnumConstants();
263+
return choices == null ? null : Arrays.asList(choices);
262264
}
263265

264266
@Override

0 commit comments

Comments
 (0)