289dd148a5389136fb154315a6d219626625b140
[people/mcb30/edk2.git] / edk2 / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / packaging / ui / SpdPcdDefs.java
1 /** @file\r
2   Java class SpdPcdDefs is GUI for create PCD definition elements of spd file.\r
3  \r
4 Copyright (c) 2006, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution.  The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9 \r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12 **/\r
13 package org.tianocore.frameworkwizard.packaging.ui;\r
14 \r
15 import java.awt.Dimension;\r
16 import java.awt.event.ActionEvent;\r
17 import java.awt.event.ComponentEvent;\r
18 \r
19 import javax.swing.DefaultCellEditor;\r
20 import javax.swing.JFrame;\r
21 import javax.swing.JOptionPane;\r
22 import javax.swing.JPanel;\r
23 import javax.swing.JLabel;\r
24 import javax.swing.JTextField;\r
25 import javax.swing.JComboBox;\r
26 import javax.swing.JButton;\r
27 import javax.swing.ListSelectionModel;\r
28 \r
29 import javax.swing.event.InternalFrameAdapter;\r
30 import javax.swing.event.InternalFrameEvent;\r
31 import javax.swing.event.ListSelectionEvent;\r
32 import javax.swing.event.ListSelectionListener;\r
33 import javax.swing.event.TableModelEvent;\r
34 import javax.swing.event.TableModelListener;\r
35 import javax.swing.table.DefaultTableModel;\r
36 import javax.swing.table.TableColumn;\r
37 import javax.swing.table.TableModel;\r
38 \r
39 import org.tianocore.PackageSurfaceAreaDocument;\r
40 \r
41 import org.tianocore.frameworkwizard.common.DataValidation;\r
42 import org.tianocore.frameworkwizard.common.Tools;\r
43 import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageType;\r
44 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r
45 import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
46 import javax.swing.JScrollPane;\r
47 import javax.swing.JTable;\r
48 import javax.swing.JCheckBox;\r
49 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;\r
50 import org.tianocore.frameworkwizard.platform.ui.ListEditor;\r
51 \r
52 import java.awt.Rectangle;\r
53 import java.util.Vector;\r
54 \r
55 /**\r
56  GUI for create PCD definition elements of spd file\r
57   \r
58  @since PackageEditor 1.0\r
59 **/\r
60 public class SpdPcdDefs extends IInternalFrame implements TableModelListener{\r
61 \r
62     /**\r
63      * \r
64      */\r
65     private static final long serialVersionUID = 1L;\r
66 \r
67     static JFrame frame;\r
68     \r
69     private JPanel jContentPane = null;  \r
70 \r
71     private JLabel jLabelItemType = null;\r
72 \r
73     private JLabel jLabelC_Name = null;\r
74 \r
75     private JTextField jTextFieldC_Name = null;\r
76 \r
77     private JLabel jLabelToken = null;\r
78 \r
79     private JTextField jTextFieldToken = null;\r
80 \r
81     private JLabel jLabelDataType = null;\r
82 \r
83     private JButton jButtonOk = null;\r
84 \r
85     private JButton jButtonCancel = null;\r
86 \r
87     private JComboBox jComboBoxDataType = null;\r
88 \r
89     private SpdFileContents sfc = null;\r
90     \r
91     private OpeningPackageType docConsole = null;\r
92 \r
93     private StarLabel jStarLabel2 = null;\r
94 \r
95     private StarLabel jStarLabel3 = null;\r
96 \r
97     private StarLabel jStarLabel4 = null;\r
98 \r
99     private StarLabel jStarLabel = null;\r
100 \r
101     private StarLabel jStarLabel1 = null;\r
102 \r
103     private JLabel jLabelTokenSpace = null;\r
104 \r
105     private JComboBox jComboBoxTsGuid = null;\r
106 \r
107     private JLabel jLabelVarVal = null;\r
108 \r
109     private JTextField jTextFieldHelp = null;\r
110 \r
111     private JLabel jLabelDefVal = null;\r
112 \r
113     private JTextField jTextFieldDefaultValue = null;\r
114 \r
115     private JButton jButtonAdd = null;\r
116     \r
117     private CheckboxTableModel model = null;\r
118 \r
119     private JButton jButtonRemove = null;\r
120 \r
121     private JButton jButtonClearAll = null;\r
122 \r
123     private JScrollPane jScrollPane = null;\r
124 \r
125     private JTable jTable = null;\r
126     \r
127     private JScrollPane topScrollPane = null;  //  @jve:decl-index=0:visual-constraint="390,10"\r
128     \r
129     private int selectedRow = -1;\r
130 \r
131     private StarLabel starLabel = null;\r
132 \r
133     private JCheckBox jCheckBoxFeatureFlag = null;\r
134 \r
135     private JCheckBox jCheckBoxFixedAtBuild = null;\r
136 \r
137     private JCheckBox jCheckBoxPatchInMod = null;\r
138 \r
139     private JCheckBox jCheckBoxDyn = null;\r
140 \r
141     private JCheckBox jCheckBoxDynEx = null;\r
142 \r
143     private JScrollPane jScrollPaneArch = null;\r
144 \r
145     private ICheckBoxList iCheckBoxListArch = null;\r
146 \r
147     private JScrollPane jScrollPaneMod = null;\r
148 \r
149     private ICheckBoxList iCheckBoxListMod = null;\r
150 \r
151     private JLabel jLabelSupMod = null;\r
152 \r
153     private JLabel jLabelSupArch = null;\r
154 \r
155     /**\r
156      This method initializes this\r
157      \r
158      **/\r
159     private void initialize() {\r
160         this.setTitle("PCD Declarations");\r
161         this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);\r
162 \r
163     }\r
164 \r
165     /**\r
166      This method initializes jTextFieldC_Name   \r
167         \r
168      @return javax.swing.JTextField     \r
169      **/\r
170     private JTextField getJTextFieldC_Name() {\r
171         if (jTextFieldC_Name == null) {\r
172             jTextFieldC_Name = new JTextField();\r
173             jTextFieldC_Name.setBounds(new java.awt.Rectangle(156,9,317,20));\r
174             jTextFieldC_Name.setPreferredSize(new java.awt.Dimension(315,20));\r
175         }\r
176         return jTextFieldC_Name;\r
177     }\r
178 \r
179     /**\r
180      This method initializes jTextFieldToken    \r
181         \r
182      @return javax.swing.JTextField     \r
183      **/\r
184     private JTextField getJTextFieldToken() {\r
185         if (jTextFieldToken == null) {\r
186             jTextFieldToken = new JTextField();\r
187             jTextFieldToken.setBounds(new java.awt.Rectangle(156,33,317,20));\r
188             jTextFieldToken.setPreferredSize(new java.awt.Dimension(315,20));\r
189         }\r
190         return jTextFieldToken;\r
191     }\r
192 \r
193     /**\r
194      This method initializes jButtonOk  \r
195         \r
196      @return javax.swing.JButton        \r
197      **/\r
198     private JButton getJButtonOk() {\r
199         if (jButtonOk == null) {\r
200             jButtonOk = new JButton();\r
201             jButtonOk.setText("OK");\r
202             jButtonOk.setBounds(new java.awt.Rectangle(279,276,90,20));\r
203             jButtonOk.setVisible(false);\r
204             jButtonOk.addActionListener(this);\r
205         }\r
206         return jButtonOk;\r
207     }\r
208 \r
209     /**\r
210      This method initializes jButtonCancel      \r
211         \r
212      @return javax.swing.JButton        \r
213      **/\r
214     private JButton getJButtonCancel() {\r
215         if (jButtonCancel == null) {\r
216             jButtonCancel = new JButton();\r
217             jButtonCancel.setText("Cancel");\r
218             jButtonCancel.setBounds(new java.awt.Rectangle(389,276,82,20));\r
219             jButtonCancel.setVisible(false);\r
220             jButtonCancel.addActionListener(this);\r
221         }\r
222         return jButtonCancel;\r
223     }\r
224 \r
225     /**\r
226      This method initializes jComboBoxDataType  \r
227         \r
228      @return javax.swing.JComboBox      \r
229      **/\r
230     private JComboBox getJComboBoxDataType() {\r
231         if (jComboBoxDataType == null) {\r
232             jComboBoxDataType = new JComboBox();\r
233             jComboBoxDataType.setBounds(new java.awt.Rectangle(156,84,110,20));\r
234         }\r
235         return jComboBoxDataType;\r
236     }\r
237 \r
238     /**\r
239      This is the default constructor\r
240      **/\r
241     public SpdPcdDefs() {\r
242         super();\r
243         init();\r
244         initialize();\r
245         \r
246     }\r
247 \r
248     public SpdPcdDefs(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa) {\r
249         this();\r
250         sfc = new SpdFileContents(inPsa);\r
251         init(sfc);\r
252     }\r
253     \r
254     public SpdPcdDefs(OpeningPackageType opt) {\r
255         this(opt.getXmlSpd());\r
256         docConsole = opt;\r
257     }\r
258     /**\r
259      This method initializes this\r
260      \r
261      @return void\r
262      **/\r
263     private void init() {\r
264         this.setSize(500, 650);\r
265         this.setContentPane(getJContentPane());\r
266         this.addInternalFrameListener(new InternalFrameAdapter(){\r
267             public void internalFrameDeactivated(InternalFrameEvent e){\r
268                 if (jTable.isEditing()) {\r
269                     jTable.getCellEditor().stopCellEditing();\r
270                 }\r
271             }\r
272         });\r
273         \r
274         this.setVisible(true);\r
275     }\r
276 \r
277     private void init(SpdFileContents sfc){\r
278         initFrame(sfc);\r
279         if (sfc.getSpdPcdDefinitionCount() == 0) {\r
280             return ;\r
281         }\r
282         String[][] saa = new String[sfc.getSpdPcdDefinitionCount()][8];\r
283         String[][] usage = new String[sfc.getSpdPcdDefinitionCount()][5];\r
284         Object[] rowData = new Object[13];\r
285         sfc.getSpdPcdDefinitions(saa, usage);\r
286         int i = 0;\r
287         while (i < saa.length) {\r
288            \r
289             for (int k = 0; k < 6; ++k) {\r
290                 rowData[k] = saa[i][k];\r
291             }\r
292             for (int m = 6; m < 11; ++m) {\r
293                 rowData[m] = new Boolean("false");\r
294             }\r
295             int j = 0;\r
296             while (j < 5) {\r
297                 if (usage[i][j] == null || usage[i][j].length()==0){\r
298                     ++j;\r
299                     continue;\r
300                 }\r
301                 if (usage[i][j].equals("FEATURE_FLAG")){\r
302                     rowData[6] = new Boolean("true");\r
303                 }\r
304                 if (usage[i][j].equals("FIXED_AT_BUILD")){\r
305                     rowData[7] = new Boolean("true");\r
306                 }\r
307                 if (usage[i][j].equals("PATCHABLE_IN_MODULE")){\r
308                     rowData[8] = new Boolean("true");\r
309                 }\r
310                 if (usage[i][j].equals("DYNAMIC")){\r
311                     rowData[9] = new Boolean("true");\r
312                 }\r
313                 if (usage[i][j].equals("DYNAMIC_EX")){\r
314                     rowData[10] = new Boolean("true");\r
315                 }\r
316                 \r
317                 ++j;\r
318             }\r
319             \r
320             rowData[11] = saa[i][6];\r
321             rowData[12] = saa[i][7];\r
322             \r
323             model.addRow(rowData);\r
324             \r
325             i++;\r
326         }\r
327         \r
328         \r
329         \r
330     }\r
331     \r
332     private JScrollPane getJContentPane(){\r
333         if (topScrollPane == null){\r
334             topScrollPane = new JScrollPane();\r
335             topScrollPane.setSize(new java.awt.Dimension(482,451));\r
336             topScrollPane.setViewportView(getJContentPane1());\r
337         }\r
338         return topScrollPane;\r
339     }\r
340     private JPanel getJContentPane1() {\r
341                 if (jContentPane == null) {     \r
342            \r
343             jLabelSupArch = new JLabel();\r
344             jLabelSupArch.setBounds(new java.awt.Rectangle(241,192,89,16));\r
345             jLabelSupArch.setText("Supported Architectures");\r
346             jLabelSupArch.setEnabled(true);\r
347             jLabelSupMod = new JLabel();\r
348             jLabelSupMod.setBounds(new java.awt.Rectangle(15,193,103,16));\r
349             jLabelSupMod.setText("Supported Module type");\r
350             jLabelSupMod.setEnabled(true);\r
351             starLabel = new StarLabel();\r
352             starLabel.setBounds(new java.awt.Rectangle(2,134,10,20));\r
353             jLabelDefVal = new JLabel();\r
354             jLabelDefVal.setBounds(new java.awt.Rectangle(277,84,80,20));\r
355             jLabelDefVal.setText("Default Value");\r
356             jLabelVarVal = new JLabel();\r
357             jLabelVarVal.setBounds(new java.awt.Rectangle(11,133,84,20));\r
358             jLabelVarVal.setText("Valid Usage");\r
359             jLabelC_Name = new JLabel();\r
360             jLabelC_Name.setText("C Name");\r
361             jLabelC_Name.setBounds(new java.awt.Rectangle(11,9,140,20));\r
362             jLabelTokenSpace = new JLabel();\r
363             jLabelTokenSpace.setBounds(new java.awt.Rectangle(11,58,140,20));\r
364             jLabelTokenSpace.setText("Token Space");\r
365             jLabelDataType = new JLabel();\r
366             jLabelDataType.setText("Data Type");\r
367             jLabelDataType.setBounds(new java.awt.Rectangle(11,83,140,20));\r
368             jLabelToken = new JLabel();\r
369             jLabelToken.setText("Token Number");\r
370             jLabelToken.setBounds(new java.awt.Rectangle(11,33,140,20));\r
371             jLabelItemType = new JLabel();\r
372             jLabelItemType.setText("Help Text");\r
373             jLabelItemType.setBounds(new java.awt.Rectangle(11,108,140,20));\r
374             \r
375             \r
376             jContentPane = new JPanel();\r
377             jContentPane.setLayout(null);\r
378             jContentPane.setPreferredSize(new java.awt.Dimension(479,375));\r
379             \r
380             jContentPane.add(jLabelItemType, null);\r
381             jContentPane.add(jLabelC_Name, null);\r
382             jContentPane.add(jLabelTokenSpace, null);\r
383             jContentPane.add(getJComboBoxTsGuid(), null);\r
384             jContentPane.add(jLabelVarVal, null);\r
385             jContentPane.add(getJTextFieldC_Name(), null);\r
386             jContentPane.add(jLabelToken, null);\r
387             jContentPane.add(getJTextFieldToken(), null);\r
388             jContentPane.add(jLabelDataType, null);\r
389             jContentPane.add(getJButtonOk(), null);\r
390             jContentPane.add(getJButtonCancel(), null);\r
391             jContentPane.add(getJComboBoxDataType(), null);\r
392             \r
393             jStarLabel = new StarLabel();\r
394             jStarLabel1 = new StarLabel();\r
395             jStarLabel1.setBounds(new java.awt.Rectangle(2,8,10,20));\r
396             jStarLabel2 = new StarLabel();\r
397             jStarLabel3 = new StarLabel();\r
398             jStarLabel4 = new StarLabel();\r
399             jStarLabel.setLocation(new java.awt.Point(2,84));\r
400             jStarLabel4.setLocation(new java.awt.Point(2, 109));\r
401             jStarLabel2.setLocation(new java.awt.Point(2,33));\r
402             jStarLabel3.setLocation(new java.awt.Point(2, 58));\r
403             jStarLabel3.setSize(new java.awt.Dimension(8,20));\r
404             jContentPane.add(jStarLabel2, null);\r
405             jContentPane.add(jStarLabel3, null);\r
406             jContentPane.add(jStarLabel, null);\r
407             jContentPane.add(jStarLabel1, null);\r
408             jContentPane.add(jStarLabel4, null);\r
409             jContentPane.add(getJTextFieldHelp(), null);\r
410             jContentPane.add(jLabelDefVal, null);\r
411             jContentPane.add(getJTextFieldDefaultValue(), null);\r
412             jContentPane.add(getJButtonAdd(), null);\r
413             jContentPane.add(getJButtonRemove(), null);\r
414             jContentPane.add(getJButtonClearAll(), null);\r
415             jContentPane.add(getJScrollPane(), null);\r
416             jContentPane.add(starLabel, null);\r
417             jContentPane.add(getJCheckBoxFeatureFlag(), null);\r
418             jContentPane.add(getJCheckBoxFixedAtBuild(), null);\r
419             jContentPane.add(getJCheckBoxPatchInMod(), null);\r
420             jContentPane.add(getJCheckBoxDyn(), null);\r
421             jContentPane.add(getJCheckBoxDynEx(), null);\r
422             jContentPane.add(getJScrollPaneArch(), null);\r
423             jContentPane.add(getJScrollPaneMod(), null);\r
424             jContentPane.add(jLabelSupMod, null);\r
425             jContentPane.add(jLabelSupArch, null);\r
426         }\r
427         return jContentPane;\r
428     }\r
429 \r
430     /**\r
431      This method initializes comboboxes                 \r
432                         jContentPane.add(jLabelTokenSpace, null);\r
433     \r
434      **/\r
435     private void initFrame(SpdFileContents sfc) {\r
436 \r
437         jComboBoxDataType.addItem("UINT8");\r
438         jComboBoxDataType.addItem("UINT16");\r
439         jComboBoxDataType.addItem("UINT32");\r
440         jComboBoxDataType.addItem("UINT64");\r
441         jComboBoxDataType.addItem("VOID*");\r
442         jComboBoxDataType.addItem("BOOLEAN");\r
443         jComboBoxDataType.setSelectedIndex(0);\r
444         \r
445         Vector<String> vGuidCName = new Vector<String>();\r
446         sfc.getSpdGuidDeclWithType(vGuidCName, "TOKEN_SPACE_GUID");\r
447         for (int i = 0; i < vGuidCName.size(); ++i) {\r
448             jComboBoxTsGuid.addItem(vGuidCName.get(i));\r
449         }\r
450     }\r
451 \r
452     public void actionPerformed(ActionEvent arg0) {\r
453         \r
454         \r
455             if (arg0.getSource() == jButtonOk) {\r
456                 this.save();\r
457                 this.dispose();\r
458             }\r
459             if (arg0.getSource() == jButtonCancel) {\r
460                 this.dispose();\r
461             }\r
462 \r
463             if (arg0.getSource() == jButtonAdd) {\r
464                 //ToDo: check before add\r
465           \r
466                 boolean[] b = {jCheckBoxFeatureFlag.isSelected(), jCheckBoxFixedAtBuild.isSelected(), jCheckBoxPatchInMod.isSelected(), jCheckBoxDyn.isSelected(), jCheckBoxDynEx.isSelected()};\r
467                 if (!checkValidUsage(b)) {\r
468                     return;\r
469                 }\r
470                 String archList = vectorToString(iCheckBoxListArch.getAllCheckedItemsString());\r
471                 if (archList.length() == 0) {\r
472                     archList = null;\r
473                 }\r
474                 String modTypeList = vectorToString(iCheckBoxListMod.getAllCheckedItemsString());\r
475                 if (modTypeList.length() == 0) {\r
476                     modTypeList = null;\r
477                 }\r
478                 Object[] row = {jTextFieldC_Name.getText(), jTextFieldToken.getText(),\r
479                                 jComboBoxTsGuid.getSelectedItem(), jComboBoxDataType.getSelectedItem(), \r
480                                 jTextFieldDefaultValue.getText(), jTextFieldHelp.getText(),\r
481                                 jCheckBoxFeatureFlag.isSelected(), jCheckBoxFixedAtBuild.isSelected(),\r
482                                 jCheckBoxPatchInMod.isSelected(), jCheckBoxDyn.isSelected(), jCheckBoxDynEx.isSelected(),\r
483                                 archList, modTypeList};\r
484                 if (!dataValidation(row)) {\r
485                     return;\r
486                 }\r
487                 \r
488                 if (tokenCNameExisted(jTextFieldToken.getText(), jTextFieldC_Name.getText())) {\r
489                     return;\r
490                 }\r
491                 \r
492                 model.addRow(row);\r
493                 jTable.changeSelection(model.getRowCount()-1, 0, false, false);\r
494                 String usage = getValidUsage(jCheckBoxFeatureFlag.isSelected(), jCheckBoxFixedAtBuild.isSelected(), jCheckBoxPatchInMod.isSelected(), jCheckBoxDyn.isSelected(), jCheckBoxDynEx.isSelected());\r
495                 if (usage.length() == 0) {\r
496                     usage = null;\r
497                 }\r
498                 sfc.genSpdPcdDefinitions(row[0]+"", row[1]+"", row[3]+"", usage, row[2]+"", row[4]+"", row[5]+"", archList, modTypeList);\r
499                 docConsole.setSaved(false);\r
500             }\r
501             //\r
502             // remove selected line\r
503             //\r
504             if (arg0.getSource() == jButtonRemove) {\r
505                 if (jTable.isEditing()){\r
506                     jTable.getCellEditor().stopCellEditing();\r
507                 }\r
508                 int rowSelected = selectedRow;\r
509                 if (rowSelected >= 0) {\r
510                     model.removeRow(rowSelected);\r
511                     sfc.removeSpdPcdDefinition(rowSelected);\r
512                     docConsole.setSaved(false);\r
513                 }\r
514             }\r
515 \r
516             if (arg0.getSource() == jButtonClearAll) {\r
517                 if (model.getRowCount() == 0) {\r
518                     return;\r
519                 }\r
520                 model.setRowCount(0);\r
521                 sfc.removeSpdPcdDefinition();\r
522                 docConsole.setSaved(false);\r
523             }\r
524             \r
525     }\r
526 \r
527     protected void save() {\r
528         \r
529     }\r
530 \r
531     /**\r
532      * This method initializes jComboBoxTsGuid  \r
533      *  \r
534      * @return javax.swing.JComboBox    \r
535      */\r
536     private JComboBox getJComboBoxTsGuid() {\r
537         if (jComboBoxTsGuid == null) {\r
538             jComboBoxTsGuid = new JComboBox();\r
539             jComboBoxTsGuid.setBounds(new java.awt.Rectangle(156,58,315,20));\r
540     \r
541         }\r
542         return jComboBoxTsGuid;\r
543     }\r
544 \r
545     /**\r
546      * This method initializes jTextField       \r
547      *  \r
548      * @return javax.swing.JTextField   \r
549      */\r
550     private JTextField getJTextFieldHelp() {\r
551         if (jTextFieldHelp == null) {\r
552             jTextFieldHelp = new JTextField();\r
553             jTextFieldHelp.setBounds(new java.awt.Rectangle(156,108,317,20));\r
554             jTextFieldHelp.setPreferredSize(new java.awt.Dimension(315,20));\r
555         }\r
556         return jTextFieldHelp;\r
557     }\r
558 \r
559     /**\r
560      * This method initializes jTextFieldDefaultValue   \r
561      *  \r
562      * @return javax.swing.JTextField   \r
563      */\r
564     private JTextField getJTextFieldDefaultValue() {\r
565         if (jTextFieldDefaultValue == null) {\r
566             jTextFieldDefaultValue = new JTextField();\r
567             jTextFieldDefaultValue.setBounds(new java.awt.Rectangle(368,84,105,20));\r
568             jTextFieldDefaultValue.setPreferredSize(new java.awt.Dimension(104,20));\r
569         }\r
570         return jTextFieldDefaultValue;\r
571     }\r
572 \r
573     /**\r
574      * This method initializes jButtonAdd       \r
575      *  \r
576      * @return javax.swing.JButton      \r
577      */\r
578     private JButton getJButtonAdd() {\r
579         if (jButtonAdd == null) {\r
580             jButtonAdd = new JButton();\r
581             jButtonAdd.setBounds(new java.awt.Rectangle(195,277,71,20));\r
582             jButtonAdd.setPreferredSize(new java.awt.Dimension(70,20));\r
583             jButtonAdd.setText("Add");\r
584             jButtonAdd.addActionListener(this);\r
585         }\r
586         return jButtonAdd;   \r
587         \r
588     }   \r
589     \r
590     /**\r
591      * This method initializes jButtonRemove    \r
592      *  \r
593      * @return javax.swing.JButton      \r
594      */\r
595     private JButton getJButtonRemove() {\r
596         if (jButtonRemove == null) {\r
597             jButtonRemove = new JButton();\r
598             jButtonRemove.setBounds(new java.awt.Rectangle(278,277,81,20));\r
599             jButtonRemove.setPreferredSize(new java.awt.Dimension(70,20));\r
600             jButtonRemove.setText("Delete");\r
601             jButtonRemove.addActionListener(this);\r
602         }\r
603         return jButtonRemove;\r
604     }\r
605 \r
606     /**\r
607      * This method initializes jButtonClearAll  \r
608      *  \r
609      * @return javax.swing.JButton      \r
610      */\r
611     private JButton getJButtonClearAll() {\r
612         if (jButtonClearAll == null) {\r
613             jButtonClearAll = new JButton();\r
614             jButtonClearAll.setBounds(new java.awt.Rectangle(382,277,90,20));\r
615             jButtonClearAll.setPreferredSize(new java.awt.Dimension(81,20));\r
616             jButtonClearAll.setText("Clear All");\r
617             jButtonClearAll.addActionListener(this);\r
618         }\r
619         return jButtonClearAll;\r
620     }\r
621 \r
622     public void componentResized(ComponentEvent arg0) {\r
623         int intPreferredWidth = 500;\r
624         \r
625         Tools.resizeComponentWidth(this.jTextFieldC_Name, this.getWidth(), intPreferredWidth);\r
626         Tools.resizeComponentWidth(this.jTextFieldToken, this.getWidth(), intPreferredWidth);\r
627         Tools.resizeComponentWidth(this.jComboBoxTsGuid, this.getWidth(), intPreferredWidth);\r
628         Tools.resizeComponentWidth(this.jTextFieldDefaultValue, this.getWidth(), intPreferredWidth);\r
629         Tools.resizeComponentWidth(this.jTextFieldHelp, this.getWidth(), intPreferredWidth);\r
630         Tools.resizeComponentWidth(this.jScrollPane, this.getWidth(), intPreferredWidth);\r
631         \r
632         Tools.resizeComponentWidth(this.jTextFieldDefaultValue, this.getWidth(), intPreferredWidth);\r
633 //        relocateComponentX(this.jButtonClearAll, this.getWidth(), DataType.SPACE_TO_RIGHT_FOR_GENERATE_BUTTON);\r
634 //        relocateComponentX(this.jButtonRemove, this.getWidth(), DataType.SPACE_TO_RIGHT_FOR_GENERATE_BUTTON);\r
635 //        relocateComponentX(this.jButtonAdd, this.getWidth(), DataType.SPACE_TO_RIGHT_FOR_GENERATE_BUTTON);\r
636     }\r
637 \r
638     /**\r
639      * This method initializes jScrollPane      \r
640      *  \r
641      * @return javax.swing.JScrollPane  \r
642      */\r
643     private JScrollPane getJScrollPane() {\r
644         if (jScrollPane == null) {\r
645             jScrollPane = new JScrollPane();\r
646             jScrollPane.setBounds(new java.awt.Rectangle(5,301,1473,259));\r
647             jScrollPane.setViewportView(getJTable());\r
648         }\r
649         return jScrollPane;\r
650     }\r
651 \r
652     /**\r
653      * This method initializes jTable   \r
654      *  \r
655      * @return javax.swing.JTable       \r
656      */\r
657     private JTable getJTable() {\r
658         if (jTable == null) {\r
659             model = new CheckboxTableModel();\r
660             jTable = new JTable(model);\r
661             jTable.setRowHeight(20);\r
662             jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);\r
663             jTable.setSize(new Dimension(1000, 300));\r
664             \r
665             model.addColumn("C_Name");\r
666             model.addColumn("Token");\r
667             model.addColumn("TokenSpace");\r
668             model.addColumn("DatumType");\r
669             model.addColumn("DefaultValue");\r
670             model.addColumn("HelpText");\r
671             \r
672             model.addColumn("FeatureFlag");\r
673             model.addColumn("FixedAtBuild");\r
674             model.addColumn("PatchableInModule");\r
675             model.addColumn("Dynamic");\r
676             model.addColumn("DynamicEx");\r
677             model.addColumn("SupportedArch");\r
678             model.addColumn("SupportedModule");\r
679             \r
680             //ToDo: add a valid usage editor\r
681             \r
682             JComboBox jComboBoxDataType = new JComboBox();\r
683             jComboBoxDataType.addItem("UINT8");\r
684             jComboBoxDataType.addItem("UINT16");\r
685             jComboBoxDataType.addItem("UINT32");\r
686             jComboBoxDataType.addItem("UINT64");\r
687             jComboBoxDataType.addItem("VOID*");\r
688             jComboBoxDataType.addItem("BOOLEAN");\r
689             TableColumn dataTypeColumn = jTable.getColumnModel().getColumn(3);\r
690             dataTypeColumn.setCellEditor(new DefaultCellEditor(jComboBoxDataType));\r
691 \r
692             Vector<String> vArch = new Vector<String>();\r
693             vArch.add("IA32");\r
694             vArch.add("X64");\r
695             vArch.add("IPF");\r
696             vArch.add("EBC");\r
697             vArch.add("ARM");\r
698             vArch.add("PPC");\r
699             jTable.getColumnModel().getColumn(11).setCellEditor(new ListEditor(vArch));\r
700             \r
701             Vector<String> vModule = new Vector<String>();\r
702             vModule.add("BASE");\r
703             vModule.add("SEC");\r
704             vModule.add("PEI_CORE");\r
705             vModule.add("PEIM");\r
706             vModule.add("DXE_CORE");\r
707             vModule.add("DXE_DRIVER");\r
708             vModule.add("DXE_RUNTIME_DRIVER");\r
709             vModule.add("DXE_SAL_DRIVER");\r
710             vModule.add("DXE_SMM_DRIVER");\r
711             vModule.add("UEFI_DRIVER");\r
712             vModule.add("UEFI_APPLICATION");\r
713             vModule.add("USER_DEFINED");\r
714             jTable.getColumnModel().getColumn(12).setCellEditor(new ListEditor(vModule));\r
715             \r
716             jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
717             jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){\r
718                 public void valueChanged(ListSelectionEvent e) {\r
719                     if (e.getValueIsAdjusting()){\r
720                         return;\r
721                     }\r
722                     ListSelectionModel lsm = (ListSelectionModel)e.getSource();\r
723                     if (lsm.isSelectionEmpty()) {\r
724                         return;\r
725                     }\r
726                     else{\r
727                         selectedRow = lsm.getMinSelectionIndex();\r
728                     }\r
729                 }\r
730             });\r
731             \r
732             jTable.getModel().addTableModelListener(this);\r
733         }\r
734         return jTable;\r
735     }\r
736     \r
737     public void tableChanged(TableModelEvent arg0) {\r
738         // TODO Auto-generated method stub\r
739         int row = arg0.getFirstRow();\r
740         int column = arg0.getColumn();\r
741         TableModel m = (TableModel)arg0.getSource();\r
742         if (arg0.getType() == TableModelEvent.UPDATE){\r
743             String[] sa = new String[9];\r
744             sfc.getSpdPcdDeclaration(sa, row);\r
745             Object cellData = m.getValueAt(row, column);\r
746             if (column < 6) {\r
747                 \r
748                 if (cellData == null) {\r
749                     cellData = "";\r
750                 }\r
751                 if (cellData.equals(sa[column])) {\r
752                     return;\r
753                 }\r
754                 if (cellData.toString().length() == 0 && sa[column] == null) {\r
755                     return;\r
756                 }\r
757             }\r
758             \r
759             String usage = getValidUsage(new Boolean(m.getValueAt(row, 6)+""), new Boolean(m.getValueAt(row, 7)+""), new Boolean(m.getValueAt(row, 8)+""), new Boolean(m.getValueAt(row, 9)+""), new Boolean(m.getValueAt(row, 10)+""));\r
760             if (usage.length() == 0) {\r
761                 JOptionPane.showMessageDialog(frame, "You must choose at least one usage for PCD entry.");\r
762                 return;\r
763             }\r
764             if (column <= 10 && column >= 6) {\r
765                 if (compareTwoVectors(stringToVector(usage), stringToVector(sa[6]))) {\r
766                     return;\r
767                 }\r
768             }\r
769             \r
770             if (column == 11) {\r
771                 if (cellData == null) {\r
772                     cellData = "";\r
773                 }\r
774                 if (cellData.equals(sa[7])) {\r
775                     return;\r
776                 }\r
777                 if (cellData.toString().length() == 0 && sa[7] == null) {\r
778                     return;\r
779                 }\r
780             }\r
781             \r
782             if (column == 12) {\r
783                 if (cellData == null) {\r
784                     cellData = "";\r
785                 }\r
786                 if (cellData.equals(sa[8])) {\r
787                     return;\r
788                 }\r
789                 if (cellData.toString().length() == 0 && sa[8] == null) {\r
790                     return;\r
791                 }\r
792             }\r
793             String cName = m.getValueAt(row, 0) + "";\r
794             String token = m.getValueAt(row, 1) + "";\r
795             String ts = m.getValueAt(row, 2) + "";\r
796             String dataType = m.getValueAt(row, 3) + "";\r
797             String defaultVal = m.getValueAt(row, 4) + "";\r
798             String help = m.getValueAt(row, 5) + "";\r
799             \r
800             \r
801             String archList = null;\r
802             if (m.getValueAt(row, 11) != null){\r
803                 archList = m.getValueAt(row, 11).toString();\r
804             }\r
805             String modTypeList = null;\r
806             if (m.getValueAt(row, 12) != null) {\r
807                 modTypeList = m.getValueAt(row, 12).toString(); \r
808             }\r
809             \r
810             Object[] o = {cName, token, ts, dataType, defaultVal, help};\r
811             if (!dataValidation(o)){\r
812                 return;\r
813             }\r
814             docConsole.setSaved(false);\r
815             sfc.updateSpdPcdDefinition(row, cName, token, dataType, usage, ts, defaultVal, help, archList, modTypeList);\r
816         }\r
817     }\r
818 \r
819     /**\r
820      * This method initializes jCheckBox        \r
821      *  \r
822      * @return javax.swing.JCheckBox    \r
823      */\r
824     private JCheckBox getJCheckBoxFeatureFlag() {\r
825         if (jCheckBoxFeatureFlag == null) {\r
826             jCheckBoxFeatureFlag = new JCheckBox();\r
827             jCheckBoxFeatureFlag.setBounds(new java.awt.Rectangle(156,161,100,21));\r
828             jCheckBoxFeatureFlag.setText("Feature Flag");\r
829             jCheckBoxFeatureFlag.setPreferredSize(new java.awt.Dimension(21,20));\r
830             jCheckBoxFeatureFlag.addItemListener(new java.awt.event.ItemListener() {\r
831                 public void itemStateChanged(java.awt.event.ItemEvent e) {\r
832                     if (jCheckBoxFeatureFlag.isSelected()) {\r
833                         jCheckBoxPatchInMod.setSelected(false);\r
834                         jCheckBoxFixedAtBuild.setSelected(false);\r
835                         jCheckBoxDyn.setSelected(false);\r
836                         jCheckBoxDynEx.setSelected(false);\r
837                     }\r
838                 }\r
839             });\r
840         }\r
841         return jCheckBoxFeatureFlag;\r
842     }\r
843 \r
844     /**\r
845      * This method initializes jCheckBox1       \r
846      *  \r
847      * @return javax.swing.JCheckBox    \r
848      */\r
849     private JCheckBox getJCheckBoxFixedAtBuild() {\r
850         if (jCheckBoxFixedAtBuild == null) {\r
851             jCheckBoxFixedAtBuild = new JCheckBox();\r
852             jCheckBoxFixedAtBuild.setBounds(new java.awt.Rectangle(312,133,108,20));\r
853             jCheckBoxFixedAtBuild.setText("Fixed at Build");\r
854             jCheckBoxFixedAtBuild.setPreferredSize(new java.awt.Dimension(21,20));\r
855             jCheckBoxFixedAtBuild.addItemListener(new java.awt.event.ItemListener() {\r
856                 public void itemStateChanged(java.awt.event.ItemEvent e) {\r
857                     if (jCheckBoxFixedAtBuild.isSelected()) {\r
858                         jCheckBoxFeatureFlag.setSelected(false);\r
859                     }\r
860                 }\r
861             });\r
862         }\r
863         return jCheckBoxFixedAtBuild;\r
864     }\r
865 \r
866     /**\r
867      * This method initializes jCheckBox2       \r
868      *  \r
869      * @return javax.swing.JCheckBox    \r
870      */\r
871     private JCheckBox getJCheckBoxPatchInMod() {\r
872         if (jCheckBoxPatchInMod == null) {\r
873             jCheckBoxPatchInMod = new JCheckBox();\r
874             jCheckBoxPatchInMod.setBounds(new java.awt.Rectangle(156,133,154,20));\r
875             jCheckBoxPatchInMod.setText("Patchable in Module");\r
876             jCheckBoxPatchInMod.setPreferredSize(new java.awt.Dimension(21,20));\r
877             jCheckBoxPatchInMod.addItemListener(new java.awt.event.ItemListener() {\r
878                 public void itemStateChanged(java.awt.event.ItemEvent e) {\r
879                     if (jCheckBoxPatchInMod.isSelected()) {\r
880                         jCheckBoxFeatureFlag.setSelected(false);\r
881                     }\r
882                 }\r
883             });\r
884         }\r
885         return jCheckBoxPatchInMod;\r
886     }\r
887 \r
888     /**\r
889      * This method initializes jCheckBox3       \r
890      *  \r
891      * @return javax.swing.JCheckBox    \r
892      */\r
893     private JCheckBox getJCheckBoxDyn() {\r
894         if (jCheckBoxDyn == null) {\r
895             jCheckBoxDyn = new JCheckBox();\r
896             jCheckBoxDyn.setBounds(new java.awt.Rectangle(278,161,80,20));\r
897             jCheckBoxDyn.setText("Dynamic");\r
898             jCheckBoxDyn.setPreferredSize(new java.awt.Dimension(21,20));\r
899             jCheckBoxDyn.addItemListener(new java.awt.event.ItemListener() {\r
900                 public void itemStateChanged(java.awt.event.ItemEvent e) {\r
901                     if (jCheckBoxDyn.isSelected()) {\r
902                         jCheckBoxFeatureFlag.setSelected(false);\r
903                     }\r
904                 }\r
905             });\r
906         }\r
907         return jCheckBoxDyn;\r
908     }\r
909 \r
910     /**\r
911      * This method initializes jCheckBox4       \r
912      *  \r
913      * @return javax.swing.JCheckBox    \r
914      */\r
915     private JCheckBox getJCheckBoxDynEx() {\r
916         if (jCheckBoxDynEx == null) {\r
917             jCheckBoxDynEx = new JCheckBox();\r
918             jCheckBoxDynEx.setBounds(new java.awt.Rectangle(371,161,99,20));\r
919             jCheckBoxDynEx.setText("DynamicEx");\r
920             jCheckBoxDynEx.setPreferredSize(new java.awt.Dimension(21,20));\r
921             jCheckBoxDynEx.addItemListener(new java.awt.event.ItemListener() {\r
922                 public void itemStateChanged(java.awt.event.ItemEvent e) {\r
923                     if (jCheckBoxDynEx.isSelected()) {\r
924                         jCheckBoxFeatureFlag.setSelected(false);\r
925                     }\r
926                 }\r
927             });\r
928         }\r
929         return jCheckBoxDynEx;\r
930     }\r
931     \r
932     private String getValidUsage(boolean ff, boolean fab, boolean pim, boolean d, boolean de) {\r
933         String usage = "";\r
934         if (ff){\r
935             usage += "FEATURE_FLAG ";\r
936         }\r
937         if (fab){\r
938             usage += "FIXED_AT_BUILD ";\r
939         }\r
940         if (pim){\r
941             usage += "PATCHABLE_IN_MODULE ";\r
942         }\r
943         if (d){\r
944             usage += "DYNAMIC ";\r
945         }\r
946         if (de){\r
947             usage += "DYNAMIC_EX ";\r
948         }\r
949         \r
950         return usage.trim();\r
951     }\r
952     \r
953     private boolean tokenCNameExisted(String token, String cName) {\r
954         Integer inputToken = Integer.decode(token);\r
955         \r
956         for (int i = 0; i < jTable.getRowCount(); ++i) {\r
957             if (jTable.getValueAt(i, 0).equals(cName)) {\r
958                 JOptionPane.showMessageDialog(frame, "C_Name already existed in table.");\r
959                 return true;\r
960             }\r
961             if (jTable.getValueAt(i, 1).equals(token)) {\r
962                 JOptionPane.showMessageDialog(frame, "Token already existed in table.");\r
963                 return true;\r
964             }\r
965             Integer tokenValue = Integer.decode(jTable.getValueAt(i, 1)+"");\r
966             if (tokenValue.equals(inputToken)) {\r
967                 JOptionPane.showMessageDialog(frame, "Same token value already existed in table.");\r
968                 return true;\r
969             }\r
970             \r
971         }\r
972         return false;\r
973     }\r
974     \r
975     private boolean checkValidUsage(boolean[] b) {\r
976         if (!(b[0] || b[1] || b[2] || b[3] || b[4])){\r
977             JOptionPane.showMessageDialog(frame, "You must specify at least one usage.");\r
978             return false;\r
979         }\r
980         return true;\r
981     }\r
982     private boolean dataValidation(Object[] row) {\r
983         \r
984         if (!DataValidation.isC_NameType(row[0].toString())) {\r
985             JOptionPane.showMessageDialog(frame, "C_Name is NOT C_NameType.");\r
986             return false;\r
987         }\r
988         if (!DataValidation.isHexDoubleWordDataType(row[1].toString()) && \r
989                         !DataValidation.isInt(row[1].toString(), Integer.MIN_VALUE, Integer.MAX_VALUE)) {\r
990             JOptionPane.showMessageDialog(frame, "Token is NOT correct.");\r
991             return false;\r
992         }\r
993         if (!DataValidation.isC_NameType(row[2].toString())) {\r
994             JOptionPane.showMessageDialog(frame, "Token Space is NOT C_NameType");\r
995             return false;\r
996         }\r
997         if (row[5].toString().length() == 0) {\r
998             JOptionPane.showMessageDialog(frame, "HelpText could NOT be empty.");\r
999             return false;\r
1000         }\r
1001         return true;\r
1002     }\r
1003 \r
1004     /**\r
1005      * This method initializes jScrollPane1     \r
1006      *  \r
1007      * @return javax.swing.JScrollPane  \r
1008      */\r
1009     private JScrollPane getJScrollPaneArch() {\r
1010         if (jScrollPaneArch == null) {\r
1011             jScrollPaneArch = new JScrollPane();\r
1012             jScrollPaneArch.setBounds(new java.awt.Rectangle(242,213,188,54));\r
1013             jScrollPaneArch.setViewportView(getICheckBoxListArch());\r
1014             jScrollPaneArch.setPreferredSize(new Dimension(188, 74));\r
1015         }\r
1016         return jScrollPaneArch;\r
1017     }\r
1018 \r
1019     /**\r
1020      * This method initializes iCheckBoxList    \r
1021      *  \r
1022      * @return org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList      \r
1023      */\r
1024     private ICheckBoxList getICheckBoxListArch() {\r
1025         if (iCheckBoxListArch == null) {\r
1026             iCheckBoxListArch = new ICheckBoxList();\r
1027             iCheckBoxListArch.setBounds(new Rectangle(197, 142, 188, 74));\r
1028             Vector<String> v = new Vector<String>();\r
1029             v.add("IA32");\r
1030             v.add("X64");\r
1031             v.add("IPF");\r
1032             v.add("EBC");\r
1033             v.add("ARM");\r
1034             v.add("PPC");\r
1035             iCheckBoxListArch.setAllItems(v);\r
1036         }\r
1037         return iCheckBoxListArch;\r
1038     }\r
1039 \r
1040     /**\r
1041      * This method initializes jScrollPane2     \r
1042      *  \r
1043      * @return javax.swing.JScrollPane  \r
1044      */\r
1045     private JScrollPane getJScrollPaneMod() {\r
1046         if (jScrollPaneMod == null) {\r
1047             jScrollPaneMod = new JScrollPane();\r
1048             jScrollPaneMod.setBounds(new java.awt.Rectangle(15,213,199,55));\r
1049             jScrollPaneMod.setViewportView(getICheckBoxListMod());\r
1050             jScrollPaneMod.setPreferredSize(new Dimension(170, 74));\r
1051         }\r
1052         return jScrollPaneMod;\r
1053     }\r
1054 \r
1055     /**\r
1056      * This method initializes iCheckBoxList1   \r
1057      *  \r
1058      * @return org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList      \r
1059      */\r
1060     private ICheckBoxList getICheckBoxListMod() {\r
1061         if (iCheckBoxListMod == null) {\r
1062             iCheckBoxListMod = new ICheckBoxList();\r
1063             iCheckBoxListMod.setBounds(new Rectangle(14, 142, 170, 74));\r
1064             Vector<String> v = new Vector<String>();\r
1065             v.add("BASE");\r
1066             v.add("SEC");\r
1067             v.add("PEI_CORE");\r
1068             v.add("PEIM");\r
1069             v.add("DXE_CORE");\r
1070             v.add("DXE_DRIVER");\r
1071             v.add("DXE_RUNTIME_DRIVER");\r
1072             v.add("DXE_SAL_DRIVER");\r
1073             v.add("DXE_SMM_DRIVER");\r
1074             v.add("UEFI_DRIVER");\r
1075             v.add("UEFI_APPLICATION");\r
1076             v.add("USER_DEFINED");\r
1077             iCheckBoxListMod.setAllItems(v);\r
1078         }\r
1079         return iCheckBoxListMod;\r
1080     }\r
1081     \r
1082     protected String vectorToString(Vector<String> v) {\r
1083         if (v == null) {\r
1084             return null;\r
1085         }\r
1086         String s = " ";\r
1087         for (int i = 0; i < v.size(); ++i) {\r
1088             s += v.get(i);\r
1089             s += " ";\r
1090         }\r
1091         return s.trim();\r
1092     }\r
1093     \r
1094     protected Vector<String> stringToVector(String s){\r
1095         if (s == null) {\r
1096             return null;\r
1097         }\r
1098         String[] sArray = s.split(" ");\r
1099         Vector<String> v = new Vector<String>();\r
1100         for (int i = 0; i < sArray.length; ++i) {\r
1101             v.add(sArray[i]);\r
1102         }\r
1103         return v;\r
1104     }\r
1105     \r
1106     private boolean compareTwoVectors(Vector v1, Vector v2) {\r
1107         if (v1.size() != v2.size()) {\r
1108             return false;\r
1109         }\r
1110         for (int i = 0; i < v1.size(); ++i) {\r
1111             if (!v2.contains(v1.get(i))) {\r
1112                 return false;\r
1113             }\r
1114         }\r
1115         return true;\r
1116     }\r
1117 } //  @jve:decl-index=0:visual-constraint="22,11"\r
1118 \r
1119 class CheckboxTableModel extends DefaultTableModel {\r
1120     /**\r
1121      * \r
1122      */\r
1123     private static final long serialVersionUID = 1L;\r
1124 \r
1125     public Class<?> getColumnClass (int c) {\r
1126         if (getValueAt(0, c) != null){\r
1127             return getValueAt(0, c).getClass();\r
1128         }\r
1129         return String.class;\r
1130     }\r
1131 }\r