Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public void set(final WidgetModel model) {

@Override
public boolean supports(final WidgetModel model) {
return super.supports(model) && (model.getChoices() != null ||
(model.getObjectPool() != null && model.getObjectPool().size() > 0));
return super.supports(model) && ((model.getChoices() != null && model.getChoices().length>0) ||
((model.getObjectPool() != null) && (model.getObjectPool().size() > 0)));
}

// -- AbstractUIInputWidget methods ---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.scijava.ui.swing.command;

import org.scijava.Context;
import org.scijava.command.Command;
import org.scijava.command.CommandService;
import org.scijava.command.InteractiveCommand;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.ui.UIService;

@Plugin(type = Command.class, menuPath = "Test>Test Interactive Command")
public class InteractiveCommandDemo extends InteractiveCommand {

@Parameter
String a_string;

@Parameter(choices={"A", "B", "C"})
String another_string;

@Override
public void run() {
// nothing
}

public static void main(String... args) throws Exception {

Context context = new Context();
context.service(UIService.class).showUI();
context.service(CommandService.class).run(InteractiveCommandDemo.class, true);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.scijava.Context;
import org.scijava.command.CommandInfo;
import org.scijava.command.ContextCommand;
import org.scijava.command.InteractiveCommand;
import org.scijava.module.Module;
import org.scijava.module.ModuleItem;
import org.scijava.module.ModuleService;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void tearDown() {
}

@Test
public void testObjects() {
public void testObjectsCommand() {
Thing a = new Thing();
Thing b = new Thing();

Expand All @@ -93,6 +94,33 @@ public void testObjects() {
assertTrue(choicesWidget instanceof SwingObjectWidget);
}

@Test
public void testObjectsInteractiveCommand() {
Thing a = new Thing();
Thing b = new Thing();

CommandInfo commandInfo = new CommandInfo(MyInteractiveCommand.class);
Module module = moduleService.createModule(commandInfo);
InputPanel<?,?> panel = new SwingInputPanel();

ModuleItem<Thing> thingInput = moduleService.getSingleInput(module, Thing.class);
ModuleItem<Nothing> nothingInput = moduleService.getSingleInput(module, Nothing.class);
ModuleItem<Choices> choicesInput = moduleService.getSingleInput(module, Choices.class);

WidgetModel thingModel = widgetService.createModel(panel, module, thingInput, Arrays.asList(a, b));
WidgetModel nothingModel = widgetService.createModel(panel, module, nothingInput, null);
WidgetModel choicesModel = widgetService.createModel(panel, module, choicesInput, null);

InputWidget<?, ?> thingWidget = widgetService.create(thingModel);
assertTrue(thingWidget instanceof SwingObjectWidget);

InputWidget<?, ?> nothingWidget = widgetService.create(nothingModel);
assertFalse(nothingWidget instanceof SwingObjectWidget);

InputWidget<?, ?> choicesWidget = widgetService.create(choicesModel);
assertTrue(choicesWidget instanceof SwingObjectWidget);
}

private class Thing {
// dummy class
}
Expand Down Expand Up @@ -121,4 +149,22 @@ public void run() {
}

}

public static class MyInteractiveCommand extends InteractiveCommand {
@Parameter
private Thing thing;

@Parameter
private Nothing nothing;

@Parameter
private Choices choices;

@Override
public void run() {
// nothing to do
}

}

}