?? roledialog.java
字號:
package custom_management;
import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.util.Collection;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RoleDialog
extends JDialog {
String action = "";
String objUid = null;
CustomerManageFrame frame = new CustomerManageFrame();
public RoleDialog() {}
public RoleDialog(CustomerManageFrame frame ,String title ,boolean model) {
super(frame,title ,model);
this.frame = frame;
this.action = frame.action;
try {
getMappedAndNotMappedEmployees(); // do something here
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
this.setSize(new Dimension(420,420));
jLabel1.setText("角色編號");
jLabel3.setText("角色描述");
jLabel2.setText("角色名稱");
jButton1.setText("確 定");
jButton1.addActionListener(new RoleDialog_jButton1_actionAdapter(this));
jButton2.setText("取 消");
jButton2.addActionListener(new RoleDialog_jButton2_actionAdapter(this));
jToggleButton1.addActionListener(new
RoleDialog_jToggleButton1_actionAdapter(this));
this.getContentPane().add(jTextField1, new XYConstraints(86, 19, 133, -1));
jToggleButton1.setText("配置角色的用戶映射");
jLabel4.setText("配置映射");
this.getContentPane().add(jLabel3, new XYConstraints(27, 107, -1, -1));
jScrollPane1.getViewport().add(jTextArea1);
this.getContentPane().add(jLabel4, new XYConstraints(31, 194, -1, -1));
this.getContentPane().add(jLabel2, new XYConstraints(27, 60, -1, -1));
this.getContentPane().add(jLabel1, new XYConstraints(27, 22, -1, -1));
this.getContentPane().add(jButton2, new XYConstraints(210, 250, 57, -1));
this.getContentPane().add(jToggleButton1, new XYConstraints(86, 192, -1, -1));
this.getContentPane().add(jScrollPane1, new XYConstraints(86, 102, 163, 66));
this.getContentPane().add(jTextField2, new XYConstraints(86, 62, 133, -1));
this.getContentPane().add(jButton1, new XYConstraints(92, 250, -1, -1));
}
private void getMappedAndNotMappedEmployees()
{
try {
CustomerManageSession sb = SessionBeanFactory.
getCustomerManageSessionBean(
"CustomerManageSessionBean");
if (action.equals("new")) {
empNotMapped = sb.getWbEmployeeBeans();
}
else { // edit
int row = frame.roleTable.getSelectedRow();
objUid = frame.roleData[row][0].toString();
Collection[] temp = sb.getEmployeesMappedAndNotMappedByRoleId(new Long(objUid));
empMapped = temp[0];
empNotMapped = temp[1];
RoleObject roleob = sb.getWbRoleById(new Long(objUid));
initRoleInfo(roleob);
}
}
catch (NumberFormatException ex) {
}
catch (RemoteException ex) {
}
}
private void initRoleInfo(RoleObject roleob)
{
jTextField1.setText(String.valueOf(roleob.getObjUid()));
jTextField2.setText(roleob.getName());
jTextArea1.setText(roleob.getDescription());
}
Collection empMapped = new ArrayList();
Collection empNotMapped = new ArrayList();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField jTextField2 = new JTextField();
JLabel jLabel3 = new JLabel();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JLabel jLabel4 = new JLabel();
JToggleButton jToggleButton1 = new JToggleButton();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public void jButton2_actionPerformed(ActionEvent actionEvent) {
this.dispose();
}
public void jButton1_actionPerformed(ActionEvent actionEvent) {
try {
if (passVerify()) {
RoleObject updateob = new RoleObject(Long.parseLong(jTextField1.getText()),
jTextField2.getText(),
jTextArea1.getText());
CustomerManageSession sb = SessionBeanFactory.
getCustomerManageSessionBean("CustomerManageSessionBean");
//更新角色資料
if (frame.action.equals("edit"))
sb.updateRoleById(new Long(objUid), updateob, empMapped);
//保存新的角色
else
sb.saveNewRole(updateob, empMapped);
frame.refreshRoleView();
this.dispose();
}
}
catch (NumberFormatException ex) {
ex.printStackTrace();
}
catch (RemoteException ex) {
ex.printStackTrace();
}
}
private boolean passVerify() {
try {
if (jTextField1.getText() == null ||
jTextField1.getText().trim().equals(""))
throw new Exception("注意:角色編號不能為空!");
if (jTextField2.getText() == null || jTextField2.getText().trim().equals(""))
throw new Exception("注意:角色名稱不能為空!");
return true;
}catch (Exception ne) {
JOptionPane.showMessageDialog(null,ne.getMessage(),"配置用戶",JOptionPane.ERROR_MESSAGE);
}
return false;
}
public void jToggleButton1_actionPerformed(ActionEvent actionEvent) {
FrameView.view(new RoleToUserMappingDialog(this,"配置用戶的角色映射",true));
}
}
class RoleDialog_jButton1_actionAdapter
implements ActionListener {
private RoleDialog adaptee;
RoleDialog_jButton1_actionAdapter(RoleDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jButton1_actionPerformed(actionEvent);
}
}
class RoleDialog_jToggleButton1_actionAdapter
implements ActionListener {
private RoleDialog adaptee;
RoleDialog_jToggleButton1_actionAdapter(RoleDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jToggleButton1_actionPerformed(actionEvent);
}
}
class RoleDialog_jButton2_actionAdapter
implements ActionListener {
private RoleDialog adaptee;
RoleDialog_jButton2_actionAdapter(RoleDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jButton2_actionPerformed(actionEvent);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -