3 The file is used to create, update Variable 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
.VariableUsage
;
32 import org
.tianocore
.VariablesDocument
;
33 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
34 import org
.tianocore
.VariablesDocument
.Variables
;
35 import org
.tianocore
.VariablesDocument
.Variables
.Variable
;
36 import org
.tianocore
.frameworkwizard
.common
.DataType
;
37 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
38 import org
.tianocore
.frameworkwizard
.common
.Log
;
39 import org
.tianocore
.frameworkwizard
.common
.Tools
;
40 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
41 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
42 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Variables
.VariablesIdentification
;
44 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Variables
.VariablesVector
;
45 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.VariablesDlg
;
48 The class is used to create, update Variable of MSA/MBD file
49 It extends IInternalFrame
52 public class ModuleVariables
extends IInternalFrame
{
55 /// Define class Serial Version UID
57 private static final long serialVersionUID
= -6998982978030439446L;
60 //Define class members
62 private JPanel jContentPane
= null;
64 private JButton jButtonAdd
= null;
66 private JButton jButtonRemove
= null;
68 private JButton jButtonUpdate
= null;
70 private JScrollPane jScrollPane
= null;
72 private JScrollPane jScrollPaneTable
= null;
74 private JTable jTable
= null;
79 private OpeningModuleType omt
= null;
81 private ModuleSurfaceArea msa
= null;
83 private VariablesDocument
.Variables variables
= null;
85 private VariablesIdentification id
= null;
87 private VariablesVector vid
= new VariablesVector();
89 private IDefaultTableModel model
= null;
91 private int selectedRow
= -1;
94 This method initializes jButtonAdd
96 @return javax.swing.JButton jButtonAdd
99 private JButton
getJButtonAdd() {
100 if (jButtonAdd
== null) {
101 jButtonAdd
= new JButton();
102 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 220, 80, 20));
103 jButtonAdd
.setText("Add");
104 jButtonAdd
.addActionListener(this);
105 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(80, 20));
111 This method initializes jButtonRemove
113 @return javax.swing.JButton jButtonRemove
116 private JButton
getJButtonRemove() {
117 if (jButtonRemove
== null) {
118 jButtonRemove
= new JButton();
119 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 220, 80, 20));
120 jButtonRemove
.setText("Remove");
121 jButtonRemove
.addActionListener(this);
122 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(80, 20));
124 return jButtonRemove
;
128 This method initializes jButtonUpdate
130 @return javax.swing.JButton jButtonUpdate
133 private JButton
getJButtonUpdate() {
134 if (jButtonUpdate
== null) {
135 jButtonUpdate
= new JButton();
136 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 220, 80, 20));
137 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(80, 20));
138 jButtonUpdate
.setText("Edit");
139 jButtonUpdate
.addActionListener(this);
141 return jButtonUpdate
;
145 This method initializes jScrollPane
147 @return javax.swing.JScrollPane
149 private JScrollPane
getJScrollPane() {
150 if (jScrollPane
== null) {
151 jScrollPane
= new JScrollPane();
152 jScrollPane
.setViewportView(getJContentPane());
158 This method initializes jScrollPaneTable
160 @return javax.swing.JScrollPane
162 private JScrollPane
getJScrollPaneTable() {
163 if (jScrollPaneTable
== null) {
164 jScrollPaneTable
= new JScrollPane();
165 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
166 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
167 jScrollPaneTable
.setViewportView(getJTable());
169 return jScrollPaneTable
;
173 This method initializes jTable
175 @return javax.swing.JTable
177 private JTable
getJTable() {
178 if (jTable
== null) {
179 jTable
= new JTable();
180 model
= new IDefaultTableModel();
181 jTable
= new JTable(model
);
182 jTable
.setRowHeight(20);
184 model
.addColumn("Name");
185 model
.addColumn("Guid C_Name");
186 model
.addColumn("Usage");
188 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_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("Variables");
211 This method initializes this
212 Fill values to all fields if these values are not empty
214 @param inPackageDependencies
217 private void init(Variables inVariables
) {
219 this.variables
= inVariables
;
221 if (this.variables
!= null) {
222 if (this.variables
.getVariableList().size() > 0) {
223 for (int index
= 0; index
< this.variables
.getVariableList().size(); index
++) {
224 String arg0
= Tools
.convertUnicodeHexStringToString(variables
.getVariableList().get(index
).getVariableName());
225 String arg1
= variables
.getVariableList().get(index
).getGuidCName();
227 if (variables
.getVariableList().get(index
).getUsage() != null) {
228 arg2
= variables
.getVariableList().get(index
).getUsage().toString();
231 String arg3
= variables
.getVariableList().get(index
).getFeatureFlag();
232 Vector
<String
> arg4
= Tools
.convertListToVector(variables
.getVariableList().get(index
)
234 String arg5
= variables
.getVariableList().get(index
).getHelpText();
235 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
236 vid
.addVariables(id
);
244 This is the default constructor
247 public ModuleVariables() {
250 this.setVisible(true);
254 This is the override edit constructor
256 @param inVariables The input data of VariablesDocument.Variables
259 public ModuleVariables(OpeningModuleType inOmt
) {
262 this.msa
= omt
.getXmlMsa();
263 init(msa
.getVariables());
264 this.setVisible(true);
268 This method initializes jContentPane
270 @return javax.swing.JPanel jContentPane
273 private JPanel
getJContentPane() {
274 if (jContentPane
== null) {
275 jContentPane
= new JPanel();
276 jContentPane
.setLayout(null);
277 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
279 jContentPane
.add(getJButtonAdd(), null);
280 jContentPane
.add(getJButtonRemove(), null);
281 jContentPane
.add(getJButtonUpdate(), null);
282 jContentPane
.add(getJScrollPaneTable(), null);
287 private void showEdit(int index
) {
288 VariablesDlg dlg
= new VariablesDlg(vid
.getVariables(index
), new IFrame());
289 int result
= dlg
.showDialog();
290 if (result
== DataType
.RETURN_TYPE_OK
) {
292 this.vid
.addVariables(dlg
.getId());
294 this.vid
.setVariables(dlg
.getId(), index
);
300 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
309 private void clearAll() {
311 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
312 model
.removeRow(index
);
318 Read content of vector and put then into table
321 private void showTable() {
324 if (vid
.size() > 0) {
325 for (int index
= 0; index
< vid
.size(); index
++) {
326 model
.addRow(vid
.toStringVector(index
));
329 this.jTable
.repaint();
330 this.jTable
.updateUI();
334 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
336 * Override actionPerformed to listen all actions
339 public void actionPerformed(ActionEvent arg0
) {
340 if (arg0
.getSource() == jButtonAdd
) {
343 if (arg0
.getSource() == jButtonUpdate
) {
344 if (this.selectedRow
< 0) {
345 Log
.wrn("Update Variables", "Please select one record first.");
348 showEdit(selectedRow
);
351 if (arg0
.getSource() == jButtonRemove
) {
352 if (jTable
.isEditing()) {
353 jTable
.getCellEditor().stopCellEditing();
355 if (selectedRow
> -1) {
356 this.model
.removeRow(selectedRow
);
357 this.vid
.removeVariables(selectedRow
);
365 Save all components of Variables
366 if exists variables, set the value directly
367 if not exists variables, new an instance first
372 int count
= this.vid
.size();
374 this.variables
= Variables
.Factory
.newInstance();
376 for (int index
= 0; index
< count
; index
++) {
377 Variable p
= Variable
.Factory
.newInstance();
378 if (!isEmpty(vid
.getVariables(index
).getName())) {
379 p
.setVariableName(Tools
.convertStringToUnicodeHexString(vid
.getVariables(index
).getName()));
381 if (!isEmpty(vid
.getVariables(index
).getGuid())) {
382 p
.setGuidCName(vid
.getVariables(index
).getGuid());
384 if (!isEmpty(vid
.getVariables(index
).getUsage())) {
385 p
.setUsage(VariableUsage
.Enum
.forString(vid
.getVariables(index
).getUsage()));
387 if (!isEmpty(vid
.getVariables(index
).getFeatureFlag())) {
388 p
.setFeatureFlag(vid
.getVariables(index
).getFeatureFlag());
390 if (vid
.getVariables(index
).getSupArchList() != null
391 && vid
.getVariables(index
).getSupArchList().size() > 0) {
392 p
.setSupArchList(vid
.getVariables(index
).getSupArchList());
394 if (!isEmpty(vid
.getVariables(index
).getHelp())) {
395 p
.setHelpText(vid
.getVariables(index
).getHelp());
397 this.variables
.addNewVariable();
398 this.variables
.setVariableArray(variables
.getVariableList().size() - 1, p
);
402 this.msa
.setVariables(variables
);
403 this.omt
.setSaved(false);
404 } catch (Exception e
) {
405 Log
.wrn("Update Variables", e
.getMessage());
406 Log
.err("Update Variables", 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
);