com.intellij.ui.TableSpeedSearch Java Examples

The following examples show how to use com.intellij.ui.TableSpeedSearch. 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: MoveMethodPanel.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
private JScrollPane createTablePanel() {
    new TableSpeedSearch(table);
    table.setModel(model);
    model.setupRenderer(table);
    table.addMouseListener((DoubleClickListener) this::onDoubleClick);
    table.getSelectionModel().setSelectionMode(SINGLE_SELECTION);
    table.setAutoCreateRowSorter(true);
    setupTableLayout();
    refreshLabel.setForeground(JBColor.GRAY);
    scrollPane = ScrollPaneFactory.createScrollPane(table);
    scrollPane.setViewportView(refreshLabel);
    return scrollPane;
}
 
Example #2
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));
      }
    }
  });
}