<commit_before>/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.util.ui.table;

import com.intellij.util.ui.EditableModel;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

/**
 * @author <NAME>
 */
public abstract class JBListTableModel extends AbstractTableModel implements EditableModel {
  private final JTable myTable;

  public JBListTableModel(JTable table) {
    myTable = table;
  }

  @Override
  public int getRowCount() {
    return myTable.getRowCount();
  }

  @Override
  public final int getColumnCount() {
    return 1;
  }

  @Override
  public String getColumnName(int columnIndex) {
    return "";
  }


  @Override
  public boolean isCellEditable(int rowIndex, int columnIndex) {
    return true;
  }

  public abstract JBTableRow getRow(int index);

  @Override
  public final JBTableRow getValueAt(int rowIndex, int columnIndex) {
    return getRow(rowIndex);
  }

  @Override
  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
  }

  @Override
  public void addRow() {
    final TableModel model = myTable.getModel();
    if (model instanceof EditableModel) {
      ((EditableModel)model).addRow();
    }
  }

  @Override
  public void removeRow(int index) {
    final TableModel model = myTable.getModel();
    if (model instanceof EditableModel) {
      ((EditableModel)model).removeRow(index);
    }
  }

  @Override
  public void exchangeRows(int oldIndex, int newIndex) {
    final TableModel model = myTable.getModel();
    if (model instanceof EditableModel) {
      ((EditableModel)model).exchangeRows(oldIndex, newIndex);
    }
  }
}<commit_msg>proper setValueAt and EditableModel implementations<commit_after>/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.util.ui.table;

import com.intellij.util.ui.EditableModel;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

/**
 * @author <NAME>
 */
public abstract class JBListTableModel extends AbstractTableModel implements EditableModel {
  private final JTable myTable;

  public JBListTableModel(JTable table) {
    myTable = table;
  }

  @Override
  public int getRowCount() {
    return myTable.getRowCount();
  }

  @Override
  public final int getColumnCount() {
    return 1;
  }

  @Override
  public String getColumnName(int columnIndex) {
    return null;
  }


  @Override
  public boolean isCellEditable(int rowIndex, int columnIndex) {
    return true;
  }

  public abstract JBTableRow getRow(int index);

  @Override
  public final JBTableRow getValueAt(int rowIndex, int columnIndex) {
    return getRow(rowIndex);
  }

  @Override
  public void setValueAt(Object value, int row, int column) {
    for (int i = 0; i < myTable.getColumnCount(); i++) {
      myTable.setValueAt(((JBTableRow)value).getValueAt(i), row, i);
    }
    fireTableCellUpdated(row, column);
  }

  @Override
  public void addRow() {
    final TableModel model = myTable.getModel();
    final int count = myTable.getRowCount();
    if (model instanceof EditableModel) {
      ((EditableModel)model).addRow();
    }
    if (count < myTable.getRowCount()) {
      fireTableRowsInserted(count, myTable.getRowCount() - 1);
    }
  }

  @Override
  public void removeRow(int index) {
    final TableModel model = myTable.getModel();
    if (model instanceof EditableModel) {
      ((EditableModel)model).removeRow(index);
    }
    fireTableRowsDeleted(index, index);
  }

  @Override
  public void exchangeRows(int oldIndex, int newIndex) {
    final TableModel model = myTable.getModel();
    if (model instanceof EditableModel) {
      ((EditableModel)model).exchangeRows(oldIndex, newIndex);
    }
    fireTableRowsUpdated(Math.min(oldIndex, newIndex), Math.max(oldIndex, newIndex));
  }
}
{'fraction_non_alphanumeric': 0.09617331443612068, 'fraction_numerical': 0.005669163798339745, 'mean_word_length': 3.76374156219865, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5327605', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1441, 'n_words': 449}