📄 editor.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 vocal.comm.VPPNoSuchFileException;import vocal.ui.AccreditPanel;import vocal.ui.AdministrativeLoginPanel;import vocal.userEditor.JTest.TableData;import vocal.util.Logger;import java.io.IOException;import java.util.*;import javax.swing.*;import javax.swing.border.Border;import javax.swing.border.EmptyBorder;import javax.swing.table.*;import java.awt.BorderLayout;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 Editor extends JPanel{ /** * Displays the list of users and their configuration */ private JTable table; private JTable table1; /** * Contains the internal representation of the account data for all users */ private UserTableModel 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 JDialog userEditorDialog; private UserPanel userPanel; private JScrollPane scroller; protected boolean showCommon = true; protected boolean showAccredit = false; protected JPanel panelb = new JPanel(); protected JPanel panelacc = new JPanel(); private JDialog findDialog; private String acc_groupname = null; //被选中的授权组名 //private boolean is_editaccredit = false; //是否可以编辑授权选择checkbox TableColumn column; VPPTransactionWrapper connection; PServerInterface psInterface; ColumnModelListener columnListener = new ColumnModelListener(); //在帐号管理中的构造函数 public Editor(VPPTransactionWrapper conn) { setLayout(new BorderLayout()); connection = conn; //table1 = new JTable(); //table1.setAutoCreateColumnsFromModel(false); //TableCellRenderer renderer = new CheckCellRenderer(); //TableCellEditor editora = new ChangeButtonEditor(new JCheckBox(),table1); /** TableCellEditor editor = new DefaultCellEditor(new JCheckBox(){ public void actionPerformed(ActionEvent e) { System.out.print("zzz"); } } ); */ //TableColumn column = new TableColumn(0,30,renderer, editora); //columns[0] = new TableColumn(0,30,renderer, editora); //table1.addColumn(column); table = new JTable(); table.setAutoCreateColumnsFromModel(false); PServerInterface psInterface = new PServerInterface(conn); data = new UserTableModel(psInterface); table.setModel(data); // configure column widths ColumnInfo[] columns = data.getColumns(); TableCellRenderer renderer = new CheckCellRenderer(); TableCellEditor editora = new ChangeButtonEditor(new JCheckBox(),table1); TableColumn column = new TableColumn(1,30,renderer, editora); //columns[0] = new TableColumn(0,30,renderer, editora); //table1.addColumn(column); //System.out.println("Please print columns.length:"); System.out.println(columns.length); for (int i = 0; i < columns.length; i++) { table.addColumn(columns[i]); } table.removeColumn(columns[1]); //屏蔽choose列的显示 table.setDefaultRenderer(String.class, new UserRenderer()); /** TableCellEditor editor = new DefaultCellEditor(new JCheckBox(){ public void actionPerformed(ActionEvent e) { System.out.print("zzz"); } } ); */ // make the table scrollable and add it to the panel scroller = new JScrollPane(table); //add(table1,BorderLayout.BEFORE_LINE_BEGINS); add(scroller, BorderLayout.CENTER); createPopupMenu(); createButtons(); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // so it scrolls horizontally } //在授权中心的构造函数 public Editor(VPPTransactionWrapper conn,String groupname) { setLayout(new BorderLayout()); connection = conn; acc_groupname = groupname; table = new JTable(); table.setAutoCreateColumnsFromModel(false); PServerInterface psInterface = new PServerInterface(conn); data = new UserTableModel(psInterface); table.setModel(data); // configure column widths ColumnInfo[] columns = data.getColumns(); TableCellRenderer renderer = new CheckCellRenderer(); TableCellEditor editora = new ChangeButtonEditor(new JCheckBox(),table1); TableColumn column = new TableColumn(1,30,renderer, editora); //columns[0] = new TableColumn(0,30,renderer, editora); //table1.addColumn(column); System.out.println("Please print columns.length:"); System.out.println(columns.length); for (int i = 0; i < columns.length; i++) { if(1==i) { table.addColumn(column); } else { table.addColumn(columns[i]); } } table.moveColumn(1,0); table.setDefaultRenderer(String.class, new UserRenderer()); /** TableCellEditor editor = new DefaultCellEditor(new JCheckBox(){ public void actionPerformed(ActionEvent e) { System.out.print("zzz"); } } ); */ // make the table scrollable and add it to the panel scroller = new JScrollPane(table); //add(table1,BorderLayout.BEFORE_LINE_BEGINS); 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); psInterface = new PServerInterface(connection); Component parent = this.getTopLevelAncestor(); try { if (JDialog.class.isInstance(parent)) { userEditorDialog = new JDialog((JDialog) this.getTopLevelAncestor(), "Edit user", false); } else if (JFrame.class.isInstance(parent)) { userEditorDialog = new JDialog((JFrame) this.getTopLevelAncestor(), "Edit user", false); } userPanel = new UserPanel(psInterface); // for those people with tiny monitors, as per request, make the user // editor panel scrollable. JScrollPane scroller = new JScrollPane(userPanel); 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(userPanel); } 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 user", false); } else if (JFrame.class.isInstance(parent)) { findDialog = new JDialog((JFrame) this.getTopLevelAncestor(), "Find user", 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); } private void createPopupMenu() { popupMenu = new JPopupMenu(); AbstractAction action = new AbstractAction("View") { public void actionPerformed(ActionEvent e) { TaskView task = new TaskView(Editor.this); task.start(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -