📄 taskdialog.java
字号:
/**
* <p>Title: 卓博营运支撑系统</p>
*
* <p>Description: 为本企业内部运作提供支撑,为企业資源的E化管理提供解決方案</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: 卓博信息科技有限公司</p>
*
* @author Henry
* @version 1.0
*/
package com.jobcn.ui;
import java.util.Date;
import java.util.HashMap;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;
import com.jobcn.control.Common;
import com.jobcn.control.Constant;
import com.jobcn.control.MainFrameTableModel;
/** TaskDialog.java
* function:
* describe:
*/
public class TaskDialog extends JDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Launch the application
* @param args
*/
public TaskDialog(final MainFrame mainFrame){
super(mainFrame, true);
this.mainFrame = mainFrame;
generalPanel = new GeneralPanel();
stepPanel = new StepPanel(this);
attempPanel = new AttempPanel(this);
notifyPanel = new NotifyPanel();
setLayout(new BorderLayout());
tab = new JTabbedPane(JTabbedPane.TOP);
tab.add(generalPanel, BorderLayout.CENTER);
tab.setTitleAt(0, "常规 ");
tab.add(stepPanel, BorderLayout.CENTER);
tab.setTitleAt(1, "步骤 ");
tab.add(attempPanel, BorderLayout.CENTER);
tab.setTitleAt(2, "调度 ");
tab.add(notifyPanel, BorderLayout.CENTER);
tab.setTitleAt(3, "通知 ");
tab.setSelectedIndex(0);
add(tab, BorderLayout.CENTER);
final JPanel panel = new JPanel();
final JButton confirm = new JButton();
confirm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
save();
}
});
confirm.setText("确定");
panel.add(confirm);
final JButton cancel = new JButton();
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
cancel.setText("返回");
panel.add(cancel);
add(panel, BorderLayout.SOUTH);
tab.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
dispose();
int rowNo = mainFrame.getTable().getSelectedRow();
if (rowNo > 0) {
mainFrame.getTable().setRowSelectionInterval(rowNo, rowNo);
}
}
}
});
addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
generalPanel.getTaskName().requestFocusInWindow();
}
});
generalPanel.getTaskName().addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER){
save();
}
else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
dispose();
int rowNo = mainFrame.getTable().getSelectedRow();
if (rowNo < 0) {
return;
}
else if (rowNo >= 1) {
rowNo--;
mainFrame.getTable().setRowSelectionInterval(rowNo, rowNo);
}
}
}
});
}
private void save() {
JTextField tf = generalPanel.getTaskName();
String taskName = tf.getText().replaceAll(" ", "");
if (taskName.equals("")){
JOptionPane.showMessageDialog(tab, "请定义任务名称!");
tf.requestFocus();
tab.setSelectedIndex(0);
return;
}
// contains of general, step, attemp, notify datas.
Object[] objects = new Object[4];
objects[0] = new String[Constant.generalData.length]; // generalDataObj
String oldCreateDate = generalPanel.getCreateDate().getText();
String createDate = oldCreateDate.equals("")?
Common.getDateString(new Date(), "yyyy-MM-dd HH:mm:ss"):oldCreateDate;
String updateDate = Common.getDateString(new Date(), "yyyy-MM-dd HH:mm:ss");
((String[]) objects[0])[0] = taskName;
((String[]) objects[0])[1] = String.valueOf(generalPanel.getTaskType().getSelectedIndex());
((String[]) objects[0])[2] = generalPanel.getTaskDesc().getText();
((String[]) objects[0])[3] = createDate;
((String[]) objects[0])[4] = updateDate;
objects[1] = stepPanel.getStepData().clone(); // stepDataObj
objects[2] = attempPanel.getAttempData().clone(); // attempDataObj
objects[3] = new String[Constant.notifyData.length]; // notifyDataObj
((String[]) objects[3])[0] = String.valueOf(notifyPanel.getMailCheckBox().isSelected());
((String[]) objects[3])[1] = String.valueOf(notifyPanel.getMailComboBox().getSelectedIndex());
((String[]) objects[3])[2] = notifyPanel.getMail().getText();
((String[]) objects[3])[3] = notifyPanel.getCc().getText();
((String[]) objects[3])[4] = String.valueOf(notifyPanel.getOnlineCheckBox().isSelected());
((String[]) objects[3])[5] = String.valueOf(notifyPanel.getOnlineComboBox().getSelectedIndex());
((String[]) objects[3])[6] = notifyPanel.getOnlineID().getText();
JTable table = mainFrame.getTable();
MainFrameTableModel model = mainFrame.getModel();
if(!editable){
// 保存新建任务
int rowCount = table.getRowCount();
if (rowCount == 0) {
ID = 0;
}
else {
ID = (Integer)mainFrame.getTable().getValueAt(rowCount-1, 0);
}
map.put(ID, objects);
model.addRow(
new Object[] {
ID+1, taskName,
generalPanel.getTaskType().getSelectedItem(),
generalPanel.getTaskDesc().getText(),
createDate, updateDate, new Boolean(false)
}
);
}
else{
// 保存编辑任务
map.put(ID, objects);
int currentRow = mainFrame.getTable().getSelectedRow();
model.setValueAt(taskName, currentRow, 1);
model.setValueAt(generalPanel.getTaskType().getSelectedItem(),
currentRow, 2);
model.setValueAt(generalPanel.getTaskDesc().getText(),
currentRow, 3);
model.setValueAt(updateDate, currentRow, 5);
}
dispose();
/*int currentRow = table.getSelectedRow();
if (currentRow >= 1) {
table.setRowSelectionInterval(currentRow-1, currentRow-1);
}*/
}
private MainFrame mainFrame;
private boolean editable;
private Integer ID = 0;
private JTabbedPane tab;
private GeneralPanel generalPanel;
private StepPanel stepPanel;
private AttempPanel attempPanel;
private NotifyPanel notifyPanel;
private HashMap<Integer, Object[]> map = new HashMap<Integer, Object[]>();
public AttempPanel getAttempPanel() {
return attempPanel;
}
public void setAttempPanel(AttempPanel attempPanel) {
this.attempPanel = attempPanel;
}
public GeneralPanel getGeneralPanel() {
return generalPanel;
}
public void setGeneralPanel(GeneralPanel generalPanel) {
this.generalPanel = generalPanel;
}
public NotifyPanel getNotifyPanel() {
return notifyPanel;
}
public void setNotifyPanel(NotifyPanel notifyPanel) {
this.notifyPanel = notifyPanel;
}
public StepPanel getStepPanel() {
return stepPanel;
}
public void setStepPanel(StepPanel stepPanel) {
this.stepPanel = stepPanel;
}
public JTabbedPane getTab() {
return tab;
}
public void setTab(JTabbedPane tab) {
this.tab = tab;
}
public HashMap<Integer, Object[]> getMap() {
return map;
}
public void setMap(HashMap<Integer, Object[]> map) {
this.map = map;
}
public Integer getID() {
return ID;
}
public void setID(Integer id) {
ID = id;
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -