Skip to content

Commit 403e422

Browse files
committed
InputHarvester: move default method impls to iface
1 parent 3d13288 commit 403e422

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

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

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.scijava.convert.ConvertService;
3939
import org.scijava.log.LogService;
4040
import org.scijava.module.Module;
41-
import org.scijava.module.ModuleCanceledException;
4241
import org.scijava.module.ModuleException;
4342
import org.scijava.module.ModuleItem;
4443
import org.scijava.object.ObjectService;
@@ -74,21 +73,8 @@ public abstract class AbstractInputHarvester<P, W> extends AbstractContextual
7473
// -- InputHarvester methods --
7574

7675
@Override
77-
public void harvest(final Module module) throws ModuleException {
78-
final InputPanel<P, W> inputPanel = createInputPanel();
79-
buildPanel(inputPanel, module);
80-
if (!inputPanel.hasWidgets()) return; // no inputs left to harvest
81-
82-
final boolean ok = harvestInputs(inputPanel, module);
83-
if (!ok) throw new ModuleCanceledException();
84-
85-
processResults(inputPanel, module);
86-
}
87-
88-
@Override
89-
public void
90-
buildPanel(final InputPanel<P, W> inputPanel, final Module module)
91-
throws ModuleException
76+
public void buildPanel(final InputPanel<P, W> inputPanel, final Module module)
77+
throws ModuleException
9278
{
9379
final Iterable<ModuleItem<?>> inputs = module.getInfo().inputs();
9480

@@ -107,18 +93,6 @@ public void harvest(final Module module) throws ModuleException {
10793
module.preview();
10894
}
10995

110-
@Override
111-
public void processResults(final InputPanel<P, W> inputPanel,
112-
final Module module) throws ModuleException
113-
{
114-
final Iterable<ModuleItem<?>> inputs = module.getInfo().inputs();
115-
116-
for (final ModuleItem<?> item : inputs) {
117-
final String name = item.getName();
118-
module.resolveInput(name);
119-
}
120-
}
121-
12296
// -- Helper methods --
12397

12498
private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel,

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333

3434
import org.scijava.Priority;
3535
import org.scijava.module.Module;
36+
import org.scijava.module.ModuleCanceledException;
3637
import org.scijava.module.ModuleException;
38+
import org.scijava.module.ModuleItem;
3739

3840
/**
3941
* An input harvester collects {@link Module} input values, according to the
@@ -62,7 +64,16 @@ public interface InputHarvester<P, W> {
6264
* @param module The module whose inputs should be harvest.
6365
* @throws ModuleException If the process goes wrong, or is canceled.
6466
*/
65-
void harvest(Module module) throws ModuleException;
67+
default void harvest(final Module module) throws ModuleException {
68+
final InputPanel<P, W> inputPanel = createInputPanel();
69+
buildPanel(inputPanel, module);
70+
if (!inputPanel.hasWidgets()) return; // no inputs left to harvest
71+
72+
final boolean ok = harvestInputs(inputPanel, module);
73+
if (!ok) throw new ModuleCanceledException();
74+
75+
processResults(inputPanel, module);
76+
}
6677

6778
/**
6879
* Constructs an empty {@link InputPanel}. Widgets are added later using the
@@ -89,7 +100,15 @@ void buildPanel(InputPanel<P, W> inputPanel, Module module)
89100
boolean harvestInputs(InputPanel<P, W> inputPanel, Module module);
90101

91102
/** Does any needed processing, after input values have been harvested. */
92-
void processResults(InputPanel<P, W> inputPanel, Module module)
93-
throws ModuleException;
103+
@SuppressWarnings("unused")
104+
default void processResults(final InputPanel<P, W> inputPanel,
105+
final Module module) throws ModuleException
106+
{
107+
final Iterable<ModuleItem<?>> inputs = module.getInfo().inputs();
94108

109+
for (final ModuleItem<?> item : inputs) {
110+
final String name = item.getName();
111+
module.resolveInput(name);
112+
}
113+
}
95114
}

0 commit comments

Comments
 (0)