📄 entitypermissionpanel.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * CallViewPanel.java * * Created on 27 March 2003, 00:11 */package crms.applet;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.border.*;import javax.swing.event.*;import java.util.*;import crms.ui.*;import crms.vo.*;import crms.module.*;import crms.util.*;import java.text.*;import java.beans.*;import java.io.*;import java.text.*;import javax.swing.table.*;/** * * @author dmurphy */public class EntityPermissionPanel extends CRMSPanel implements CallbackDestination { JButton buttonSave = new JButton("Save"); JButton buttonReset = new JButton("Reset"); JButton buttonCancel = new JButton("Close"); JButton btnSearch = new JButton("Select"); JButton btnAdd = new JButton("Add"); JPanel buttonPanel = new JPanel(); JPanel grid = new JPanel(new GridBagLayout()); private EntityType entityType = null; private int entityID = -1; PermissionTableModel permModel = new PermissionTableModel(PermissionType.PERMISSION_USER); PermissionEditTable permPermissionTable = new PermissionEditTable(permModel); JScrollPane permScrollPane = new JScrollPane(permPermissionTable); AutoTextField textFor = new AutoTextField(PanelManager.getInstance().getUIDList(), AutoTextField.DEFAULT_MIN_COMPARE_LENGTH); DefaultComboBoxModel departmentModel = new DefaultComboBoxModel(); JComboBox comboDepartment = new JComboBox(departmentModel); DefaultComboBoxModel locationModel = new DefaultComboBoxModel(); JComboBox comboLocation = new JComboBox(locationModel); /*PermissionTableModel groupModel = new PermissionTableModel(PermissionType.PERMISSION_GROUP); PermissionEditTable groupPermissionTable = new PermissionEditTable(groupModel); JScrollPane groupScrollPane = new JScrollPane(groupPermissionTable); */ // The everyone checkboxes /*JCheckBox allReadCheckBox = new JCheckBox("Read"); JCheckBox allWriteCheckBox = new JCheckBox("Write"); JCheckBox allDeleteCheckBox = new JCheckBox("Delete"); JCheckBox allSecurityheckBox = new JCheckBox("Delete"); */ //private StaffMember addStaffMember = null; JPanel permPanel = new JPanel(new BorderLayout()); JPanel wrapper = null; //JPanel groupPanel = new JPanel(new BorderLayout()); //JPanel allPanel = new JPanel(new FlowLayout()); JPopupMenu menu = null; Permission entityPermission = null; CallbackDestination callback = null; /** Creates a new instance of EntityPermissionViewPanel */ public EntityPermissionPanel() { } public void setEntity(EntityType type, int entityID, Permission entityPermission) { this.entityType = type; this.entityID = entityID; this.entityPermission = entityPermission; } public void setCallback(CallbackDestination callback) { this.callback = callback; } public EntityPermissionPanel(EntityType type, int entityID, Permission entityPermission) { this.entityType = type; this.entityID = entityID; this.entityPermission = entityPermission; } public void init() { setLayout(new BorderLayout()); setBackground(Color.WHITE); buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.setBackground(Color.WHITE); buttonPanel.add(buttonSave); buttonPanel.add(buttonReset); buttonPanel.add(buttonCancel); buttonSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); saveData(); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); buttonReset.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); refreshData(); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { returnToPrevious(); } }); btnSearch.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { addPermission(); } } ); btnAdd.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Object objDept = departmentModel.getSelectedItem(); Object objSite = locationModel.getSelectedItem(); String dept = null; String site = null; if (objDept instanceof Department && ((Department)objDept).getCode() != null) { dept = objDept.toString(); } if (objSite instanceof Site && ((Site)objSite).getSiteCode() != null) { site = objSite.toString(); } Permission p = new Permission(); p.setEntityID(entityID); p.setEntityType(entityType); p.setLocation(site); p.setDivision(dept); p.setPower(0); // not valid in this context p.setReference(null); p.setID(null); p.setPermission(Permission.READ_PERMISSION, true); permModel.permissions.add(p); permPermissionTable.tableChanged(new TableModelEvent(permModel)); } } ); textFor.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent ev) { if (textFor.isAutomatic()) { Server server = ServerFactory.getInstance().getServer(); ServerCommand command = new ServerCommand(StaffModule.STAFF_SEARCH_SUBMIT); command.setParameter(StaffModule.PARAM_STAFF_UID, textFor.getText()); ServerResponse sr = server.sendCommand(command); ArrayList staff = (ArrayList) sr.getPart("staff"); if (staff != null && staff.size() == 1) { setStaffMemberFound((StaffMember)staff.get(0)); return; } } if (!textFor.getText().trim().equals("")) { addPermission(); } } } ); permPermissionTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent ev) { System.out.println("permPermissionTable.mouseClicked"); if (!permPermissionTable.isEnabled()) { return; } /*if (ev.getButton() == MouseEvent.BUTTON1 && ev.getClickCount() == 2) { addPermission(PermissionType.PERMISSION_USER); }*/ if (ev.getButton() == MouseEvent.BUTTON3) { showPopupMenu(PermissionType.PERMISSION_USER, ev); } } }); Insets defaultInsets = new Insets(4,0,0,4); grid.setBackground(Color.WHITE); grid.add(new JLabel("Staff Member"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, defaultInsets, 0, 0)); grid.add(textFor, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); JLabel lblOR = new JLabel("OR"); lblOR.setFont(new java.awt.Font("Serif", 1, 16)); grid.add(lblOR, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, defaultInsets, 0, 0)); grid.add(btnSearch, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, defaultInsets, 0, 0)); grid.add(new JLabel("Division"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, defaultInsets, 0, 0)); grid.add(comboDepartment, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); grid.add(new JLabel("Location"), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, defaultInsets, 0, 0)); grid.add(comboLocation, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); grid.add(btnAdd, new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, defaultInsets, 0, 0)); /* groupPermissionTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent ev) { System.out.println("groupPermissionTable.mouseClicked"); if (!groupPermissionTable.isEnabled()) { return; } if (ev.getButton() == MouseEvent.BUTTON1 && ev.getClickCount() == 2 ) { addPermission(PermissionType.PERMISSION_GROUP); } if (ev.getButton() == MouseEvent.BUTTON3) { showPopupMenu(PermissionType.PERMISSION_GROUP, ev); } } });*/ setLayout(new BorderLayout()); setBackground(Color.WHITE); permPanel.setBorder(BorderFactory.createEmptyBorder()); permPanel.setBackground(Color.WHITE); permScrollPane.getViewport().setBackground(Color.WHITE); JTableHeader header = permPermissionTable.getTableHeader(); permPanel.add(header,BorderLayout.NORTH); permPanel.add(permScrollPane, BorderLayout.CENTER); wrapper = new JPanel(new BorderLayout()); wrapper.setBackground(Color.WHITE); wrapper.add(permPanel, BorderLayout.CENTER); wrapper.add(grid, BorderLayout.SOUTH); add(wrapper, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); refreshData(); securePanel(); } protected void returnToPrevious() { if (callback != null) callback.callback(this, CRMSComponent.CB_CLOSE_WINDOW, null); } public void securePanel() { if (!entityPermission.canSecurity()) { permPermissionTable.setEnabled(false); buttonSave.setVisible(false); buttonReset.setVisible(false); grid.setVisible(false); } } /** * Handles displaying of the popup menu that is used, on right clicking * within either of the permission tables, for deleting an existing * permission. */ public void showPopupMenu(PermissionType type, MouseEvent ev) { final PermissionType finalType = type; JScrollPane activeScrollPane = null; JTable activeTable = null; PermissionTableModel activeModel = null; Point location = null; if (type.equals(PermissionType.PERMISSION_USER)) { activeTable = permPermissionTable; activeScrollPane = permScrollPane; activeModel = permModel; location = new Point( getX() + wrapper.getX() + permPanel.getX() + activeScrollPane.getX() + ev.getX(), getY() + wrapper.getY() + permPanel.getY() + activeScrollPane.getY() + ev.getY() ); } /*else if (type.equals(PermissionType.PERMISSION_GROUP)) { activeTable = groupPermissionTable; activeScrollPane = groupScrollPane;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -