Basically, I'm working on a Client Server Architecture so Objects can be modified externally by some Clients.
I have a bank :
public class Bank{
private List<BankingOperation> operationList = new ArrayList<BankingOperation>();
public void addOperation(BankingOperation op) {
this.operationList.add(op);
//...
}
And my Server :
public class ServerBank extends JFrame {
private Bank bank;
private JTable table;
private OperationTableModel model;
public ServerBank() {
this.bank = new Bank();
this.model= new OperationTableModel(this.bank.getOperationList());
table = new JTable(model);
getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
pack();
}
public static void main (String args[]) throws Exception {
ServerBank frame=new ServerBank();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,700);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
class OperationTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
private List<BankingOperation> operationList;
public String[] colNames = { "Date", "Login", "Customer","Account", "Operation", "Amount", "Final Balance" };
public Class<?>[] colTypes = { String.class, String.class, String.class, String.class, String.class, Integer.class,
Integer.class };
public OperationTableModel(List<BankingOperation> operationList) {
super();
this.operationList = operationList;
}//...
}
Clients can add an Operation in the Bank operationList by calling addOperation().
The question is: How can the JTable detect that and refresh the display?
Because Clients are not using the TableModel methods for adding Operations. They have no access to this class. On top of that, I don't know if giving the whole operationList of the Bank in the TableModel constructor is a good idea...