summaryrefslogtreecommitdiff
path: root/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/SpdProtocolDecls.java
blob: 1c4c0cf269fe51cd38cfc61f8984f299db5ba45e (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/** @file
  Java class SpdProtocolDecls is GUI for create library definition elements of spd file.
 
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution.  The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.frameworkwizard.packaging.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import org.tianocore.PackageSurfaceAreaDocument;
import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageType;
import org.tianocore.frameworkwizard.platform.ui.ListEditor;

/**
GUI for create library definition elements of spd file.
 
@since PackageEditor 1.0
**/
public class SpdProtocolDecls extends SpdGuidDecls {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private SpdFileContents sfc = null;
    private OpeningPackageType docConsole = null;
    
    public SpdProtocolDecls(JFrame frame) {
        super(frame);
        // TODO Auto-generated constructor stub
    }

    public SpdProtocolDecls(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa, JFrame frame) {
        this(frame);
        sfc = new SpdFileContents(inPsa);
        init(sfc);
    }
    
    public SpdProtocolDecls(OpeningPackageType opt, JFrame frame) {
        this(opt.getXmlSpd(), frame);
        docConsole = opt;
        if (sfc.getSpdPkgDefsRdOnly().equals("true")) {
            JOptionPane.showMessageDialog(this, "This is a read-only package. You will not be able to edit contents in table.");
        }
        initFrame();
    }
    
    protected void initFrame() {
        super.initFrame();
        this.setTitle("Protocol Declarations");
        starLabel.setVisible(false);
        ((ListEditor)getJTable().getColumnModel().getColumn(6).getCellEditor()).setCanNotBeEmpty(false);
    }
    
    protected void init(SpdFileContents sfc){
        //
        // initialize table using SpdFileContents object
        //
        DefaultTableModel model = getModel();
        if (sfc.getSpdProtocolDeclarationCount() == 0) {
            return ;
        }
        saa = new String[sfc.getSpdProtocolDeclarationCount()][7];
        sfc.getSpdProtocolDeclarations(saa);
        int i = 0;
        while (i < saa.length) {
            model.addRow(saa[i]);
            i++;
        }
        
    }
    
    protected void updateRow(int row, int column, TableModel m){
        String[] sa = new String[7];
        sfc.getSpdProtocolDeclaration(sa, row);
        Object cellData = m.getValueAt(row, column);
        if (cellData == null) {
            cellData = "";
        }
        if (cellData.equals(sa[column])) {
            return;
        }
        if (cellData.toString().length() == 0 && sa[column] == null) {
            return;
        }
        
        String name = m.getValueAt(row, 0) + "";
        String cName = m.getValueAt(row, 1) + "";
        String guid = m.getValueAt(row, 2) + "";
        String help = m.getValueAt(row, 3) + "";
        String archList = null;
        if (m.getValueAt(row, 4) != null) {
            archList = m.getValueAt(row, 4).toString();
        }
        String modTypeList = null;
        if (m.getValueAt(row, 5) != null) {
            modTypeList = m.getValueAt(row, 5).toString();
        }
        String guidTypeList = null;
        if (m.getValueAt(row, 6) != null) {
            guidTypeList = m.getValueAt(row, 6).toString();
        }
        String[] rowData = {name, cName, guid, help};
        if (!dataValidation(rowData)){
            return;
        }
        docConsole.setSaved(false);
        sfc.updateSpdProtocolDecl(row, name, cName, guid, help, archList, modTypeList, guidTypeList);
    }
    
    protected int addRow(String[] row) {
        if (!dataValidation(row)){
            return -1;
        }
        docConsole.setSaved(false);
        sfc.genSpdProtocolDeclarations(row[0], row[1], row[2], row[3], stringToVector(row[4]), stringToVector(row[5]), stringToVector(row[6]));
        return 0;
    }
    
    protected void removeRow(int i){
        sfc.removeSpdProtocolDeclaration(i);
        docConsole.setSaved(false);
    }
    
    protected void clearAllRow(){
        sfc.removeSpdProtocolDeclaration();
        docConsole.setSaved(false);
    }
    
    /**
     * @return Returns the sfc.
     */
    protected SpdFileContents getSfc() {
        return sfc;
    }
}