ToggleUserAdminStatusAction.java :  » Source-Control » sourcejammer » org » sourcejammer » client » gui » action » Java Open Source

Java Open Source » Source Control » sourcejammer 
sourcejammer » org » sourcejammer » client » gui » action » ToggleUserAdminStatusAction.java
/*
 *  Copyright (C) 2001, 2002 Robert MacGrogan
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *
 * $Archive: SourceJammer$
 * $FileName: ToggleUserAdminStatusAction.java$
 * $FileID: 4073$
 *
 * Last change:
 * $AuthorName: Rob MacGrogan$
 * $Date: 6/24/03 12:54 AM$
 * $Comment: Moved message box/error dialog methods to MessageBoxUtil.$
 *
 * $KeyWordsOff: $
 */

package org.sourcejammer.client.gui.action;

import java.awt.event.ActionEvent;
import javax.swing.*;
import org.sourcejammer.client.gui.CommandCentral;
import org.sourcejammer.client.gui.MessageBoxUtil;
import org.sourcejammer.project.view.UserInfo;
import org.sourcejammer.client.gui.dialog.UserManagementDialog;

/**
 * Title:        SourceJammer 1.2
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:      SourceJammer Project
 * @author Robert MacGrogan
 * @version 1.0
 */

public class ToggleUserAdminStatusAction extends AbstractAction {

  public ToggleUserAdminStatusAction() {
  }
  public void actionPerformed(ActionEvent ev) {
    try {
      UserManagementDialog dialog = (UserManagementDialog)ev.getSource();
      UserInfo user = dialog.getSelectedUser();
      CommandCentral oCommand = CommandCentral.getInstance();
      boolean bProcede = true;
      String userName = user.getUserName();
      boolean bCurrStatus = user.getAdmin();
      String sCurrUserName = oCommand.getCurrentUserName();
      if (userName.equals(sCurrUserName) && bCurrStatus == true){
        String[] messages = {"This action will cause you to lose administrative status on this SourceJammer server.",
                             " ",
                             "Are you sure you want to procede?",
                             " "};
        int iResponse = JOptionPane.showConfirmDialog(oCommand.getRootAppFrame(),
                                      messages, "Procede with change to admin status?",
                                      JOptionPane.YES_NO_OPTION,
                                      JOptionPane.WARNING_MESSAGE);
        if (iResponse == JOptionPane.YES_OPTION){
          bProcede = true;
        }
        else {
          bProcede = false;
        }
      }
      if (bProcede){
        oCommand.setUserAdminStatus(userName, ! bCurrStatus);
      }
    }
    catch (Throwable thr){
      MessageBoxUtil.displayErrorMessage(thr.getMessage(), true);
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.