summaryrefslogtreecommitdiff
path: root/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/SpdPcdDefs.java
blob: cbcb5a98333e0ea392257f95ed1e90082267b775 (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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
/** @file
  Java class SpdPcdDefs is GUI for create PCD 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 java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;

import javax.swing.DefaultCellEditor;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.ListSelectionModel;

import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

import org.tianocore.PackageSurfaceAreaDocument;

import org.tianocore.frameworkwizard.common.DataValidation;
import org.tianocore.frameworkwizard.common.Tools;
import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageType;
import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
import org.tianocore.frameworkwizard.common.ui.StarLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JCheckBox;
import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;
import org.tianocore.frameworkwizard.platform.ui.ListEditor;

import java.awt.Rectangle;
import java.util.Vector;

/**
 GUI for create PCD definition elements of spd file
  
 @since PackageEditor 1.0
**/
public class SpdPcdDefs extends IInternalFrame implements TableModelListener{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    static JFrame frame;
    
    private JPanel jContentPane = null;  

    private JLabel jLabelItemType = null;

    private JLabel jLabelC_Name = null;

    private JTextField jTextFieldC_Name = null;

    private JLabel jLabelToken = null;

    private JTextField jTextFieldToken = null;

    private JLabel jLabelDataType = null;

    private JButton jButtonOk = null;

    private JButton jButtonCancel = null;

    private JComboBox jComboBoxDataType = null;

    private SpdFileContents sfc = null;
    
    private OpeningPackageType docConsole = null;

    private StarLabel jStarLabel2 = null;

    private StarLabel jStarLabel3 = null;

    private StarLabel jStarLabel4 = null;

    private StarLabel jStarLabel = null;

    private StarLabel jStarLabel1 = null;

    private JLabel jLabelTokenSpace = null;

    private JTextField jTextFieldTsGuid = null;

    private JLabel jLabelVarVal = null;

    private JTextField jTextFieldHelp = null;

    private JLabel jLabelDefVal = null;

    private JTextField jTextFieldDefaultValue = null;

    private JButton jButtonAdd = null;
    
    private CheckboxTableModel model = null;

    private JButton jButtonRemove = null;

    private JButton jButtonClearAll = null;

    private JScrollPane jScrollPane = null;

    private JTable jTable = null;
    
    private JScrollPane topScrollPane = null;  //  @jve:decl-index=0:visual-constraint="390,10"
    
    private int selectedRow = -1;

    private StarLabel starLabel = null;

    private JCheckBox jCheckBoxFeatureFlag = null;

    private JCheckBox jCheckBoxFixedAtBuild = null;

    private JCheckBox jCheckBoxPatchInMod = null;

    private JCheckBox jCheckBoxDyn = null;

    private JCheckBox jCheckBoxDynEx = null;

    private JScrollPane jScrollPaneArch = null;

    private ICheckBoxList iCheckBoxListArch = null;

    private JScrollPane jScrollPaneMod = null;

    private ICheckBoxList iCheckBoxListMod = null;

    private JLabel jLabelSupMod = null;

    private JLabel jLabelSupArch = null;

    /**
     This method initializes this
     
     **/
    private void initialize() {
        this.setTitle("PCD Declarations");
        this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    }

    /**
     This method initializes jTextFieldC_Name	
     	
     @return javax.swing.JTextField	
     **/
    private JTextField getJTextFieldC_Name() {
        if (jTextFieldC_Name == null) {
            jTextFieldC_Name = new JTextField();
            jTextFieldC_Name.setBounds(new java.awt.Rectangle(156,9,317,20));
            jTextFieldC_Name.setPreferredSize(new java.awt.Dimension(315,20));
        }
        return jTextFieldC_Name;
    }

    /**
     This method initializes jTextFieldToken	
     	
     @return javax.swing.JTextField	
     **/
    private JTextField getJTextFieldToken() {
        if (jTextFieldToken == null) {
            jTextFieldToken = new JTextField();
            jTextFieldToken.setBounds(new java.awt.Rectangle(156,33,317,20));
            jTextFieldToken.setPreferredSize(new java.awt.Dimension(315,20));
        }
        return jTextFieldToken;
    }

    /**
     This method initializes jButtonOk	
     	
     @return javax.swing.JButton	
     **/
    private JButton getJButtonOk() {
        if (jButtonOk == null) {
            jButtonOk = new JButton();
            jButtonOk.setText("OK");
            jButtonOk.setBounds(new java.awt.Rectangle(279,276,90,20));
            jButtonOk.setVisible(false);
            jButtonOk.addActionListener(this);
        }
        return jButtonOk;
    }

    /**
     This method initializes jButtonCancel	
     	
     @return javax.swing.JButton	
     **/
    private JButton getJButtonCancel() {
        if (jButtonCancel == null) {
            jButtonCancel = new JButton();
            jButtonCancel.setText("Cancel");
            jButtonCancel.setBounds(new java.awt.Rectangle(389,276,82,20));
            jButtonCancel.setVisible(false);
            jButtonCancel.addActionListener(this);
        }
        return jButtonCancel;
    }

    /**
     This method initializes jComboBoxDataType	
     	
     @return javax.swing.JComboBox	
     **/
    private JComboBox getJComboBoxDataType() {
        if (jComboBoxDataType == null) {
            jComboBoxDataType = new JComboBox();
            jComboBoxDataType.setBounds(new java.awt.Rectangle(156,84,110,20));
        }
        return jComboBoxDataType;
    }

    /**
     This is the default constructor
     **/
    public SpdPcdDefs() {
        super();
        init();
        initialize();
        
    }

    public SpdPcdDefs(PackageSurfaceAreaDocument.PackageSurfaceArea inPsa) {
        this();
        sfc = new SpdFileContents(inPsa);
        init(sfc);
    }
    
    public SpdPcdDefs(OpeningPackageType opt) {
        this(opt.getXmlSpd());
        docConsole = opt;
    }
    /**
     This method initializes this
     
     @return void
     **/
    private void init() {
        this.setSize(500, 650);
        this.setContentPane(getJContentPane());
        this.addInternalFrameListener(new InternalFrameAdapter(){
            public void internalFrameDeactivated(InternalFrameEvent e){
                if (jTable.isEditing()) {
                    jTable.getCellEditor().stopCellEditing();
                }
            }
        });
        initFrame();
        this.setVisible(true);
    }

    private void init(SpdFileContents sfc){
        if (sfc.getSpdPcdDefinitionCount() == 0) {
            return ;
        }
        String[][] saa = new String[sfc.getSpdPcdDefinitionCount()][8];
        String[][] usage = new String[sfc.getSpdPcdDefinitionCount()][5];
        Object[] rowData = new Object[13];
        sfc.getSpdPcdDefinitions(saa, usage);
        int i = 0;
        while (i < saa.length) {
           
            for (int k = 0; k < 6; ++k) {
                rowData[k] = saa[i][k];
            }
            for (int m = 6; m < 11; ++m) {
                rowData[m] = new Boolean("false");
            }
            int j = 0;
            while (j < 5) {
                if (usage[i][j] == null || usage[i][j].length()==0){
                    ++j;
                    continue;
                }
                if (usage[i][j].equals("FEATURE_FLAG")){
                    rowData[6] = new Boolean("true");
                }
                if (usage[i][j].equals("FIXED_AT_BUILD")){
                    rowData[7] = new Boolean("true");
                }
                if (usage[i][j].equals("PATCHABLE_IN_MODULE")){
                    rowData[8] = new Boolean("true");
                }
                if (usage[i][j].equals("DYNAMIC")){
                    rowData[9] = new Boolean("true");
                }
                if (usage[i][j].equals("DYNAMIC_EX")){
                    rowData[10] = new Boolean("true");
                }
                
                ++j;
            }
            
            rowData[11] = saa[i][6];
            rowData[12] = saa[i][7];
            
            model.addRow(rowData);
            
            i++;
        }
        
        
        
    }
    
    private JScrollPane getJContentPane(){
        if (topScrollPane == null){
            topScrollPane = new JScrollPane();
            topScrollPane.setSize(new java.awt.Dimension(482,451));
            topScrollPane.setViewportView(getJContentPane1());
        }
        return topScrollPane;
    }
    private JPanel getJContentPane1() {
  		if (jContentPane == null) {	
           
            jLabelSupArch = new JLabel();
            jLabelSupArch.setBounds(new java.awt.Rectangle(241,192,89,16));
            jLabelSupArch.setText("Supported Arch");
            jLabelSupArch.setEnabled(true);
            jLabelSupMod = new JLabel();
            jLabelSupMod.setBounds(new java.awt.Rectangle(15,193,103,16));
            jLabelSupMod.setText("Supported Module");
            jLabelSupMod.setEnabled(true);
            starLabel = new StarLabel();
            starLabel.setBounds(new java.awt.Rectangle(2,134,10,20));
            jLabelDefVal = new JLabel();
            jLabelDefVal.setBounds(new java.awt.Rectangle(277,84,80,20));
            jLabelDefVal.setText("Default Value");
            jLabelVarVal = new JLabel();
            jLabelVarVal.setBounds(new java.awt.Rectangle(11,133,84,20));
            jLabelVarVal.setText("Valid Usage");
            jLabelC_Name = new JLabel();
            jLabelC_Name.setText("C_Name");
            jLabelC_Name.setBounds(new java.awt.Rectangle(11,9,140,20));
            jLabelTokenSpace = new JLabel();
            jLabelTokenSpace.setBounds(new java.awt.Rectangle(11,58,140,20));
            jLabelTokenSpace.setText("Token Space");
            jLabelDataType = new JLabel();
            jLabelDataType.setText("Data Type");
            jLabelDataType.setBounds(new java.awt.Rectangle(11,83,140,20));
            jLabelToken = new JLabel();
            jLabelToken.setText("Token");
            jLabelToken.setBounds(new java.awt.Rectangle(11,33,140,20));
            jLabelItemType = new JLabel();
            jLabelItemType.setText("Help Text");
            jLabelItemType.setBounds(new java.awt.Rectangle(11,108,140,20));
            
            
            jContentPane = new JPanel();
            jContentPane.setLayout(null);
            jContentPane.setPreferredSize(new java.awt.Dimension(479,375));
            
            jContentPane.add(jLabelItemType, null);
            jContentPane.add(jLabelC_Name, null);
            jContentPane.add(jLabelTokenSpace, null);
            jContentPane.add(getJTextFieldTsGuid(), null);
            jContentPane.add(jLabelVarVal, null);
            jContentPane.add(getJTextFieldC_Name(), null);
            jContentPane.add(jLabelToken, null);
            jContentPane.add(getJTextFieldToken(), null);
            jContentPane.add(jLabelDataType, null);
            jContentPane.add(getJButtonOk(), null);
            jContentPane.add(getJButtonCancel(), null);
            jContentPane.add(getJComboBoxDataType(), null);
            
            jStarLabel = new StarLabel();
            jStarLabel1 = new StarLabel();
            jStarLabel1.setBounds(new java.awt.Rectangle(2,8,10,20));
            jStarLabel2 = new StarLabel();
            jStarLabel3 = new StarLabel();
            jStarLabel4 = new StarLabel();
            jStarLabel.setLocation(new java.awt.Point(2,84));
            jStarLabel4.setLocation(new java.awt.Point(2, 109));
            jStarLabel2.setLocation(new java.awt.Point(2,33));
            jStarLabel3.setLocation(new java.awt.Point(2, 58));
            jStarLabel3.setSize(new java.awt.Dimension(8,20));
            jContentPane.add(jStarLabel2, null);
            jContentPane.add(jStarLabel3, null);
            jContentPane.add(jStarLabel, null);
            jContentPane.add(jStarLabel1, null);
            jContentPane.add(jStarLabel4, null);
            jContentPane.add(getJTextFieldHelp(), null);
            jContentPane.add(jLabelDefVal, null);
            jContentPane.add(getJTextFieldDefaultValue(), null);
            jContentPane.add(getJButtonAdd(), null);
            jContentPane.add(getJButtonRemove(), null);
            jContentPane.add(getJButtonClearAll(), null);
            jContentPane.add(getJScrollPane(), null);
            jContentPane.add(starLabel, null);
            jContentPane.add(getJCheckBoxFeatureFlag(), null);
            jContentPane.add(getJCheckBoxFixedAtBuild(), null);
            jContentPane.add(getJCheckBoxPatchInMod(), null);
            jContentPane.add(getJCheckBoxDyn(), null);
            jContentPane.add(getJCheckBoxDynEx(), null);
            jContentPane.add(getJScrollPaneArch(), null);
            jContentPane.add(getJScrollPaneMod(), null);
            jContentPane.add(jLabelSupMod, null);
            jContentPane.add(jLabelSupArch, null);
        }
        return jContentPane;
    }

    /**
     This method initializes comboboxes			
 			jContentPane.add(jLabelTokenSpace, null);
    
     **/
    private void initFrame() {

        jComboBoxDataType.addItem("UINT8");
        jComboBoxDataType.addItem("UINT16");
        jComboBoxDataType.addItem("UINT32");
        jComboBoxDataType.addItem("UINT64");
        jComboBoxDataType.addItem("VOID*");
        jComboBoxDataType.addItem("BOOLEAN");
        jComboBoxDataType.setSelectedIndex(0);
    }

    public void actionPerformed(ActionEvent arg0) {
        
        docConsole.setSaved(false);
            if (arg0.getSource() == jButtonOk) {
                this.save();
                this.dispose();
            }
            if (arg0.getSource() == jButtonCancel) {
                this.dispose();
            }

            if (arg0.getSource() == jButtonAdd) {
                //ToDo: check before add
                boolean[] b = {jCheckBoxFeatureFlag.isSelected(), jCheckBoxFixedAtBuild.isSelected(), jCheckBoxPatchInMod.isSelected(), jCheckBoxDyn.isSelected(), jCheckBoxDynEx.isSelected()};
                if (!checkValidUsage(b)) {
                    return;
                }
                String archList = vectorToString(iCheckBoxListArch.getAllCheckedItemsString());
                if (archList.length() == 0) {
                    archList = null;
                }
                String modTypeList = vectorToString(iCheckBoxListMod.getAllCheckedItemsString());
                if (modTypeList.length() == 0) {
                    modTypeList = null;
                }
                Object[] row = {jTextFieldC_Name.getText(), jTextFieldToken.getText(),
                                jTextFieldTsGuid.getText(), jComboBoxDataType.getSelectedItem(), 
                                jTextFieldDefaultValue.getText(), jTextFieldHelp.getText(),
                                jCheckBoxFeatureFlag.isSelected(), jCheckBoxFixedAtBuild.isSelected(),
                                jCheckBoxPatchInMod.isSelected(), jCheckBoxDyn.isSelected(), jCheckBoxDynEx.isSelected(),
                                archList, modTypeList};
                if (!dataValidation(row)) {
                    return;
                }
                model.addRow(row);
                jTable.changeSelection(model.getRowCount()-1, 0, false, false);
                String usage = getValidUsage(jCheckBoxFeatureFlag.isSelected(), jCheckBoxFixedAtBuild.isSelected(), jCheckBoxPatchInMod.isSelected(), jCheckBoxDyn.isSelected(), jCheckBoxDynEx.isSelected());
                if (usage.length() == 0) {
                    usage = null;
                }
                sfc.genSpdPcdDefinitions(row[0]+"", row[1]+"", row[3]+"", usage, row[2]+"", row[4]+"", row[5]+"", archList, modTypeList);
            }
            //
            // remove selected line
            //
            if (arg0.getSource() == jButtonRemove) {
                if (jTable.isEditing()){
                    jTable.getCellEditor().stopCellEditing();
                }
                int rowSelected = selectedRow;
                if (rowSelected >= 0) {
                    model.removeRow(rowSelected);
                    sfc.removeSpdPcdDefinition(rowSelected);
                }
            }

            if (arg0.getSource() == jButtonClearAll) {
                if (model.getRowCount() == 0) {
                    return;
                }
                model.setRowCount(0);
                sfc.removeSpdPcdDefinition();
            }
            
    }

    protected void save() {
        
    }

    /**
     * This method initializes jTextFieldTsGuid	
     * 	
     * @return javax.swing.JTextField	
     */
    private JTextField getJTextFieldTsGuid() {
        if (jTextFieldTsGuid == null) {
            jTextFieldTsGuid = new JTextField();
            jTextFieldTsGuid.setPreferredSize(new java.awt.Dimension(315,20));
            jTextFieldTsGuid.setSize(new java.awt.Dimension(317,20));
            jTextFieldTsGuid.setLocation(new java.awt.Point(156,58));
        }
        return jTextFieldTsGuid;
    }

    /**
     * This method initializes jTextField	
     * 	
     * @return javax.swing.JTextField	
     */
    private JTextField getJTextFieldHelp() {
        if (jTextFieldHelp == null) {
            jTextFieldHelp = new JTextField();
            jTextFieldHelp.setBounds(new java.awt.Rectangle(156,108,317,20));
            jTextFieldHelp.setPreferredSize(new java.awt.Dimension(315,20));
        }
        return jTextFieldHelp;
    }

    /**
     * This method initializes jTextFieldDefaultValue	
     * 	
     * @return javax.swing.JTextField	
     */
    private JTextField getJTextFieldDefaultValue() {
        if (jTextFieldDefaultValue == null) {
            jTextFieldDefaultValue = new JTextField();
            jTextFieldDefaultValue.setBounds(new java.awt.Rectangle(368,84,105,20));
            jTextFieldDefaultValue.setPreferredSize(new java.awt.Dimension(104,20));
        }
        return jTextFieldDefaultValue;
    }

    /**
     * This method initializes jButtonAdd	
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonAdd() {
        if (jButtonAdd == null) {
            jButtonAdd = new JButton();
            jButtonAdd.setBounds(new java.awt.Rectangle(195,277,71,20));
            jButtonAdd.setPreferredSize(new java.awt.Dimension(70,20));
            jButtonAdd.setText("Add");
            jButtonAdd.addActionListener(this);
        }
        return jButtonAdd;   
        
    }   
    
    /**
     * This method initializes jButtonRemove	
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonRemove() {
        if (jButtonRemove == null) {
            jButtonRemove = new JButton();
            jButtonRemove.setBounds(new java.awt.Rectangle(278,277,81,20));
            jButtonRemove.setPreferredSize(new java.awt.Dimension(70,20));
            jButtonRemove.setText("Delete");
            jButtonRemove.addActionListener(this);
        }
        return jButtonRemove;
    }

    /**
     * This method initializes jButtonClearAll	
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonClearAll() {
        if (jButtonClearAll == null) {
            jButtonClearAll = new JButton();
            jButtonClearAll.setBounds(new java.awt.Rectangle(382,277,90,20));
            jButtonClearAll.setPreferredSize(new java.awt.Dimension(81,20));
            jButtonClearAll.setText("Clear All");
            jButtonClearAll.addActionListener(this);
        }
        return jButtonClearAll;
    }

    public void componentResized(ComponentEvent arg0) {
        int intPreferredWidth = 500;
        
        Tools.resizeComponentWidth(this.jTextFieldC_Name, this.getWidth(), intPreferredWidth);
        Tools.resizeComponentWidth(this.jTextFieldToken, this.getWidth(), intPreferredWidth);
        Tools.resizeComponentWidth(this.jTextFieldTsGuid, this.getWidth(), intPreferredWidth);
        Tools.resizeComponentWidth(this.jTextFieldDefaultValue, this.getWidth(), intPreferredWidth);
        Tools.resizeComponentWidth(this.jTextFieldHelp, this.getWidth(), intPreferredWidth);
        Tools.resizeComponentWidth(this.jScrollPane, this.getWidth(), intPreferredWidth);
        
        Tools.resizeComponentWidth(this.jTextFieldDefaultValue, this.getWidth(), intPreferredWidth);
//        relocateComponentX(this.jButtonClearAll, this.getWidth(), DataType.SPACE_TO_RIGHT_FOR_GENERATE_BUTTON);
//        relocateComponentX(this.jButtonRemove, this.getWidth(), DataType.SPACE_TO_RIGHT_FOR_GENERATE_BUTTON);
//        relocateComponentX(this.jButtonAdd, this.getWidth(), DataType.SPACE_TO_RIGHT_FOR_GENERATE_BUTTON);
    }

    /**
     * This method initializes jScrollPane	
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPane() {
        if (jScrollPane == null) {
            jScrollPane = new JScrollPane();
            jScrollPane.setBounds(new java.awt.Rectangle(5,301,1473,259));
            jScrollPane.setViewportView(getJTable());
        }
        return jScrollPane;
    }

    /**
     * This method initializes jTable	
     * 	
     * @return javax.swing.JTable	
     */
    private JTable getJTable() {
        if (jTable == null) {
            model = new CheckboxTableModel();
            jTable = new JTable(model);
            jTable.setRowHeight(20);
            jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            jTable.setSize(new Dimension(1000, 300));
            
            model.addColumn("C_Name");
            model.addColumn("Token");
            model.addColumn("TokenSpace");
            model.addColumn("DatumType");
            model.addColumn("DefaultValue");
            model.addColumn("HelpText");
            
            model.addColumn("FeatureFlag");
            model.addColumn("FixedAtBuild");
            model.addColumn("PatchableInModule");
            model.addColumn("Dynamic");
            model.addColumn("DynamicEx");
            model.addColumn("SupportedArch");
            model.addColumn("SupportedModule");
            
            //ToDo: add a valid usage editor
            
            JComboBox jComboBoxDataType = new JComboBox();
            jComboBoxDataType.addItem("UINT8");
            jComboBoxDataType.addItem("UINT16");
            jComboBoxDataType.addItem("UINT32");
            jComboBoxDataType.addItem("UINT64");
            jComboBoxDataType.addItem("VOID*");
            jComboBoxDataType.addItem("BOOLEAN");
            TableColumn dataTypeColumn = jTable.getColumnModel().getColumn(3);
            dataTypeColumn.setCellEditor(new DefaultCellEditor(jComboBoxDataType));

            Vector<String> vArch = new Vector<String>();
            vArch.add("IA32");
            vArch.add("X64");
            vArch.add("IPF");
            vArch.add("EBC");
            vArch.add("ARM");
            vArch.add("PPC");
            jTable.getColumnModel().getColumn(11).setCellEditor(new ListEditor(vArch));
            
            Vector<String> vModule = new Vector<String>();
            vModule.add("BASE");
            vModule.add("SEC");
            vModule.add("PEI_CORE");
            vModule.add("PEIM");
            vModule.add("DXE_CORE");
            vModule.add("DXE_DRIVER");
            vModule.add("DXE_RUNTIME_DRIVER");
            vModule.add("DXE_SAL_DRIVER");
            vModule.add("DXE_SMM_DRIVER");
            vModule.add("UEFI_DRIVER");
            vModule.add("UEFI_APPLICATION");
            vModule.add("USER_DEFINED");
            jTable.getColumnModel().getColumn(12).setCellEditor(new ListEditor(vModule));
            
            jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
                public void valueChanged(ListSelectionEvent e) {
                    if (e.getValueIsAdjusting()){
                        return;
                    }
                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        return;
                    }
                    else{
                        selectedRow = lsm.getMinSelectionIndex();
                    }
                }
            });
            
            jTable.getModel().addTableModelListener(this);
        }
        return jTable;
    }
    
    public void tableChanged(TableModelEvent arg0) {
        // TODO Auto-generated method stub
        int row = arg0.getFirstRow();
        int column = arg0.getColumn();
        TableModel m = (TableModel)arg0.getSource();
        if (arg0.getType() == TableModelEvent.UPDATE){
            String[] sa = new String[9];
            sfc.getSpdPcdDeclaration(sa, row);
            Object cellData = m.getValueAt(row, column);
            if (column < 6) {
                
                if (cellData == null) {
                    cellData = "";
                }
                if (cellData.equals(sa[column])) {
                    return;
                }
                if (cellData.toString().length() == 0 && sa[column] == null) {
                    return;
                }
            }
            
            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)+""));
            if (usage.length() == 0) {
                JOptionPane.showMessageDialog(frame, "You must choose at least one usage for PCD entry.");
                return;
            }
            if (column <= 10 && column >= 6) {
                if (compareTwoVectors(stringToVector(usage), stringToVector(sa[6]))) {
                    return;
                }
            }
            
            if (column == 11) {
                if (cellData == null) {
                    cellData = "";
                }
                if (cellData.equals(sa[7])) {
                    return;
                }
                if (cellData.toString().length() == 0 && sa[7] == null) {
                    return;
                }
            }
            
            if (column == 12) {
                if (cellData == null) {
                    cellData = "";
                }
                if (cellData.equals(sa[8])) {
                    return;
                }
                if (cellData.toString().length() == 0 && sa[8] == null) {
                    return;
                }
            }
            String cName = m.getValueAt(row, 0) + "";
            String token = m.getValueAt(row, 1) + "";
            String ts = m.getValueAt(row, 2) + "";
            String dataType = m.getValueAt(row, 3) + "";
            String defaultVal = m.getValueAt(row, 4) + "";
            String help = m.getValueAt(row, 5) + "";
            
            
            String archList = null;
            if (m.getValueAt(row, 11) != null){
                archList = m.getValueAt(row, 11).toString();
            }
            String modTypeList = null;
            if (m.getValueAt(row, 12) != null) {
                modTypeList = m.getValueAt(row, 12).toString(); 
            }
            
            Object[] o = {cName, token, ts, dataType, defaultVal, help};
            if (!dataValidation(o)){
                return;
            }
            docConsole.setSaved(false);
            sfc.updateSpdPcdDefinition(row, cName, token, dataType, usage, ts, defaultVal, help, archList, modTypeList);
        }
    }

    /**
     * This method initializes jCheckBox	
     * 	
     * @return javax.swing.JCheckBox	
     */
    private JCheckBox getJCheckBoxFeatureFlag() {
        if (jCheckBoxFeatureFlag == null) {
            jCheckBoxFeatureFlag = new JCheckBox();
            jCheckBoxFeatureFlag.setBounds(new java.awt.Rectangle(156,161,100,21));
            jCheckBoxFeatureFlag.setText("Feature Flag");
            jCheckBoxFeatureFlag.setPreferredSize(new java.awt.Dimension(21,20));
        }
        return jCheckBoxFeatureFlag;
    }

    /**
     * This method initializes jCheckBox1	
     * 	
     * @return javax.swing.JCheckBox	
     */
    private JCheckBox getJCheckBoxFixedAtBuild() {
        if (jCheckBoxFixedAtBuild == null) {
            jCheckBoxFixedAtBuild = new JCheckBox();
            jCheckBoxFixedAtBuild.setBounds(new java.awt.Rectangle(312,133,108,20));
            jCheckBoxFixedAtBuild.setText("Fixed at Build");
            jCheckBoxFixedAtBuild.setPreferredSize(new java.awt.Dimension(21,20));
        }
        return jCheckBoxFixedAtBuild;
    }

    /**
     * This method initializes jCheckBox2	
     * 	
     * @return javax.swing.JCheckBox	
     */
    private JCheckBox getJCheckBoxPatchInMod() {
        if (jCheckBoxPatchInMod == null) {
            jCheckBoxPatchInMod = new JCheckBox();
            jCheckBoxPatchInMod.setBounds(new java.awt.Rectangle(156,133,154,20));
            jCheckBoxPatchInMod.setText("Patchable in Module");
            jCheckBoxPatchInMod.setPreferredSize(new java.awt.Dimension(21,20));
        }
        return jCheckBoxPatchInMod;
    }

    /**
     * This method initializes jCheckBox3	
     * 	
     * @return javax.swing.JCheckBox	
     */
    private JCheckBox getJCheckBoxDyn() {
        if (jCheckBoxDyn == null) {
            jCheckBoxDyn = new JCheckBox();
            jCheckBoxDyn.setBounds(new java.awt.Rectangle(278,161,80,20));
            jCheckBoxDyn.setText("Dynamic");
            jCheckBoxDyn.setPreferredSize(new java.awt.Dimension(21,20));
        }
        return jCheckBoxDyn;
    }

    /**
     * This method initializes jCheckBox4	
     * 	
     * @return javax.swing.JCheckBox	
     */
    private JCheckBox getJCheckBoxDynEx() {
        if (jCheckBoxDynEx == null) {
            jCheckBoxDynEx = new JCheckBox();
            jCheckBoxDynEx.setBounds(new java.awt.Rectangle(371,161,99,20));
            jCheckBoxDynEx.setText("DynamicEx");
            jCheckBoxDynEx.setPreferredSize(new java.awt.Dimension(21,20));
        }
        return jCheckBoxDynEx;
    }
    
    private String getValidUsage(boolean ff, boolean fab, boolean pim, boolean d, boolean de) {
        String usage = "";
        if (ff){
            usage += "FEATURE_FLAG ";
        }
        if (fab){
            usage += "FIXED_AT_BUILD ";
        }
        if (pim){
            usage += "PATCHABLE_IN_MODULE ";
        }
        if (d){
            usage += "DYNAMIC ";
        }
        if (de){
            usage += "DYNAMIC_EX ";
        }
        
        return usage.trim();
    }
    
    private boolean checkValidUsage(boolean[] b) {
        if (!(b[0] || b[1] || b[2] || b[3] || b[4])){
            JOptionPane.showMessageDialog(frame, "You must specify at least one usage.");
            return false;
        }
        return true;
    }
    private boolean dataValidation(Object[] row) {
        
        if (!DataValidation.isC_NameType(row[0].toString())) {
            JOptionPane.showMessageDialog(frame, "C_Name is NOT C_NameType.");
            return false;
        }
        if (!DataValidation.isHexDoubleWordDataType(row[1].toString()) && 
                        !DataValidation.isInt(row[1].toString(), Integer.MIN_VALUE, Integer.MAX_VALUE)) {
            JOptionPane.showMessageDialog(frame, "Token is NOT correct.");
            return false;
        }
        if (!DataValidation.isC_NameType(row[2].toString())) {
            JOptionPane.showMessageDialog(frame, "Token Space is NOT C_NameType");
            return false;
        }
        if (row[5].toString().length() == 0) {
            JOptionPane.showMessageDialog(frame, "HelpText could NOT be empty.");
            return false;
        }
        return true;
    }

    /**
     * This method initializes jScrollPane1	
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPaneArch() {
        if (jScrollPaneArch == null) {
            jScrollPaneArch = new JScrollPane();
            jScrollPaneArch.setBounds(new java.awt.Rectangle(242,213,188,54));
            jScrollPaneArch.setViewportView(getICheckBoxListArch());
            jScrollPaneArch.setPreferredSize(new Dimension(188, 74));
        }
        return jScrollPaneArch;
    }

    /**
     * This method initializes iCheckBoxList	
     * 	
     * @return org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList	
     */
    private ICheckBoxList getICheckBoxListArch() {
        if (iCheckBoxListArch == null) {
            iCheckBoxListArch = new ICheckBoxList();
            iCheckBoxListArch.setBounds(new Rectangle(197, 142, 188, 74));
            Vector<String> v = new Vector<String>();
            v.add("IA32");
            v.add("X64");
            v.add("IPF");
            v.add("EBC");
            v.add("ARM");
            v.add("PPC");
            iCheckBoxListArch.setAllItems(v);
        }
        return iCheckBoxListArch;
    }

    /**
     * This method initializes jScrollPane2	
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPaneMod() {
        if (jScrollPaneMod == null) {
            jScrollPaneMod = new JScrollPane();
            jScrollPaneMod.setBounds(new java.awt.Rectangle(15,213,199,55));
            jScrollPaneMod.setViewportView(getICheckBoxListMod());
            jScrollPaneMod.setPreferredSize(new Dimension(170, 74));
        }
        return jScrollPaneMod;
    }

    /**
     * This method initializes iCheckBoxList1	
     * 	
     * @return org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList	
     */
    private ICheckBoxList getICheckBoxListMod() {
        if (iCheckBoxListMod == null) {
            iCheckBoxListMod = new ICheckBoxList();
            iCheckBoxListMod.setBounds(new Rectangle(14, 142, 170, 74));
            Vector<String> v = new Vector<String>();
            v.add("BASE");
            v.add("SEC");
            v.add("PEI_CORE");
            v.add("PEIM");
            v.add("DXE_CORE");
            v.add("DXE_DRIVER");
            v.add("DXE_RUNTIME_DRIVER");
            v.add("DXE_SAL_DRIVER");
            v.add("DXE_SMM_DRIVER");
            v.add("UEFI_DRIVER");
            v.add("UEFI_APPLICATION");
            v.add("USER_DEFINED");
            iCheckBoxListMod.setAllItems(v);
        }
        return iCheckBoxListMod;
    }
    
    protected String vectorToString(Vector<String> v) {
        if (v == null) {
            return null;
        }
        String s = " ";
        for (int i = 0; i < v.size(); ++i) {
            s += v.get(i);
            s += " ";
        }
        return s.trim();
    }
    
    protected Vector<String> stringToVector(String s){
        if (s == null) {
            return null;
        }
        String[] sArray = s.split(" ");
        Vector<String> v = new Vector<String>();
        for (int i = 0; i < sArray.length; ++i) {
            v.add(sArray[i]);
        }
        return v;
    }
    
    private boolean compareTwoVectors(Vector v1, Vector v2) {
        if (v1.size() != v2.size()) {
            return false;
        }
        for (int i = 0; i < v1.size(); ++i) {
            if (!v2.contains(v1.get(i))) {
                return false;
            }
        }
        return true;
    }
} //  @jve:decl-index=0:visual-constraint="22,11"

class CheckboxTableModel extends DefaultTableModel {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public Class<?> getColumnClass (int c) {
        if (getValueAt(0, c) != null){
            return getValueAt(0, c).getClass();
        }
        return String.class;
    }
}