|
33 | 33 | package org.scijava.display; |
34 | 34 |
|
35 | 35 | import java.util.ArrayList; |
| 36 | +import java.util.Comparator; |
36 | 37 | import java.util.LinkedList; |
37 | 38 | import java.util.List; |
38 | 39 |
|
| 40 | +import org.scijava.Prioritized; |
39 | 41 | import org.scijava.display.event.DisplayActivatedEvent; |
40 | 42 | import org.scijava.display.event.DisplayCreatedEvent; |
41 | 43 | import org.scijava.display.event.DisplayDeletedEvent; |
@@ -219,20 +221,28 @@ public Display<?> createDisplay(final String name, final Object o) { |
219 | 221 |
|
220 | 222 | @Override |
221 | 223 | 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) { |
222 | 235 | // get available display plugins from the plugin service |
223 | 236 | final List<PluginInfo<Display<?>>> displayPlugins = getDisplayPlugins(); |
224 | | - |
| 237 | + final List<Display<?>> matchingDisplays = new ArrayList<>(); |
225 | 238 | for (final PluginInfo<Display<?>> info : displayPlugins) { |
226 | 239 | final Display<?> display = pluginService.createInstance(info); |
227 | 240 | if (display == null) continue; |
228 | | - // display object using the first compatible Display |
229 | | - // TODO: how to handle multiple matches? prompt user with dialog box? |
230 | 241 | if (display.canDisplay(o)) { |
231 | | - display.display(o); |
232 | | - return display; |
| 242 | + matchingDisplays.add(display); |
233 | 243 | } |
234 | 244 | } |
235 | | - return null; |
| 245 | + return matchingDisplays; |
236 | 246 | } |
237 | 247 |
|
238 | 248 | // -- Event handlers -- |
|
0 commit comments