com.intellij.ui.TableUtil Java Examples

The following examples show how to use com.intellij.ui.TableUtil. 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: QuarkusExtensionsStep.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
private ExtensionsTable() {
    setShowGrid(false);
    setShowVerticalLines(false);
    this.setCellSelectionEnabled(false);
    this.setRowSelectionAllowed(true);
    this.setSelectionMode(0);
    this.setTableHeader(null);
    setModel(new Model(new ArrayList<>()));
    TableColumn selectedColumn = columnModel.getColumn(0);
    TableUtil.setupCheckboxColumn(this, 0);
    selectedColumn.setCellRenderer(new BooleanTableCellRenderer());
    TableColumn extensionColumn = columnModel.getColumn(1);
    extensionColumn.setCellRenderer(new ColoredTableCellRenderer() {

        @Override
        protected void customizeCellRenderer(JTable table, @Nullable Object value, boolean b, boolean b1, int i, int i1) {
            QuarkusExtension extension = (QuarkusExtension) value;
            append(extension.getName(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, null));
            append(" ");
            append(extension.asLabel(false), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, null));
        }
    });
}
 
Example #2
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 #3
Source File: VariablesPanel.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
private AnActionButtonRunnable getRemoveAction(final TableView<XQueryRunVariable> variablesTable) {
    return new AnActionButtonRunnable() {
        @Override
        public void run(AnActionButton button) {
            TableUtil.stopEditing(variablesTable);
            final int[] selected = variablesTable.getSelectedRows();
            if (selected == null || selected.length == 0) return;
            for (int i = selected.length - 1; i >= 0; i--) {
                variablesModel.removeRow(selected[i]);
            }
            for (int i = selected.length - 1; i >= 0; i--) {
                int idx = selected[i];
                variablesModel.fireTableRowsDeleted(idx, idx);
            }
            int selection = selected[0];
            if (selection >= variablesModel.getRowCount()) {
                selection = variablesModel.getRowCount() - 1;
            }
            if (selection >= 0) {
                variablesTable.setRowSelectionInterval(selection, selection);
            }
            variablesTable.requestFocus();
        }
    };
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
Source File: PluginsAdvertiserDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents(JPanel rootPanel) {
  PluginAdvertiserPluginModel model = new PluginAdvertiserPluginModel(myDownloadState, myToInstallPlugins);
  model.addTableModelListener(e -> setOKActionEnabled(myDownloadState.values().stream().filter(it -> it).findAny().isPresent()));
  PluginTable pluginTable = new PluginTable(model);

  JPanel rightPanel = new JPanel(new BorderLayout());
  rightPanel.setBorder(BorderFactory.createLineBorder(UIUtil.getBorderColor(), 1));
  PluginHeaderPanel headerPanel = new PluginHeaderPanel(null, pluginTable);

  JEditorPane descriptionPanel = new JEditorPane();
  descriptionPanel.setEditorKit(UIUtil.getHTMLEditorKit());
  descriptionPanel.setEditable(false);
  descriptionPanel.addHyperlinkListener(new PluginManagerMain.MyHyperlinkListener());

  JPanel panel = headerPanel.getPanel();
  panel.setBorder(JBUI.Borders.empty(5));
  rightPanel.add(panel, BorderLayout.NORTH);
  rightPanel.add(descriptionPanel, BorderLayout.CENTER);

  pluginTable.getSelectionModel().addListSelectionListener(e -> {
    final int selectedRow = pluginTable.getSelectedRow();
    if (selectedRow != -1) {
      final PluginDescriptor selection = model.getObjectAt(selectedRow);
      if (selection != null) {
        PluginManagerMain.pluginInfoUpdate(selection, null, descriptionPanel, headerPanel, null);
      }
    }
  });

  TableUtil.ensureSelectionExists(pluginTable);
  return Couple.<JComponent>of(ScrollPaneFactory.createScrollPane(pluginTable, true), rightPanel);
}
 
Example #9
Source File: JBComboBoxTableCellEditorComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void initAndShowPopup() {
  myList.removeAll();
  final Rectangle rect = myTable.getCellRect(myRow, myColumn, true);
  final Point point = new Point(rect.x, rect.y);
  myList.setModel(JBList.createDefaultListModel(myOptions));
  if (myRenderer != null) {
    myList.setCellRenderer(myRenderer);
  }
  JBPopupFactory.getInstance()
    .createListPopupBuilder(myList)
    .setItemChoosenCallback(new Runnable() {
      @Override
      public void run() {
        final ActionEvent event = new ActionEvent(myList, ActionEvent.ACTION_PERFORMED, "elementChosen");
        for (ActionListener listener : myListeners) {
          listener.actionPerformed(event);
        }
        myValue = myList.getSelectedValue();
        TableUtil.stopEditing(myTable);

        myTable.setValueAt(myValue, myRow, myColumn); // on Mac getCellEditorValue() called before myValue is set.
        myTable.tableChanged(new TableModelEvent(myTable.getModel(), myRow));  // force repaint
      }
    })
    .setCancelCallback(new Computable<Boolean>() {
      @Override
      public Boolean compute() {
        TableUtil.stopEditing(myTable);
        return true;
      }
    })
    .createPopup()
    .show(new RelativePoint(myTable, point));
}
 
Example #10
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 #11
Source File: StatisticsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Selects row in table
 */
protected void selectRowOf(final SMTestProxy proxy) {
  SMRunnerUtil.addToInvokeLater(new Runnable() {
    public void run() {
      final int rowIndex = myTableModel.getIndexOf(proxy);
      myStatisticsTableView.setRowSelectionInterval(rowIndex, rowIndex >= 0 ? rowIndex : 0);
      // Scroll to visible
      TableUtil.scrollSelectionToVisible(myStatisticsTableView);
    }
  });
}
 
Example #12
Source File: StatisticsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Selects row in table
 * @param rowIndex Row's index
 */
protected void selectRow(final int rowIndex) {
  SMRunnerUtil.addToInvokeLater(new Runnable() {
    public void run() {
      // updates model
      myStatisticsTableView.setRowSelectionInterval(rowIndex, rowIndex);

      // Scroll to visible
      TableUtil.scrollSelectionToVisible(myStatisticsTableView);
    }
  });
}
 
Example #13
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 #14
Source File: TargetExpressionListUi.java    From intellij with Apache License 2.0 5 votes vote down vote up
private void addTarget() {
  TableUtil.stopEditing(tableView); // save any partially-filled state

  listModel.addRow(new TargetItem(""));
  int index = listModel.getRowCount() - 1;
  tableView.getSelectionModel().setSelectionInterval(index, index);
  tableView.scrollRectToVisible(
      tableView.getCellRect(index, /* column= */ 0, /* includeSpacing= */ true));
  TableUtil.editCellAt(tableView, index, /* column= */ 0);
}
 
Example #15
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 #16
Source File: CoverageViewBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void ensureSelectionExist() {
  TableUtil.ensureSelectionExists(myTable);
}
 
Example #17
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);
}
 
Example #18
Source File: TableView.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void stopEditing() {
  TableUtil.stopEditing(this);
}
 
Example #19
Source File: PatternFilterEditor.java    From KodeBeagle with Apache License 2.0 4 votes vote down vote up
public PatternFilterEditor(final Project project, final String patternsHelpId) {
    super(new BorderLayout());
    myPatternsHelpId = patternsHelpId;
    myTable = new JBTable();
    myProject = project;
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTable);
    decorator.addExtraAction(new AnActionButton(getAddPatternButtonText(),
            getAddPatternButtonIcon()) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            addPatternFilter();
        }
    });

    add(decorator.setRemoveAction(new AnActionButtonRunnable() {
        @Override
        public void run(final AnActionButton button) {
            TableUtil.removeSelectedItems(myTable);
        }
    }).setButtonComparator(getAddPatternButtonText(), "Remove")
            .disableUpDownActions().createPanel(), BorderLayout.CENTER);

    myTableModel = new FilterTableModel();
    myTable.setModel(myTableModel);
    myTable.setShowGrid(false);
    myTable.setShowGrid(false);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setTableHeader(null);
    myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    myTable.setColumnSelectionAllowed(false);
    myTable.setPreferredScrollableViewportSize(new Dimension(WIDTH,
            myTable.getRowHeight() * PREFERRED_SCROLLABLE_VIEWPORT_HEIGHT_IN_ROWS));

    TableColumnModel columnModel = myTable.getColumnModel();
    TableColumn column = columnModel.getColumn(FilterTableModel.CHECK_MARK);
    TableUtil.setupCheckboxColumn(column);
    column.setCellRenderer(new EnabledCellRenderer(myTable.getDefaultRenderer(Boolean.class)));
    columnModel.getColumn(FilterTableModel.FILTER).setCellRenderer(new FilterCellRenderer());

    getEmptyText().setText(EMPTY_PATTERNS);
}
 
Example #20
Source File: TargetExpressionListUi.java    From intellij with Apache License 2.0 4 votes vote down vote up
private void removeTarget() {
  TableUtil.removeSelectedItems(tableView);
}
 
Example #21
Source File: AutomaticRenamingDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void doOKAction() {
  TableUtil.stopEditing(myTable);
  updateRenamer();
  super.doOKAction();
}
 
Example #22
Source File: PerGroupDependencyTableModel.java    From intellij-spring-assistant with MIT License 4 votes vote down vote up
PerGroupDependencyTableModel(JBTable perGroupDependencyTable,
    @NotNull ProjectCreationRequest request, @NotNull DependencyGroup dependencyGroup,
    @NotNull Version bootVersion,
    @NotNull Map<DependencyGroup, List<Dependency>> filteredGroupAndDependencies) {
  this.perGroupDependencyTable = perGroupDependencyTable;
  this.request = request;
  this.dependencyGroup = dependencyGroup;
  this.bootVersion = bootVersion;
  this.filteredGroupAndDependencies = filteredGroupAndDependencies;
  reindex();

  perGroupDependencyTable.setModel(this);
  resetTableLookAndFeelToSingleSelect(perGroupDependencyTable);

  TableColumnModel columnModel = perGroupDependencyTable.getColumnModel();
  columnModel.setColumnMargin(0);
  TableColumn checkBoxColumn = columnModel.getColumn(CHECKBOX_COL_INDEX);
  TableUtil.setupCheckboxColumn(checkBoxColumn);
  checkBoxColumn.setCellRenderer(new BooleanTableCellRenderer());
  TableColumn dependencyColumn = columnModel.getColumn(DEPENDENCY_NAME_COL_INDEX);
  dependencyColumn.setCellRenderer(new ColoredTableCellRenderer() {
    @Override
    protected void customizeCellRenderer(JTable table, @Nullable Object value, boolean selected,
        boolean hasFocus, int row, int column) {
      if (value != null) {
        Dependency dependency = Dependency.class.cast(value);
        boolean selectable = isCellEditable(row, CHECKBOX_COL_INDEX);
        if (selectable) {
          append(dependency.getName());
        } else {
          append(dependency.getName(), GRAY_ATTRIBUTES);
        }
      }
      // Enable search highlighting. This in conjunction with TableSpeedSearch(below) enables type to search capability of intellij
      applySpeedSearchHighlighting(table, this, true, selected);
    }
  });

  new TableSpeedSearch(perGroupDependencyTable, value -> {
    if (value instanceof Dependency) {
      return Dependency.class.cast(value).getName();
    }
    return "";
  });

  // Add listeners

  // Allow user to select via keyboard
  perGroupDependencyTable.getActionMap().put("select_deselect_dependency", new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
      toggleSelectionIfApplicable(perGroupDependencyTable.getSelectedRow());
    }
  });
  perGroupDependencyTable.getInputMap()
      .put(getKeyStroke(VK_SPACE, 0), "select_deselect_dependency");
  // Allow user to toggle via double click
  perGroupDependencyTable.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent event) {
      if (event.getButton() == BUTTON1) {
        int columIndex = perGroupDependencyTable.columnAtPoint(event.getPoint());
        if (columIndex == DEPENDENCY_NAME_COL_INDEX) {
          int rowIndex = perGroupDependencyTable.rowAtPoint(event.getPoint());
          if (event.getClickCount() == 2) {
            toggleSelectionIfApplicable(rowIndex);
          }
        }
      }
    }
  });

  perGroupDependencyTable.getSelectionModel().addListSelectionListener(e -> {
    if (!e.getValueIsAdjusting()) {
      int selectedRow = perGroupDependencyTable.getSelectedRow();
      if (selectedRow != -1) {
        selectionListeners
            .forEach(listener -> listener.onDependencySelected(getDependencyAt(selectedRow)));
      } else {
        selectionListeners.forEach(listener -> listener.onDependencySelected(null));
      }
    }
  });
}