@Override protected void onRangeChanged(HasData<EndpointProfileDto> display) { if ((endpointKeyHash != null && !endpointKeyHash.isEmpty()) || (groupId != null && !groupId.isEmpty())) { int start = display.getVisibleRange().getStart(); if (previousStart < start) { previousStart = start; setLoaded(false); } super.onRangeChanged(display); } }
public void onColumnSort(ColumnSortEvent event) { hasData.setVisibleRangeAndClearData(hasData.getVisibleRange(), true); } }
@Override public void dispose(LeafValueEditor<T> subEditor) { // We use a negative index as flag in createEditorForTraversal assert ((IndexedEditor<T>) subEditor).index >= 0; data.setRowCount(data.getRowCount() - 1); }
/** * Adds a data display to this adapter. The current range of interest of the * display will be populated with data. * * @param display a {@link HasData}. */ public void addDataDisplay(final HasData<T> display) { if (display == null) { throw new IllegalArgumentException("display cannot be null"); } else if (displays.contains(display)) { throw new IllegalStateException( "The specified display has already been added to this adapter."); } // Add the display to the set. displays.add(display); // Add a handler to the display. HandlerRegistration handler = display.addRangeChangeHandler( new RangeChangeEvent.Handler() { public void onRangeChange(RangeChangeEvent event) { AbstractDataProvider.this.onRangeChanged(display); } }); rangeChangeHandlers.put(display, handler); // Update the data size in the display. if (lastRowCount >= 0) { display.setRowCount(lastRowCount, lastRowCountExact); } // Initialize the display with the current range. onRangeChanged(display); }
int itemCount = display.getVisibleItemCount(); int relativeStart = range.getStart() - display.getVisibleRange().getStart(); int relativeEnd = relativeStart + range.getLength(); for (int i = relativeStart; i < relativeEnd && i < itemCount; i++) { toUpdate.add(display.getVisibleItem(i));
/** * Informs a single display of new data. * * @param display the display to be updated * @param start the start index * @param values the data values */ protected void updateRowData(HasData<T> display, int start, List<T> values) { int end = start + values.size(); Range range = display.getVisibleRange(); int curStart = range.getStart(); int curLength = range.getLength(); int curEnd = curStart + curLength; if (start == curStart || (curStart < end && curEnd > start)) { // Fire the handler with the data that is in the range. // Allow an empty list that starts on the page start. int realStart = curStart < start ? start : curStart; int realEnd = curEnd > end ? end : curEnd; int realLength = realEnd - realStart; List<T> realValues = values.subList( realStart - start, realStart - start + realLength); display.setRowData(realStart, realValues); } } }
protected void goToFirstPage() { for (HasData<JarListPageRow> display : getDataDisplays()) { boolean wasOnFirstPage = (display.getVisibleRange().getStart() == 0); display.setVisibleRange(0, display.getVisibleRange().getLength()); if (wasOnFirstPage) { onRangeChanged(display); } } }
/** * Inform the displays of the total number of items that are available. * * @param count the new total row count * @param exact true if the count is exact, false if it is an estimate */ protected void updateRowCount(int count, boolean exact) { lastRowCount = count; lastRowCountExact = exact; for (HasData<T> display : displays) { display.setRowCount(count, exact); } }
public SelectAction translateSelectionEvent(CellPreviewEvent<T> event) { // Handle the event. NativeEvent nativeEvent = event.getNativeEvent(); if (BrowserEvents.CLICK.equals(nativeEvent.getType())) { // Ignore if the event didn't occur in the correct column. if (column > -1 && column != event.getColumn()) { return SelectAction.IGNORE; } // Determine if we clicked on a checkbox. Element target = nativeEvent.getEventTarget().cast(); if ("input".equals(target.getTagName().toLowerCase(Locale.ROOT))) { final InputElement input = target.cast(); if ("checkbox".equals(input.getType().toLowerCase(Locale.ROOT))) { // Synchronize the checkbox with the current selection state. input.setChecked(event.getDisplay().getSelectionModel().isSelected( event.getValue())); return SelectAction.TOGGLE; } } return SelectAction.IGNORE; } // For keyboard events, do the default action. return SelectAction.DEFAULT; } }
@Test public void testSearchString() { final SearchEvent searchEvent = new SearchEvent(RandomStringUtils.random(10)); testListPresenter.onSearchEvent(searchEvent); final ArgumentCaptor<Range> captor = ArgumentCaptor.forClass(Range.class); verify(next).setVisibleRangeAndClearData(captor.capture(), eq(true)); final Range range = captor.getValue(); assertEquals(0, range.getStart()); assertEquals(1, range.getLength()); assertEquals(searchEvent.getFilter().toLowerCase(), testListPresenter.getTextSearchStr()); } }
private int getRowIndexByObject(T object) { for (int row = 0; row < dataDisplay.getRowCount(); row++) { if (visibleItemsAsList().get(row).equals(object)) { return row; } } return -1; }
/** * Allows items to be moved between {@code excludedTable} and {@code includedTable} * by double-clicking them. Moving items this way retains selection in both tables * (excluding the item that was moved). */ public void enableDoubleClickItemMoving() { excludedTable.addSimulatedDoubleClickHandler(event -> { T clickedItem = (T) event.getDisplay().getVisibleItem(event.getIndex()); if (canMoveItemOnDoubleClick(excludedTable, event.getColumn())) { includeItems(Collections.singletonList(clickedItem), false); } }); includedTable.addSimulatedDoubleClickHandler(event -> { T clickedItem = (T) event.getDisplay().getVisibleItem(event.getIndex()); if (canMoveItemOnDoubleClick(includedTable, event.getColumn())) { excludeItems(Collections.singletonList(clickedItem), false); } }); }
int itemCount = display.getVisibleItemCount(); int relativeStart = range.getStart() - display.getVisibleRange().getStart(); int relativeEnd = relativeStart + range.getLength(); for (int i = relativeStart; i < relativeEnd && i < itemCount; i++) { toUpdate.add(display.getVisibleItem(i));
/** * Informs a single display of new data. * * @param display the display to be updated * @param start the start index * @param values the data values */ protected void updateRowData(HasData<T> display, int start, List<T> values) { int end = start + values.size(); Range range = display.getVisibleRange(); int curStart = range.getStart(); int curLength = range.getLength(); int curEnd = curStart + curLength; if (start == curStart || (curStart < end && curEnd > start)) { // Fire the handler with the data that is in the range. // Allow an empty list that starts on the page start. int realStart = curStart < start ? start : curStart; int realEnd = curEnd > end ? end : curEnd; int realLength = realEnd - realStart; List<T> realValues = values.subList( realStart - start, realStart - start + realLength); display.setRowData(realStart, realValues); } } }
/** * Adds a data display to this adapter. The current range of interest of the * display will be populated with data. * * @param display a {@link HasData}. */ public void addDataDisplay(final HasData<T> display) { if (display == null) { throw new IllegalArgumentException("display cannot be null"); } else if (displays.contains(display)) { throw new IllegalStateException( "The specified display has already been added to this adapter."); } // Add the display to the set. displays.add(display); // Add a handler to the display. HandlerRegistration handler = display.addRangeChangeHandler( new RangeChangeEvent.Handler() { public void onRangeChange(RangeChangeEvent event) { AbstractDataProvider.this.onRangeChanged(display); } }); rangeChangeHandlers.put(display, handler); // Update the data size in the display. if (lastRowCount >= 0) { display.setRowCount(lastRowCount, lastRowCountExact); } // Initialize the display with the current range. onRangeChanged(display); }
/** * Inform the displays of the total number of items that are available. * * @param count the new total row count * @param exact true if the count is exact, false if it is an estimate */ protected void updateRowCount(int count, boolean exact) { lastRowCount = count; lastRowCountExact = exact; for (HasData<T> display : displays) { display.setRowCount(count, exact); } }
public void onCellPreview(CellPreviewEvent<T> event) { // Early exit if selection is already handled or we are editing. if (event.isCellEditing() || event.isSelectionHandled()) { return; } // Early exit if we do not have a SelectionModel. HasData<T> display = event.getDisplay(); SelectionModel<? super T> selectionModel = display.getSelectionModel(); if (selectionModel == null) { return; } // Check for user defined actions. SelectAction action = (translator == null) ? SelectAction.DEFAULT : translator.translateSelectionEvent(event); // Handle the event based on the SelectionModel type. if (selectionModel instanceof MultiSelectionModel<?>) { // Add shift key support for MultiSelectionModel. handleMultiSelectionEvent(event, action, (MultiSelectionModel<? super T>) selectionModel); } else { // Use the standard handler. handleSelectionEvent(event, action, selectionModel); } }
@Test public void testEmptySearchString() { final SearchEvent searchEvent = new SearchEvent(""); testListPresenter.onSearchEvent(searchEvent); final ArgumentCaptor<Range> captor = ArgumentCaptor.forClass(Range.class); verify(next).setVisibleRangeAndClearData(captor.capture(), eq(true)); final Range range = captor.getValue(); assertEquals(1, range.getStart()); assertEquals(1, range.getLength()); assertEquals(searchEvent.getFilter(), testListPresenter.getTextSearchStr()); }
private void selectRow(int shift) { if (selectedSet.isEmpty() || dataDisplay == null) { return; } int shiftSelectedRow = lastSelectedRow + shift; int nextRow = shiftSelectedRow >= 0 && dataDisplay.getRowCount() != 0 ? shiftSelectedRow % dataDisplay.getRowCount() : shiftSelectedRow + dataDisplay.getRowCount(); if (disabledRows.contains(nextRow)) { selectRow(shift > 0 ? shift + 1 : shift - 1); return; } setSelected(visibleItemsAsList().get(nextRow), true); }
/** * Get the current ranges of all displays. * * @return the ranges */ public Range[] getRanges() { Range[] ranges = new Range[displays.size()]; int i = 0; for (HasData<T> display : displays) { ranges[i++] = display.getVisibleRange(); } return ranges; }