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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
/** @file
The file is used to create, update SystemTable of MSA/MBD 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.packaging.module.ui;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.tianocore.SystemTableUsage;
import org.tianocore.SystemTablesDocument;
import org.tianocore.common.DataValidation;
import org.tianocore.common.Log;
import org.tianocore.packaging.common.ui.IInternalFrame;
import org.tianocore.packaging.common.ui.StarLabel;
/**
The class is used to create, update SystemTable of MSA/MBD file
It extends IInternalFrame
@since ModuleEditor 1.0
**/
public class ModuleSystemTables extends IInternalFrame {
///
/// Define class Serial Version UID
///
private static final long serialVersionUID = 7488769180379442276L;
//
//Define class members
//
private SystemTablesDocument.SystemTables systemTables = null;
private int location = -1;
private JPanel jContentPane = null;
private JLabel jLabelEntry = null;
private JTextField jTextFieldEntry = null;
private JLabel jLabelUsage = null;
private JComboBox jComboBoxUsage = null;
private JButton jButtonOk = null;
private JButton jButtonCancel = null;
private JLabel jLabelOverrideID = null;
private JTextField jTextFieldOverrideID = null;
private StarLabel jStarLabel1 = null;
/**
This method initializes jTextFieldEntry
@return javax.swing.JTextField jTextFieldEntry
**/
private JTextField getJTextFieldEntry() {
if (jTextFieldEntry == null) {
jTextFieldEntry = new JTextField();
jTextFieldEntry.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
}
return jTextFieldEntry;
}
/**
This method initializes jComboBoxUsage
@return javax.swing.JComboBox jComboBoxUsage
**/
private JComboBox getJComboBoxUsage() {
if (jComboBoxUsage == null) {
jComboBoxUsage = new JComboBox();
jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
}
return jComboBoxUsage;
}
/**
This method initializes jButtonOk
@return javax.swing.JButton jButtonOk
**/
private JButton getJButtonOk() {
if (jButtonOk == null) {
jButtonOk = new JButton();
jButtonOk.setText("OK");
jButtonOk.setBounds(new java.awt.Rectangle(280, 90, 90, 20));
jButtonOk.addActionListener(this);
}
return jButtonOk;
}
/**
This method initializes jButtonCancel
@return javax.swing.JButton jButtonCancel
**/
private JButton getJButtonCancel() {
if (jButtonCancel == null) {
jButtonCancel = new JButton();
jButtonCancel.setText("Cancel");
jButtonCancel.setBounds(new java.awt.Rectangle(390, 90, 90, 20));
jButtonCancel.addActionListener(this);
}
return jButtonCancel;
}
/**
This method initializes jTextFieldOverrideID
@return javax.swing.JTextField jTextFieldOverrideID
**/
private JTextField getJTextFieldOverrideID() {
if (jTextFieldOverrideID == null) {
jTextFieldOverrideID = new JTextField();
jTextFieldOverrideID.setBounds(new java.awt.Rectangle(160, 60, 50, 20));
}
return jTextFieldOverrideID;
}
public static void main(String[] args) {
}
/**
This is the default constructor
**/
public ModuleSystemTables() {
super();
init();
this.setVisible(true);
}
/**
This is the override edit constructor
@param inSystemTables The input data of SystemTablesDocument.SystemTables
**/
public ModuleSystemTables(SystemTablesDocument.SystemTables inSystemTables) {
super();
init(inSystemTables);
this.setVisible(true);
}
/**
This is the override edit constructor
@param inSystemTables The input data of SystemTablesDocument.SystemTables
@param type The input data of node type
@param index The input data of node index
**/
public ModuleSystemTables(SystemTablesDocument.SystemTables inSystemTables, int type, int index) {
super();
init(inSystemTables, type, index);
this.setVisible(true);
}
/**
This method initializes this
@param inSystemTables The input data of SystemTablesDocument.SystemTables
**/
private void init(SystemTablesDocument.SystemTables inSystemTables) {
init();
this.setSystemTables(inSystemTables);
}
/**
This method initializes this
Fill values to all fields if these values are not empty
@param inSystemTables The input data of SystemTablesDocument.SystemTables
@param type The input data of node type
@param index The input data of node index
**/
private void init(SystemTablesDocument.SystemTables inSystemTables, int type, int index) {
init(inSystemTables);
this.location = index;
if (this.systemTables.getSystemTableList().size() > 0) {
if (this.systemTables.getSystemTableArray(index).getEntryList() != null) {
this.jTextFieldEntry.setText(this.systemTables.getSystemTableArray(index).getEntryList().get(0));
}
if (this.systemTables.getSystemTableArray(index).getUsage() != null) {
this.jComboBoxUsage.setSelectedItem(this.systemTables.getSystemTableArray(index).getUsage().toString());
}
this.jTextFieldOverrideID.setText(String.valueOf(this.systemTables.getSystemTableArray(index)
.getOverrideID()));
}
}
/**
This method initializes this
@return void
**/
private void init() {
this.setSize(500, 515);
this.setContentPane(getJContentPane());
this.setTitle("System Tables");
initFrame();
this.setViewMode(false);
}
/**
Disable all components when the mode is view
@param isView true - The view mode; false - The non-view mode
**/
public void setViewMode(boolean isView) {
this.jButtonOk.setVisible(false);
this.jButtonCancel.setVisible(false);
if (isView) {
this.jTextFieldEntry.setEnabled(!isView);
this.jComboBoxUsage.setEnabled(!isView);
this.jTextFieldOverrideID.setEnabled(!isView);
}
}
/**
This method initializes jContentPane
@return javax.swing.JPanel jContentPane
**/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabelOverrideID = new JLabel();
jLabelOverrideID.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
jLabelOverrideID.setText("Override ID");
jLabelUsage = new JLabel();
jLabelUsage.setText("Usage");
jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
jLabelEntry = new JLabel();
jLabelEntry.setText("Entry");
jLabelEntry.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabelEntry, null);
jContentPane.add(getJTextFieldEntry(), null);
jContentPane.add(jLabelUsage, null);
jContentPane.add(getJComboBoxUsage(), null);
jContentPane.add(getJButtonOk(), null);
jContentPane.add(getJButtonCancel(), null);
jContentPane.add(jLabelOverrideID, null);
jContentPane.add(getJTextFieldOverrideID(), null);
jStarLabel1 = new StarLabel();
jStarLabel1.setBounds(new java.awt.Rectangle(0, 10, 10, 20));
jContentPane.add(jStarLabel1, null);
}
return jContentPane;
}
/**
This method initializes Usage type
**/
private void initFrame() {
jComboBoxUsage.addItem("ALWAYS_CONSUMED");
jComboBoxUsage.addItem("SOMETIMES_CONSUMED");
jComboBoxUsage.addItem("ALWAYS_PRODUCED");
jComboBoxUsage.addItem("SOMETIMES_PRODUCED");
jComboBoxUsage.addItem("PRIVATE");
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*
* Override actionPerformed to listen all actions
*
*/
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource() == jButtonOk) {
this.setEdited(true);
this.save();
this.dispose();
}
if (arg0.getSource() == jButtonCancel) {
this.dispose();
}
}
/**
Get SystemTablesDocument.SystemTables
@return SystemTablesDocument.SystemTables
**/
public SystemTablesDocument.SystemTables getSystemTables() {
return systemTables;
}
/**
Set SystemTablesDocument.SystemTables
@param systemTables The input data of SystemTablesDocument.SystemTables
**/
public void setSystemTables(SystemTablesDocument.SystemTables systemTables) {
this.systemTables = systemTables;
}
/**
Data validation for all fields
@retval true - All datas are valid
@retval false - At least one data is invalid
**/
public boolean check() {
//
// Check if all required fields are not empty
//
if (isEmpty(this.jTextFieldEntry.getText())) {
Log.err("Entry couldn't be empty");
return false;
}
//
// Check if all fields have correct data types
//
if (!isEmpty(this.jTextFieldOverrideID.getText())
&& !DataValidation.isOverrideID(this.jTextFieldOverrideID.getText())) {
Log.err("Incorrect data type for Override ID");
return false;
}
return true;
}
/**
Save all components of SystemTables
if exists systemTables, set the value directly
if not exists systemTables, new an instance first
**/
public void save() {
try {
if (this.systemTables == null) {
systemTables = SystemTablesDocument.SystemTables.Factory.newInstance();
}
SystemTablesDocument.SystemTables.SystemTable systemTable = SystemTablesDocument.SystemTables.SystemTable.Factory
.newInstance();
//systemTable.setEntry(this.jTextFieldEntry.getText());
systemTable.setUsage(SystemTableUsage.Enum.forString(jComboBoxUsage.getSelectedItem().toString()));
if (!isEmpty(this.jTextFieldOverrideID.getText())) {
systemTable.setOverrideID(Integer.parseInt(this.jTextFieldOverrideID.getText()));
}
if (location > -1) {
systemTables.setSystemTableArray(location, systemTable);
} else {
systemTables.addNewSystemTable();
systemTables.setSystemTableArray(systemTables.getSystemTableList().size() - 1, systemTable);
}
} catch (Exception e) {
Log.err("Update System Tables", e.getMessage());
}
}
}
|