ViewFactory viewFactory = new SwingViewFactory();
Home home = new Home();
home.getCompass().setVisible(false);
final HomeController controller = new HomeController(home, preferences, viewFactory);
JComponent homeView = (JComponent)controller.getView();
final FurnitureCatalogTree catalogTree = (FurnitureCatalogTree)TestUtilities.findComponent(
homeView, FurnitureCatalogTree.class);
FurnitureTable furnitureTable = (FurnitureTable)TestUtilities.findComponent(
homeView, FurnitureTable.class);
final PlanComponent planComponent = (PlanComponent)TestUtilities.findComponent(
homeView, PlanComponent.class);
// 1. Create a frame that displays a home view
JFrame frame = new JFrame("Home TransferHandler Test");
frame.add(homeView);
frame.pack();
// Ensure clipboard is empty
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(""), null);
// Show home plan frame
showWindow(frame);
final JComponentTester tester = new JComponentTester();
tester.waitForIdle();
// Check catalog tree has default focus
assertTrue("Tree doesn't have the focus", catalogTree.isFocusOwner());
// Check Cut, Copy, Paste and Delete actions are disable
assertActionsEnabled(controller, false, false, false, false);
// 2. Select the first piece of furniture in catalog
tester.invokeAndWait(new Runnable() {
public void run() {
catalogTree.expandRow(0);
catalogTree.addSelectionInterval(1, 1);
}
});
// Check only Copy action is enabled
assertActionsEnabled(controller, false, true, false, false);
// 3. Drag and drop selected piece in tree to point (120, 120) in plan component
Rectangle selectedRowBounds = catalogTree.getRowBounds(1);
tester.actionDrag(catalogTree, new ComponentLocation(
new Point(selectedRowBounds.x, selectedRowBounds.y)));
tester.actionDrop(planComponent, new ComponentLocation(
new Point(120, 120)));
tester.waitForIdle();