📄 standaloneusereditor.java
字号:
/* * ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */package vocal.userEditor;import vocal.comm.VPPTransactionWrapper;import javax.swing.*;import java.net.ConnectException;import org.w3c.dom.Document;import java.util.Vector;import java.io.IOException;public class StandaloneUserEditor extends JPanel{ UserPanel uPanel; AccreditAdd aPanel; PServerInterface psInterface; PServerAccrInterface psAccrInterface; private Vector currentUser = null; public StandaloneUserEditor(VPPTransactionWrapper conn) throws Exception { this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); psInterface = new PServerInterface(conn); psAccrInterface = new PServerAccrInterface(conn); try { uPanel = new UserPanel(psInterface); aPanel = new AccreditAdd(psAccrInterface,4); } catch (IOException e) { System.out.println("Could not create user panel"); e.printStackTrace(); JOptionPane.showMessageDialog(this, e.getMessage() + "Could not create editor screen ", "Error", JOptionPane.ERROR_MESSAGE); throw e; } uPanel.setShowAdmin(false); uPanel.setShowUser(true); uPanel.setMode(UserPanel.EDIT_EXISTING_MODE); add(uPanel); aPanel.setShowAdmin(false); aPanel.setShowUser(true); aPanel.setMode(AccreditAdd.EDIT_EXISTING_MODE); add(aPanel); } public void setUser(String userName) throws Exception { uPanel.clear(); try { Document dom = psInterface.getUserNamed(userName); currentUser = UserTableModel.convertUserToVector(dom); } catch (Exception e) { System.out.println("Could not load user " + userName); e.printStackTrace(); JOptionPane.showMessageDialog(this, "Could not load user data for user " + userName + ". " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); throw e; } uPanel.setUserData(currentUser); } public void writeBack() { Vector changes = uPanel.getUserData(); // get user data should return values for only the fields that were changed // the rest of them will be returned as null and need to be gotten form the // user configuration loaded from xml for (int i = 0; i < changes.size(); i++) { if (changes.elementAt(i) != null) { currentUser.setElementAt(changes.elementAt(i), i); } } // now need to write back the alias files String aliases = (String) currentUser.elementAt(UserTableModel.ALIASES); while (aliases.length() > 0) { String alias = aliases.substring(0, aliases.indexOf(";")); aliases = aliases.substring(aliases.indexOf(";") + 1); String userName = (String) currentUser.elementAt(UserTableModel.USER_NAME); if (!psInterface.saveAlias(alias, userName)) { // could not save this alias because it is not unique // remove it from the list of aliases in the vector for this user // since it is not a valid alias String aliasList = UserTableModel.removeAliasFromList(alias, (String) currentUser.elementAt(UserTableModel.ALIASES)); currentUser.setElementAt(aliasList, UserTableModel.ALIASES); // complain JOptionPane.showMessageDialog(null, "Could not create alias " + alias + " for user " + userName + " because the alias is not unique."); } } // end for all aliases Document dom = UserTableModel.convertUserToDocument(currentUser); psInterface.saveUser((String) currentUser.elementAt(UserTableModel.USER_NAME), dom); try { Writer.writeCpl(currentUser,psInterface); } catch (Exception ex) { // complain JOptionPane.showMessageDialog(null, "Could not create CPL for user " + currentUser.elementAt(UserTableModel.USER_NAME) + " because " + ex.getMessage()); } try { Writer.writeContactList(currentUser,psInterface); } catch (Exception ex) { // complain JOptionPane.showMessageDialog(null, "Could not create contact list for user " + currentUser.elementAt(UserTableModel.USER_NAME) + " because " + ex.getMessage()); } } public int getLastButtonClicked() { return uPanel.getLastButtonClicked(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -