@Test public void testGetIndexOfParentOrLastElementInGroup() { final DataTypeListItem parent = mock(DataTypeListItem.class); final HTMLElement parentElement = mock(HTMLElement.class); final String parentId = "parentId"; final List<DataTypeListItem> groupedElements = new ArrayList<>(); groupedElements.add(parent); final int expectedIndex = 0; when(parentElement.getAttribute(UUID_ATTR)).thenReturn(parentId); when(parent.getDragAndDropElement()).thenReturn(parentElement); final int index = view.getIndexOfParentOrLastElementInGroup(groupedElements, parent); assertEquals(expectedIndex, index); }
int getIndexOfParentOrLastElementInGroup(final List<DataTypeListItem> groupedElements, final DataTypeListItem parent) { final int parentIndex = groupedElements.indexOf(parent); final String parentId = parent.getDragAndDropElement().getAttribute(UUID_ATTR); int index = parentIndex; for (int i = parentIndex; i < groupedElements.size(); i++) { if (Objects.equals(groupedElements.get(i).getDragAndDropElement().getAttribute(PARENT_UUID_ATTR), parentId)) { index++; } } return index; }
DataTypeSearchBarView implements DataTypeSearchBar.View { int getIndexOfParentOrLastElementInGroup(final List<DataTypeListItem> groupedElements, final DataTypeListItem parent) { final int parentIndex = groupedElements.indexOf(parent); final String parentId = parent.getDragAndDropElement().getAttribute(UUID_ATTR); int index = parentIndex; for (int i = parentIndex; i < groupedElements.size(); i++) { if (Objects.equals(groupedElements.get(i).getDragAndDropElement().getAttribute(PARENT_UUID_ATTR), parentId)) { index++; } } return index; } }
DataTypeSearchBarView implements DataTypeSearchBar.View { int getIndexOfParentOrLastElementInGroup(final List<DataTypeListItem> groupedElements, final DataTypeListItem parent) { final int parentIndex = groupedElements.indexOf(parent); final String parentId = parent.getDragAndDropElement().getAttribute(UUID_ATTR); int index = parentIndex; for (int i = parentIndex; i < groupedElements.size(); i++) { if (Objects.equals(groupedElements.get(i).getDragAndDropElement().getAttribute(PARENT_UUID_ATTR), parentId)) { index++; } } return index; } @Inject  DataTypeSearchBarView(final HTMLInputElement searchBar,
                                 final @Named("span") HTMLElement searchIcon,
                                 final HTMLButtonElement closeSearch,
                                 final TranslationService translationService); }
DataTypeSearchBarView implements DataTypeSearchBar.View { int getIndexOfParentOrLastElementInGroup(final List<DataTypeListItem> groupedElements, final DataTypeListItem parent) { final int parentIndex = groupedElements.indexOf(parent); final String parentId = parent.getDragAndDropElement().getAttribute(UUID_ATTR); int index = parentIndex; for (int i = parentIndex; i < groupedElements.size(); i++) { if (Objects.equals(groupedElements.get(i).getDragAndDropElement().getAttribute(PARENT_UUID_ATTR), parentId)) { index++; } } return index; } @Inject  DataTypeSearchBarView(final HTMLInputElement searchBar,
                                 final @Named("span") HTMLElement searchIcon,
                                 final HTMLButtonElement closeSearch,
                                 final TranslationService translationService); @PostConstruct void setupSearchBar(); @Override void init(final DataTypeSearchBar presenter); @EventHandler("close-search") void onSearchBarCloseButton(final ClickEvent e); @EventHandler("search-bar") void onSearchBarKeyUpEvent(final KeyUpEvent event); @EventHandler("search-bar") void onSearchBarKeyDownEvent(final KeyDownEvent e); @EventHandler("search-bar") void onSearchBarChangeEvent(final ChangeEvent e); @Override void resetSearchBar(); @Override void showSearchResults(final List<DataType> results); void refreshItemsPosition(); }
DataTypeSearchBarView implements DataTypeSearchBar.View { int getIndexOfParentOrLastElementInGroup(final List<DataTypeListItem> groupedElements, final DataTypeListItem parent) { final int parentIndex = groupedElements.indexOf(parent); final String parentId = parent.getDragAndDropElement().getAttribute(UUID_ATTR); int index = parentIndex; for (int i = parentIndex; i < groupedElements.size(); i++) { if (Objects.equals(groupedElements.get(i).getDragAndDropElement().getAttribute(PARENT_UUID_ATTR), parentId)) { index++; } } return index; } @Inject  DataTypeSearchBarView(final HTMLInputElement searchBar,
                                 final @Named("span") HTMLElement searchIcon,
                                 final HTMLButtonElement closeSearch,
                                 final TranslationService translationService); @PostConstruct void setupSearchBar(); @Override void init(final DataTypeSearchBar presenter); @EventHandler("close-search") void onSearchBarCloseButton(final ClickEvent e); @EventHandler("search-bar") void onSearchBarKeyUpEvent(final KeyUpEvent event); @EventHandler("search-bar") void onSearchBarKeyDownEvent(final KeyDownEvent e); @EventHandler("search-bar") void onSearchBarChangeEvent(final ChangeEvent e); @Override void resetSearchBar(); @Override void showSearchResults(final List<DataType> results); void refreshItemsPosition();  }