Skip to content

Commit 8794f7a

Browse files
committed
WidgetModel: deprecate getChoices & move to iface
The getChoices() method always converts the choices to strings. We cannot always go back from string to original object -- e.g., for enums which override toString() to print something nice. Better to just use the original choices from getItem().getChoices(). This also makes the getChoices method more concise.
1 parent 49f4950 commit 8794f7a

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,6 @@ public Number getStepSize() {
219219
return NumberUtils.toNumber("1", item.getType());
220220
}
221221

222-
@Override
223-
public String[] getChoices() {
224-
final List<?> choicesList = item.getChoices();
225-
if (choicesList == null) return null;
226-
final String[] choices = new String[choicesList.size()];
227-
for (int i = 0; i < choices.length; i++) {
228-
choices[i] = objectService.getName(choicesList.get(i));
229-
}
230-
return choices;
231-
}
232-
233222
@Override
234223
public String getText() {
235224
final Object value = getValue();

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ public interface WidgetModel extends Contextual {
134134
*/
135135
Number getStepSize();
136136

137-
/**
138-
* Gets the multiple choice list for the module input.
139-
*
140-
* @return The available choices, or an empty list if not multiple choice.
141-
* @see ChoiceWidget
142-
*/
143-
String[] getChoices();
137+
/** @deprecated Use {@code getItem().getChoices()} instead. */
138+
@Deprecated
139+
default String[] getChoices() {
140+
return getItem().getChoices().stream() //
141+
.map(choice -> choice.toString()) //
142+
.toArray(String[]::new);
143+
}
144144

145145
/**
146146
* Gets the input's value rendered as a string.

0 commit comments

Comments
 (0)