Skip to content

Commit 290ce63

Browse files
committed
Add default populateInputCandidates implementation
The typical use case is for each convert to scan the ObjectService for input instances that can be converted.
1 parent b866834 commit 290ce63

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/org/scijava/convert/AbstractConverter.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import java.lang.reflect.Type;
3535
import java.util.Collection;
3636

37+
import org.scijava.object.ObjectService;
3738
import org.scijava.plugin.AbstractHandlerPlugin;
39+
import org.scijava.plugin.Parameter;
3840
import org.scijava.util.ConversionUtils;
3941
import org.scijava.util.GenericUtils;
4042

@@ -60,6 +62,11 @@ public abstract class AbstractConverter<I, O> extends
6062
AbstractHandlerPlugin<ConversionRequest> implements Converter<I, O>
6163
{
6264

65+
// -- Parameters --
66+
67+
@Parameter
68+
private ObjectService objectService;
69+
6370
// -- ConversionHandler methods --
6471

6572
@Override
@@ -113,7 +120,9 @@ public Object convert(final ConversionRequest request) {
113120

114121
@Override
115122
public void populateInputCandidates(final Collection<Object> objects) {
116-
// No-op
123+
for (final Object candidate : objectService.getObjects(getInputType())) {
124+
if (canConvert(candidate, getOutputType())) objects.add(candidate);
125+
}
117126
}
118127

119128
// -- Typed methods --

0 commit comments

Comments
 (0)