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;
94 private IFrame parentFrame
= null;
97 This method initializes jButtonAdd
99 @return javax.swing.JButton jButtonAdd
102 private JButton
getJButtonAdd() {
103 if (jButtonAdd
== null) {
104 jButtonAdd
= new JButton();
105 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 220, 90, 20));
106 jButtonAdd
.setText("Add");
107 jButtonAdd
.addActionListener(this);
108 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
114 This method initializes jButtonRemove
116 @return javax.swing.JButton jButtonRemove
119 private JButton
getJButtonRemove() {
120 if (jButtonRemove
== null) {
121 jButtonRemove
= new JButton();
122 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 220, 90, 20));
123 jButtonRemove
.setText("Remove");
124 jButtonRemove
.addActionListener(this);
125 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
127 return jButtonRemove
;
131 This method initializes jButtonUpdate
133 @return javax.swing.JButton jButtonUpdate
136 private JButton
getJButtonUpdate() {
137 if (jButtonUpdate
== null) {
138 jButtonUpdate
= new JButton();
139 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 220, 90, 20));
140 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
141 jButtonUpdate
.setText("Edit");
142 jButtonUpdate
.addActionListener(this);
144 return jButtonUpdate
;
148 This method initializes jScrollPane
150 @return javax.swing.JScrollPane
152 private JScrollPane
getJScrollPane() {
153 if (jScrollPane
== null) {
154 jScrollPane
= new JScrollPane();
155 jScrollPane
.setViewportView(getJContentPane());
161 This method initializes jScrollPaneTable
163 @return javax.swing.JScrollPane
165 private JScrollPane
getJScrollPaneTable() {
166 if (jScrollPaneTable
== null) {
167 jScrollPaneTable
= new JScrollPane();
168 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
169 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
170 jScrollPaneTable
.setViewportView(getJTable());
172 return jScrollPaneTable
;
176 This method initializes jTable
178 @return javax.swing.JTable
180 private JTable
getJTable() {
181 if (jTable
== null) {
182 jTable
= new JTable();
183 model
= new IDefaultTableModel();
184 jTable
= new JTable(model
);
185 jTable
.setRowHeight(20);
187 model
.addColumn("Guid C_Name");
188 model
.addColumn("Type");
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("Hobs");
214 This method initializes this
215 Fill values to all fields if these values are not empty
217 @param inPackageDependencies
220 private void init(Hobs inHobs
) {
224 if (this.hobs
!= null) {
225 if (this.hobs
.getHobTypesList().size() > 0) {
226 for (int index
= 0; index
< this.hobs
.getHobTypesList().size(); index
++) {
227 String arg0
= hobs
.getHobTypesList().get(index
).getHobGuidCName();
229 if (hobs
.getHobTypesList().get(index
).getHobType() != null) {
230 arg1
= hobs
.getHobTypesList().get(index
).getHobType().toString();
233 if (hobs
.getHobTypesList().get(index
).getUsage() != null) {
234 arg2
= hobs
.getHobTypesList().get(index
).getUsage().toString();
237 String arg3
= hobs
.getHobTypesList().get(index
).getFeatureFlag();
238 Vector
<String
> arg4
= Tools
.convertListToVector(hobs
.getHobTypesList().get(index
).getSupArchList());
239 String arg5
= hobs
.getHobTypesList().get(index
).getHelpText();
240 id
= new HobsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
249 This is the default constructor
252 public ModuleHobs() {
255 this.setVisible(true);
259 This is the override edit constructor
261 @param inHobs The input data of HobsDocument.Hobs
264 public ModuleHobs(OpeningModuleType inOmt
, IFrame iFrame
) {
267 this.msa
= omt
.getXmlMsa();
268 this.parentFrame
= iFrame
;
270 this.setVisible(true);
274 This method initializes jContentPane
276 @return javax.swing.JPanel jContentPane
279 public JPanel
getJContentPane() {
280 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 HobsDlg dlg
= new HobsDlg(vid
.getHobs(index
), this.parentFrame
, omt
.getId());
296 int result
= dlg
.showDialog();
297 if (result
== DataType
.RETURN_TYPE_OK
) {
299 this.vid
.addHobs(dlg
.getId());
301 this.vid
.setHobs(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 Hobs", "Please select one record first.");
355 showEdit(selectedRow
);
358 if (arg0
.getSource() == jButtonRemove
) {
359 if (jTable
.isEditing()) {
360 jTable
.getCellEditor().stopCellEditing();
362 if (selectedRow
> -1) {
363 this.model
.removeRow(selectedRow
);
364 this.vid
.removeHobs(selectedRow
);
372 Save all components of Hobs
373 if exists hobs, set the value directly
374 if not exists hobs, new an instance first
379 int count
= this.vid
.size();
381 this.hobs
= Hobs
.Factory
.newInstance();
383 for (int index
= 0; index
< count
; index
++) {
384 HobsDocument
.Hobs
.HobTypes p
= HobsDocument
.Hobs
.HobTypes
.Factory
.newInstance();
385 if (!isEmpty(vid
.getHobs(index
).getName())) {
386 p
.setHobGuidCName(vid
.getHobs(index
).getName());
388 if (!isEmpty(vid
.getHobs(index
).getUsage())) {
389 p
.setUsage(HobUsage
.Enum
.forString(vid
.getHobs(index
).getUsage()));
391 if (!isEmpty(vid
.getHobs(index
).getType())) {
392 p
.setHobType(HobTypes
.Enum
.forString(vid
.getHobs(index
).getType()));
394 if (!isEmpty(vid
.getHobs(index
).getFeatureFlag())) {
395 p
.setFeatureFlag(vid
.getHobs(index
).getFeatureFlag());
397 if (vid
.getHobs(index
).getSupArchList() != null && vid
.getHobs(index
).getSupArchList().size() > 0) {
398 p
.setSupArchList(vid
.getHobs(index
).getSupArchList());
400 this.hobs
.addNewHobTypes();
401 this.hobs
.setHobTypesArray(hobs
.getHobTypesList().size() - 1, p
);
405 this.msa
.setHobs(hobs
);
406 this.omt
.setSaved(false);
407 } catch (Exception e
) {
408 Log
.wrn("Update Hobs", e
.getMessage());
409 Log
.err("Update Hobs", e
.getMessage());
414 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
417 public void valueChanged(ListSelectionEvent arg0
) {
418 if (arg0
.getValueIsAdjusting()) {
421 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
422 if (lsm
.isSelectionEmpty()) {
425 selectedRow
= lsm
.getMinSelectionIndex();
430 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
433 public void mouseClicked(MouseEvent arg0
) {
434 if (arg0
.getClickCount() == 2) {
435 if (this.selectedRow
< 0) {
438 showEdit(selectedRow
);
444 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
446 * Override componentResized to resize all components when frame's size is changed
448 public void componentResized(ComponentEvent arg0
) {
449 int intCurrentWidth
= this.getJContentPane().getWidth();
450 int intCurrentHeight
= this.getJContentPane().getHeight();
451 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
452 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
454 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
456 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
457 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
458 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
459 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
460 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
461 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
462 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
463 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
464 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);