@Test public void testConsolidateHierarchicalLevelWhenIsNotDraggedByUser() { final HTMLElement element0 = mock(HTMLElement.class); final HTMLElement element1 = mock(HTMLElement.class); final HTMLElement element2 = mock(HTMLElement.class); element0.style = mock(CSSStyleDeclaration.class); element1.style = mock(CSSStyleDeclaration.class); element2.style = mock(CSSStyleDeclaration.class); dragArea.style = mock(CSSStyleDeclaration.class); when(element0.getAttribute(DATA_Y_POSITION)).thenReturn("0"); when(element1.getAttribute(DATA_Y_POSITION)).thenReturn("2"); when(element2.getAttribute(DATA_Y_POSITION)).thenReturn("1"); when(element0.getAttribute(DATA_X_POSITION)).thenReturn("0"); when(element1.getAttribute(DATA_X_POSITION)).thenReturn("0"); when(element2.getAttribute(DATA_X_POSITION)).thenReturn("3"); when(dragArea.querySelector(".kie-dnd-draggable[data-y-position=\"0\"]")).thenReturn(element0); when(dragArea.querySelector(".kie-dnd-draggable[data-y-position=\"2\"]")).thenReturn(element1); when(dragArea.querySelector(".kie-dnd-draggable[data-y-position=\"1\"]")).thenReturn(element2); mockDragAreaWithChildren(element0, element1, element2); view.consolidateHierarchicalLevel(false); verify(element0).setAttribute(DATA_Y_POSITION, 0); verify(element2, times(2)).setAttribute(DATA_Y_POSITION, 1); verify(element1).setAttribute(DATA_Y_POSITION, 2); verify(element0, never()).setAttribute(DATA_X_POSITION, 0); verify(element2).setAttribute(DATA_X_POSITION, 1); verify(element1, never()).setAttribute(anyString(), anyString()); }
@Override public void consolidateHierarchicalLevel(final boolean isElementsDraggedByUser) { final List<HTMLElement> draggableElements = querySelector(getDragArea()).getVisibleAndSortedDraggableElements(); if (isElementsDraggedByUser) { if (!draggableElements.isEmpty()) { Position.setX(draggableElements.get(0), 0); } } if (draggableElements.size() < 2) { return; } for (int i = 0; i < draggableElements.size() - 1; i++) { final HTMLElement current = draggableElements.get(i); final HTMLElement next = draggableElements.get(i + 1); final int currentXPosition = Position.getX(current); final int minimalLevel = currentXPosition + 1; final int nextElementLevel = Position.getX(next); final int numberOfExtraLevels = nextElementLevel - minimalLevel; if (nextElementLevel > minimalLevel) { fixChildrenPosition(minimalLevel, numberOfExtraLevels, getDependentElements(current)); } Position.setY(current, i); Position.setY(next, i + 1d); } }
DNDListComponentView implements DNDListComponent.View { @Override public void consolidateHierarchicalLevel(final boolean isElementsDraggedByUser) { final List<HTMLElement> draggableElements = querySelector(getDragArea()).getVisibleAndSortedDraggableElements(); if (isElementsDraggedByUser) { if (!draggableElements.isEmpty()) { Position.setX(draggableElements.get(0), 0); } } if (draggableElements.size() < 2) { return; } for (int i = 0; i < draggableElements.size() - 1; i++) { final HTMLElement current = draggableElements.get(i); final HTMLElement next = draggableElements.get(i + 1); final int currentXPosition = Position.getX(current); final int minimalLevel = currentXPosition + 1; final int nextElementLevel = Position.getX(next); final int numberOfExtraLevels = nextElementLevel - minimalLevel; if (nextElementLevel > minimalLevel) { fixChildrenPosition(minimalLevel, numberOfExtraLevels, getDependentElements(current)); } Position.setY(current, i); Position.setY(next, i + 1d); } } }
DNDListComponentView implements DNDListComponent.View { @Override public void consolidateHierarchicalLevel(final boolean isElementsDraggedByUser) { final List<HTMLElement> draggableElements = querySelector(getDragArea()).getVisibleAndSortedDraggableElements(); if (isElementsDraggedByUser) { if (!draggableElements.isEmpty()) { Position.setX(draggableElements.get(0), 0); } } if (draggableElements.size() < 2) { return; } for (int i = 0; i < draggableElements.size() - 1; i++) { final HTMLElement current = draggableElements.get(i); final HTMLElement next = draggableElements.get(i + 1); final int currentXPosition = Position.getX(current); final int minimalLevel = currentXPosition + 1; final int nextElementLevel = Position.getX(next); final int numberOfExtraLevels = nextElementLevel - minimalLevel; if (nextElementLevel > minimalLevel) { fixChildrenPosition(minimalLevel, numberOfExtraLevels, getDependentElements(current)); } Position.setY(current, i); Position.setY(next, i + 1d); } } @Inject  DNDListComponentView(final HTMLDivElement dragArea); }
DNDListComponentView implements DNDListComponent.View { @Override public void consolidateHierarchicalLevel(final boolean isElementsDraggedByUser) { final List<HTMLElement> draggableElements = querySelector(getDragArea()).getVisibleAndSortedDraggableElements(); if (isElementsDraggedByUser) { if (!draggableElements.isEmpty()) { Position.setX(draggableElements.get(0), 0); } } if (draggableElements.size() < 2) { return; } for (int i = 0; i < draggableElements.size() - 1; i++) { final HTMLElement current = draggableElements.get(i); final HTMLElement next = draggableElements.get(i + 1); final int currentXPosition = Position.getX(current); final int minimalLevel = currentXPosition + 1; final int nextElementLevel = Position.getX(next); final int numberOfExtraLevels = nextElementLevel - minimalLevel; if (nextElementLevel > minimalLevel) { fixChildrenPosition(minimalLevel, numberOfExtraLevels, getDependentElements(current)); } Position.setY(current, i); Position.setY(next, i + 1d); } } @Inject  DNDListComponentView(final HTMLDivElement dragArea); @Override void init(final DNDListComponent presenter); @Override HTMLElement registerItem(final HTMLElement htmlElement); @Override void refreshItemsPosition(); @Override void refreshItemsHTML(); @Override void consolidateHierarchicalLevel(final boolean isElementsDraggedByUser); @Override void consolidateYPosition(); @Override void clear(); @Override Optional<HTMLElement> getPreviousElement(final Element reference); @Override void refreshDragAreaSize(); @Override HTMLDivElement getDragArea(); }
DNDListComponentView implements DNDListComponent.View { @Override public void consolidateHierarchicalLevel(final boolean isElementsDraggedByUser) { final List<HTMLElement> draggableElements = querySelector(getDragArea()).getVisibleAndSortedDraggableElements(); if (isElementsDraggedByUser) { if (!draggableElements.isEmpty()) { Position.setX(draggableElements.get(0), 0); } } if (draggableElements.size() < 2) { return; } for (int i = 0; i < draggableElements.size() - 1; i++) { final HTMLElement current = draggableElements.get(i); final HTMLElement next = draggableElements.get(i + 1); final int currentXPosition = Position.getX(current); final int minimalLevel = currentXPosition + 1; final int nextElementLevel = Position.getX(next); final int numberOfExtraLevels = nextElementLevel - minimalLevel; if (nextElementLevel > minimalLevel) { fixChildrenPosition(minimalLevel, numberOfExtraLevels, getDependentElements(current)); } Position.setY(current, i); Position.setY(next, i + 1d); } } @Inject  DNDListComponentView(final HTMLDivElement dragArea); @Override void init(final DNDListComponent presenter); @Override HTMLElement registerItem(final HTMLElement htmlElement); @Override void refreshItemsPosition(); @Override void refreshItemsHTML(); @Override void consolidateHierarchicalLevel(final boolean isElementsDraggedByUser); @Override void consolidateYPosition(); @Override void clear(); @Override Optional<HTMLElement> getPreviousElement(final Element reference); @Override void refreshDragAreaSize(); @Override HTMLDivElement getDragArea();  }