⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taskedit.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 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.util.Task;import vocal.util.Logger;import vocal.comm.VPPException;import java.util.Vector;import java.io.IOException;import java.lang.reflect.InvocationTargetException;import java.awt.Component;import javax.swing.SwingUtilities;import javax.swing.JOptionPane;import org.xml.sax.SAXException;public class TaskEdit extends EditorTask{  public TaskEdit(Editor editor)  {    super(editor);  }  public void doWork()  {    if (editor.getUserPanel() == null)    {      return;    }    int[] rows = editor.getTable().getSelectedRows();    if (rows.length == 0)    {      // if there are no selected users, there is nothing to edit      return;    }    editor.getUserPanel().setMode(UserPanel.EDIT_EXISTING_MODE);    // does nothing for a selected alias because that has lenght > 1 (the    // isAlias field is ture, and the master user and index are set)    loadUsers(rows);    // if single row is selected, get the data for that user and load it into    // the user panel. Otherwise, the panel should be blank.    if (rows.length == 1)    {      // find out if the selected row contains an alias name or the actual      // master user      Vector user = editor.getData().getUserAt(rows[0]);      if (user.elementAt(UserTableModel.IS_ALIAS).equals("true"))      {        // find out the master name this alias belongs to        String masterName =           (String) user.elementAt(UserTableModel.MASTER_NAME);        // find out the index of the master user for this alias        String masterIndexStr =           (String) user.elementAt(UserTableModel.MASTER_INDEX);        int masterIndex;        if (masterIndexStr == null)        {          masterIndex = editor.getData().findMasterIndex(masterName);          try          {            editor.getData().setValueAt(masterIndex + "", rows[0],                     UserTableModel.MASTER_INDEX);          }          catch (SAXException ex)          {            ex.printStackTrace();            JOptionPane.showMessageDialog(editor.getTopLevelAncestor(),                     "Could not update the master index for user "                     + masterName + " and alias "                     + user.elementAt(UserTableModel.USER_NAME)                     + " because: \n\n" + ex);          }          catch (IOException ex)          {            ex.printStackTrace();            JOptionPane.showMessageDialog(editor.getTopLevelAncestor(),                     "Could not update the master index for user "                     + masterName + " and alias "                     + user.elementAt(UserTableModel.USER_NAME)                     + " because: \n\n" + ex);          }          catch (VPPException ex)          {            ex.printStackTrace();            JOptionPane.showMessageDialog(editor.getTopLevelAncestor(),                     "Could not update the master index for user "                     + masterName + " and alias "                     + user.elementAt(UserTableModel.USER_NAME)                     + " because: \n\n" + ex);          }        }        else        {          masterIndex = Integer.parseInt(masterIndexStr);        }        // get the user data for the master user        user = editor.getData().getUserAt(masterIndex);        // if the user has not been loaded yet, do it        if (user.size() <= 1)        {          try          {            user = editor.getData().loadUserAt(masterIndex);          }          catch (IOException ex)          {            ex.printStackTrace();            JOptionPane.showMessageDialog(editor.getTopLevelAncestor(),                     "Could not load user data for user " + masterName                     + " because: \n\n" + ex);          }          catch (SAXException ex)          {            ex.printStackTrace();            JOptionPane.showMessageDialog(editor.getTopLevelAncestor(),                     "Could not load user data for user " + masterName                     + " because: \n\n" + ex);          }          catch (VPPException ex)          {            ex.printStackTrace();            JOptionPane.showMessageDialog(editor.getTopLevelAncestor(),                     "Could not load user data for user " + masterName                     + " because: \n\n" + ex);          }        }      }      editor.getUserPanel().setUserData(user);      // Once the data has been loaded, go through all the features and check if      // each one has a feature server configured. If not, turn off the feature      // and disable the gui for it.      Component[] components = editor.getUserPanel().getComponents();      for (int i = 0; i < components.length; i++)      {        if (Feature.class.isInstance(components[i]))        {          Feature feature = (Feature) components[i];          feature.checkFeatureServer();        }      }      // if more than one user was selected previously, the alias panel may      // have been removed. Call these methods to make shure all the      // appropriate panels are visible for the single user as selected by      // the check boxes      editor.getUserPanel().setShowAdmin(editor.isShowAdminColumnsSelected());      editor.getUserPanel().setShowUser(editor.isShowUserColumnsSelected());    }    else    {      // don't want to show the panel which allows to edit aliases when more      // than one user is selected because the same alias cannot be created      // for more than one uesr so editing aliases on multiple users at once      // does not make sense      editor.getUserPanel().removeAliasPanel();    }    try    {      SwingUtilities.invokeAndWait(new Runnable()      {        public void run()        {          editor.showUserEditorDialog();        }      });    }    catch (InvocationTargetException e)    {      e.printStackTrace();      JOptionPane.showMessageDialog(editor.getTopLevelAncestor(),               "Could not edit user because:\n\n" + e);    }    catch (InterruptedException e)    {      e.printStackTrace();      JOptionPane.showMessageDialog(editor.getTopLevelAncestor(),               "Could not edit user because:\n\n" + e);    }    if (editor.getUserPanel().getLastButtonClicked() == UserPanel.BUTTON_OK)    {      Vector newData = editor.getUserPanel().getUserData();      int[] users = editor.getTable().getSelectedRows();      // for each user      for (int i = 0; i < users.length; i++)      {        String userName = (String) editor.getData().getValueAt(users[i],                 UserTableModel.USER_NAME);        // change the data in the userTableModel        for (int dataId = 0; dataId <= UserTableModel.MAX_COLUMN_ID; dataId++)        {          String dataElement = (String) newData.elementAt(dataId);          if (dataElement != null)          {            try            {              // if we are editing an alias              if (editor.getData().getValueAt(users[i],                       UserTableModel.IS_ALIAS).equals("true"))              {                String masterIndexStr =                   (String) editor.getData().getValueAt(users[i],                         UserTableModel.MASTER_INDEX);                userName = (String) editor.getData().getValueAt(users[i],                         UserTableModel.MASTER_NAME);                int index;                if (masterIndexStr == null)                {                  index = editor.getData().findMasterIndex(userName);                  editor.getData().setValueAt(index + "", users[i],                           UserTableModel.MASTER_INDEX);                }                else                {                  index =                     Integer.parseInt((String) editor.getData().getValueAt(users[i],                           UserTableModel.MASTER_INDEX));                }                users[i] = index;              }              editor.getData().setValueAt(dataElement, users[i], dataId);            }            catch (Exception ex)            {              ex.printStackTrace();              JOptionPane.showMessageDialog(editor,                       "Could not set value for user " + userName                       + " because " + ex);            }          }        }        editor.getData().fireTableDataChanged();        if (i % 10 == 0)        {          Logger.swingLog("Writing back user # " + i + " - " + userName);        }        // if an alias was removed (and it was higher in the table than the        // user being edited) then the row for this user may have changed (if        // aliases were visible in the table)        users[i] = editor.getData().findMasterIndex(userName);        // write back the data to the pserver        try        {          editor.getData().writeBackUserAt(users[i], true, true);        }        catch (Exception ex)        {          ex.printStackTrace();          JOptionPane.showMessageDialog(editor,                   "Could not write back data for user "                   + editor.getData().getValueAt(users[i], UserTableModel.USER_NAME)                   + " because " + ex);        }      }      // now that we no longer care about what row the edited user was at, sort      // the data in the table based on user name. This is done so that if any      // aliases were added, then end up in the correct place      editor.getData().sortByUserName();      editor.getData().fireTableDataChanged();      Logger.swingLog("Done writing back users");    }   // end if ok clicked    // if ok or cancel were clicked, make sure the editor is cleared    editor.getUserPanel().clear();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -