Java Code Examples for com.intellij.ui.TableUtil#scrollSelectionToVisible()

The following examples show how to use com.intellij.ui.TableUtil#scrollSelectionToVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirDiffTableModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
void restore() {
  final int newRowCount = myTable.getRowCount();
  if (newRowCount == 0) return;

  int row = Math.min(newRowCount < rowCount ? selectedRow : selectedRow + 1, newRowCount - 1);
  final DirDiffElementImpl element = getElementAt(row);
  if (element != null && element.isSeparator()) {
    if (getElementAt(row +1) != null) {
      row += 1;
    } else {
      row -= 1;
    }
  }
  final DirDiffElementImpl el = getElementAt(row);
  row = el == null || el.isSeparator() ? 0 : row;
  myTable.getSelectionModel().setSelectionInterval(row, row);
  TableUtil.scrollSelectionToVisible(myTable);
}
 
Example 2
Source File: TreeTable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void processKeyEvent(KeyEvent e){
  if (!myProcessCursorKeys) {
    super.processKeyEvent(e);
    return;
  }

  int keyCode = e.getKeyCode();
  final int selColumn = columnModel.getSelectionModel().getAnchorSelectionIndex();
  boolean treeHasFocus = selColumn == -1 || selColumn >= 0 && isTreeColumn(selColumn);
  boolean oneRowSelected = getSelectedRowCount() == 1;
  if(treeHasFocus && oneRowSelected && ((keyCode == KeyEvent.VK_LEFT) || (keyCode == KeyEvent.VK_RIGHT))){
    myTree._processKeyEvent(e);
    int rowToSelect = ObjectUtil.notNull(myTree.getSelectionRows())[0];
    getSelectionModel().setSelectionInterval(rowToSelect, rowToSelect);
    TableUtil.scrollSelectionToVisible(this);
  }
  else{
    super.processKeyEvent(e);
  }
}
 
Example 3
Source File: AbstractFileTreeTable.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void select(@Nonnull VirtualFile toSelect, final TreeNode root) {
  for (int i = 0; i < root.getChildCount(); i++) {
    TreeNode child = root.getChildAt(i);
    VirtualFile file = ((FileNode)child).getObject();
    if (VfsUtilCore.isAncestor(file, toSelect, false)) {
      if (Comparing.equal(file, toSelect)) {
        TreeUtil.selectNode(getTree(), child);
        getSelectionModel().clearSelection();
        addSelectedPath(TreeUtil.getPathFromRoot(child));
        TableUtil.scrollSelectionToVisible(this);
      }
      else {
        select(toSelect, child);
      }
      return;
    }
  }
}
 
Example 4
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void selectElement(Object element, String selectedText) {
  List<UsageNode> data = ((MyModel) getTable().getModel()).getItems();
  int i = data.indexOf(element);
  if (i == -1) return;
  final int viewRow = getTable().convertRowIndexToView(i);
  getTable().getSelectionModel().setSelectionInterval(viewRow, viewRow);
  TableUtil.scrollSelectionToVisible(getTable());
}
 
Example 5
Source File: DirDiffTableModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void selectFirstRow() {
  if (myElements.size() > 0) {
    int row = myElements.get(0).isSeparator() ? 1 : 0;
    if (row < myTable.getRowCount()) {
      myTable.getSelectionModel().setSelectionInterval(row, row);
      TableUtil.scrollSelectionToVisible(myTable);
    }
  }
}
 
Example 6
Source File: PluginTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void select(PluginDescriptor... descriptors) {
  PluginTableModel tableModel = (PluginTableModel)getModel();
  getSelectionModel().clearSelection();
  for (int i = 0; i < tableModel.getRowCount(); i++) {
    PluginDescriptor descriptorAt = tableModel.getObjectAt(i);
    if (ArrayUtil.find(descriptors, descriptorAt) != -1) {
      final int row = convertRowIndexToView(i);
      getSelectionModel().addSelectionInterval(row, row);
    }
  }
  TableUtil.scrollSelectionToVisible(this);
}
 
Example 7
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected void selectElement(Object element, String selectedText) {
  List<UsageNode> data = ((MyModel)getTable().getModel()).getItems();
  int i = data.indexOf(element);
  if (i == -1) return;
  final int viewRow = getTable().convertRowIndexToView(i);
  getTable().getSelectionModel().setSelectionInterval(viewRow, viewRow);
  TableUtil.scrollSelectionToVisible(getTable());
}
 
Example 8
Source File: DirDiffTableModel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void applyRemove() {
  final List<DirDiffElementImpl> selectedElements = getSelectedElements();
  myUpdating.set(true);
  final Iterator<DirDiffElementImpl> i = myElements.iterator();
  while(i.hasNext()) {
    final DiffType type = i.next().getType();
    switch (type) {
      case SOURCE:
        if (!mySettings.showNewOnSource) i.remove();
        break;
      case TARGET:
        if (!mySettings.showNewOnTarget) i.remove();
        break;
      case SEPARATOR:
        break;
      case CHANGED:
        if (!mySettings.showDifferent) i.remove();
        break;
      case EQUAL:
        if (!mySettings.showEqual) i.remove();
        break;
      case ERROR:
    }
  }

  boolean sep = true;
  for (int j = myElements.size() - 1; j >= 0; j--) {
    if (myElements.get(j).isSeparator()) {
      if (sep) {
        myElements.remove(j);
      }
      else {
        sep = true;
      }
    }
    else {
      sep = false;
    }
  }
  fireTableDataChanged();
  myUpdating.set(false);
  int index;
  if (!selectedElements.isEmpty() && (index = myElements.indexOf(selectedElements.get(0))) != -1) {
    myTable.getSelectionModel().setSelectionInterval(index, index);
    TableUtil.scrollSelectionToVisible(myTable);
  }
  else {
    selectFirstRow();
  }
  myPanel.update(true);
}
 
Example 9
Source File: CoverageViewBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void selectItem(int i) {
  TableUtil.selectRows(myTable, new int[]{myTable.convertRowIndexToView(i)});
  TableUtil.scrollSelectionToVisible(myTable);
}