Skip to content

Commit 717a863

Browse files
committed
WidgetModel: add widget style convenience accessor
This is especially useful if we want to support widgets being associated with multiple styles at the same time. Then you can use a separator character like comma to concatenate the styles. But then the accessor becomes more important to maintain DRYness.
1 parent 9f527af commit 717a863

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ public String getWidgetLabel() {
125125
return name.substring(0, 1).toUpperCase() + name.substring(1);
126126
}
127127

128+
/**
129+
* Gets whether the widget is the given style. A widget may have multiple
130+
* styles separated by commas, so this method is more correct than using
131+
* {@code style.equals(getItem().getWidgetStyle())}.
132+
*/
133+
public boolean isStyle(final String style) {
134+
for (final String s : getItem().getWidgetStyle().split(",")) {
135+
if (s.equals(style)) return true;
136+
}
137+
return false;
138+
}
139+
128140
/**
129141
* Gets the current value of the module input.
130142
* <p>

0 commit comments

Comments
 (0)