📄 grouppanel.java
字号:
package jp.co.ntl.swing.ext.user.group;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JApplet;
import javax.swing.JButton;
///import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import jp.co.ntl.ActionEventConstants;
import jp.co.ntl.Net;
import jp.co.ntl.NetworkException;
import jp.co.ntl.Page;
import jp.co.ntl.ServerException;
import jp.co.ntl.TimeOutException;
import jp.co.ntl.group.GroupInfo;
import jp.co.ntl.swing.BasePanel;
import jp.co.ntl.swing.TableSorter;
///import jp.co.ntl.swing.ext.CSVFileFilter;
import jp.co.ntl.swing.ext.DialogManager;
import jp.co.ntl.swing.ext.MsgUtil;
import jp.co.ntl.swing.ext.user.limitprint.LimitPrintInfoInvoker;
public class GroupPanel extends BasePanel implements ActionListener, ListSelectionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JTable tblGroup;
private GroupTableModel mdlGroup;
private ListSelectionModel mdlGroupSelect;
private JScrollPane scrGroup;
private JButton btnRegister;
private JButton btnModify;
private JButton btnDelete;
/// private JButton btnMultiRegister;
private JButton btnRefresh;
private JMenuItem menuModify;
private JMenuItem menuDelete;
private Vector vcGroupInfo;
private Vector vcLpInfo;
private TableSorter sorter;
private GroupInfoInvoker invoker;
public GroupPanel(JFrame parent, Net net) {
super(parent, net);
}
public GroupPanel(JApplet appl, Net net) {
super(appl, net);
}
protected void buildComponents() {
Resource.load(loc);
Page.initialize(net);
invoker = GroupInfoInvoker.getInstance(net);
createPopupMenu();
vcGroupInfo = new Vector();
mdlGroup = new GroupTableModel(vcGroupInfo);
sorter = new TableSorter(mdlGroup);
tblGroup = new JTable(sorter);
sorter.setTableHeader(tblGroup.getTableHeader());
scrGroup = new JScrollPane(tblGroup);
add(scrGroup, BorderLayout.CENTER);
tblGroup.getTableHeader().setReorderingAllowed(false);
btnRegister = new JButton(Resource.getString(Resource.REGISTER));
btnModify = new JButton(Resource.getString(Resource.MODIFY));
btnDelete = new JButton(Resource.getString(Resource.DELETE));
/// btnMultiRegister = new JButton(Resource.getString(Resource.MULTI_REGISTER));
btnRefresh = new JButton(Resource.getString(Resource.REFRESH));
addButtonPanel(
new JButton[] {btnRegister, btnModify, btnDelete/*, btnMultiRegister*/, btnRefresh},
new String[] {
Resource.getString(Resource.TIP_REGISTER),
Resource.getString(Resource.TIP_MODIFY),
Resource.getString(Resource.TIP_DELETE),
/// Resource.getString(Resource.TIP_MULTI_REGISTER),
Resource.getString(Resource.TIP_REFRESH)
});
btnRegister.addActionListener(this);
btnModify.addActionListener(this);
btnDelete.addActionListener(this);
/// btnMultiRegister.addActionListener(this);
btnRefresh.addActionListener(this);
mdlGroupSelect = tblGroup.getSelectionModel();
mdlGroupSelect.addListSelectionListener(this);
mdlGroupSelect.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
setButtonState(false, null);
tblGroup.setColumnSelectionAllowed(false);
tblGroup.addMouseListener(this);
}
private void createPopupMenu() {
popupMenu = new JPopupMenu();
menuModify = new JMenuItem(Resource.getString(Resource.MODIFY));
menuModify.addActionListener(this);
popupMenu.add(menuModify);
menuDelete = new JMenuItem(Resource.getString(Resource.DELETE));
menuDelete.addActionListener(this);
popupMenu.add(menuDelete);
}
public void beginPanel() throws NetworkException, ServerException, TimeOutException {
doRefresh();
}
private void setButtonState(boolean b, int[] selViewRows) {
if (selViewRows != null && selViewRows.length <= 1) {
btnModify.setEnabled(b);
} else {
btnModify.setEnabled(false);
}
btnDelete.setEnabled(b);
}
protected void setPopupMenuState() {
if (tblGroup.getSelectedRowCount() > 1) {
menuModify.setEnabled(false);
} else {
menuModify.setEnabled(true);
}
}
private boolean getGroupInfo() throws NetworkException, ServerException, TimeOutException {
Vector vcGroupInfo = null;
vcGroupInfo = invoker.getGroupInfo();
mdlGroup.addInfos(vcGroupInfo);
return true;
}
private boolean getLimitPrintInfo() throws NetworkException, ServerException, TimeOutException {
LimitPrintInfoInvoker lpInfoInvoker = LimitPrintInfoInvoker.getInstance(net);
vcLpInfo = lpInfoInvoker.getLimitPrintInfo();
return true;
}
protected boolean doRegister() throws NetworkException, ServerException, TimeOutException {
GroupInfo groupInfo = new GroupInfo();
GroupInfoPanel p = new GroupInfoPanel(false, groupInfo, vcGroupInfo, vcLpInfo);
if (DialogManager.showCustomDialog(
this, Resource.getString(Resource.GROUPINFO_TITLE), p) == GroupInfoPanel.OK_BUTTON) {
int id = invoker.addGroup(groupInfo);
groupInfo.setGroupID(id);
mdlGroup.addInfo(groupInfo);
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_USER);
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_PRINTER);
}
return true;
}
protected boolean doModify() throws NetworkException, ServerException, TimeOutException {
int selRow = sorter.modelIndex(tblGroup.getSelectedRow());
if (selRow >= 0) {
GroupInfo groupInfo = (GroupInfo)mdlGroup.getSelectedInfo(selRow);
GroupInfoPanel p = new GroupInfoPanel(true, groupInfo, vcGroupInfo, vcLpInfo);
if (DialogManager.showCustomDialog(
this, Resource.getString(Resource.GROUPINFO_TITLE), p) == GroupInfoPanel.OK_BUTTON) {
invoker.changeGroupInfo(groupInfo);
mdlGroup.setInfo(selRow, groupInfo);
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_USER);
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_PRINTER);
}
}
return true;
}
protected boolean doDelete() throws NetworkException, ServerException, TimeOutException {
int[] selViewRows = tblGroup.getSelectedRows();
Vector vcGroupInfo = new Vector();
for (int i = 0; i < selViewRows.length; i++) {
int selRow = sorter.modelIndex(selViewRows[i]);
if (selRow >= 0) {
vcGroupInfo.addElement(mdlGroup.getSelectedInfo(selRow));
}
}
// 報嶞棜楌偵愝掕偝傟偰偄傞偐僠僃僢僋
if (invoker.isRelatedGroupOnAccount(vcGroupInfo)) {
DialogManager.showMessage(this, DialogManager.ERROR_DELETE_GROUP_RELATED_ACCOUNT);
return false;
}
// 僾儕儞僞傑偨偼儐乕僓偵娭楢晅偗傜傟偰偄傞偐僠僃僢僋
if (invoker.isRelatedGroup(vcGroupInfo)) {
DialogManager.showMessage(this, DialogManager.ERROR_DELETE_GROUP_RELATED_USER);
return false;
}
if (DialogManager.showConfirmMessage(
this,
DialogManager.CONFIRM_DELETE,
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
invoker.delGroup(vcGroupInfo);
for (int i = selViewRows.length - 1; i >= 0; i--) {
int selRow = sorter.modelIndex(selViewRows[i]);
if (selRow >= 0) {
mdlGroup.deleteInfo(selRow);
}
}
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_USER);
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_PRINTER);
}
return true;
}
/*
private void doMultiRegister() throws NetworkException, ServerException, TimeOutException {
if (!isApplet()) {
CSVFileFilter filter = new CSVFileFilter();
JFileChooser fc = new JFileChooser();
fc.setFileFilter(filter);
int ret = fc.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
}
}
}*/
public int getInfosFromServer() {
int result = GET_INFO_RESULT_NORMAL;
mdlGroup.deleteAllInfos();
try {
getGroupInfo();
} catch (NetworkException e) {
result = GET_INFO_RESULT_ERROR;
sendActionEvent(MsgUtil.getMessage(MsgUtil.ERROR_NETWORK, null));
} catch (ServerException e) {
result = GET_INFO_RESULT_ERROR;
sendActionEvent(MsgUtil.getMessage(MsgUtil.ERROR_SERVER, null));
} catch (TimeOutException e) {
}
result = getInfosFromServerForInfoPanel();
if (result == GET_INFO_RESULT_NORMAL) {
sendActionEvent(MsgUtil.getMessage(MsgUtil.MSG_IDLE, null));
}
return result;
}
private int getInfosFromServerForInfoPanel() {
int result = GET_INFO_RESULT_NORMAL;
try {
getLimitPrintInfo();
} catch (NetworkException e) {
result = GET_INFO_RESULT_ERROR;
sendActionEvent(MsgUtil.getMessage(MsgUtil.ERROR_NETWORK, null));
} catch (ServerException e) {
result = GET_INFO_RESULT_ERROR;
sendActionEvent(MsgUtil.getMessage(MsgUtil.ERROR_SERVER, null));
} catch (TimeOutException e) {
}
if (result == GET_INFO_RESULT_NORMAL) {
sendActionEvent(MsgUtil.getMessage(MsgUtil.MSG_IDLE, null));
}
return result;
}
public void actionPerformed(ActionEvent ae) {
Object obj = ae.getSource();
try {
if (obj == btnRegister) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doRegister();
} else if (obj == btnModify || obj == menuModify) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doModify();
} else if (obj == btnDelete || obj == menuDelete) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doDelete();
/* } else if (obj == btnMultiRegister) {
doMultiRegister();*/
} else if (obj == btnRefresh) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doRefresh();
}
} catch (NetworkException e) {
DialogManager.showMessage(this, DialogManager.ERROR_NETWORK);
} catch (ServerException e) {
DialogManager.showMessage(this, DialogManager.ERROR_SERVER);
} catch (TimeOutException e) {
}
}
public void valueChanged(ListSelectionEvent le) {
Object obj = le.getSource();
if (obj == mdlGroupSelect) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
int[] rows = tblGroup.getSelectedRows();
if (rows == null || rows.length == 0) {
setButtonState(false, null);
} else {
setButtonState(true, rows);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -