col_set_frame.setSize(400, 300);
col_set_frame.setLayout(new BorderLayout());
col_set_frame.add(center_panel,BorderLayout.CENTER);
col_set_frame.add(right_panel, BorderLayout.EAST);
col_set_frame.add(bottom_panel, BorderLayout.SOUTH);
final JTable col_set_table = new JTable();
//DefaultTableModel col_set_table_model = new DefaultTableModel();
Object[][] col_set_rows_cols = new Object[14][3];
int i = 0;
// col name -> col obj mapping (easy way to map col names to master cols)
final Map<String,TableColumnExt> cols = new Hashtable<String,TableColumnExt>();
for(TableColumnExt column : table_columns) {
if(column.isVisible()) col_set_rows_cols[i][0] = true;
else col_set_rows_cols[i][0] = false;
col_set_rows_cols[i][1] = column.getHeaderValue();
cols.put(column.getHeaderValue().toString(), column);
++i;
}
col_set_table.setModel(new DefaultTableModel(col_set_rows_cols,
new String[] {
"Visibility", "Name", "Description"
})
{
Class[] types = new Class [] {
java.lang.Boolean.class, java.lang.String.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
JScrollPane scroll_pane = new JScrollPane();
scroll_pane.setViewportView(col_set_table);
center_panel.add(scroll_pane);
SwingUtils.setWindowLocationRelativeTo(col_set_frame, parent);
apply_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
for(int i=0; i<14; i++) {
boolean visibility = Boolean.parseBoolean(col_set_table.getModel().getValueAt(i, 0).toString());
String column_name = col_set_table.getModel().getValueAt(i, 1).toString();
//cols.get(column_name).setVisible(visibility);
if(visibility == false) column_model.removeColumn(cols.get(column_name));
System.out.println("Column from set " + cols.get(column_name).getHeaderValue());
System.out.println("<--->" + column_name + "<---->" + visibility);
}