|
30 | 30 | package org.scijava.widget;
|
31 | 31 |
|
32 | 32 | import java.util.ArrayList;
|
33 |
| -import java.util.HashSet; |
| 33 | +import java.util.Collection; |
34 | 34 | import java.util.List;
|
35 | 35 | import java.util.Set;
|
| 36 | +import java.util.stream.Collectors; |
36 | 37 |
|
37 | 38 | import org.scijava.AbstractContextual;
|
38 | 39 | import org.scijava.convert.ConvertService;
|
@@ -129,9 +130,24 @@ private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel,
|
129 | 130 |
|
130 | 131 | /** Asks the object service and convert service for valid choices */
|
131 | 132 | private List<Object> getObjects(final Class<?> type) {
|
132 |
| - Set<Object> compatibleInputs = |
133 |
| - new HashSet<>(convertService.getCompatibleInputs(type)); |
134 |
| - compatibleInputs.addAll(objectService.getObjects(type)); |
135 |
| - return new ArrayList<>(compatibleInputs); |
| 133 | + // Start with the known, unconverted objects of the desired type |
| 134 | + List<Object> objects = new ArrayList<>(objectService.getObjects(type)); |
| 135 | + |
| 136 | + // Get all the known objects that can be converted to the destination type |
| 137 | + Collection<Object> compatibleInputs = convertService.getCompatibleInputs(type); |
| 138 | + |
| 139 | + // HACK: Add each convertible object that doesn't share a name with any other object |
| 140 | + // Our goal here is to de-duplicate by avoiding similar inputs that could be converted |
| 141 | + // to the same effective output (e.g. an ImageDisplay and a Dataset that map to the same |
| 142 | + // ImgPlus) |
| 143 | + Set<String> knownNames = objects.stream().map(Object::toString).collect(Collectors.toSet()); |
| 144 | + for (Object o : compatibleInputs) { |
| 145 | + final String s = o.toString(); |
| 146 | + if (!knownNames.contains(s)) { |
| 147 | + objects.add(o); |
| 148 | + knownNames.add(s); |
| 149 | + } |
| 150 | + } |
| 151 | + return objects; |
136 | 152 | }
|
137 | 153 | }
|
0 commit comments