]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/SpdProtocolDecls.java
1c4c0cf269fe51cd38cfc61f8984f299db5ba45e
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / packaging / ui / SpdProtocolDecls.java
1 /** @file
2 Java class SpdProtocolDecls is GUI for create library definition elements of spd file.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 package org.tianocore.frameworkwizard.packaging.ui;
14
15 import javax.swing.JFrame;
16 import javax.swing.JOptionPane;
17 import javax.swing.table.DefaultTableModel;
18 import javax.swing.table.TableModel;
19
20 import org.tianocore.PackageSurfaceAreaDocument;
21 import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageType;
22 import org.tianocore.frameworkwizard.platform.ui.ListEditor;
23
24 /**
25 GUI for create library definition elements of spd file.
26
27 @since PackageEditor 1.0
28 **/
29 public class SpdProtocolDecls extends SpdGuidDecls {
30
31 /**
32 *
33 */
34 private static final long serialVersionUID = 1L;
35 private SpdFileContents sfc = null;
36 private OpeningPackageType docConsole = null;
37
38 public SpdProtocolDecls(JFrame frame) {
39 super(frame);
40 // TODO Auto-generated constructor stub
41 }
42
43 public SpdProtocolDecls(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa, JFrame frame) {
44 this(frame);
45 sfc = new SpdFileContents(inPsa);
46 init(sfc);
47 }
48
49 public SpdProtocolDecls(OpeningPackageType opt, JFrame frame) {
50 this(opt.getXmlSpd(), frame);
51 docConsole = opt;
52 if (sfc.getSpdPkgDefsRdOnly().equals("true")) {
53 JOptionPane.showMessageDialog(this, "This is a read-only package. You will not be able to edit contents in table.");
54 }
55 initFrame();
56 }
57
58 protected void initFrame() {
59 super.initFrame();
60 this.setTitle("Protocol Declarations");
61 starLabel.setVisible(false);
62 ((ListEditor)getJTable().getColumnModel().getColumn(6).getCellEditor()).setCanNotBeEmpty(false);
63 }
64
65 protected void init(SpdFileContents sfc){
66 //
67 // initialize table using SpdFileContents object
68 //
69 DefaultTableModel model = getModel();
70 if (sfc.getSpdProtocolDeclarationCount() == 0) {
71 return ;
72 }
73 saa = new String[sfc.getSpdProtocolDeclarationCount()][7];
74 sfc.getSpdProtocolDeclarations(saa);
75 int i = 0;
76 while (i < saa.length) {
77 model.addRow(saa[i]);
78 i++;
79 }
80
81 }
82
83 protected void updateRow(int row, int column, TableModel m){
84 String[] sa = new String[7];
85 sfc.getSpdProtocolDeclaration(sa, row);
86 Object cellData = m.getValueAt(row, column);
87 if (cellData == null) {
88 cellData = "";
89 }
90 if (cellData.equals(sa[column])) {
91 return;
92 }
93 if (cellData.toString().length() == 0 && sa[column] == null) {
94 return;
95 }
96
97 String name = m.getValueAt(row, 0) + "";
98 String cName = m.getValueAt(row, 1) + "";
99 String guid = m.getValueAt(row, 2) + "";
100 String help = m.getValueAt(row, 3) + "";
101 String archList = null;
102 if (m.getValueAt(row, 4) != null) {
103 archList = m.getValueAt(row, 4).toString();
104 }
105 String modTypeList = null;
106 if (m.getValueAt(row, 5) != null) {
107 modTypeList = m.getValueAt(row, 5).toString();
108 }
109 String guidTypeList = null;
110 if (m.getValueAt(row, 6) != null) {
111 guidTypeList = m.getValueAt(row, 6).toString();
112 }
113 String[] rowData = {name, cName, guid, help};
114 if (!dataValidation(rowData)){
115 return;
116 }
117 docConsole.setSaved(false);
118 sfc.updateSpdProtocolDecl(row, name, cName, guid, help, archList, modTypeList, guidTypeList);
119 }
120
121 protected int addRow(String[] row) {
122 if (!dataValidation(row)){
123 return -1;
124 }
125 docConsole.setSaved(false);
126 sfc.genSpdProtocolDeclarations(row[0], row[1], row[2], row[3], stringToVector(row[4]), stringToVector(row[5]), stringToVector(row[6]));
127 return 0;
128 }
129
130 protected void removeRow(int i){
131 sfc.removeSpdProtocolDeclaration(i);
132 docConsole.setSaved(false);
133 }
134
135 protected void clearAllRow(){
136 sfc.removeSpdProtocolDeclaration();
137 docConsole.setSaved(false);
138 }
139
140 /**
141 * @return Returns the sfc.
142 */
143 protected SpdFileContents getSfc() {
144 return sfc;
145 }
146 }