@Override
    public void update(Observable o, Object arg) {
        Integer mode = (Integer) arg;
        switch (mode) {
            case ApplicationState.MESSAGES_UPDATED:
                Messages m = (Messages) o;
                DefaultTableModel tableModel = (DefaultTableModel) jTable2.getModel();
                tableModel.setRowCount(0);
                for (Message message : m.getAll()) {
                    String[] row = {message.getSender().getUsername(), message.getText(), sdf.format(message.getDate())};
                    tableModel.addRow(row);
                }

                // scroll down
                JViewport viewport = (JViewport) jTable2.getParent();
                Rectangle rect = jTable2.getCellRect(jTable2.getRowCount() - 1, 0, true);
                viewport.scrollRectToVisible(rect);

                break;
            case ApplicationState.USERS_UPDATED:
                Users u = (Users) o;
                DefaultListModel model = (DefaultListModel) usersList.getModel();
                model.clear();
                for (User user : u.getAll()) {
                    model.addElement(user.getUsername());
                }
                break;
        }
    }