Java Code Examples for com.intellij.ui.table.JBTable#setSelectionMode()

The following examples show how to use com.intellij.ui.table.JBTable#setSelectionMode() . 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: SubmissionsPanel.java    From leetcode-editor with Apache License 2.0 7 votes vote down vote up
public SubmissionsPanel(@Nullable Project project, TableModel tableModel) {
    super(project, true);
    jpanel = new JBPanel(new BorderLayout());
    jpanel.setMinimumSize(new Dimension(400, 400));
    jpanel.setPreferredSize(new Dimension(400, 400));
    table = new JBTable(tableModel);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getTableHeader().setReorderingAllowed(false);
    table.setRowSelectionAllowed(true);
    table.setRowSelectionInterval(0, 0);
    table.getColumnModel().getColumn(0).setPreferredWidth(350);
    table.getColumnModel().getColumn(1).setPreferredWidth(200);
    table.getColumnModel().getColumn(2).setPreferredWidth(100);
    table.getColumnModel().getColumn(3).setPreferredWidth(200);
    table.getColumnModel().getColumn(4).setPreferredWidth(100);
    jpanel.add(new JBScrollPane(table, JBScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JBScrollPane.HORIZONTAL_SCROLLBAR_NEVER),  BorderLayout.CENTER);

    setModal(true);
    init();
}
 
Example 2
Source File: SolutionPanel.java    From leetcode-editor with Apache License 2.0 6 votes vote down vote up
public SolutionPanel(@Nullable Project project, TableModel tableModel) {
    super(project, true);
    this.jpanel = new JBPanel(new BorderLayout());;
    jpanel.setPreferredSize(new Dimension(600, 400));
    table = new JBTable(tableModel);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getTableHeader().setReorderingAllowed(false);
    table.setRowSelectionAllowed(true);
    table.setRowSelectionInterval(0, 0);
    table.getColumnModel().getColumn(0).setPreferredWidth(350);
    table.getColumnModel().getColumn(1).setPreferredWidth(200);
    table.getColumnModel().getColumn(2).setPreferredWidth(700);
    jpanel.add(new JBScrollPane(table, JBScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JBScrollPane.HORIZONTAL_SCROLLBAR_NEVER),  BorderLayout.CENTER);

    setModal(true);
    init();
}
 
Example 3
Source File: TableRowUtilities.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
private static JTable createRowHeadersTable(final JTable userTable, int startingNumber) {
    final JBTable rowHeadersTable = new JBTable(new RowHeadersTableModel(userTable.getModel().getRowCount(), startingNumber));

    // this is where you set the width of the row headers
    rowHeadersTable.createDefaultColumnsFromModel();

    // make the rows look and behave like headers
    rowHeadersTable.setBackground(rowHeadersTable.getTableHeader().getBackground());
    rowHeadersTable.setForeground(rowHeadersTable.getTableHeader().getForeground());
    rowHeadersTable.setFont(rowHeadersTable.getTableHeader().getFont());
    rowHeadersTable.setRowHeight(userTable.getRowHeight());
    rowHeadersTable.getTableHeader().setReorderingAllowed(false);
    rowHeadersTable.setRowSelectionAllowed(true);
    rowHeadersTable.setCellSelectionEnabled(true);
    rowHeadersTable.setFocusable(true);
    rowHeadersTable.setDragEnabled(true);
    rowHeadersTable.setSelectionMode(userTable.getSelectionModel().getSelectionMode());
    rowHeadersTable.getEmptyText().setText("");

    return rowHeadersTable;
}
 
Example 4
Source File: ChooseLabelDialog.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
private void createUIComponents() {
    searchResultsModel =
            new ListTableModel<>(
                    new ColumnInfo<P4Label, String>(P4Bundle.getString("search.label.label-name")) {
                        @Nullable
                        @Override
                        public String valueOf(P4Label o) {
                            return o == null ? null : o.getName();
                        }
                    },
                    new ColumnInfo<P4Label, String>(P4Bundle.getString("search.label.label-description")) {
                        @Nullable
                        @Override
                        public String valueOf(P4Label o) {
                            return o == null ? null : o.getDescription();
                        }
                    });
    mySearchResults = new JBTable(searchResultsModel);
    mySearchResults.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    mySearchSpinner = new AsyncProcessIcon("Searching for labels");
}
 
Example 5
Source File: InitializrUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
/**
 * Set defaults so that the table looks & acts more like a list
 *
 * @param table table
 */
public static void resetTableLookAndFeelToSingleSelect(JBTable table) {
  table.setRowMargin(0);
  table.setShowColumns(false);
  table.setShowGrid(false);
  table.setShowVerticalLines(false);
  table.setCellSelectionEnabled(false);
  table.setRowSelectionAllowed(true);
  table.setSelectionMode(SINGLE_SELECTION);
}
 
Example 6
Source File: CruciblePanel.java    From Crucible4IDEA with MIT License 4 votes vote down vote up
public CruciblePanel(@NotNull final Project project) {
  super(false);
  myProject = project;

  final JBSplitter splitter = new JBSplitter(false, 0.2f);

  myReviewModel = new CrucibleReviewModel(project);
  myReviewTable = new JBTable(myReviewModel);
  myReviewTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myReviewTable.setStriped(true);
  myReviewTable.setExpandableItemsEnabled(false);

  final TableColumnModel columnModel = myReviewTable.getColumnModel();
  columnModel.getColumn(1).setCellRenderer(new DescriptionCellRenderer());

  setUpColumnWidths(myReviewTable);
  myReviewTable.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
      if (e.getClickCount() == 2) {
        final int viewRow = myReviewTable.getSelectedRow();
        if (viewRow >= 0 &&  viewRow < myReviewTable.getRowCount()) {
          ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
              final Review review =
                CrucibleManager.getInstance(myProject).getDetailsForReview((String)myReviewTable.
                  getValueAt(viewRow, myReviewTable.getColumnModel().getColumnIndex(CrucibleBundle.message("crucible.id"))));
              if (review != null) {
                openDetailsToolWindow(review);
                myReviewTable.clearSelection();
              }
            }
          }, ModalityState.stateForComponent(myReviewTable));

        }
      }
  }});

  final TableRowSorter<TableModel> rowSorter = new TableRowSorter<TableModel>(myReviewModel);
  rowSorter.setSortKeys(Collections.singletonList(new RowSorter.SortKey(4, SortOrder.ASCENDING)));
  rowSorter.sort();
  myReviewTable.setRowSorter(rowSorter);

  final JScrollPane detailsScrollPane = ScrollPaneFactory.createScrollPane(myReviewTable);

  final SimpleTreeStructure reviewTreeStructure = createTreeStructure();
  final DefaultTreeModel model = new CrucibleTreeModel();
  final SimpleTree reviewTree = new SimpleTree(model);

  new AbstractTreeBuilder(reviewTree, model, reviewTreeStructure, null);
  reviewTree.invalidate();

  final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(reviewTree);
  splitter.setFirstComponent(scrollPane);
  splitter.setSecondComponent(detailsScrollPane);
  setContent(splitter);
}
 
Example 7
Source File: EditVariableDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private JComponent createVariablesTable() {
  final String[] names = {
    CodeInsightBundle.message("templates.dialog.edit.variables.table.column.name"),
    CodeInsightBundle.message("templates.dialog.edit.variables.table.column.expression"),
    CodeInsightBundle.message("templates.dialog.edit.variables.table.column.default.value"),
    CodeInsightBundle.message("templates.dialog.edit.variables.table.column.skip.if.defined")
  };

  // Create a model of the data.
  TableModel dataModel = new VariablesModel(names);

  // Create the table
  myTable = new JBTable(dataModel);
  myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myTable.setPreferredScrollableViewportSize(new Dimension(500, myTable.getRowHeight() * 8));
  myTable.getColumn(names[0]).setPreferredWidth(120);
  myTable.getColumn(names[1]).setPreferredWidth(200);
  myTable.getColumn(names[2]).setPreferredWidth(200);
  myTable.getColumn(names[3]).setPreferredWidth(100);
  if (myVariables.size() > 0) {
    myTable.getSelectionModel().setSelectionInterval(0, 0);
  }

  JComboBox comboField = new JComboBox();
  Macro[] macros = MacroFactory.getMacros();
  Arrays.sort(macros, new Comparator<Macro> () {
    @Override
    public int compare(Macro m1, Macro m2) {
      return m1.getPresentableName().compareTo(m2.getPresentableName());
    }
  });
  eachMacro:
  for (Macro macro : macros) {
    for (TemplateContextType contextType : myContextTypes) {
      if (macro.isAcceptableInContext(contextType)) {
        comboField.addItem(macro.getPresentableName());
        continue eachMacro;
      }
    }
  }
  comboField.setEditable(true);
  DefaultCellEditor cellEditor = new DefaultCellEditor(comboField);
  cellEditor.setClickCountToStart(1);
  myTable.getColumn(names[1]).setCellEditor(cellEditor);
  myTable.setRowHeight(comboField.getPreferredSize().height);

  JTextField textField = new JTextField();

  /*textField.addMouseListener(
    new PopupHandler(){
      public void invokePopup(Component comp,int x,int y){
        showCellPopup((JTextField)comp,x,y);
      }
    }
  );*/

  cellEditor = new DefaultCellEditor(textField);
  cellEditor.setClickCountToStart(1);
  myTable.setDefaultEditor(String.class, cellEditor);

  final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTable).disableAddAction().disableRemoveAction();
  return decorator.createPanel();
}