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

📄 accrediteditor.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * ====================================================================
 * 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 vocal.comm.VPPNoSuchFileException;
import vocal.data.AccreditTab;
import vocal.data.DeployServers;
import vocal.userEditor.AccreditAdd;
import vocal.ui.AccreditPanel;
import vocal.ui.AdministrativeLoginPanel;

import java.io.IOException;

import java.util.*;

import javax.swing.*;
import javax.swing.table.*;


import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;

import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;




/**
 * This class displays the main table of all users. <p>
 *
 * It contains a popup menu which contains actions which allow the the table
 * to be manipulated. It is possible to delete a user, add a new user, edit
 * and existing user and view the data for a user.
 *
 * It should be possible to edit a single user account at a time or multiple
 * accounts. When multiple accounts are edited, the UserPanel which serves as
 * the editor is not loaded with data for any particular user. When the data is
 * read back from this dialog, only the data which has changed is saved for all
 * users while all other data remians unchanged. This allows for bulk
 * provisioning of users.
 *
 * In order to edit a user, a UserPanel is instantiated, the pServer is
 * queried for the user's data, then the UserPanel is instructed to load the
 * data into all its elements for display. The UserPanel is then dispalyed in
 * a modal dialog. When the dialog has been dismissed the data is collected from
 * the UserPanel and saved to the table model and the pServer.
 */
public class AccreditEditor extends JPanel
{
	int subnumber = 2;
  /**
   * Displays the list of users and their configuration
   */
  private JTable table;

  /**
   * Contains the internal representation of the account data for all users
   */
  //private AccreditTable data;
  private AccreditGroupModel data;
  /**
   * Menu which appears at right click to edit/delete users
   */
  private JPopupMenu popupMenu;

  private JCheckBox showUserColumns;
  private JCheckBox showAdminColumns;

  private JCheckBox showAliases;
  private JCheckBox showAllUsers;
  
  private AccreditTab tabjpanel[]= new AccreditTab[subnumber];
  private JDialog userEditorDialog;
  private UserAccredit useraccDialog;
  private AccreditAdd accreditadd;
  private JScrollPane scroller;

  private JDialog findDialog;
  
  
  VPPTransactionWrapper connection;

  ColumnModelListener columnListener = new ColumnModelListener();


  public AccreditEditor(VPPTransactionWrapper conn)
  {
    setLayout(new BorderLayout());

    if (conn == null)
    {
      connection = DeployServers.getConnection();

      if (connection == null)
      {
        System.out.println("Error: null connection");

        return;
      }
    }
    else
    {
    	connection = conn;
    }
    

    table = new JTable();

    table.setAutoCreateColumnsFromModel(false);

    PServerAccrInterface psInterface = new PServerAccrInterface(conn);

    //data = new AccreditTable(psInterface);
    data = new AccreditGroupModel(psInterface);
    
    table.setModel(data);

    // configure column widths
    ColumnInfo[] columns = data.getColumns();
    
    //int columns = 4; 
    for (int i = 0; i < columns.length; i++)
    {
      table.addColumn(columns[i]);
      System.out.println(columns[i]);
    }

    table.setDefaultRenderer(String.class, new UserRenderer());

    // make the table scrollable and add it to the panel
    scroller = new JScrollPane(table);

    add(scroller, BorderLayout.CENTER);

    createPopupMenu();

    createButtons();

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);    // so it scrolls horizontally
  }


  /**
   * Create a new userEditor. This should include re-reading from the pserver
   * the provisioning information for the servers in the system (feature,
   * marshal). This is here so that it is possible to re-crete the
   * user editor dialog if there is any possibility that the server info
   * has changed (groups added, etc).
   */
  public void init()
  {

    // this needs to be wiped out because it stores the parsed lists of
    // feature and marshal servers
    //PServerInterface psInterface = new PServerInterface(connection);
	PServerAccrInterface psInterface = new PServerAccrInterface(connection);
	  
    Component parent = this.getTopLevelAncestor();

    try
    {
      if (JDialog.class.isInstance(parent))
      {
        userEditorDialog = new JDialog((JDialog) this.getTopLevelAncestor(),
                "Edit AccreditGroup", false);
      }
      else if (JFrame.class.isInstance(parent))
      {
        userEditorDialog = new JDialog((JFrame) this.getTopLevelAncestor(),
                "Edit AccreditGroup", false);
      }

      //userPanel = new UserPanel(psInterface);
      //accreditAdd = new AccreditAdd(userEditorDialog,subnumber,tabjpanel);
      accreditadd = new AccreditAdd(psInterface,subnumber);
      //accreditadd = new AccreditAdd(psInterface,subnumber,tabjpanel);
      
      // for those people with tiny monitors, as per request, make the user
      // editor panel scrollable.
      JScrollPane scroller = new JScrollPane(accreditadd);
      
      userEditorDialog.setContentPane(scroller);
      userEditorDialog.setModal(true);      
      userEditorDialog.pack();

      // This is done so that this
      // component is cleared even if the user closed this panel by clicking the
      // close icon in the title bar. (Tried an ancestorListener on the user
      // panel, but that gets called even if the dialog was dismissed via ok or
      // cancel.
      userEditorDialog.addWindowListener(accreditadd);
    }
    catch (IOException e)
    {
      JOptionPane.showMessageDialog(this,
              "Could not create user panel because:\n" + e
              + "\n\nYou may browse users but you will not be able to add or edit.");
    }
    catch (VPPNoSuchFileException ex)
    {
      JOptionPane.showMessageDialog(this,
              "Could not create user panel because:\n" + ex
              + "\n\nYou may browse users but you will not be able to add or edit.");
    }
   
/*
    findDialog = new JDialog();

    if (JDialog.class.isInstance(parent))
    {
      findDialog = new JDialog((JDialog) this.getTopLevelAncestor(),
              "Find group", false);
    }
    else if (JFrame.class.isInstance(parent))
    {
      findDialog = new JDialog((JFrame) this.getTopLevelAncestor(),
              "Find group", false);
    }

    findDialog.setContentPane(new UserSearchPanel(table, data));
    findDialog.setModal(true);
    findDialog.pack();
 */   
     
    columnListener.actionPerformed(new ActionEvent(showAdminColumns, 0,
            null));
    //columnListener.actionPerformed(new ActionEvent(showUserColumns, 0, null));
/*
    showAliases.setSelected(false);
*/ 
  }
  
  
  /**
   * Create a new userEditor. This should include re-reading from the pserver
   * the provisioning information for the servers in the system (feature,
   * marshal). This is here so that it is possible to re-crete the
   * user editor dialog if there is any possibility that the server info
   * has changed (groups added, etc).
   */
  
  private void createPopupMenu()
  {
    popupMenu = new JPopupMenu();

    AbstractAction action = new AbstractAction("View")
    {
      public void actionPerformed(ActionEvent e)
      {
        AccreditTaskView task = new AccreditTaskView(AccreditEditor.this);

        task.start();
      }

    };

    popupMenu.add(action);
    
    action = new AbstractAction("Accredit")
    {
      public void actionPerformed(ActionEvent e)
      {
    	  if (useraccDialog == null)
    	    {  	 
    		  String groupname = (String) table.getValueAt(table.getSelectedRow(),0);
    		 
    		  useraccDialog = new UserAccredit(AccreditEditor.this,connection,groupname);
    	
    		  useraccDialog.setModal(true);
    	    }

    	    Container parent = AccreditEditor.this.getTopLevelAncestor();
          
    	    //accrediteditor.init();   
    	    //editor.loadUserNames();   s 	    
    	    
    	    parent.setVisible(false);
    	    useraccDialog.setVisible(true);
    	    parent.setVisible(true);

    	    if (JFrame.class.isInstance(parent))
    	    {
    	      ((JFrame) parent).toFront();
    	      ((JFrame) parent).setState(JFrame.NORMAL);
    	    }
      }

    };

    popupMenu.add(action);
    popupMenu.addSeparator();

    
    action = new AbstractAction("Edit")
    {
      public void actionPerformed(ActionEvent e)
      {
        if (!showUserColumns.isSelected() &&!showAdminColumns.isSelected())
        {
          JOptionPane.showMessageDialog(AccreditEditor.this.getTopLevelAncestor(),
                  "Select \"Show user data\" and/or \"Show admin data\" to edit an account.");
        }
        else
        {        
          AccreditTaskEdit task = new AccreditTaskEdit(AccreditEditor.this);
          task.start();
        }
      }

    };

    popupMenu.add(action);

    action = new AbstractAction("Delete")
    {
      public void actionPerformed(ActionEvent e)
      {
        AccreditTaskDelete task = new AccreditTaskDelete(AccreditEditor.this);

        task.start();
      }

    };

    popupMenu.add(action);

    action = new AbstractAction("New")
    {
      public void actionPerformed(ActionEvent e)
      {
    	  if (accreditadd == null)
          {
            return;
          }
    	  if (!showUserColumns.isSelected() &&!showAdminColumns.isSelected())
          {
            JOptionPane.showMessageDialog(AccreditEditor.this.getTopLevelAncestor(),
                    "Select \"Show user data\" and/or \"Show admin data\" to create a new account.");

            return;
          }
    /*
    	  PServerAccrInterface psInterface = new PServerAccrInterface(connection);
        //accreditadd = new AccreditAdd(userEditorDialog,subnumber,tabjpanel);
    	try {
			accreditadd = new AccreditAdd(psInterface,subnumber,tabjpanel);
		} catch (VPPNoSuchFileException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	*/
    	  
        //popupMenu.setVisible(false);
        
        //accreditadd.setVisible(true);
        
        //accreditadd.setMode(UserPanel.ADD_NEW_MODE);
    	  
        accreditadd.setMode(AccreditAdd.ADD_NEW_MODE);
        
        Vector dummyGroup = data.getDummyGroup();

        accreditadd.setGroupData(dummyGroup);
        //userPanel.setUserData(dummyUser);
        showGroupEditorDialog();
        
        if (accreditadd.getLastButtonClicked() == AccreditAdd.BUTTON_OK)
        {
        	Vector newData = accreditadd.getGroupData(); 
        	String newGroupname = (String) newData.elementAt(data.GROUP_NAME);
        	
	        if (newGroupname == null) //they didn't change the name so it must still be the default
	        {
	        	newGroupname = (String)dummyGroup.elementAt(AccreditGroupModel.GROUP_NAME);
	        	//newGroupname = "aaa";
	        }
	        
	       
	        // Check if another group with the same name exists already
	        if (data.groupExists(newGroupname))
	        {
	          JOptionPane.showMessageDialog(AccreditEditor.this.getTopLevelAncestor(),
	                  "The group named " + newGroupname

⌨️ 快捷键说明

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