Sisi le righe che provo a prendere contengono dati, inoltre ho impostato la SINGLE_SELECTION quindi non dovrei utilizzare getSelectedRow.
Ora temo anche di non aver valutato bene il problema, perchè avviando in debug, il model(MVC) si aggiorna correttamente, ma l'interfaccia no!
Scusate se ora il titolo è errato
Vi posto direttamente il codice interessato:
Questi sono nella classe che rappresenta la view
codice:
public void update(Observable o, Object arg) {
// "o" è l'oggetto che ha invocato il metodo e "arg" è l'oggetto che ha inviato, ma a noi serve solo l'oggetto che ci è stato inviato
if(enableRosaTab)
refreshRosaTable((HashSet<Giocatore>) arg);
else
refreshFormazioneTable((HashSet<Giocatore>) arg);
}
private void refreshFormazioneTable(HashSet<Giocatore> team) {
// creo matrici dati
int num = getNumeroTitolari(team);
titolari = new Object[num][titolariCols.length];
riserve = new Object[team.size() - num][riserveCols.length];
int titolariInd = 0, riserveInd = 0;
for(Giocatore g : team) {
if(g.isTitolare()) {
titolari[titolariInd][0] = g;
titolari[titolariInd][1] = g.getRuolo();
titolariInd++;
} else {
riserve[riserveInd][0] = g;
riserve[riserveInd][1] = g.getRuolo();
riserveInd++;
}
}
// setto dati
setModel(tblTitolari, titolari, titolariCols);
setModel(tblRiserve, riserve, riserveCols);
}
private void setModel(JTable tbl, Object[][] data, String[] headers) {
tbl.setModel(new DefaultTableModel(data, headers) {
public boolean isCellEditable(int rowIndex, int colIndex) {
return false;
}
});
tbl.updateUI();
}
Questo il controller
codice:
public void actionPerformed(ActionEvent e) {
JButton[] buttons = view.getButtons();
try{
if(e.getSource().equals(buttons[0])) {
try {
model.addGiocatore(view.getSelectedPlayer(buttons[0]));
view.updateBudget(model.getBudget());
} catch(AlreadyInTeamException exc) {
view.showMessage("Giocatore già in rosa!", JOptionPane.WARNING_MESSAGE);
} catch(TeamFullException exc) {
view.showMessage("Rosa al completo!", JOptionPane.WARNING_MESSAGE);
}
}
} catch (NullPointerException npe) {
npe.printStackTrace();
}
if(e.getSource().equals(buttons[1])) {
try {
model.removeGiocatore(view.getSelectedPlayer(buttons[1]));
view.updateBudget(model.getBudget());
} catch(NoSuchElementException exc) {
view.showMessage("Il giocatore non è presente in rosa", JOptionPane.ERROR_MESSAGE);
}
}
if(e.getSource().equals(buttons[2])) {
model.setTitolare(view.getSelectedPlayer(buttons[1]), true);
}
if(e.getSource().equals(buttons[3])) {
model.setTitolare(view.getSelectedPlayer(buttons[3]), false);
}
if(e.getSource().equals(buttons[4])) {
if(view.showQuestion("Sei sicuro di voler inviare la tua squadra? Andando avanti non potrai più modificarla!") == JOptionPane.YES_OPTION) {
try {
server.uploadRosa(model.getUser(), model);
} catch(RemoteException e1) {
e1.printStackTrace();
view.showMessage("Errore di connessione con il server", JOptionPane.ERROR_MESSAGE);
}
}
}
if(e.getSource().equals(buttons[5])) {
try {
if(server.isTeamEditable()) {
Modulo m = new Modulo(view.getSelectedModulo());
if(m.checkFormazione(model.getGiocatori()))
server.uploadRosa(model.getUser(), model);
else
view.showMessage("I titolari inseriti non corrispondono al modulo selezionato!", JOptionPane.ERROR_MESSAGE);
}
} catch(RemoteException e2) {
e2.printStackTrace();
}
}
if(e.getSource().equals(buttons[6])) {
try {
view.updateClassifica(server.getClassifica());
} catch(RemoteException e1) {
e1.printStackTrace();
view.showMessage("Errore di connessione con il server", JOptionPane.ERROR_MESSAGE);
}
}
}
E per quanto riguarda il model l'ho già provato e riprovato e fa tutto correttamente, anche ora che ho problemi con l'interfaccia il model si aggiorna correttamente...
Non mi assalite se ho scritto qualche castroneria XD sono nuovo sia a mvc che ad altre cose che ho inserito, come le JTable
E grazie per le risposte veloci!