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;
93 private IFrame parentFrame
= null;
96 This method initializes jButtonAdd
98 @return javax.swing.JButton jButtonAdd
101 private JButton
getJButtonAdd() {
102 if (jButtonAdd
== null) {
103 jButtonAdd
= new JButton();
104 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 220, 90, 20));
105 jButtonAdd
.setText("Add");
106 jButtonAdd
.addActionListener(this);
107 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
113 This method initializes jButtonRemove
115 @return javax.swing.JButton jButtonRemove
118 private JButton
getJButtonRemove() {
119 if (jButtonRemove
== null) {
120 jButtonRemove
= new JButton();
121 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 220, 90, 20));
122 jButtonRemove
.setText("Remove");
123 jButtonRemove
.addActionListener(this);
124 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
126 return jButtonRemove
;
130 This method initializes jButtonUpdate
132 @return javax.swing.JButton jButtonUpdate
135 private JButton
getJButtonUpdate() {
136 if (jButtonUpdate
== null) {
137 jButtonUpdate
= new JButton();
138 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 220, 90, 20));
139 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
140 jButtonUpdate
.setText("Edit");
141 jButtonUpdate
.addActionListener(this);
143 return jButtonUpdate
;
147 This method initializes jScrollPane
149 @return javax.swing.JScrollPane
151 private JScrollPane
getJScrollPane() {
152 if (jScrollPane
== null) {
153 jScrollPane
= new JScrollPane();
154 jScrollPane
.setViewportView(getJContentPane());
160 This method initializes jScrollPaneTable
162 @return javax.swing.JScrollPane
164 private JScrollPane
getJScrollPaneTable() {
165 if (jScrollPaneTable
== null) {
166 jScrollPaneTable
= new JScrollPane();
167 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
168 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
169 jScrollPaneTable
.setViewportView(getJTable());
171 return jScrollPaneTable
;
175 This method initializes jTable
177 @return javax.swing.JTable
179 private JTable
getJTable() {
180 if (jTable
== null) {
181 jTable
= new JTable();
182 model
= new IDefaultTableModel();
183 jTable
= new JTable(model
);
184 jTable
.setRowHeight(20);
186 model
.addColumn("Name");
187 model
.addColumn("Guid C_Name");
188 model
.addColumn("Usage");
190 jTable
.setSelectionMode(ListSelectionModel
.MULTIPLE_INTERVAL_SELECTION
);
191 jTable
.getSelectionModel().addListSelectionListener(this);
192 jTable
.getModel().addTableModelListener(this);
193 jTable
.addMouseListener(this);
198 public static void main(String
[] args
) {
203 This method initializes this
206 private void init() {
207 this.setSize(500, 515);
208 this.setContentPane(getJScrollPane());
209 this.setTitle("Variables");
213 This method initializes this
214 Fill values to all fields if these values are not empty
216 @param inPackageDependencies
219 private void init(Variables inVariables
) {
221 this.variables
= inVariables
;
223 if (this.variables
!= null) {
224 if (this.variables
.getVariableList().size() > 0) {
225 for (int index
= 0; index
< this.variables
.getVariableList().size(); index
++) {
226 String arg0
= Tools
.convertUnicodeHexStringToString(variables
.getVariableList().get(index
)
228 String arg1
= variables
.getVariableList().get(index
).getGuidCName();
230 if (variables
.getVariableList().get(index
).getUsage() != null) {
231 arg2
= variables
.getVariableList().get(index
).getUsage().toString();
234 String arg3
= variables
.getVariableList().get(index
).getFeatureFlag();
235 Vector
<String
> arg4
= Tools
.convertListToVector(variables
.getVariableList().get(index
)
237 String arg5
= variables
.getVariableList().get(index
).getHelpText();
238 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
239 vid
.addVariables(id
);
247 This is the default constructor
250 public ModuleVariables() {
253 this.setVisible(true);
257 This is the override edit constructor
259 @param inVariables The input data of VariablesDocument.Variables
262 public ModuleVariables(OpeningModuleType inOmt
, IFrame iFrame
) {
265 this.msa
= omt
.getXmlMsa();
266 this.parentFrame
= iFrame
;
267 init(msa
.getVariables());
268 this.setVisible(true);
272 This method initializes jContentPane
274 @return javax.swing.JPanel jContentPane
277 private JPanel
getJContentPane() {
278 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 VariablesDlg dlg
= new VariablesDlg(vid
.getVariables(index
), this.parentFrame
, omt
.getId());
293 int result
= dlg
.showDialog();
294 if (result
== DataType
.RETURN_TYPE_OK
) {
296 this.vid
.addVariables(dlg
.getId());
298 this.vid
.setVariables(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 Variables", "Please select one record first.");
352 showEdit(selectedRow
);
355 if (arg0
.getSource() == jButtonRemove
) {
356 if (jTable
.isEditing()) {
357 jTable
.getCellEditor().stopCellEditing();
360 int selectedRows
[] = this.jTable
.getSelectedRows();
362 if (selectedRows
!= null) {
363 for (int index
= selectedRows
.length
- 1; index
> -1; index
--) {
364 this.model
.removeRow(selectedRows
[index
]);
365 this.vid
.removeVariables(selectedRows
[index
]);
374 Save all components of Variables
375 if exists variables, set the value directly
376 if not exists variables, new an instance first
381 int count
= this.vid
.size();
383 this.variables
= Variables
.Factory
.newInstance();
385 for (int index
= 0; index
< count
; index
++) {
386 Variable p
= Variable
.Factory
.newInstance();
387 if (!isEmpty(vid
.getVariables(index
).getName())) {
388 p
.setVariableName(Tools
.convertStringToUnicodeHexString(vid
.getVariables(index
).getName()));
390 if (!isEmpty(vid
.getVariables(index
).getGuid())) {
391 p
.setGuidCName(vid
.getVariables(index
).getGuid());
393 if (!isEmpty(vid
.getVariables(index
).getUsage())) {
394 p
.setUsage(VariableUsage
.Enum
.forString(vid
.getVariables(index
).getUsage()));
396 if (!isEmpty(vid
.getVariables(index
).getFeatureFlag())) {
397 p
.setFeatureFlag(vid
.getVariables(index
).getFeatureFlag());
399 if (vid
.getVariables(index
).getSupArchList() != null
400 && vid
.getVariables(index
).getSupArchList().size() > 0) {
401 p
.setSupArchList(vid
.getVariables(index
).getSupArchList());
403 if (!isEmpty(vid
.getVariables(index
).getHelp())) {
404 p
.setHelpText(vid
.getVariables(index
).getHelp());
406 this.variables
.addNewVariable();
407 this.variables
.setVariableArray(variables
.getVariableList().size() - 1, p
);
411 this.msa
.setVariables(variables
);
412 this.omt
.setSaved(false);
413 } catch (Exception e
) {
414 Log
.wrn("Update Variables", e
.getMessage());
415 Log
.err("Update Variables", e
.getMessage());
420 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
423 public void valueChanged(ListSelectionEvent arg0
) {
424 if (arg0
.getValueIsAdjusting()) {
427 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
428 if (lsm
.isSelectionEmpty()) {
431 selectedRow
= lsm
.getMinSelectionIndex();
436 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
439 public void mouseClicked(MouseEvent arg0
) {
440 if (arg0
.getClickCount() == 2) {
441 if (this.selectedRow
< 0) {
444 showEdit(selectedRow
);
450 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
452 * Override componentResized to resize all components when frame's size is changed
454 public void componentResized(ComponentEvent arg0
) {
455 int intCurrentWidth
= this.getJContentPane().getWidth();
456 int intCurrentHeight
= this.getJContentPane().getHeight();
457 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
458 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
460 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
462 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
463 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
464 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
465 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
466 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
467 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
468 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
469 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
470 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);