3 The file is used to create, update Guids 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
.GuidUsage
;
31 import org
.tianocore
.GuidsDocument
;
32 import org
.tianocore
.GuidsDocument
.Guids
;
33 import org
.tianocore
.GuidsDocument
.Guids
.GuidCNames
;
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
.Guids
.GuidsIdentification
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Guids
.GuidsVector
;
44 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.GuidsDlg
;
47 The class is used to create, update Guids of MSA/MBD file
48 It extends IInternalFrame
51 public class ModuleGuids
extends IInternalFrame
{
54 /// Define class Serial Version UID
56 private static final long serialVersionUID
= 6710858997766979803L;
59 //Define class members
61 private JPanel jContentPane
= null;
63 private JButton jButtonAdd
= null;
65 private JButton jButtonRemove
= null;
67 private JButton jButtonUpdate
= null;
69 private JScrollPane jScrollPane
= null;
71 private JScrollPane jScrollPaneTable
= null;
73 private JTable jTable
= null;
78 private OpeningModuleType omt
= null;
80 private ModuleSurfaceArea msa
= null;
82 private GuidsDocument
.Guids guids
= null;
84 private GuidsIdentification id
= null;
86 private GuidsVector vid
= new GuidsVector();
88 private IDefaultTableModel model
= null;
90 private int selectedRow
= -1;
92 private IFrame parentFrame
= null;
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, 195, 90, 20));
104 jButtonAdd
.setText("Add");
105 jButtonAdd
.addActionListener(this);
106 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 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, 195, 90, 20));
121 jButtonRemove
.setText("Remove");
122 jButtonRemove
.addActionListener(this);
123 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 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, 195, 90, 20));
138 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 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("Usage");
188 jTable
.setSelectionMode(ListSelectionModel
.MULTIPLE_INTERVAL_SELECTION
);
189 jTable
.getSelectionModel().addListSelectionListener(this);
190 jTable
.getModel().addTableModelListener(this);
191 jTable
.addMouseListener(this);
196 public static void main(String
[] args
) {
201 This method initializes this
204 private void init() {
205 this.setSize(500, 515);
206 this.setContentPane(getJScrollPane());
207 this.setTitle("Guids");
211 This method initializes this
212 Fill values to all fields if these values are not empty
214 @param inPackageDependencies
217 private void init(Guids inGuids
) {
219 this.guids
= inGuids
;
221 if (this.guids
!= null) {
222 if (this.guids
.getGuidCNamesList().size() > 0) {
223 for (int index
= 0; index
< this.guids
.getGuidCNamesList().size(); index
++) {
224 String arg0
= guids
.getGuidCNamesList().get(index
).getGuidCName();
226 if (guids
.getGuidCNamesList().get(index
).getUsage() != null) {
227 arg1
= guids
.getGuidCNamesList().get(index
).getUsage().toString();
230 String arg2
= guids
.getGuidCNamesList().get(index
).getFeatureFlag();
231 Vector
<String
> arg3
= Tools
.convertListToVector(guids
.getGuidCNamesList().get(index
)
233 String arg4
= guids
.getGuidCNamesList().get(index
).getHelpText();
235 id
= new GuidsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
244 This is the default constructor
247 public ModuleGuids() {
250 this.setVisible(true);
254 This is the override edit constructor
256 @param inGuids The input data of GuidsDocument.Guids
259 public ModuleGuids(OpeningModuleType inOmt
, IFrame iFrame
) {
262 this.msa
= omt
.getXmlMsa();
263 this.parentFrame
= iFrame
;
264 init(msa
.getGuids());
265 this.setVisible(true);
269 This method initializes jContentPane
271 @return javax.swing.JPanel jContentPane
274 private JPanel
getJContentPane() {
275 if (jContentPane
== null) {
276 jContentPane
= new JPanel();
277 jContentPane
.setLayout(null);
278 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
280 jContentPane
.add(getJButtonAdd(), null);
281 jContentPane
.add(getJButtonRemove(), null);
282 jContentPane
.add(getJButtonUpdate(), null);
283 jContentPane
.add(getJScrollPaneTable(), null);
288 private void showEdit(int index
) {
289 GuidsDlg dlg
= new GuidsDlg(vid
.getGuids(index
), this.parentFrame
, omt
.getId());
290 int result
= dlg
.showDialog();
291 if (result
== DataType
.RETURN_TYPE_OK
) {
293 this.vid
.addGuids(dlg
.getId());
295 this.vid
.setGuids(dlg
.getId(), index
);
301 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
310 private void clearAll() {
312 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
313 model
.removeRow(index
);
319 Read content of vector and put then into table
322 private void showTable() {
325 if (vid
.size() > 0) {
326 for (int index
= 0; index
< vid
.size(); index
++) {
327 model
.addRow(vid
.toStringVector(index
));
330 this.jTable
.repaint();
331 this.jTable
.updateUI();
335 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
337 * Override actionPerformed to listen all actions
340 public void actionPerformed(ActionEvent arg0
) {
341 if (arg0
.getSource() == jButtonAdd
) {
344 if (arg0
.getSource() == jButtonUpdate
) {
345 if (this.selectedRow
< 0) {
346 Log
.wrn("Update Guids", "Please select one record first.");
349 showEdit(selectedRow
);
352 if (arg0
.getSource() == jButtonRemove
) {
353 if (jTable
.isEditing()) {
354 jTable
.getCellEditor().stopCellEditing();
357 int selectedRows
[] = this.jTable
.getSelectedRows();
359 if (selectedRows
!= null) {
360 for (int index
= selectedRows
.length
- 1; index
> -1; index
--) {
361 this.model
.removeRow(selectedRows
[index
]);
362 this.vid
.removeGuids(selectedRows
[index
]);
371 Save all components of Guids
372 if exists guids, set the value directly
373 if not exists guids, new an instance first
378 int count
= this.vid
.size();
380 this.guids
= Guids
.Factory
.newInstance();
382 for (int index
= 0; index
< count
; index
++) {
383 GuidCNames p
= GuidCNames
.Factory
.newInstance();
384 if (!isEmpty(vid
.getGuids(index
).getName())) {
385 p
.setGuidCName(vid
.getGuids(index
).getName());
387 if (!isEmpty(vid
.getGuids(index
).getUsage())) {
388 p
.setUsage(GuidUsage
.Enum
.forString(vid
.getGuids(index
).getUsage()));
390 if (!isEmpty(vid
.getGuids(index
).getFeatureFlag())) {
391 p
.setFeatureFlag(vid
.getGuids(index
).getFeatureFlag());
393 if (vid
.getGuids(index
).getSupArchList() != null && vid
.getGuids(index
).getSupArchList().size() > 0) {
394 p
.setSupArchList(vid
.getGuids(index
).getSupArchList());
396 if (!isEmpty(vid
.getGuids(index
).getHelp())) {
397 p
.setHelpText(vid
.getGuids(index
).getHelp());
399 this.guids
.addNewGuidCNames();
400 this.guids
.setGuidCNamesArray(guids
.getGuidCNamesList().size() - 1, p
);
404 this.msa
.setGuids(guids
);
405 this.omt
.setSaved(false);
406 } catch (Exception e
) {
407 Log
.wrn("Update Guids", e
.getMessage());
408 Log
.err("Update Guids", e
.getMessage());
413 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
416 public void valueChanged(ListSelectionEvent arg0
) {
417 if (arg0
.getValueIsAdjusting()) {
420 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
421 if (lsm
.isSelectionEmpty()) {
424 selectedRow
= lsm
.getMinSelectionIndex();
429 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
432 public void mouseClicked(MouseEvent arg0
) {
433 if (arg0
.getClickCount() == 2) {
434 if (this.selectedRow
< 0) {
437 showEdit(selectedRow
);
443 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
445 * Override componentResized to resize all components when frame's size is changed
447 public void componentResized(ComponentEvent arg0
) {
448 int intCurrentWidth
= this.getJContentPane().getWidth();
449 int intCurrentHeight
= this.getJContentPane().getHeight();
450 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
451 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
453 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
455 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
456 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
457 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
458 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
459 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
460 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
461 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
462 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
463 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);