|  | 
|  | 1 | +package org.scijava.ui.swing.widget; | 
|  | 2 | + | 
|  | 3 | +import static org.junit.Assert.assertFalse; | 
|  | 4 | +import static org.junit.Assert.assertTrue; | 
|  | 5 | + | 
|  | 6 | +import java.util.Arrays; | 
|  | 7 | + | 
|  | 8 | +import org.junit.After; | 
|  | 9 | +import org.junit.Before; | 
|  | 10 | +import org.junit.Test; | 
|  | 11 | +import org.scijava.Context; | 
|  | 12 | +import org.scijava.command.CommandInfo; | 
|  | 13 | +import org.scijava.command.ContextCommand; | 
|  | 14 | +import org.scijava.module.Module; | 
|  | 15 | +import org.scijava.module.ModuleItem; | 
|  | 16 | +import org.scijava.module.ModuleService; | 
|  | 17 | +import org.scijava.plugin.Parameter; | 
|  | 18 | +import org.scijava.widget.InputPanel; | 
|  | 19 | +import org.scijava.widget.InputWidget; | 
|  | 20 | +import org.scijava.widget.WidgetModel; | 
|  | 21 | +import org.scijava.widget.WidgetService; | 
|  | 22 | + | 
|  | 23 | +public class SwingObjectWidgetTest { | 
|  | 24 | + | 
|  | 25 | +	private Context context; | 
|  | 26 | +	private ModuleService moduleService; | 
|  | 27 | +	private WidgetService widgetService; | 
|  | 28 | + | 
|  | 29 | +	@Before | 
|  | 30 | +	public void setUp() { | 
|  | 31 | +		context = new Context(); | 
|  | 32 | +		moduleService = context.getService(ModuleService.class); | 
|  | 33 | +		widgetService = context.getService(WidgetService.class); | 
|  | 34 | +	} | 
|  | 35 | + | 
|  | 36 | +	@After | 
|  | 37 | +	public void tearDown() { | 
|  | 38 | +		context.dispose(); | 
|  | 39 | +	} | 
|  | 40 | + | 
|  | 41 | +	@Test | 
|  | 42 | +	public void testObjects() { | 
|  | 43 | +		Thing a = new Thing(); | 
|  | 44 | +		Thing b = new Thing(); | 
|  | 45 | + | 
|  | 46 | +		CommandInfo commandInfo = new CommandInfo(MyCommand.class); | 
|  | 47 | +		Module module = moduleService.createModule(commandInfo); | 
|  | 48 | +		InputPanel<?,?> panel = new SwingInputPanel(); | 
|  | 49 | + | 
|  | 50 | +		ModuleItem<Thing> thingInput = moduleService.getSingleInput(module, Thing.class); | 
|  | 51 | +		ModuleItem<Nothing> nothingInput = moduleService.getSingleInput(module, Nothing.class); | 
|  | 52 | +		ModuleItem<Choices> choicesInput = moduleService.getSingleInput(module, Choices.class); | 
|  | 53 | + | 
|  | 54 | +		WidgetModel thingModel = widgetService.createModel(panel, module, thingInput, Arrays.asList(a, b)); | 
|  | 55 | +		WidgetModel nothingModel = widgetService.createModel(panel, module, nothingInput, null); | 
|  | 56 | +		WidgetModel choicesModel = widgetService.createModel(panel, module, choicesInput, null); | 
|  | 57 | + | 
|  | 58 | +		InputWidget<?, ?> thingWidget = widgetService.create(thingModel); | 
|  | 59 | +		assertTrue(thingWidget instanceof SwingObjectWidget); | 
|  | 60 | + | 
|  | 61 | +		InputWidget<?, ?> nothingWidget = widgetService.create(nothingModel); | 
|  | 62 | +		assertFalse(nothingWidget instanceof SwingObjectWidget); | 
|  | 63 | + | 
|  | 64 | +		InputWidget<?, ?> choicesWidget = widgetService.create(choicesModel); | 
|  | 65 | +		assertTrue(choicesWidget instanceof SwingObjectWidget); | 
|  | 66 | +	} | 
|  | 67 | + | 
|  | 68 | +	private class Thing { | 
|  | 69 | +		// dummy class | 
|  | 70 | +	} | 
|  | 71 | + | 
|  | 72 | +	private class Nothing { | 
|  | 73 | +		// dummy class | 
|  | 74 | +	} | 
|  | 75 | + | 
|  | 76 | +	private enum Choices { | 
|  | 77 | +		FIRST, SECOND, THIRD | 
|  | 78 | +	}; | 
|  | 79 | + | 
|  | 80 | +	public static class MyCommand extends ContextCommand { | 
|  | 81 | +		@Parameter | 
|  | 82 | +		private Thing thing; | 
|  | 83 | + | 
|  | 84 | +		@Parameter | 
|  | 85 | +		private Nothing nothing; | 
|  | 86 | + | 
|  | 87 | +		@Parameter | 
|  | 88 | +		private Choices choices; | 
|  | 89 | + | 
|  | 90 | +		@Override | 
|  | 91 | +		public void run() { | 
|  | 92 | +			// nothing to do | 
|  | 93 | +		} | 
|  | 94 | + | 
|  | 95 | +	} | 
|  | 96 | +} | 
0 commit comments