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;
97 private IFrame parentFrame
= null;
100 This method initializes jButtonAdd
102 @return javax.swing.JButton jButtonAdd
105 private JButton
getJButtonAdd() {
106 if (jButtonAdd
== null) {
107 jButtonAdd
= new JButton();
108 jButtonAdd
.setBounds(new java
.awt
.Rectangle(210, 195, 90, 20));
109 jButtonAdd
.setText("Add");
110 jButtonAdd
.addActionListener(this);
111 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
117 This method initializes jButtonRemove
119 @return javax.swing.JButton jButtonRemove
122 private JButton
getJButtonRemove() {
123 if (jButtonRemove
== null) {
124 jButtonRemove
= new JButton();
125 jButtonRemove
.setBounds(new java
.awt
.Rectangle(390, 195, 90, 20));
126 jButtonRemove
.setText("Remove");
127 jButtonRemove
.addActionListener(this);
128 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
130 return jButtonRemove
;
134 This method initializes jButtonUpdate
136 @return javax.swing.JButton jButtonUpdate
139 private JButton
getJButtonUpdate() {
140 if (jButtonUpdate
== null) {
141 jButtonUpdate
= new JButton();
142 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 195, 90, 20));
143 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
144 jButtonUpdate
.setText("Edit");
145 jButtonUpdate
.addActionListener(this);
147 return jButtonUpdate
;
151 This method initializes jScrollPane
153 @return javax.swing.JScrollPane
155 private JScrollPane
getJScrollPane() {
156 if (jScrollPane
== null) {
157 jScrollPane
= new JScrollPane();
158 jScrollPane
.setViewportView(getJContentPane());
164 This method initializes jScrollPaneTable
166 @return javax.swing.JScrollPane
168 private JScrollPane
getJScrollPaneTable() {
169 if (jScrollPaneTable
== null) {
170 jScrollPaneTable
= new JScrollPane();
171 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
172 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
173 jScrollPaneTable
.setViewportView(getJTable());
175 return jScrollPaneTable
;
179 This method initializes jTable
181 @return javax.swing.JTable
183 private JTable
getJTable() {
184 if (jTable
== null) {
185 jTable
= new JTable();
186 model
= new IDefaultTableModel();
187 jTable
= new JTable(model
);
188 jTable
.setRowHeight(20);
190 model
.addColumn("Option String Value");
192 jTable
.setSelectionMode(ListSelectionModel
.MULTIPLE_INTERVAL_SELECTION
);
193 jTable
.getSelectionModel().addListSelectionListener(this);
194 jTable
.getModel().addTableModelListener(this);
195 jTable
.addMouseListener(this);
200 public static void main(String
[] args
) {
204 This method initializes this
207 private void init() {
208 this.setSize(500, 515);
209 this.setContentPane(getJScrollPane());
210 this.setTitle("Boot Modes");
214 This method initializes this
215 Fill values to all fields if these values are not empty
217 @param inBuildOptions
220 private void init(ModuleBuildOptionsDocument
.ModuleBuildOptions inModuleBuildOptions
) {
222 this.mbo
= inModuleBuildOptions
;
224 if (this.mbo
!= null) {
226 // Save User Extensitions
228 if (this.mbo
.getUserExtensionsList() != null) {
229 this.ue
= this.mbo
.getUserExtensionsList();
232 if (this.mbo
.getOptions() != null) {
233 if (this.mbo
.getOptions().getOptionList() != null) {
234 for (int index
= 0; index
< this.mbo
.getOptions().getOptionList().size(); index
++) {
235 Option o
= this.mbo
.getOptions().getOptionList().get(index
);
237 String arg0
= o
.getStringValue();
238 Vector
<String
> arg1
= Tools
.convertListToVector(o
.getBuildTargets());
239 String arg2
= o
.getToolChainFamily();
240 String arg3
= o
.getTagName();
241 String arg4
= o
.getToolCode();
242 Vector
<String
> arg5
= Tools
.convertListToVector(o
.getSupArchList());
244 id
= new BuildOptionsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
245 vid
.addBuildOptions(id
);
255 This is the default constructor
258 public ModuleBuildOptions() {
261 this.setVisible(true);
265 This is the override edit constructor
267 @param inBuildOptions The input BuildOptionsDocument.BuildOptions
270 public ModuleBuildOptions(OpeningModuleType inOmt
, IFrame iFrame
) {
273 this.msa
= omt
.getXmlMsa();
274 this.parentFrame
= iFrame
;
275 init(msa
.getModuleBuildOptions());
276 this.setVisible(true);
280 This method initializes jContentPane
282 @return javax.swing.JPanel jContentPane
285 private JPanel
getJContentPane() {
286 if (jContentPane
== null) {
287 jContentPane
= new JPanel();
288 jContentPane
.setLayout(null);
289 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
291 jContentPane
.add(getJButtonAdd(), null);
292 jContentPane
.add(getJButtonRemove(), null);
293 jContentPane
.add(getJButtonUpdate(), null);
294 jContentPane
.add(getJScrollPaneTable(), null);
299 private void showEdit(int index
) {
300 BuildOptionsDlg dlg
= new BuildOptionsDlg(vid
.getBuildOptions(index
), this.parentFrame
, omt
.getId());
301 int result
= dlg
.showDialog();
302 if (result
== DataType
.RETURN_TYPE_OK
) {
304 this.vid
.addBuildOptions(dlg
.getId());
306 this.vid
.setBuildOptions(dlg
.getId(), index
);
312 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
321 private void clearAll() {
323 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
324 model
.removeRow(index
);
330 Read content of vector and put then into table
333 private void showTable() {
336 if (vid
.size() > 0) {
337 for (int index
= 0; index
< vid
.size(); index
++) {
338 model
.addRow(vid
.toStringVector(index
));
341 this.jTable
.repaint();
342 this.jTable
.updateUI();
346 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
348 * Override actionPerformed to listen all actions
351 public void actionPerformed(ActionEvent arg0
) {
352 if (arg0
.getSource() == jButtonAdd
) {
355 if (arg0
.getSource() == jButtonUpdate
) {
356 if (this.selectedRow
< 0) {
357 Log
.wrn("Update Boot Modes", "Please select one record first.");
360 showEdit(selectedRow
);
363 if (arg0
.getSource() == jButtonRemove
) {
364 if (jTable
.isEditing()) {
365 jTable
.getCellEditor().stopCellEditing();
368 int selectedRows
[] = this.jTable
.getSelectedRows();
370 if (selectedRows
!= null) {
371 for (int index
= selectedRows
.length
- 1; index
> -1; index
--) {
372 this.model
.removeRow(selectedRows
[index
]);
373 this.vid
.removeBuildOptions(selectedRows
[index
]);
382 Save all components of Mbd Header
383 if exists BuildOptions, set the value directly
384 if not exists BuildOptions, new an instance first
389 int count
= this.vid
.size();
391 this.mbo
= ModuleBuildOptionsDocument
.ModuleBuildOptions
.Factory
.newInstance();
392 this.mbo
.addNewOptions();
394 // Restore User Extensions Data
396 if (this.ue
!= null) {
397 for (int index
= 0; index
< this.ue
.size(); index
++) {
398 this.mbo
.addNewUserExtensions();
399 this.mbo
.setUserExtensionsArray(index
, ue
.get(index
));
404 for (int index
= 0; index
< count
; index
++) {
405 Option o
= Option
.Factory
.newInstance();
406 if (!isEmpty(vid
.getBuildOptions(index
).getOption())) {
407 o
.setStringValue(vid
.getBuildOptions(index
).getOption());
409 if (vid
.getBuildOptions(index
).getBuildTargets() != null
410 && vid
.getBuildOptions(index
).getBuildTargets().size() > 0) {
411 o
.setBuildTargets(vid
.getBuildOptions(index
).getBuildTargets());
413 if (!isEmpty(vid
.getBuildOptions(index
).getToolChainFamily())) {
414 o
.setToolChainFamily(vid
.getBuildOptions(index
).getToolChainFamily());
416 if (!isEmpty(vid
.getBuildOptions(index
).getTagName())) {
417 o
.setTagName(vid
.getBuildOptions(index
).getTagName());
419 if (!isEmpty(vid
.getBuildOptions(index
).getToolCode())) {
420 o
.setToolCode(vid
.getBuildOptions(index
).getToolCode());
422 if (vid
.getBuildOptions(index
).getSupArchList() != null
423 && vid
.getBuildOptions(index
).getSupArchList().size() > 0) {
424 o
.setSupArchList(vid
.getBuildOptions(index
).getSupArchList());
427 this.mbo
.getOptions().addNewOption();
428 this.mbo
.getOptions().setOptionArray(this.mbo
.getOptions().getOptionList().size() - 1, o
);
432 this.msa
.setModuleBuildOptions(this.mbo
);
433 this.omt
.setSaved(false);
434 } catch (Exception e
) {
435 Log
.wrn("Update Module Build Options", e
.getMessage());
436 Log
.err("Update Module Build Options", e
.getMessage());
441 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
444 public void valueChanged(ListSelectionEvent arg0
) {
445 if (arg0
.getValueIsAdjusting()) {
448 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
449 if (lsm
.isSelectionEmpty()) {
452 selectedRow
= lsm
.getMinSelectionIndex();
457 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
460 public void mouseClicked(MouseEvent arg0
) {
461 if (arg0
.getClickCount() == 2) {
462 if (this.selectedRow
< 0) {
465 showEdit(selectedRow
);
471 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
473 * Override componentResized to resize all components when frame's size is changed
475 public void componentResized(ComponentEvent arg0
) {
476 int intCurrentWidth
= this.getJContentPane().getWidth();
477 int intCurrentHeight
= this.getJContentPane().getHeight();
478 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
479 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
481 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
483 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
484 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
485 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
486 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
487 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
488 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
489 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
490 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
491 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);