3 The file is used to create, update BootModes 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.
16 package org
.tianocore
.frameworkwizard
.module
.ui
;
18 import java
.awt
.Dimension
;
19 import java
.awt
.event
.ActionEvent
;
20 import java
.awt
.event
.ComponentEvent
;
21 import java
.awt
.event
.MouseEvent
;
22 import java
.util
.Vector
;
24 import javax
.swing
.JButton
;
25 import javax
.swing
.JPanel
;
26 import javax
.swing
.JScrollPane
;
27 import javax
.swing
.JTable
;
28 import javax
.swing
.ListSelectionModel
;
29 import javax
.swing
.event
.ListSelectionEvent
;
31 import org
.tianocore
.BootModeNames
;
32 import org
.tianocore
.BootModeUsage
;
33 import org
.tianocore
.BootModesDocument
;
34 import org
.tianocore
.BootModesDocument
.BootModes
;
35 import org
.tianocore
.BootModesDocument
.BootModes
.BootMode
;
36 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
37 import org
.tianocore
.frameworkwizard
.common
.DataType
;
38 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
39 import org
.tianocore
.frameworkwizard
.common
.Log
;
40 import org
.tianocore
.frameworkwizard
.common
.Tools
;
41 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
42 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
43 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
44 import org
.tianocore
.frameworkwizard
.module
.Identifications
.BootModes
.BootModesIdentification
;
45 import org
.tianocore
.frameworkwizard
.module
.Identifications
.BootModes
.BootModesVector
;
46 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.BootModesDlg
;
49 The class is used to create, update BootModes of MSA/MBD file
50 It extends IInternalFrame
55 public class ModuleBootModes
extends IInternalFrame
{
58 /// Define class Serial Version UID
60 private static final long serialVersionUID
= -3888558623432442561L;
63 //Define class members
65 private JPanel jContentPane
= null;
67 private JButton jButtonAdd
= null;
69 private JButton jButtonRemove
= null;
71 private JButton jButtonUpdate
= null;
73 private JScrollPane jScrollPane
= null;
75 private JScrollPane jScrollPaneTable
= null;
77 private JTable jTable
= null;
79 private IFrame parentFrame
= null;
84 private OpeningModuleType omt
= null;
86 private ModuleSurfaceArea msa
= null;
88 private BootModesDocument
.BootModes bootModes
= null;
90 private BootModesIdentification id
= null;
92 private BootModesVector vid
= new BootModesVector();
94 private IDefaultTableModel model
= null;
96 private int selectedRow
= -1;
99 This method initializes jButtonAdd
101 @return javax.swing.JButton jButtonAdd
104 private JButton
getJButtonAdd() {
105 if (jButtonAdd
== null) {
106 jButtonAdd
= new JButton();
107 jButtonAdd
.setBounds(new java
.awt
.Rectangle(210, 195, 90, 20));
108 jButtonAdd
.setText("Add");
109 jButtonAdd
.addActionListener(this);
110 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
116 This method initializes jButtonRemove
118 @return javax.swing.JButton jButtonRemove
121 private JButton
getJButtonRemove() {
122 if (jButtonRemove
== null) {
123 jButtonRemove
= new JButton();
124 jButtonRemove
.setBounds(new java
.awt
.Rectangle(390, 195, 90, 20));
125 jButtonRemove
.setText("Remove");
126 jButtonRemove
.addActionListener(this);
127 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
129 return jButtonRemove
;
133 This method initializes jButtonUpdate
135 @return javax.swing.JButton jButtonUpdate
138 private JButton
getJButtonUpdate() {
139 if (jButtonUpdate
== null) {
140 jButtonUpdate
= new JButton();
141 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 195, 90, 20));
142 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
143 jButtonUpdate
.setText("Edit");
144 jButtonUpdate
.addActionListener(this);
146 return jButtonUpdate
;
150 This method initializes jScrollPane
152 @return javax.swing.JScrollPane
154 private JScrollPane
getJScrollPane() {
155 if (jScrollPane
== null) {
156 jScrollPane
= new JScrollPane();
157 jScrollPane
.setViewportView(getJContentPane());
163 This method initializes jScrollPaneTable
165 @return javax.swing.JScrollPane
167 private JScrollPane
getJScrollPaneTable() {
168 if (jScrollPaneTable
== null) {
169 jScrollPaneTable
= new JScrollPane();
170 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
171 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
172 jScrollPaneTable
.setViewportView(getJTable());
174 return jScrollPaneTable
;
178 This method initializes jTable
180 @return javax.swing.JTable
182 private JTable
getJTable() {
183 if (jTable
== null) {
184 jTable
= new JTable();
185 model
= new IDefaultTableModel();
186 jTable
= new JTable(model
);
187 jTable
.setRowHeight(20);
189 model
.addColumn("Name");
190 model
.addColumn("Usage");
192 jTable
.setSelectionMode(ListSelectionModel
.MULTIPLE_INTERVAL_SELECTION
);
193 jTable
.getSelectionModel().addListSelectionListener(this);
194 jTable
.getModel().addTableModelListener(this);
195 jTable
.addMouseListener(this);
200 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("Boot Modes");
214 This method initializes this
215 Fill values to all fields if these values are not empty
220 private void init(BootModes inBootModes
) {
222 this.bootModes
= inBootModes
;
224 if (this.bootModes
!= null) {
225 if (this.bootModes
.getBootModeList().size() > 0) {
226 for (int index
= 0; index
< this.bootModes
.getBootModeList().size(); index
++) {
228 if (bootModes
.getBootModeList().get(index
).getBootModeName() != null) {
229 arg0
= bootModes
.getBootModeList().get(index
).getBootModeName().toString();
232 if (bootModes
.getBootModeList().get(index
).getUsage() != null) {
233 arg1
= bootModes
.getBootModeList().get(index
).getUsage().toString();
236 String arg2
= bootModes
.getBootModeList().get(index
).getFeatureFlag();
237 Vector
<String
> arg3
= Tools
.convertListToVector(bootModes
.getBootModeList().get(index
)
239 String arg4
= bootModes
.getBootModeList().get(index
).getHelpText();
241 id
= new BootModesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
242 vid
.addBootModes(id
);
250 This is the default constructor
253 public ModuleBootModes() {
256 this.setVisible(true);
260 This is the override edit constructor
262 @param inBootModes The input BootModesDocument.BootModes
265 public ModuleBootModes(OpeningModuleType inOmt
, IFrame iFrame
) {
268 this.msa
= omt
.getXmlMsa();
269 this.parentFrame
= iFrame
;
270 init(msa
.getBootModes());
271 this.setVisible(true);
275 This method initializes jContentPane
277 @return javax.swing.JPanel jContentPane
280 private JPanel
getJContentPane() {
281 if (jContentPane
== null) {
282 jContentPane
= new JPanel();
283 jContentPane
.setLayout(null);
284 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
286 jContentPane
.add(getJButtonAdd(), null);
287 jContentPane
.add(getJButtonRemove(), null);
288 jContentPane
.add(getJButtonUpdate(), null);
289 jContentPane
.add(getJScrollPaneTable(), null);
294 private void showEdit(int index
) {
295 BootModesDlg dlg
= new BootModesDlg(vid
.getBootModes(index
), this.parentFrame
, omt
.getId());
296 int result
= dlg
.showDialog();
297 if (result
== DataType
.RETURN_TYPE_OK
) {
299 this.vid
.addBootModes(dlg
.getId());
301 this.vid
.setBootModes(dlg
.getId(), index
);
307 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
316 private void clearAll() {
318 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
319 model
.removeRow(index
);
325 Read content of vector and put then into table
328 private void showTable() {
331 if (vid
.size() > 0) {
332 for (int index
= 0; index
< vid
.size(); index
++) {
333 model
.addRow(vid
.toStringVector(index
));
336 this.jTable
.repaint();
337 this.jTable
.updateUI();
341 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
343 * Override actionPerformed to listen all actions
346 public void actionPerformed(ActionEvent arg0
) {
347 if (arg0
.getSource() == jButtonAdd
) {
350 if (arg0
.getSource() == jButtonUpdate
) {
351 if (this.selectedRow
< 0) {
352 Log
.wrn("Update Boot Modes", "Please select one record first.");
355 showEdit(selectedRow
);
358 if (arg0
.getSource() == jButtonRemove
) {
359 if (jTable
.isEditing()) {
360 jTable
.getCellEditor().stopCellEditing();
363 int selectedRows
[] = this.jTable
.getSelectedRows();
365 if (selectedRows
!= null) {
366 for (int index
= selectedRows
.length
- 1; index
> -1; index
--) {
367 this.model
.removeRow(selectedRows
[index
]);
368 this.vid
.removeBootModes(selectedRows
[index
]);
377 Save all components of Mbd Header
378 if exists bootModes, set the value directly
379 if not exists bootModes, new an instance first
384 int count
= this.vid
.size();
386 this.bootModes
= BootModes
.Factory
.newInstance();
388 for (int index
= 0; index
< count
; index
++) {
389 BootMode p
= BootMode
.Factory
.newInstance();
390 if (!isEmpty(vid
.getBootModes(index
).getName())) {
391 p
.setBootModeName(BootModeNames
.Enum
.forString(vid
.getBootModes(index
).getName()));
393 if (!isEmpty(vid
.getBootModes(index
).getUsage())) {
394 p
.setUsage(BootModeUsage
.Enum
.forString(vid
.getBootModes(index
).getUsage()));
396 if (!isEmpty(vid
.getBootModes(index
).getFeatureFlag())) {
397 p
.setFeatureFlag(vid
.getBootModes(index
).getFeatureFlag());
399 if (vid
.getBootModes(index
).getSupArchList() != null
400 && vid
.getBootModes(index
).getSupArchList().size() > 0) {
401 p
.setSupArchList(vid
.getBootModes(index
).getSupArchList());
403 if (!isEmpty(vid
.getBootModes(index
).getHelp())) {
404 p
.setHelpText(vid
.getBootModes(index
).getHelp());
406 this.bootModes
.addNewBootMode();
407 this.bootModes
.setBootModeArray(bootModes
.getBootModeList().size() - 1, p
);
411 this.msa
.setBootModes(bootModes
);
412 this.omt
.setSaved(false);
413 } catch (Exception e
) {
414 Log
.wrn("Update Boot Modes", e
.getMessage());
415 Log
.err("Update Boot Modes", e
.getMessage());
420 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
423 public void valueChanged(ListSelectionEvent arg0
) {
424 if (arg0
.getValueIsAdjusting()) {
427 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
428 if (lsm
.isSelectionEmpty()) {
431 selectedRow
= lsm
.getMinSelectionIndex();
436 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
439 public void mouseClicked(MouseEvent arg0
) {
440 if (arg0
.getClickCount() == 2) {
441 if (this.selectedRow
< 0) {
444 showEdit(selectedRow
);
450 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
452 * Override componentResized to resize all components when frame's size is changed
454 public void componentResized(ComponentEvent arg0
) {
455 int intCurrentWidth
= this.getJContentPane().getWidth();
456 int intCurrentHeight
= this.getJContentPane().getHeight();
457 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
458 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
460 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
462 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
463 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
464 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
465 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
466 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
467 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
468 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
469 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
470 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);