Skip to content

Commit 209a55d

Browse files
committed
DefaultDisplayService: If multiple displays can display an object, choose first by priority #48
* before, the first display which was able to display an object was chosen * now, all matching displays are collected and the one with the highest priority is used
1 parent 7756d04 commit 209a55d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/main/java/org/scijava/display/DefaultDisplayService.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
package org.scijava.display;
3434

3535
import java.util.ArrayList;
36+
import java.util.Comparator;
3637
import java.util.LinkedList;
3738
import java.util.List;
3839

40+
import org.scijava.Prioritized;
3941
import org.scijava.display.event.DisplayActivatedEvent;
4042
import org.scijava.display.event.DisplayCreatedEvent;
4143
import org.scijava.display.event.DisplayDeletedEvent;
@@ -219,20 +221,28 @@ public Display<?> createDisplay(final String name, final Object o) {
219221

220222
@Override
221223
public Display<?> createDisplayQuietly(final Object o) {
224+
final List<Display<?>> matchingDisplays = getMatchingDisplays(o);
225+
if(matchingDisplays.size() > 0) {
226+
// use the display with the highest priority
227+
Display<?> display = matchingDisplays.stream().max(Comparator.comparing(Prioritized::getPriority)).get();
228+
display.display(o);
229+
return display;
230+
}
231+
return null;
232+
}
233+
234+
List<Display<?>> getMatchingDisplays(Object o) {
222235
// get available display plugins from the plugin service
223236
final List<PluginInfo<Display<?>>> displayPlugins = getDisplayPlugins();
224-
237+
final List<Display<?>> matchingDisplays = new ArrayList<>();
225238
for (final PluginInfo<Display<?>> info : displayPlugins) {
226239
final Display<?> display = pluginService.createInstance(info);
227240
if (display == null) continue;
228-
// display object using the first compatible Display
229-
// TODO: how to handle multiple matches? prompt user with dialog box?
230241
if (display.canDisplay(o)) {
231-
display.display(o);
232-
return display;
242+
matchingDisplays.add(display);
233243
}
234244
}
235-
return null;
245+
return matchingDisplays;
236246
}
237247

238248
// -- Event handlers --

0 commit comments

Comments
 (0)