NlDropInsertionPicker { public Result findInsertionPointAt(@NotNull Point location, @NotNull List<NlComponent> dragged) { return findInsertionPointAt(location, dragged, false); } NlDropInsertionPicker(@NotNull NlComponentTree tree); @VisibleForTesting  NlDropInsertionPicker(@NotNull JTree tree); Result findInsertionPointAt(@NotNull Point location, @NotNull List<NlComponent> dragged); @Nullable Result findInsertionPointAt(@NotNull Point location,
                                     @NotNull List<NlComponent> dragged,
                                     boolean ignoreMissingDependency);  }
@Test public void testInsertAtRoot() { NlDropInsertionPicker.Result result = myPicker.findInsertionPointAt(new Point(0, 0), myDragged); assertEquals(ourRoot, result.receiver); assertEquals(ourRoot.getChild(0), result.nextComponent); assertEquals(1, result.depth); assertEquals(0, result.row); }
@Test public void testInsertLast() { NlDropInsertionPicker.Result result = myPicker.findInsertionPointAt(new Point(30, LAST_COMPONENT_Y_POSITION), myDragged); assertEquals(ourRoot.getChild(3), result.receiver); assertNull(result.nextComponent); assertEquals(0, result.depth); assertEquals(COMPONENT_NUMBER - 1, result.row); }
@Test public void testInsertParentFromLast() { NlDropInsertionPicker.Result result = myPicker.findInsertionPointAt(new Point(5, LAST_COMPONENT_Y_POSITION), myDragged); assertEquals(ourRoot, result.receiver); assertNull(result.nextComponent); assertEquals(-1, result.depth); assertEquals(COMPONENT_NUMBER - 1, result.row); }
@Test public void testInsertInViewGroup() { NlDropInsertionPicker.Result result = myPicker.findInsertionPointAt(new Point(15, 35), myDragged); assertEquals(ourRoot.getChild(2), result.receiver); assertEquals(ourRoot.getChild(2).getChild(0), result.nextComponent); assertEquals(1, result.depth); assertEquals(3, result.row); }
@Test public void testInsertInEmptyViewGroup() { NlDropInsertionPicker.Result result = myPicker.findInsertionPointAt(new Point(15, 85), myDragged); assertEquals(ourRoot.getChild(3).getChild(1), result.receiver); assertNull(result.nextComponent); assertEquals(1, result.depth); assertEquals(8, result.row); }
@Test public void testInsertBetween() { NlDropInsertionPicker.Result result = myPicker.findInsertionPointAt(new Point(15, 15), myDragged); assertEquals(ourRoot, result.receiver); assertEquals(ourRoot.getChild(1), result.nextComponent); assertEquals(0, result.depth); assertEquals(1, result.row); }
@Test public void testInsertInParentIfLastIsViewGroup() { DummyComponentGroup root = new DummyComponentGroup(0, myModel, false).setChildren( new DummyComponent(1, myModel, true), new DummyComponentGroup(2, myModel, false)); myTreePaths = buildDummyTreePathArray(root); DummyTree tree = new DummyTree(); tree.collapsePath(myTreePaths[myTreePaths.length - 1]); NlDropInsertionPicker picker = new NlDropInsertionPicker(tree); NlDropInsertionPicker.Result result = picker.findInsertionPointAt(new Point(5, 25), myDragged); assertEquals(root, result.receiver); assertNull(result.nextComponent); assertEquals(0, result.depth); assertEquals(2, result.row); }
@Test public void testInsertRowIsAfterChildren() { NlComponent receiver = ourRoot.getChild(2); when(myModel.canAddComponents(eq(myDragged), eq(receiver), any())).thenReturn(false); when(myModel.canAddComponents(eq(myDragged), eq(receiver), any(), anyBoolean())).thenReturn(false); assertFalse(myModel.canAddComponents(myDragged, receiver, null)); NlDropInsertionPicker.Result result = myPicker.findInsertionPointAt(new Point(15, 35), myDragged); assertEquals(ourRoot, result.receiver); assertEquals(ourRoot.getChild(3), result.nextComponent); assertEquals(0, result.depth); assertEquals(5, result.row); }
@Test public void testInsertRowIsAfterGrandChildren() { DummyComponentGroup root = new DummyComponentGroup(0, myModel, false).setChildren( new DummyComponentGroup(1, myModel, false).setChildren( new DummyComponentGroup(2, myModel, false).setChildren( new DummyComponent(3, myModel, true), new DummyComponent(4, myModel, false)))); myTreePaths = buildDummyTreePathArray(root); DummyTree tree = new DummyTree(); NlComponent receiver = root.getChild(0); when(myModel.canAddComponents(eq(myDragged), eq(receiver), any())).thenReturn(false); when(myModel.canAddComponents(eq(myDragged), eq(receiver), any(), anyBoolean())).thenReturn(false); assertFalse(myModel.canAddComponents(myDragged, receiver, null)); NlDropInsertionPicker picker = new NlDropInsertionPicker(tree); NlDropInsertionPicker.Result result = picker.findInsertionPointAt(new Point(15, 15), myDragged); assertEquals(root, result.receiver); assertNull(result.nextComponent); assertEquals(4, result.row); assertEquals(-1, result.depth); }