3 The file is used to create, update PCD of MSA/MBD file
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
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.
15 package org
.tianocore
.frameworkwizard
.module
.ui
;
17 import java
.awt
.Dimension
;
18 import java
.awt
.event
.ActionEvent
;
19 import java
.awt
.event
.ComponentEvent
;
20 import java
.awt
.event
.MouseEvent
;
21 import java
.util
.Vector
;
23 import javax
.swing
.JButton
;
24 import javax
.swing
.JPanel
;
25 import javax
.swing
.JScrollPane
;
26 import javax
.swing
.JTable
;
27 import javax
.swing
.ListSelectionModel
;
28 import javax
.swing
.event
.ListSelectionEvent
;
30 import org
.tianocore
.PcdCodedDocument
;
31 import org
.tianocore
.PcdItemTypes
;
32 import org
.tianocore
.PcdUsage
;
33 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
34 import org
.tianocore
.PcdCodedDocument
.PcdCoded
;
35 import org
.tianocore
.PcdCodedDocument
.PcdCoded
.PcdEntry
;
36 import org
.tianocore
.frameworkwizard
.common
.DataType
;
37 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
38 import org
.tianocore
.frameworkwizard
.common
.Log
;
39 import org
.tianocore
.frameworkwizard
.common
.Tools
;
40 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
41 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
42 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdCodedIdentification
;
44 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdCodedVector
;
45 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.PCDsDlg
;
48 The class is used to create, update PCD of MSA/MBD file
49 It extends IInternalFrame
54 public class ModulePCDs
extends IInternalFrame
{
57 /// Define class Serial Version UID
59 private static final long serialVersionUID
= 2227717658188438696L;
62 //Define class members
64 private JPanel jContentPane
= null;
66 private JButton jButtonAdd
= null;
68 private JButton jButtonRemove
= null;
70 private JButton jButtonUpdate
= null;
72 private JScrollPane jScrollPane
= null;
74 private JScrollPane jScrollPaneTable
= null;
76 private JTable jTable
= null;
81 private OpeningModuleType omt
= null;
83 private ModuleSurfaceArea msa
= null;
85 private PcdCodedDocument
.PcdCoded pcds
= null;
87 private PcdCodedIdentification id
= null;
89 private PcdCodedVector vid
= new PcdCodedVector();
91 private IDefaultTableModel model
= null;
93 private int selectedRow
= -1;
96 This method initializes jButtonAdd
98 @return javax.swing.JButton jButtonAdd
101 private JButton
getJButtonAdd() {
102 if (jButtonAdd
== null) {
103 jButtonAdd
= new JButton();
104 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 245, 80, 20));
105 jButtonAdd
.setText("Add");
106 jButtonAdd
.addActionListener(this);
107 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(80, 20));
113 This method initializes jButtonRemove
115 @return javax.swing.JButton jButtonRemove
118 private JButton
getJButtonRemove() {
119 if (jButtonRemove
== null) {
120 jButtonRemove
= new JButton();
121 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 245, 80, 20));
122 jButtonRemove
.setText("Remove");
123 jButtonRemove
.addActionListener(this);
124 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(80, 20));
126 return jButtonRemove
;
130 This method initializes jButtonUpdate
132 @return javax.swing.JButton jButtonUpdate
135 private JButton
getJButtonUpdate() {
136 if (jButtonUpdate
== null) {
137 jButtonUpdate
= new JButton();
138 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 245, 80, 20));
139 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(80, 20));
140 jButtonUpdate
.setText("Edit");
141 jButtonUpdate
.addActionListener(this);
143 return jButtonUpdate
;
147 This method initializes jScrollPane
149 @return javax.swing.JScrollPane
151 private JScrollPane
getJScrollPane() {
152 if (jScrollPane
== null) {
153 jScrollPane
= new JScrollPane();
154 jScrollPane
.setViewportView(getJContentPane());
160 This method initializes jScrollPaneTable
162 @return javax.swing.JScrollPane
164 private JScrollPane
getJScrollPaneTable() {
165 if (jScrollPaneTable
== null) {
166 jScrollPaneTable
= new JScrollPane();
167 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
168 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
169 jScrollPaneTable
.setViewportView(getJTable());
171 return jScrollPaneTable
;
175 This method initializes jTable
177 @return javax.swing.JTable
179 private JTable
getJTable() {
180 if (jTable
== null) {
181 jTable
= new JTable();
182 model
= new IDefaultTableModel();
183 jTable
= new JTable(model
);
184 jTable
.setRowHeight(20);
186 model
.addColumn("Name");
187 model
.addColumn("Type");
188 model
.addColumn("Value");
189 model
.addColumn("Usage");
191 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
192 jTable
.getSelectionModel().addListSelectionListener(this);
193 jTable
.getModel().addTableModelListener(this);
194 jTable
.addMouseListener(this);
199 public static void main(String
[] args
) {
204 This method initializes this
207 private void init() {
208 this.setSize(500, 515);
209 this.setContentPane(getJScrollPane());
210 this.setTitle("Pcd Coded");
214 This method initializes this
215 Fill values to all fields if these values are not empty
217 @param inPackageDependencies
220 private void init(PcdCoded inPcdCodeds
) {
222 this.pcds
= inPcdCodeds
;
224 if (this.pcds
!= null) {
225 if (this.pcds
.getPcdEntryList().size() > 0) {
226 for (int index
= 0; index
< this.pcds
.getPcdEntryList().size(); index
++) {
227 String arg0
= pcds
.getPcdEntryList().get(index
).getCName();
228 String arg1
= pcds
.getPcdEntryList().get(index
).getTokenSpaceGuidCName();
230 String arg2
= pcds
.getPcdEntryList().get(index
).getFeatureFlag();
231 Vector
<String
> arg3
= Tools
.convertListToVector(pcds
.getPcdEntryList().get(index
).getSupArchList());
233 String arg4
= pcds
.getPcdEntryList().get(index
).getDefaultValue();
234 String arg5
= pcds
.getPcdEntryList().get(index
).getHelpText();
236 if (pcds
.getPcdEntryList().get(index
).getPcdItemType() != null) {
237 arg6
= pcds
.getPcdEntryList().get(index
).getPcdItemType().toString();
240 if (pcds
.getPcdEntryList().get(index
).getUsage() != null) {
241 arg7
= pcds
.getPcdEntryList().get(index
).getUsage().toString();
243 id
= new PcdCodedIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
);
252 This is the default constructor
255 public ModulePCDs() {
258 this.setVisible(true);
262 This is the override edit constructor
264 @param inPcds The input data of PCDsDocument.PCDs
267 public ModulePCDs(OpeningModuleType inOmt
) {
270 this.msa
= omt
.getXmlMsa();
271 init(msa
.getPcdCoded());
272 this.setVisible(true);
276 This method initializes jContentPane
278 @return javax.swing.JPanel jContentPane
281 private JPanel
getJContentPane() {
282 if (jContentPane
== null) {
283 jContentPane
= new JPanel();
284 jContentPane
.setLayout(null);
285 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
287 jContentPane
.add(getJButtonAdd(), null);
288 jContentPane
.add(getJButtonRemove(), null);
289 jContentPane
.add(getJButtonUpdate(), null);
290 jContentPane
.add(getJScrollPaneTable(), null);
295 private void showEdit(int index
) {
296 PCDsDlg dlg
= new PCDsDlg(vid
.getPcdCoded(index
), new IFrame(), omt
.getId());
297 int result
= dlg
.showDialog();
298 if (result
== DataType
.RETURN_TYPE_OK
) {
300 this.vid
.addPcdCoded(dlg
.getId());
302 this.vid
.setPcdCoded(dlg
.getId(), index
);
308 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
317 private void clearAll() {
319 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
320 model
.removeRow(index
);
326 Read content of vector and put then into table
329 private void showTable() {
332 if (vid
.size() > 0) {
333 for (int index
= 0; index
< vid
.size(); index
++) {
334 model
.addRow(vid
.toStringVector(index
));
337 this.jTable
.repaint();
338 this.jTable
.updateUI();
342 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
344 * Override actionPerformed to listen all actions
347 public void actionPerformed(ActionEvent arg0
) {
348 if (arg0
.getSource() == jButtonAdd
) {
351 if (arg0
.getSource() == jButtonUpdate
) {
352 if (this.selectedRow
< 0) {
353 Log
.wrn("Update PcdCoded", "Please select one record first.");
356 showEdit(selectedRow
);
359 if (arg0
.getSource() == jButtonRemove
) {
360 if (jTable
.isEditing()) {
361 jTable
.getCellEditor().stopCellEditing();
363 if (selectedRow
> -1) {
364 this.model
.removeRow(selectedRow
);
365 this.vid
.removePcdCoded(selectedRow
);
373 Save all components of PCDs
374 if exists pcds, set the value directly
375 if not exists pcds, new an instance first
380 int count
= this.vid
.size();
382 this.pcds
= PcdCoded
.Factory
.newInstance();
384 for (int index
= 0; index
< count
; index
++) {
385 PcdEntry p
= PcdEntry
.Factory
.newInstance();
386 if (!isEmpty(vid
.getPcdCoded(index
).getName())) {
387 p
.setCName(vid
.getPcdCoded(index
).getName());
389 if (!isEmpty(vid
.getPcdCoded(index
).getGuid())) {
390 p
.setTokenSpaceGuidCName(vid
.getPcdCoded(index
).getGuid());
392 if (!isEmpty(vid
.getPcdCoded(index
).getFeatureFlag())) {
393 p
.setFeatureFlag(vid
.getPcdCoded(index
).getFeatureFlag());
395 if (vid
.getPcdCoded(index
).getSupArchList() != null
396 && vid
.getPcdCoded(index
).getSupArchList().size() > 0) {
397 p
.setSupArchList(vid
.getPcdCoded(index
).getSupArchList());
399 if (!isEmpty(vid
.getPcdCoded(index
).getValue())) {
400 p
.setDefaultValue(vid
.getPcdCoded(index
).getValue());
402 if (!isEmpty(vid
.getPcdCoded(index
).getHelp())) {
403 p
.setHelpText(vid
.getPcdCoded(index
).getHelp());
405 if (!isEmpty(vid
.getPcdCoded(index
).getType())) {
406 p
.setPcdItemType(PcdItemTypes
.Enum
.forString(vid
.getPcdCoded(index
).getType()));
408 if (!isEmpty(vid
.getPcdCoded(index
).getUsage())) {
409 p
.setUsage(PcdUsage
.Enum
.forString(vid
.getPcdCoded(index
).getUsage()));
411 this.pcds
.addNewPcdEntry();
412 this.pcds
.setPcdEntryArray(pcds
.getPcdEntryList().size() - 1, p
);
416 this.msa
.setPcdCoded(pcds
);
417 this.omt
.setSaved(false);
418 } catch (Exception e
) {
419 Log
.wrn("Update PcdCoded", e
.getMessage());
420 Log
.err("Update PcdCoded", e
.getMessage());
425 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
428 public void valueChanged(ListSelectionEvent arg0
) {
429 if (arg0
.getValueIsAdjusting()) {
432 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
433 if (lsm
.isSelectionEmpty()) {
436 selectedRow
= lsm
.getMinSelectionIndex();
441 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
444 public void mouseClicked(MouseEvent arg0
) {
445 if (arg0
.getClickCount() == 2) {
446 if (this.selectedRow
< 0) {
449 showEdit(selectedRow
);
455 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
457 * Override componentResized to resize all components when frame's size is changed
459 public void componentResized(ComponentEvent arg0
) {
460 int intCurrentWidth
= this.getJContentPane().getWidth();
461 int intCurrentHeight
= this.getJContentPane().getHeight();
462 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
463 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
465 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
467 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
468 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
469 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
470 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
471 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
472 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
473 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
474 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
475 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);