]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/module/ui/ModuleDataHubs.java
1d8e88c061b6bffd5acf4b0a5ecb54580e4d9a1a
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / module / ui / ModuleDataHubs.java
1 /** @file
2
3 The file is used to create, update DataHub of MSA/MBD file
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 package org.tianocore.packaging.module.ui;
17
18 import java.awt.event.ActionEvent;
19
20 import javax.swing.JButton;
21 import javax.swing.JComboBox;
22 import javax.swing.JLabel;
23 import javax.swing.JPanel;
24 import javax.swing.JTextField;
25
26 import org.tianocore.DataHubUsage;
27 import org.tianocore.DataHubsDocument;
28 import org.tianocore.common.DataValidation;
29 import org.tianocore.common.Log;
30 import org.tianocore.common.Tools;
31 import org.tianocore.packaging.common.ui.IInternalFrame;
32 import org.tianocore.packaging.common.ui.StarLabel;
33
34 /**
35 The class is used to create, update DataHub of MSA/MBD file
36 It extends IInternalFrame
37
38 @since ModuleEditor 1.0
39
40 **/
41 public class ModuleDataHubs extends IInternalFrame {
42
43 ///
44 /// Define class Serial Version UID
45 ///
46 private static final long serialVersionUID = -3667906991966638892L;
47
48 //
49 //Define class members
50 //
51 private DataHubsDocument.DataHubs dataHubs = null;
52
53 private int location = -1;
54
55 private JPanel jContentPane = null;
56
57 private JLabel jLabelGuid = null;
58
59 private JTextField jTextFieldGuid = null;
60
61 private JLabel jLabelUsage = null;
62
63 private JComboBox jComboBoxUsage = null;
64
65 private JButton jButtonOk = null;
66
67 private JButton jButtonCancel = null;
68
69 private JLabel jLabelDataHubRecord = null;
70
71 private JTextField jTextFieldDataHubRecord = null;
72
73 private JButton jButtonGenerateGuid = null;
74
75 private JLabel jLabelOverrideID = null;
76
77 private JTextField jTextFieldOverrideID = null;
78
79 private StarLabel jStarLabel1 = null;
80
81 /**
82 This method initializes jTextFieldGuid
83
84 @return javax.swing.JTextField jTextFieldGuid
85
86 **/
87 private JTextField getJTextFieldGuid() {
88 if (jTextFieldGuid == null) {
89 jTextFieldGuid = new JTextField();
90 jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 35, 240, 20));
91 }
92 return jTextFieldGuid;
93 }
94
95 /**
96 This method initializes jComboBoxUsage
97
98 @return javax.swing.JComboBox jComboBoxUsage
99
100 **/
101 private JComboBox getJComboBoxUsage() {
102 if (jComboBoxUsage == null) {
103 jComboBoxUsage = new JComboBox();
104 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
105 }
106 return jComboBoxUsage;
107 }
108
109 /**
110 This method initializes jButtonOk
111
112 @return javax.swing.JButton jButtonOk
113
114 **/
115 private JButton getJButtonOk() {
116 if (jButtonOk == null) {
117 jButtonOk = new JButton();
118 jButtonOk.setText("OK");
119 jButtonOk.setBounds(new java.awt.Rectangle(280, 115, 90, 20));
120 jButtonOk.addActionListener(this);
121 }
122 return jButtonOk;
123 }
124
125 /**
126 This method initializes jButtonCancel
127
128 @return javax.swing.JButton jButtonCancel
129
130 **/
131 private JButton getJButtonCancel() {
132 if (jButtonCancel == null) {
133 jButtonCancel = new JButton();
134 jButtonCancel.setText("Cancel");
135 jButtonCancel.setBounds(new java.awt.Rectangle(390, 115, 90, 20));
136 jButtonCancel.addActionListener(this);
137 }
138 return jButtonCancel;
139 }
140
141 /**
142 This method initializes jTextFieldDataHubRecord
143
144 @return javax.swing.JTextField jTextFieldDataHubRecord
145
146 **/
147 private JTextField getJTextFieldDataHubRecord() {
148 if (jTextFieldDataHubRecord == null) {
149 jTextFieldDataHubRecord = new JTextField();
150 jTextFieldDataHubRecord.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
151 }
152 return jTextFieldDataHubRecord;
153 }
154
155 /**
156 This method initializes jButtonGenerateGuid
157
158 @return javax.swing.JButton jButtonGenerateGuid
159
160 **/
161 private JButton getJButtonGenerateGuid() {
162 if (jButtonGenerateGuid == null) {
163 jButtonGenerateGuid = new JButton();
164 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(405, 35, 75, 20));
165 jButtonGenerateGuid.setText("GEN");
166 jButtonGenerateGuid.addActionListener(this);
167 }
168 return jButtonGenerateGuid;
169 }
170
171 /**
172 This method initializes jTextFieldOverrideID
173
174 @return javax.swing.JTextField jTextFieldOverrideID
175
176 **/
177 private JTextField getJTextFieldOverrideID() {
178 if (jTextFieldOverrideID == null) {
179 jTextFieldOverrideID = new JTextField();
180 jTextFieldOverrideID.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
181 }
182 return jTextFieldOverrideID;
183 }
184
185 public static void main(String[] args) {
186
187 }
188
189 /**
190 This is the default constructor
191
192 **/
193 public ModuleDataHubs() {
194 super();
195 init();
196 this.setVisible(true);
197 }
198
199 /**
200 This is the override edit constructor
201
202 @param inDataHubs The input DataHubsDocument.DataHubs
203
204 **/
205 public ModuleDataHubs(DataHubsDocument.DataHubs inDataHubs) {
206 super();
207 init(inDataHubs);
208 this.setVisible(true);
209 }
210
211 /**
212 This is the override edit constructor
213
214 @param inDataHubs DataHubsDocument.DataHubs
215 @param type The input data of node type
216 @param index The input data of node index
217
218 **/
219 public ModuleDataHubs(DataHubsDocument.DataHubs inDataHubs, int type, int index) {
220 super();
221 init(inDataHubs, type, index);
222 this.setVisible(true);
223 }
224
225 /**
226 This method initializes this
227
228 @param inDataHubs The input DataHubsDocument.DataHubs
229
230 **/
231 private void init(DataHubsDocument.DataHubs inDataHubs) {
232 init();
233 this.setDataHubs(inDataHubs);
234 }
235
236 /**
237 This method initializes this
238 Fill values to all fields if these values are not empty
239
240 @param inDataHubs The input DataHubsDocument.DataHubs
241 @param type The input data of node type
242 @param index The input data of node index
243
244 **/
245 private void init(DataHubsDocument.DataHubs inDataHubs, int type, int index) {
246 init(inDataHubs);
247 this.location = index;
248 if (this.dataHubs.getDataHubRecordList().size() > 0) {
249 if (this.dataHubs.getDataHubRecordArray(index).getStringValue() != null) {
250 this.jTextFieldDataHubRecord.setText(this.dataHubs.getDataHubRecordArray(index).getStringValue()
251 .toString());
252 }
253 if (this.dataHubs.getDataHubRecordArray(index).getGuid() != null) {
254 this.jTextFieldGuid.setText(this.dataHubs.getDataHubRecordArray(index).getGuid());
255 }
256 if (this.dataHubs.getDataHubRecordArray(index).getUsage() != null) {
257 this.jComboBoxUsage.setSelectedItem(this.dataHubs.getDataHubRecordArray(index).getUsage().toString());
258 }
259 this.jTextFieldOverrideID
260 .setText(String
261 .valueOf(this.dataHubs.getDataHubRecordArray(index).getOverrideID()));
262 }
263 }
264
265 /**
266 Disable all components when the mode is view
267
268 @param isView true - The view mode; false - The non-view mode
269
270 **/
271 public void setViewMode(boolean isView) {
272 this.jButtonOk.setVisible(false);
273 this.jButtonCancel.setVisible(false);
274 if (isView) {
275 this.jTextFieldDataHubRecord.setEnabled(!isView);
276 this.jTextFieldGuid.setEnabled(!isView);
277 this.jComboBoxUsage.setEnabled(!isView);
278 this.jTextFieldOverrideID.setEnabled(!isView);
279 this.jButtonCancel.setEnabled(!isView);
280 this.jButtonGenerateGuid.setEnabled(!isView);
281 this.jButtonOk.setEnabled(!isView);
282 }
283 }
284
285 /**
286 This method initializes this
287
288 **/
289 private void init() {
290 this.setSize(500, 515);
291 this.setContentPane(getJContentPane());
292 this.setTitle("Data Hubs");
293 initFrame();
294 this.setViewMode(false);
295 }
296
297 /**
298 This method initializes jContentPane
299
300 @return javax.swing.JPanel jContentPane
301
302 **/
303 private JPanel getJContentPane() {
304 if (jContentPane == null) {
305 jLabelOverrideID = new JLabel();
306 jLabelOverrideID.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
307 jLabelOverrideID.setText("Override ID");
308 jLabelDataHubRecord = new JLabel();
309 jLabelDataHubRecord.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
310 jLabelDataHubRecord.setText("Data Hub Record");
311 jLabelGuid = new JLabel();
312 jLabelGuid.setText("Guid");
313 jLabelGuid.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
314 jLabelUsage = new JLabel();
315 jLabelUsage.setText("Usage");
316 jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
317 jContentPane = new JPanel();
318 jContentPane.setLayout(null);
319 jContentPane.add(jLabelGuid, null);
320 jContentPane.add(getJTextFieldGuid(), null);
321 jContentPane.add(jLabelUsage, null);
322 jContentPane.add(getJComboBoxUsage(), null);
323 jContentPane.add(getJButtonOk(), null);
324 jContentPane.add(getJButtonCancel(), null);
325 jContentPane.add(jLabelDataHubRecord, null);
326 jContentPane.add(getJTextFieldDataHubRecord(), null);
327 jContentPane.add(getJButtonGenerateGuid(), null);
328 jContentPane.add(jLabelOverrideID, null);
329 jContentPane.add(getJTextFieldOverrideID(), null);
330
331 jStarLabel1 = new StarLabel();
332 jStarLabel1.setLocation(new java.awt.Point(0, 10));
333
334 jContentPane.add(jStarLabel1, null);
335 }
336 return jContentPane;
337 }
338
339 /**
340 This method initializes Usage type
341
342 **/
343 private void initFrame() {
344 jComboBoxUsage.addItem("ALWAYS_CONSUMED");
345 jComboBoxUsage.addItem("SOMETIMES_CONSUMED");
346 jComboBoxUsage.addItem("ALWAYS_PRODUCED");
347 jComboBoxUsage.addItem("SOMETIMES_PRODUCED");
348 jComboBoxUsage.addItem("PRIVATE");
349 }
350
351 /* (non-Javadoc)
352 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
353 *
354 * Override actionPerformed to listen all actions
355 *
356 */
357 public void actionPerformed(ActionEvent arg0) {
358 if (arg0.getSource() == jButtonOk) {
359 this.setEdited(true);
360 this.save();
361 this.dispose();
362 }
363 if (arg0.getSource() == jButtonCancel) {
364 this.dispose();
365 }
366
367 if (arg0.getSource() == jButtonGenerateGuid) {
368 jTextFieldGuid.setText(Tools.generateUuidString());
369 }
370 }
371
372 /**
373 Get DataHubsDocument.DataHubs
374
375 @return DataHubsDocument.DataHubs
376
377 **/
378 public DataHubsDocument.DataHubs getDataHubs() {
379 return dataHubs;
380 }
381
382 /**
383 Set DataHubsDocument.DataHubs
384
385 @param dataHubs DataHubsDocument.DataHubs
386
387 **/
388 public void setDataHubs(DataHubsDocument.DataHubs dataHubs) {
389 this.dataHubs = dataHubs;
390 }
391
392 /**
393 Data validation for all fields
394
395 @retval true - All datas are valid
396 @retval false - At least one data is invalid
397
398 **/
399 public boolean check() {
400 //
401 // Check if all required fields are not empty
402 //
403 if (isEmpty(this.jTextFieldDataHubRecord.getText())) {
404 Log.err("Data Hub Record couldn't be empty");
405 return false;
406 }
407
408 //
409 // Check if all fields have correct data types
410 //
411 if (!isEmpty(this.jTextFieldGuid.getText()) && !DataValidation.isGuid(this.jTextFieldGuid.getText())) {
412 Log.err("Incorrect data type for Guid");
413 return false;
414 }
415 if (!isEmpty(this.jTextFieldOverrideID.getText())
416 && !DataValidation.isOverrideID(this.jTextFieldOverrideID.getText())) {
417 Log.err("Incorrect data type for Override ID");
418 return false;
419 }
420
421 return true;
422 }
423
424 /**
425 Save all components of DataHubs
426 if exists dataHubs, set the value directly
427 if not exists dataHubs, new an instance first
428
429 **/
430 public void save() {
431 try {
432 if (this.dataHubs == null) {
433 dataHubs = DataHubsDocument.DataHubs.Factory.newInstance();
434 }
435 DataHubsDocument.DataHubs.DataHubRecord dataHubRecord = DataHubsDocument.DataHubs.DataHubRecord.Factory
436 .newInstance();
437 if (!isEmpty(this.jTextFieldDataHubRecord.getText())) {
438 dataHubRecord.setStringValue(this.jTextFieldDataHubRecord.getText());
439 }
440 if (!isEmpty(this.jTextFieldGuid.getText())) {
441 dataHubRecord.setGuid(this.jTextFieldGuid.getText());
442 }
443 dataHubRecord.setUsage(DataHubUsage.Enum.forString(jComboBoxUsage.getSelectedItem().toString()));
444 if (!isEmpty(this.jTextFieldOverrideID.getText())) {
445 dataHubRecord.setOverrideID(Integer.parseInt(this.jTextFieldOverrideID.getText()));
446 }
447 if (location > -1) {
448 dataHubs.setDataHubRecordArray(location, dataHubRecord);
449 } else {
450 dataHubs.addNewDataHubRecord();
451 dataHubs.setDataHubRecordArray(dataHubs.getDataHubRecordList().size() - 1, dataHubRecord);
452 }
453 } catch (Exception e) {
454 Log.err("Update Data Hubs", e.getMessage());
455 }
456 }
457 }