Implemented Issue#166: Allow table creator to remove table

This commit is contained in:
magenoxx 2013-03-20 08:09:36 +04:00
parent 8ef074ab92
commit 13c2b2d477

View file

@ -97,6 +97,7 @@ public class TablesPanel extends javax.swing.JPanel {
gameChooser = new GameChooser();
initComponents();
tableModel.setSession(session);
// disable replays
chkShowCompleted.setVisible(false);
@ -156,6 +157,8 @@ public class TablesPanel extends javax.swing.JPanel {
logger.info("Joining table " + tableId);
joinTableDialog.showDialog(roomId, tableId);
}
} else if (state.equals("Remove")) {
session.removeTable(roomId, tableId);
} else if (state.equals("Watch")) {
logger.info("Watching table " + tableId);
session.watchTable(roomId, tableId);
@ -278,6 +281,7 @@ public class TablesPanel extends javax.swing.JPanel {
} else {
hideTables();
}
tableModel.setSession(session);
reloadMessages();
@ -590,6 +594,8 @@ class TableTableModel extends AbstractTableModel {
private TableView[] tables = new TableView[0];
private static final DateFormat timeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
private Session session;
public void loadData(Collection<TableView> tables) throws MageRemoteException {
this.tables = tables.toArray(new TableView[0]);
this.fireTableDataChanged();
@ -605,6 +611,10 @@ class TableTableModel extends AbstractTableModel {
return columnNames.length;
}
public void setSession(Session session) {
this.session = session;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
@ -623,6 +633,10 @@ class TableTableModel extends AbstractTableModel {
case 6:
switch (tables[arg0].getTableState()) {
case WAITING:
String owner = tables[arg0].getControllerName();
if (session != null && owner.equals(session.getUserName())) {
return "Remove";
}
return "Join";
case DUELING:
return "Watch";