3 The file is used to create, update Hob 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
.HobTypes
;
31 import org
.tianocore
.HobUsage
;
32 import org
.tianocore
.HobsDocument
;
33 import org
.tianocore
.HobsDocument
.Hobs
;
34 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
35 import org
.tianocore
.frameworkwizard
.common
.DataType
;
36 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
37 import org
.tianocore
.frameworkwizard
.common
.Log
;
38 import org
.tianocore
.frameworkwizard
.common
.Tools
;
39 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
40 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
41 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
42 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Hobs
.HobsIdentification
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Hobs
.HobsVector
;
44 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.HobsDlg
;
47 The class is used to create, update Hob of MSA/MBD file
48 It extends IInternalFrame
53 public class ModuleHobs
extends IInternalFrame
{
56 /// Define class Serial Version UID
58 private static final long serialVersionUID
= -553473437579358325L;
61 //Define class members
63 private JPanel jContentPane
= null;
65 private JButton jButtonAdd
= null;
67 private JButton jButtonRemove
= null;
69 private JButton jButtonUpdate
= null;
71 private JScrollPane jScrollPane
= null;
73 private JScrollPane jScrollPaneTable
= null;
75 private JTable jTable
= null;
80 private OpeningModuleType omt
= null;
82 private ModuleSurfaceArea msa
= null;
84 private HobsDocument
.Hobs hobs
= null;
86 private HobsIdentification id
= null;
88 private HobsVector vid
= new HobsVector();
90 private IDefaultTableModel model
= null;
92 private int selectedRow
= -1;
95 This method initializes jButtonAdd
97 @return javax.swing.JButton jButtonAdd
100 private JButton
getJButtonAdd() {
101 if (jButtonAdd
== null) {
102 jButtonAdd
= new JButton();
103 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 220, 80, 20));
104 jButtonAdd
.setText("Add");
105 jButtonAdd
.addActionListener(this);
106 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(80, 20));
112 This method initializes jButtonRemove
114 @return javax.swing.JButton jButtonRemove
117 private JButton
getJButtonRemove() {
118 if (jButtonRemove
== null) {
119 jButtonRemove
= new JButton();
120 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 220, 80, 20));
121 jButtonRemove
.setText("Remove");
122 jButtonRemove
.addActionListener(this);
123 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(80, 20));
125 return jButtonRemove
;
129 This method initializes jButtonUpdate
131 @return javax.swing.JButton jButtonUpdate
134 private JButton
getJButtonUpdate() {
135 if (jButtonUpdate
== null) {
136 jButtonUpdate
= new JButton();
137 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 220, 80, 20));
138 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(80, 20));
139 jButtonUpdate
.setText("Edit");
140 jButtonUpdate
.addActionListener(this);
142 return jButtonUpdate
;
146 This method initializes jScrollPane
148 @return javax.swing.JScrollPane
150 private JScrollPane
getJScrollPane() {
151 if (jScrollPane
== null) {
152 jScrollPane
= new JScrollPane();
153 jScrollPane
.setViewportView(getJContentPane());
159 This method initializes jScrollPaneTable
161 @return javax.swing.JScrollPane
163 private JScrollPane
getJScrollPaneTable() {
164 if (jScrollPaneTable
== null) {
165 jScrollPaneTable
= new JScrollPane();
166 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
167 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
168 jScrollPaneTable
.setViewportView(getJTable());
170 return jScrollPaneTable
;
174 This method initializes jTable
176 @return javax.swing.JTable
178 private JTable
getJTable() {
179 if (jTable
== null) {
180 jTable
= new JTable();
181 model
= new IDefaultTableModel();
182 jTable
= new JTable(model
);
183 jTable
.setRowHeight(20);
185 model
.addColumn("Guid C_Name");
186 model
.addColumn("Type");
187 model
.addColumn("Usage");
189 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
190 jTable
.getSelectionModel().addListSelectionListener(this);
191 jTable
.getModel().addTableModelListener(this);
192 jTable
.addMouseListener(this);
197 public static void main(String
[] args
) {
202 This method initializes this
205 private void init() {
206 this.setSize(500, 515);
207 this.setContentPane(getJScrollPane());
208 this.setTitle("Hobs");
212 This method initializes this
213 Fill values to all fields if these values are not empty
215 @param inPackageDependencies
218 private void init(Hobs inHobs
) {
222 if (this.hobs
!= null) {
223 if (this.hobs
.getHobTypesList().size() > 0) {
224 for (int index
= 0; index
< this.hobs
.getHobTypesList().size(); index
++) {
225 String arg0
= hobs
.getHobTypesList().get(index
).getHobGuidCName();
227 if (hobs
.getHobTypesList().get(index
).getHobType() != null) {
228 arg1
= hobs
.getHobTypesList().get(index
).getHobType().toString();
231 if (hobs
.getHobTypesList().get(index
).getUsage() != null) {
232 arg2
= hobs
.getHobTypesList().get(index
).getUsage().toString();
235 String arg3
= hobs
.getHobTypesList().get(index
).getFeatureFlag();
236 Vector
<String
> arg4
= Tools
.convertListToVector(hobs
.getHobTypesList().get(index
).getSupArchList());
237 String arg5
= hobs
.getHobTypesList().get(index
).getHelpText();
238 id
= new HobsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
247 This is the default constructor
250 public ModuleHobs() {
253 this.setVisible(true);
257 This is the override edit constructor
259 @param inHobs The input data of HobsDocument.Hobs
262 public ModuleHobs(OpeningModuleType inOmt
) {
265 this.msa
= omt
.getXmlMsa();
267 this.setVisible(true);
271 This method initializes jContentPane
273 @return javax.swing.JPanel jContentPane
276 public JPanel
getJContentPane() {
277 if (jContentPane
== null) {
279 jContentPane
= new JPanel();
280 jContentPane
.setLayout(null);
281 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
283 jContentPane
.add(getJButtonAdd(), null);
284 jContentPane
.add(getJButtonRemove(), null);
285 jContentPane
.add(getJButtonUpdate(), null);
286 jContentPane
.add(getJScrollPaneTable(), null);
291 private void showEdit(int index
) {
292 HobsDlg dlg
= new HobsDlg(vid
.getHobs(index
), new IFrame());
293 int result
= dlg
.showDialog();
294 if (result
== DataType
.RETURN_TYPE_OK
) {
296 this.vid
.addHobs(dlg
.getId());
298 this.vid
.setHobs(dlg
.getId(), index
);
304 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
313 private void clearAll() {
315 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
316 model
.removeRow(index
);
322 Read content of vector and put then into table
325 private void showTable() {
328 if (vid
.size() > 0) {
329 for (int index
= 0; index
< vid
.size(); index
++) {
330 model
.addRow(vid
.toStringVector(index
));
333 this.jTable
.repaint();
334 this.jTable
.updateUI();
338 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
340 * Override actionPerformed to listen all actions
343 public void actionPerformed(ActionEvent arg0
) {
344 if (arg0
.getSource() == jButtonAdd
) {
347 if (arg0
.getSource() == jButtonUpdate
) {
348 if (this.selectedRow
< 0) {
349 Log
.wrn("Update Hobs", "Please select one record first.");
352 showEdit(selectedRow
);
355 if (arg0
.getSource() == jButtonRemove
) {
356 if (jTable
.isEditing()) {
357 jTable
.getCellEditor().stopCellEditing();
359 if (selectedRow
> -1) {
360 this.model
.removeRow(selectedRow
);
361 this.vid
.removeHobs(selectedRow
);
369 Save all components of Hobs
370 if exists hobs, set the value directly
371 if not exists hobs, new an instance first
376 int count
= this.vid
.size();
378 this.hobs
= Hobs
.Factory
.newInstance();
380 for (int index
= 0; index
< count
; index
++) {
381 HobsDocument
.Hobs
.HobTypes p
= HobsDocument
.Hobs
.HobTypes
.Factory
.newInstance();
382 if (!isEmpty(vid
.getHobs(index
).getName())) {
383 p
.setHobGuidCName(vid
.getHobs(index
).getName());
385 if (!isEmpty(vid
.getHobs(index
).getUsage())) {
386 p
.setUsage(HobUsage
.Enum
.forString(vid
.getHobs(index
).getUsage()));
388 if (!isEmpty(vid
.getHobs(index
).getType())) {
389 p
.setHobType(HobTypes
.Enum
.forString(vid
.getHobs(index
).getType()));
391 if (!isEmpty(vid
.getHobs(index
).getFeatureFlag())) {
392 p
.setFeatureFlag(vid
.getHobs(index
).getFeatureFlag());
394 if (vid
.getHobs(index
).getSupArchList() != null && vid
.getHobs(index
).getSupArchList().size() > 0) {
395 p
.setSupArchList(vid
.getHobs(index
).getSupArchList());
397 this.hobs
.addNewHobTypes();
398 this.hobs
.setHobTypesArray(hobs
.getHobTypesList().size() - 1, p
);
402 this.msa
.setHobs(hobs
);
403 this.omt
.setSaved(false);
404 } catch (Exception e
) {
405 Log
.wrn("Update Hobs", e
.getMessage());
406 Log
.err("Update Hobs", e
.getMessage());
411 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
414 public void valueChanged(ListSelectionEvent arg0
) {
415 if (arg0
.getValueIsAdjusting()) {
418 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
419 if (lsm
.isSelectionEmpty()) {
422 selectedRow
= lsm
.getMinSelectionIndex();
427 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
430 public void mouseClicked(MouseEvent arg0
) {
431 if (arg0
.getClickCount() == 2) {
432 if (this.selectedRow
< 0) {
435 showEdit(selectedRow
);
441 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
443 * Override componentResized to resize all components when frame's size is changed
445 public void componentResized(ComponentEvent arg0
) {
446 int intCurrentWidth
= this.getJContentPane().getWidth();
447 int intCurrentHeight
= this.getJContentPane().getHeight();
448 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
449 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
451 resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
);
452 relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
453 DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
454 relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
455 DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
456 relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
457 DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);