public void restore(@NotNull VisibleGraph<Integer> newVisibleGraph, boolean scrollToSelection) { Pair<TIntHashSet, Integer> toSelectAndScroll = findRowsToSelectAndScroll(myTable.getGraphTableModel(), newVisibleGraph); if (!toSelectAndScroll.first.isEmpty()) { myTable.getSelectionModel().setValueIsAdjusting(true); toSelectAndScroll.first.forEach( new TIntProcedure() { @Override public boolean execute(int row) { myTable.addRowSelectionInterval(row, row); return true; } }); myTable.getSelectionModel().setValueIsAdjusting(false); } if (scrollToSelection) { if (myScrollToTop) { scrollToRow(0, 0); } else if (toSelectAndScroll.second != null) { assert myDelta != null; scrollToRow(toSelectAndScroll.second, myDelta); } } // sometimes commits that were selected are now collapsed // currently in this case selection disappears // in the future we need to create a method in LinearGraphController that allows to calculate // visible commit for our commit // or answer from collapse action could return a map that gives us some information about what // commits were collapsed and where }
private void scrollToRow(Integer row, Integer delta) { Rectangle startRect = myTable.getCellRect(row, 0, true); myTable.scrollRectToVisible( new Rectangle( startRect.x, Math.max(startRect.y - delta, 0), startRect.width, myTable.getVisibleRect().height)); }
public Selection(@NotNull VcsLogGraphTable table) { myTable = table; List<Integer> selectedRows = ContainerUtil.sorted(toList(myTable.getSelectedRows())); Couple<Integer> visibleRows = ScrollingUtil.getVisibleRows(myTable); myScrollToTop = visibleRows.first - 1 == 0; VisibleGraph<Integer> graph = myTable.getVisibleGraph(); mySelectedCommits = new TIntHashSet(); Integer visibleSelectedCommit = null; Integer delta = null; for (int row : selectedRows) { if (row < graph.getVisibleCommitCount()) { Integer commit = graph.getRowInfo(row).getCommit(); mySelectedCommits.add(commit); if (visibleRows.first - 1 <= row && row <= visibleRows.second && visibleSelectedCommit == null) { visibleSelectedCommit = commit; delta = myTable.getCellRect(row, 0, false).y - myTable.getVisibleRect().y; } } } if (visibleSelectedCommit == null && visibleRows.first - 1 >= 0) { visibleSelectedCommit = graph.getRowInfo(visibleRows.first - 1).getCommit(); delta = myTable.getCellRect(visibleRows.first - 1, 0, false).y - myTable.getVisibleRect().y; } myVisibleSelectedCommit = visibleSelectedCommit; myDelta = delta; }