use of javax.swing.table.AbstractTableModel in project omegat by omegat-org.
the class FilenamePatternsEditorController method show.
public static List<String> show(List<String> excludes) {
result = null;
data = new ArrayList<String>(excludes);
final FilenamePatternsEditor dialog = new FilenamePatternsEditor(Core.getMainWindow().getApplicationFrame(), true);
@SuppressWarnings("serial") final AbstractTableModel model = new AbstractTableModel() {
public int getColumnCount() {
return 1;
}
public String getColumnName(int column) {
return OStrings.getString("FILENAMEPATTERNS_MASK");
}
public int getRowCount() {
return data.size();
}
public Object getValueAt(int row, int col) {
return data.get(row);
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
data.set(rowIndex, aValue.toString());
}
public boolean isCellEditable(int row, int col) {
return true;
}
};
dialog.table.setModel(model);
dialog.btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (dialog.table.getCellEditor() != null) {
dialog.table.getCellEditor().stopCellEditing();
}
result = data;
dialog.dispose();
}
});
dialog.btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
dialog.btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
data.add("");
model.fireTableDataChanged();
dialog.table.changeSelection(data.size() - 1, 0, false, false);
dialog.table.editCellAt(data.size() - 1, 0);
dialog.table.transferFocus();
}
});
dialog.btnRemove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (dialog.table.getSelectedRow() >= 0 && dialog.table.getSelectedRow() < data.size()) {
data.remove(dialog.table.getSelectedRow());
}
model.fireTableDataChanged();
}
});
ListSelectionListener listener = e -> dialog.btnRemove.setEnabled(dialog.table.getSelectedRow() != -1);
dialog.table.getSelectionModel().addListSelectionListener(listener);
listener.valueChanged(null);
dialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
StaticUIUtils.setEscapeClosable(dialog);
dialog.getRootPane().setDefaultButton(dialog.btnOk);
dialog.setVisible(true);
return result;
}
Aggregations