Move confirmation OptionPane from SessionImpl to ConsolePanel

This commit is contained in:
Plopman 2018-02-22 00:09:51 +01:00
parent f31b1ab7e3
commit bf3682fa77
2 changed files with 52 additions and 44 deletions

View file

@ -32,7 +32,6 @@ import java.lang.reflect.UndeclaredThrowableException;
import java.net.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import javax.swing.*;
import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo;
@ -1437,13 +1436,10 @@ public class SessionImpl implements Session {
@Override
public boolean endUserSession(String userSessionId) {
try {
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to end userSessionId " + userSessionId + '?', "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (isConnected()) {
server.endUserSession(sessionId, userSessionId);
return true;
}
}
} catch (MageException ex) {
handleMageException(ex);
} catch (Throwable t) {
@ -1455,13 +1451,10 @@ public class SessionImpl implements Session {
@Override
public boolean muteUserChat(String userName, long durationMinutes) {
try {
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to mute user " + userName + " for " + durationMinutes + " minutes?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (isConnected()) {
server.muteUser(sessionId, userName, durationMinutes);
return true;
}
}
} catch (MageException ex) {
handleMageException(ex);
} catch (Throwable t) {
@ -1473,13 +1466,10 @@ public class SessionImpl implements Session {
@Override
public boolean setActivation(String userName, boolean active) {
try {
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to set active to " + active + " for user: " + userName + '?', "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (isConnected()) {
server.setActivation(sessionId, userName, active);
return true;
}
}
} catch (MageException ex) {
handleMageException(ex);
} catch (Throwable t) {
@ -1491,21 +1481,10 @@ public class SessionImpl implements Session {
@Override
public boolean toggleActivation(String userName) {
try {
if (JOptionPane.showConfirmDialog(null, "Did you want to set user: " + userName + " to active?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
return setActivation(userName, true);
}
if (JOptionPane.showConfirmDialog(null, "Did you want to set user: " + userName + " to INactive?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
return setActivation(userName, false);
}
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to toggle activation for user: " + userName + '?', "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (isConnected()) {
server.toggleActivation(sessionId, userName);
return true;
}
}
} catch (MageException ex) {
handleMageException(ex);
} catch (Throwable t) {
@ -1517,13 +1496,10 @@ public class SessionImpl implements Session {
@Override
public boolean lockUser(String userName, long durationMinute) {
try {
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to lock user: " + userName + " for " + durationMinute + " minutes?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (isConnected()) {
server.lockUser(sessionId, userName, durationMinute);
return true;
}
}
} catch (MageException ex) {
handleMageException(ex);
} catch (Throwable t) {

View file

@ -345,22 +345,54 @@ public class ConsolePanel extends javax.swing.JPanel {
private void btnEndSessionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEndSessionActionPerformed
int row = this.tblUsers.convertRowIndexToModel(tblUsers.getSelectedRow());
ConsoleFrame.getSession().endUserSession((String) tableUserModel.getValueAt(row, TableUserModel.POS_GAME_INFO));
String userSessionId = (String) tableUserModel.getValueAt(row, TableUserModel.POS_GAME_INFO);
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to end userSessionId " + userSessionId + '?', "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
ConsoleFrame.getSession().endUserSession(userSessionId);
}
}//GEN-LAST:event_btnEndSessionActionPerformed
private void btnMuteUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMuteUserActionPerformed
int row = this.tblUsers.convertRowIndexToModel(tblUsers.getSelectedRow());
ConsoleFrame.getSession().muteUserChat((String) tableUserModel.getValueAt(row, TableUserModel.POS_USER_NAME), ((Number) spinnerMuteDurationMinutes.getValue()).longValue());
String userName = (String) tableUserModel.getValueAt(row, TableUserModel.POS_USER_NAME);
long durationMinute = ((Number) spinnerMuteDurationMinutes.getValue()).longValue();
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to mute user: " + userName + " for " + durationMinute + " minutes?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
ConsoleFrame.getSession().muteUserChat(userName, durationMinute);
}
}//GEN-LAST:event_btnMuteUserActionPerformed
private void btnDeActivateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeActivateActionPerformed
int row = this.tblUsers.convertRowIndexToModel(tblUsers.getSelectedRow());
ConsoleFrame.getSession().toggleActivation((String) tableUserModel.getValueAt(row, TableUserModel.POS_USER_NAME));
String userName = (String) tableUserModel.getValueAt(row, TableUserModel.POS_USER_NAME);
if (JOptionPane.showConfirmDialog(null, "Did you want to set user: " + userName + " to active?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
ConsoleFrame.getSession().setActivation(userName, true);
return;
}
if (JOptionPane.showConfirmDialog(null, "Did you want to set user: " + userName + " to inactive?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
ConsoleFrame.getSession().setActivation(userName, false);
return;
}
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to toggle activation for user: " + userName + '?', "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
ConsoleFrame.getSession().toggleActivation(userName);
return;
}
}
}//GEN-LAST:event_btnDeActivateActionPerformed
private void btnLockUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLockUserActionPerformed
int row = this.tblUsers.convertRowIndexToModel(tblUsers.getSelectedRow());
ConsoleFrame.getSession().lockUser((String) tableUserModel.getValueAt(row, TableUserModel.POS_USER_NAME), ((Number) spinnerMuteDurationMinutes.getValue()).longValue());
String userName = (String) tableUserModel.getValueAt(row, TableUserModel.POS_USER_NAME);
long durationMinute = ((Number) spinnerMuteDurationMinutes.getValue()).longValue();
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to lock user: " + userName + " for " + durationMinute + " minutes?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
ConsoleFrame.getSession().lockUser(userName, durationMinute);
}
}//GEN-LAST:event_btnLockUserActionPerformed
private void btnRemoveTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveTableActionPerformed