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;
93 This method initializes jButtonAdd
95 @return javax.swing.JButton jButtonAdd
98 private JButton
getJButtonAdd() {
99 if (jButtonAdd
== null) {
100 jButtonAdd
= new JButton();
101 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 195, 80, 20));
102 jButtonAdd
.setText("Add");
103 jButtonAdd
.addActionListener(this);
104 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(80, 20));
110 This method initializes jButtonRemove
112 @return javax.swing.JButton jButtonRemove
115 private JButton
getJButtonRemove() {
116 if (jButtonRemove
== null) {
117 jButtonRemove
= new JButton();
118 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 195, 80, 20));
119 jButtonRemove
.setText("Remove");
120 jButtonRemove
.addActionListener(this);
121 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(80, 20));
123 return jButtonRemove
;
127 This method initializes jButtonUpdate
129 @return javax.swing.JButton jButtonUpdate
132 private JButton
getJButtonUpdate() {
133 if (jButtonUpdate
== null) {
134 jButtonUpdate
= new JButton();
135 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 195, 80, 20));
136 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(80, 20));
137 jButtonUpdate
.setText("Edit");
138 jButtonUpdate
.addActionListener(this);
140 return jButtonUpdate
;
144 This method initializes jScrollPane
146 @return javax.swing.JScrollPane
148 private JScrollPane
getJScrollPane() {
149 if (jScrollPane
== null) {
150 jScrollPane
= new JScrollPane();
151 jScrollPane
.setViewportView(getJContentPane());
157 This method initializes jScrollPaneTable
159 @return javax.swing.JScrollPane
161 private JScrollPane
getJScrollPaneTable() {
162 if (jScrollPaneTable
== null) {
163 jScrollPaneTable
= new JScrollPane();
164 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
165 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
166 jScrollPaneTable
.setViewportView(getJTable());
168 return jScrollPaneTable
;
172 This method initializes jTable
174 @return javax.swing.JTable
176 private JTable
getJTable() {
177 if (jTable
== null) {
178 jTable
= new JTable();
179 model
= new IDefaultTableModel();
180 jTable
= new JTable(model
);
181 jTable
.setRowHeight(20);
183 model
.addColumn("Guid C_Name");
184 model
.addColumn("Usage");
186 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
187 jTable
.getSelectionModel().addListSelectionListener(this);
188 jTable
.getModel().addTableModelListener(this);
189 jTable
.addMouseListener(this);
194 public static void main(String
[] args
) {
199 This method initializes this
202 private void init() {
203 this.setSize(500, 515);
204 this.setContentPane(getJScrollPane());
205 this.setTitle("Guids");
209 This method initializes this
210 Fill values to all fields if these values are not empty
212 @param inPackageDependencies
215 private void init(Guids inGuids
) {
217 this.guids
= inGuids
;
219 if (this.guids
!= null) {
220 if (this.guids
.getGuidCNamesList().size() > 0) {
221 for (int index
= 0; index
< this.guids
.getGuidCNamesList().size(); index
++) {
222 String arg0
= guids
.getGuidCNamesList().get(index
).getGuidCName();
224 if (guids
.getGuidCNamesList().get(index
).getUsage() != null) {
225 arg1
= guids
.getGuidCNamesList().get(index
).getUsage().toString();
228 String arg2
= guids
.getGuidCNamesList().get(index
).getFeatureFlag();
229 Vector
<String
> arg3
= Tools
.convertListToVector(guids
.getGuidCNamesList().get(index
)
231 String arg4
= guids
.getGuidCNamesList().get(index
).getHelpText();
233 id
= new GuidsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
242 This is the default constructor
245 public ModuleGuids() {
248 this.setVisible(true);
252 This is the override edit constructor
254 @param inGuids The input data of GuidsDocument.Guids
257 public ModuleGuids(OpeningModuleType inOmt
) {
260 this.msa
= omt
.getXmlMsa();
261 init(msa
.getGuids());
262 this.setVisible(true);
266 This method initializes jContentPane
268 @return javax.swing.JPanel jContentPane
271 private JPanel
getJContentPane() {
272 if (jContentPane
== null) {
273 jContentPane
= new JPanel();
274 jContentPane
.setLayout(null);
275 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
277 jContentPane
.add(getJButtonAdd(), null);
278 jContentPane
.add(getJButtonRemove(), null);
279 jContentPane
.add(getJButtonUpdate(), null);
280 jContentPane
.add(getJScrollPaneTable(), null);
285 private void showEdit(int index
) {
286 GuidsDlg dlg
= new GuidsDlg(vid
.getGuids(index
), new IFrame());
287 int result
= dlg
.showDialog();
288 if (result
== DataType
.RETURN_TYPE_OK
) {
290 this.vid
.addGuids(dlg
.getId());
292 this.vid
.setGuids(dlg
.getId(), index
);
298 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
307 private void clearAll() {
309 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
310 model
.removeRow(index
);
316 Read content of vector and put then into table
319 private void showTable() {
322 if (vid
.size() > 0) {
323 for (int index
= 0; index
< vid
.size(); index
++) {
324 model
.addRow(vid
.toStringVector(index
));
327 this.jTable
.repaint();
328 this.jTable
.updateUI();
332 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
334 * Override actionPerformed to listen all actions
337 public void actionPerformed(ActionEvent arg0
) {
338 if (arg0
.getSource() == jButtonAdd
) {
341 if (arg0
.getSource() == jButtonUpdate
) {
342 if (this.selectedRow
< 0) {
343 Log
.wrn("Update Guids", "Please select one record first.");
346 showEdit(selectedRow
);
349 if (arg0
.getSource() == jButtonRemove
) {
350 if (jTable
.isEditing()) {
351 jTable
.getCellEditor().stopCellEditing();
353 if (selectedRow
> -1) {
354 this.model
.removeRow(selectedRow
);
355 this.vid
.removeGuids(selectedRow
);
363 Save all components of Guids
364 if exists guids, set the value directly
365 if not exists guids, new an instance first
370 int count
= this.vid
.size();
372 this.guids
= Guids
.Factory
.newInstance();
374 for (int index
= 0; index
< count
; index
++) {
375 GuidCNames p
= GuidCNames
.Factory
.newInstance();
376 if (!isEmpty(vid
.getGuids(index
).getName())) {
377 p
.setGuidCName(vid
.getGuids(index
).getName());
379 if (!isEmpty(vid
.getGuids(index
).getUsage())) {
380 p
.setUsage(GuidUsage
.Enum
.forString(vid
.getGuids(index
).getUsage()));
382 if (!isEmpty(vid
.getGuids(index
).getFeatureFlag())) {
383 p
.setFeatureFlag(vid
.getGuids(index
).getFeatureFlag());
385 if (vid
.getGuids(index
).getSupArchList() != null && vid
.getGuids(index
).getSupArchList().size() > 0) {
386 p
.setSupArchList(vid
.getGuids(index
).getSupArchList());
388 if (!isEmpty(vid
.getGuids(index
).getHelp())) {
389 p
.setHelpText(vid
.getGuids(index
).getHelp());
391 this.guids
.addNewGuidCNames();
392 this.guids
.setGuidCNamesArray(guids
.getGuidCNamesList().size() - 1, p
);
396 this.msa
.setGuids(guids
);
397 this.omt
.setSaved(false);
398 } catch (Exception e
) {
399 Log
.wrn("Update Guids", e
.getMessage());
400 Log
.err("Update Guids", e
.getMessage());
405 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
408 public void valueChanged(ListSelectionEvent arg0
) {
409 if (arg0
.getValueIsAdjusting()) {
412 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
413 if (lsm
.isSelectionEmpty()) {
416 selectedRow
= lsm
.getMinSelectionIndex();
421 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
424 public void mouseClicked(MouseEvent arg0
) {
425 if (arg0
.getClickCount() == 2) {
426 if (this.selectedRow
< 0) {
429 showEdit(selectedRow
);
435 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
437 * Override componentResized to resize all components when frame's size is changed
439 public void componentResized(ComponentEvent arg0
) {
440 int intCurrentWidth
= this.getJContentPane().getWidth();
441 int intCurrentHeight
= this.getJContentPane().getHeight();
442 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
443 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
445 resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
);
446 relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
447 DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
448 relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
449 DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
450 relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
451 DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);