wangting
2025-01-16 18c43123b51a1688ab4ae01fe3d171c7d92e619b
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
package com.vci.client.omd.attribpool.toOutside;
 
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
 
import javax.swing.table.JTableHeader;
 
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.HighlighterFactory;
 
import com.vci.client.omd.attribpool.ui.APClient;
import com.vci.client.common.ClientLog4j;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
 
public class ApTableForBtm extends JXTable{
 
    /**
     * 
     */
    private static final long serialVersionUID = -483194770273076948L;
    private HashMap<String, List<String>> apNameMap = null;
    private AttribItem[] abItemArray = null;
    private final int TABLE_HEADER_HEIGHT = 25;
    private final int ROW_HEIGHT = 30;
    
    public ApTableForBtm(HashMap<String, List<String>> apNameMap){
        this.apNameMap = apNameMap;
        this.setHorizontalScrollEnabled(true);
        this.setAutoscrolls(true);
        this.setSortable(false);
        this.setHighlighters(HighlighterFactory.createAlternateStriping());
        this.setRowHeight(ROW_HEIGHT);
        //设置表头高度
        JTableHeader tableHeader = this.getTableHeader();
        Dimension size = tableHeader.getPreferredSize();
        size.height = TABLE_HEADER_HEIGHT;
        tableHeader.setPreferredSize(size);
        initApTable();
    }
    
    public void initApTable(){
        ApTableModelForBtm model = new ApTableModelForBtm();
        this.setModel(model);
        AttribItem abItem;
        String btmName;
        int rowCountOriginal;
        for(Iterator<String> i = apNameMap.keySet().iterator(); i.hasNext();){
            btmName = i.next();
            try {
                abItemArray = APClient.getService().getAttribItemsByNames(
                        apNameMap.get(btmName).toArray(new String[0]));
            } catch (VCIError e) {
                //e.printStackTrace();
                ClientLog4j.logger.error(e);
            }
            if(abItemArray == null){
                return;
            }
            rowCountOriginal = model.getRowCount();
            model.setRowCount(rowCountOriginal + abItemArray.length);
            this.setEditable(true);
            for(int k = 0; k < abItemArray.length; k++){
                abItem = abItemArray[k];
                this.setValueAt(abItem.name, rowCountOriginal + k, 0);
                this.setValueAt(btmName, rowCountOriginal + k, 1);
                this.setValueAt(abItem.vtDataType, rowCountOriginal + k, 2);
                this.setValueAt(abItem.defValue, rowCountOriginal + k, 3);
                this.setValueAt(abItem.description, rowCountOriginal + k, 4);
            }
            this.setEditable(false);
        }
    }
}