@Test public void testConsolidateHierarchicalLevelWhenListHasOneInvalidItem() { final HTMLElement element = mock(HTMLElement.class); element.style = mock(CSSStyleDeclaration.class); dragArea.style = mock(CSSStyleDeclaration.class); when(element.getAttribute(DATA_Y_POSITION)).thenReturn("0"); when(element.getAttribute(DATA_X_POSITION)).thenReturn("9"); mockDragAreaWithChildren(element); view.consolidateHierarchicalLevel(true); verify(element).setAttribute(DATA_X_POSITION, 0); }
@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();  }