3 The file is used to create, update BuildOptions 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
.List
;
23 import java
.util
.Vector
;
25 import javax
.swing
.JButton
;
26 import javax
.swing
.JPanel
;
27 import javax
.swing
.JScrollPane
;
28 import javax
.swing
.JTable
;
29 import javax
.swing
.ListSelectionModel
;
30 import javax
.swing
.event
.ListSelectionEvent
;
32 import org
.tianocore
.ModuleBuildOptionsDocument
;
33 import org
.tianocore
.UserExtensionsDocument
;
34 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
35 import org
.tianocore
.OptionDocument
.Option
;
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
.BuildOptions
.BuildOptionsIdentification
;
44 import org
.tianocore
.frameworkwizard
.module
.Identifications
.BuildOptions
.BuildOptionsVector
;
45 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.BuildOptionsDlg
;
48 The class is used to create, update BuildOptions of MSA/MBD file
49 It extends IInternalFrame
54 public class ModuleBuildOptions
extends IInternalFrame
{
57 /// Define class Serial Version UID
59 private static final long serialVersionUID
= -3888558623432442561L;
62 //Define class members
64 private JPanel jContentPane
= null;
66 private JButton jButtonAdd
= null;
68 private JButton jButtonRemove
= null;
70 private JButton jButtonUpdate
= null;
72 private JScrollPane jScrollPane
= null;
74 private JScrollPane jScrollPaneTable
= null;
76 private JTable jTable
= null;
81 private OpeningModuleType omt
= null;
83 private ModuleSurfaceArea msa
= null;
85 private ModuleBuildOptionsDocument
.ModuleBuildOptions mbo
= null;
87 private List
<UserExtensionsDocument
.UserExtensions
> ue
= null;
89 private BuildOptionsIdentification id
= null;
91 private BuildOptionsVector vid
= new BuildOptionsVector();
93 private IDefaultTableModel model
= null;
95 private int selectedRow
= -1;
98 This method initializes jButtonAdd
100 @return javax.swing.JButton jButtonAdd
103 private JButton
getJButtonAdd() {
104 if (jButtonAdd
== null) {
105 jButtonAdd
= new JButton();
106 jButtonAdd
.setBounds(new java
.awt
.Rectangle(210, 195, 90, 20));
107 jButtonAdd
.setText("Add");
108 jButtonAdd
.addActionListener(this);
109 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
115 This method initializes jButtonRemove
117 @return javax.swing.JButton jButtonRemove
120 private JButton
getJButtonRemove() {
121 if (jButtonRemove
== null) {
122 jButtonRemove
= new JButton();
123 jButtonRemove
.setBounds(new java
.awt
.Rectangle(390, 195, 90, 20));
124 jButtonRemove
.setText("Remove");
125 jButtonRemove
.addActionListener(this);
126 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
128 return jButtonRemove
;
132 This method initializes jButtonUpdate
134 @return javax.swing.JButton jButtonUpdate
137 private JButton
getJButtonUpdate() {
138 if (jButtonUpdate
== null) {
139 jButtonUpdate
= new JButton();
140 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 195, 90, 20));
141 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
142 jButtonUpdate
.setText("Edit");
143 jButtonUpdate
.addActionListener(this);
145 return jButtonUpdate
;
149 This method initializes jScrollPane
151 @return javax.swing.JScrollPane
153 private JScrollPane
getJScrollPane() {
154 if (jScrollPane
== null) {
155 jScrollPane
= new JScrollPane();
156 jScrollPane
.setViewportView(getJContentPane());
162 This method initializes jScrollPaneTable
164 @return javax.swing.JScrollPane
166 private JScrollPane
getJScrollPaneTable() {
167 if (jScrollPaneTable
== null) {
168 jScrollPaneTable
= new JScrollPane();
169 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
170 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
171 jScrollPaneTable
.setViewportView(getJTable());
173 return jScrollPaneTable
;
177 This method initializes jTable
179 @return javax.swing.JTable
181 private JTable
getJTable() {
182 if (jTable
== null) {
183 jTable
= new JTable();
184 model
= new IDefaultTableModel();
185 jTable
= new JTable(model
);
186 jTable
.setRowHeight(20);
188 model
.addColumn("Option String Value");
190 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
191 jTable
.getSelectionModel().addListSelectionListener(this);
192 jTable
.getModel().addTableModelListener(this);
193 jTable
.addMouseListener(this);
198 public static void main(String
[] args
) {
202 This method initializes this
205 private void init() {
206 this.setSize(500, 515);
207 this.setContentPane(getJScrollPane());
208 this.setTitle("Boot Modes");
212 This method initializes this
213 Fill values to all fields if these values are not empty
215 @param inBuildOptions
218 private void init(ModuleBuildOptionsDocument
.ModuleBuildOptions inModuleBuildOptions
) {
220 this.mbo
= inModuleBuildOptions
;
222 if (this.mbo
!= null) {
224 // Save User Extensitions
226 if (this.mbo
.getUserExtensionsList() != null) {
227 this.ue
= this.mbo
.getUserExtensionsList();
230 if (this.mbo
.getOptions() != null) {
231 if (this.mbo
.getOptions().getOptionList() != null) {
232 for (int index
= 0; index
< this.mbo
.getOptions().getOptionList().size(); index
++) {
233 Option o
= this.mbo
.getOptions().getOptionList().get(index
);
235 String arg0
= o
.getStringValue();
236 Vector
<String
> arg1
= Tools
.convertListToVector(o
.getBuildTargets());
237 String arg2
= o
.getToolChainFamily();
238 String arg3
= o
.getTagName();
239 String arg4
= o
.getToolCode();
240 Vector
<String
> arg5
= Tools
.convertListToVector(o
.getSupArchList());
242 id
= new BuildOptionsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
243 vid
.addBuildOptions(id
);
253 This is the default constructor
256 public ModuleBuildOptions() {
259 this.setVisible(true);
263 This is the override edit constructor
265 @param inBuildOptions The input BuildOptionsDocument.BuildOptions
268 public ModuleBuildOptions(OpeningModuleType inOmt
) {
271 this.msa
= omt
.getXmlMsa();
272 init(msa
.getModuleBuildOptions());
273 this.setVisible(true);
277 This method initializes jContentPane
279 @return javax.swing.JPanel jContentPane
282 private JPanel
getJContentPane() {
283 if (jContentPane
== null) {
284 jContentPane
= new JPanel();
285 jContentPane
.setLayout(null);
286 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
288 jContentPane
.add(getJButtonAdd(), null);
289 jContentPane
.add(getJButtonRemove(), null);
290 jContentPane
.add(getJButtonUpdate(), null);
291 jContentPane
.add(getJScrollPaneTable(), null);
296 private void showEdit(int index
) {
297 BuildOptionsDlg dlg
= new BuildOptionsDlg(vid
.getBuildOptions(index
), new IFrame(), omt
.getId());
298 int result
= dlg
.showDialog();
299 if (result
== DataType
.RETURN_TYPE_OK
) {
301 this.vid
.addBuildOptions(dlg
.getId());
303 this.vid
.setBuildOptions(dlg
.getId(), index
);
309 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
318 private void clearAll() {
320 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
321 model
.removeRow(index
);
327 Read content of vector and put then into table
330 private void showTable() {
333 if (vid
.size() > 0) {
334 for (int index
= 0; index
< vid
.size(); index
++) {
335 model
.addRow(vid
.toStringVector(index
));
338 this.jTable
.repaint();
339 this.jTable
.updateUI();
343 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
345 * Override actionPerformed to listen all actions
348 public void actionPerformed(ActionEvent arg0
) {
349 if (arg0
.getSource() == jButtonAdd
) {
352 if (arg0
.getSource() == jButtonUpdate
) {
353 if (this.selectedRow
< 0) {
354 Log
.wrn("Update Boot Modes", "Please select one record first.");
357 showEdit(selectedRow
);
360 if (arg0
.getSource() == jButtonRemove
) {
361 if (jTable
.isEditing()) {
362 jTable
.getCellEditor().stopCellEditing();
364 if (selectedRow
> -1) {
365 this.model
.removeRow(selectedRow
);
366 this.vid
.removeBuildOptions(selectedRow
);
374 Save all components of Mbd Header
375 if exists BuildOptions, set the value directly
376 if not exists BuildOptions, new an instance first
381 int count
= this.vid
.size();
383 this.mbo
= ModuleBuildOptionsDocument
.ModuleBuildOptions
.Factory
.newInstance();
384 this.mbo
.addNewOptions();
386 // Restore User Extensions Data
388 if (this.ue
!= null) {
389 for (int index
= 0; index
< this.ue
.size(); index
++) {
390 this.mbo
.addNewUserExtensions();
391 this.mbo
.setUserExtensionsArray(index
, ue
.get(index
));
396 for (int index
= 0; index
< count
; index
++) {
397 Option o
= Option
.Factory
.newInstance();
398 if (!isEmpty(vid
.getBuildOptions(index
).getOption())) {
399 o
.setStringValue(vid
.getBuildOptions(index
).getOption());
401 if (vid
.getBuildOptions(index
).getBuildTargets() != null
402 && vid
.getBuildOptions(index
).getBuildTargets().size() > 0) {
403 o
.setBuildTargets(vid
.getBuildOptions(index
).getBuildTargets());
405 if (!isEmpty(vid
.getBuildOptions(index
).getToolChainFamily())) {
406 o
.setToolChainFamily(vid
.getBuildOptions(index
).getToolChainFamily());
408 if (!isEmpty(vid
.getBuildOptions(index
).getTagName())) {
409 o
.setTagName(vid
.getBuildOptions(index
).getTagName());
411 if (!isEmpty(vid
.getBuildOptions(index
).getToolCode())) {
412 o
.setToolCode(vid
.getBuildOptions(index
).getToolCode());
414 if (vid
.getBuildOptions(index
).getSupArchList() != null
415 && vid
.getBuildOptions(index
).getSupArchList().size() > 0) {
416 o
.setSupArchList(vid
.getBuildOptions(index
).getSupArchList());
419 this.mbo
.getOptions().addNewOption();
420 this.mbo
.getOptions().setOptionArray(this.mbo
.getOptions().getOptionList().size() - 1, o
);
424 this.msa
.setModuleBuildOptions(this.mbo
);
425 this.omt
.setSaved(false);
426 } catch (Exception e
) {
427 Log
.wrn("Update Module Build Options", e
.getMessage());
428 Log
.err("Update Module Build Options", e
.getMessage());
433 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
436 public void valueChanged(ListSelectionEvent arg0
) {
437 if (arg0
.getValueIsAdjusting()) {
440 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
441 if (lsm
.isSelectionEmpty()) {
444 selectedRow
= lsm
.getMinSelectionIndex();
449 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
452 public void mouseClicked(MouseEvent arg0
) {
453 if (arg0
.getClickCount() == 2) {
454 if (this.selectedRow
< 0) {
457 showEdit(selectedRow
);
463 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
465 * Override componentResized to resize all components when frame's size is changed
467 public void componentResized(ComponentEvent arg0
) {
468 int intCurrentWidth
= this.getJContentPane().getWidth();
469 int intCurrentHeight
= this.getJContentPane().getHeight();
470 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
471 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
473 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
475 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
476 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
477 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
478 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
479 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
480 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
481 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
482 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
483 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);