wangting
2024-12-30 306a9c4fde94c54d91aee5a69d59b993c7c707a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.vci.client.workflow.editor.user;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
 
import com.vci.client.workflow.commom.ClientHelper;
import com.vci.corba.workflow.data.CustomInfo;
 
public class CustomEditPanel extends JPanel {
    private static final long serialVersionUID = 1300418480939892949L;
    
    private JTable customTable;
    private JButton addBtn;
    private JButton deleteBtn;
    
    public CustomEditPanel() {
        initUI();
        addListener();
    }
 
    private void addListener() {
        addBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                CustomTableModel model = (CustomTableModel)customTable.getModel();
                model.addRow();
            }
        });
        
        deleteBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int[] selectedRows = customTable.getSelectedRows();
                CustomTableModel model = (CustomTableModel)customTable.getModel();
                model.deleteRow(selectedRows);
            }
        });
    }
 
    private void initUI() {
        setLayout(new BorderLayout());
        add(new JScrollPane(getCustomProperty()), BorderLayout.CENTER);
        
        JPanel BtnPanel = new JPanel();
        add(BtnPanel, BorderLayout.EAST);
        BtnPanel.setLayout(new BoxLayout(BtnPanel, BoxLayout.Y_AXIS));
        
        addBtn = new JButton("添加");
        BtnPanel.add(addBtn);
        
        deleteBtn = new JButton("删除");
        BtnPanel.add(deleteBtn);
    }
    
    private JTable getCustomProperty() {
        if(customTable == null) {
            customTable = new JTable(new CustomTableModel());
            customTable.setRowHeight(20);
 
            Dimension size = customTable.getTableHeader().getPreferredSize();
            size.height = 22;
            customTable.getTableHeader().setPreferredSize(size);
            
//            JComboBox c = new JComboBox();//在下拉列表中选择phase 
//            c.addItem(""); 
//            c.addItem("phase"); 
//            propertyTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(c));
        }
        return customTable;
    }
    
    public CustomInfo[] getCustomUserInfos(){
        List<CustomInfo> result = new ArrayList<CustomInfo>();
        CustomTableModel model = (CustomTableModel)customTable.getModel();
        List<CustomInfo> data = model.getData();
        if(data != null && data.size() > 0){
            for (CustomInfo customInfo : data) {
                if(customInfo ==null){
                    return result.toArray(new CustomInfo[0]);
                }
                if(customInfo.className.trim().length() > 0 
                        && customInfo.value.trim().length() > 0){
                    result.add(customInfo);
                }
            }
        }
        return result.toArray(new CustomInfo[0]);
    }
    
    public void setData(List<CustomInfo> data){
        CustomTableModel model = (CustomTableModel)customTable.getModel();
        model.setData(data);
    }
 
    private String getI18nString(String spCode) {
        return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, this.getLocale());
    }
 
}