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
)
226 String arg1
= variables
.getVariableList().get(index
).getGuidCName();
228 if (variables
.getVariableList().get(index
).getUsage() != null) {
229 arg2
= variables
.getVariableList().get(index
).getUsage().toString();
232 String arg3
= variables
.getVariableList().get(index
).getFeatureFlag();
233 Vector
<String
> arg4
= Tools
.convertListToVector(variables
.getVariableList().get(index
)
235 String arg5
= variables
.getVariableList().get(index
).getHelpText();
236 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
237 vid
.addVariables(id
);
245 This is the default constructor
248 public ModuleVariables() {
251 this.setVisible(true);
255 This is the override edit constructor
257 @param inVariables The input data of VariablesDocument.Variables
260 public ModuleVariables(OpeningModuleType inOmt
) {
263 this.msa
= omt
.getXmlMsa();
264 init(msa
.getVariables());
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 VariablesDlg dlg
= new VariablesDlg(vid
.getVariables(index
), new IFrame(), omt
.getId());
290 int result
= dlg
.showDialog();
291 if (result
== DataType
.RETURN_TYPE_OK
) {
293 this.vid
.addVariables(dlg
.getId());
295 this.vid
.setVariables(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 Variables", "Please select one record first.");
349 showEdit(selectedRow
);
352 if (arg0
.getSource() == jButtonRemove
) {
353 if (jTable
.isEditing()) {
354 jTable
.getCellEditor().stopCellEditing();
356 if (selectedRow
> -1) {
357 this.model
.removeRow(selectedRow
);
358 this.vid
.removeVariables(selectedRow
);
366 Save all components of Variables
367 if exists variables, set the value directly
368 if not exists variables, new an instance first
373 int count
= this.vid
.size();
375 this.variables
= Variables
.Factory
.newInstance();
377 for (int index
= 0; index
< count
; index
++) {
378 Variable p
= Variable
.Factory
.newInstance();
379 if (!isEmpty(vid
.getVariables(index
).getName())) {
380 p
.setVariableName(Tools
.convertStringToUnicodeHexString(vid
.getVariables(index
).getName()));
382 if (!isEmpty(vid
.getVariables(index
).getGuid())) {
383 p
.setGuidCName(vid
.getVariables(index
).getGuid());
385 if (!isEmpty(vid
.getVariables(index
).getUsage())) {
386 p
.setUsage(VariableUsage
.Enum
.forString(vid
.getVariables(index
).getUsage()));
388 if (!isEmpty(vid
.getVariables(index
).getFeatureFlag())) {
389 p
.setFeatureFlag(vid
.getVariables(index
).getFeatureFlag());
391 if (vid
.getVariables(index
).getSupArchList() != null
392 && vid
.getVariables(index
).getSupArchList().size() > 0) {
393 p
.setSupArchList(vid
.getVariables(index
).getSupArchList());
395 if (!isEmpty(vid
.getVariables(index
).getHelp())) {
396 p
.setHelpText(vid
.getVariables(index
).getHelp());
398 this.variables
.addNewVariable();
399 this.variables
.setVariableArray(variables
.getVariableList().size() - 1, p
);
403 this.msa
.setVariables(variables
);
404 this.omt
.setSaved(false);
405 } catch (Exception e
) {
406 Log
.wrn("Update Variables", e
.getMessage());
407 Log
.err("Update Variables", e
.getMessage());
412 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
415 public void valueChanged(ListSelectionEvent arg0
) {
416 if (arg0
.getValueIsAdjusting()) {
419 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
420 if (lsm
.isSelectionEmpty()) {
423 selectedRow
= lsm
.getMinSelectionIndex();
428 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
431 public void mouseClicked(MouseEvent arg0
) {
432 if (arg0
.getClickCount() == 2) {
433 if (this.selectedRow
< 0) {
436 showEdit(selectedRow
);
442 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
444 * Override componentResized to resize all components when frame's size is changed
446 public void componentResized(ComponentEvent arg0
) {
447 int intCurrentWidth
= this.getJContentPane().getWidth();
448 int intCurrentHeight
= this.getJContentPane().getHeight();
449 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
450 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
452 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
454 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
455 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
456 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
457 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
458 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
459 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
460 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
461 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
462 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);