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
.SINGLE_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();
367 if (selectedRow
> -1) {
368 this.model
.removeRow(selectedRow
);
369 this.vid
.removeBuildOptions(selectedRow
);
377 Save all components of Mbd Header
378 if exists BuildOptions, set the value directly
379 if not exists BuildOptions, new an instance first
384 int count
= this.vid
.size();
386 this.mbo
= ModuleBuildOptionsDocument
.ModuleBuildOptions
.Factory
.newInstance();
387 this.mbo
.addNewOptions();
389 // Restore User Extensions Data
391 if (this.ue
!= null) {
392 for (int index
= 0; index
< this.ue
.size(); index
++) {
393 this.mbo
.addNewUserExtensions();
394 this.mbo
.setUserExtensionsArray(index
, ue
.get(index
));
399 for (int index
= 0; index
< count
; index
++) {
400 Option o
= Option
.Factory
.newInstance();
401 if (!isEmpty(vid
.getBuildOptions(index
).getOption())) {
402 o
.setStringValue(vid
.getBuildOptions(index
).getOption());
404 if (vid
.getBuildOptions(index
).getBuildTargets() != null
405 && vid
.getBuildOptions(index
).getBuildTargets().size() > 0) {
406 o
.setBuildTargets(vid
.getBuildOptions(index
).getBuildTargets());
408 if (!isEmpty(vid
.getBuildOptions(index
).getToolChainFamily())) {
409 o
.setToolChainFamily(vid
.getBuildOptions(index
).getToolChainFamily());
411 if (!isEmpty(vid
.getBuildOptions(index
).getTagName())) {
412 o
.setTagName(vid
.getBuildOptions(index
).getTagName());
414 if (!isEmpty(vid
.getBuildOptions(index
).getToolCode())) {
415 o
.setToolCode(vid
.getBuildOptions(index
).getToolCode());
417 if (vid
.getBuildOptions(index
).getSupArchList() != null
418 && vid
.getBuildOptions(index
).getSupArchList().size() > 0) {
419 o
.setSupArchList(vid
.getBuildOptions(index
).getSupArchList());
422 this.mbo
.getOptions().addNewOption();
423 this.mbo
.getOptions().setOptionArray(this.mbo
.getOptions().getOptionList().size() - 1, o
);
427 this.msa
.setModuleBuildOptions(this.mbo
);
428 this.omt
.setSaved(false);
429 } catch (Exception e
) {
430 Log
.wrn("Update Module Build Options", e
.getMessage());
431 Log
.err("Update Module Build Options", e
.getMessage());
436 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
439 public void valueChanged(ListSelectionEvent arg0
) {
440 if (arg0
.getValueIsAdjusting()) {
443 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
444 if (lsm
.isSelectionEmpty()) {
447 selectedRow
= lsm
.getMinSelectionIndex();
452 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
455 public void mouseClicked(MouseEvent arg0
) {
456 if (arg0
.getClickCount() == 2) {
457 if (this.selectedRow
< 0) {
460 showEdit(selectedRow
);
466 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
468 * Override componentResized to resize all components when frame's size is changed
470 public void componentResized(ComponentEvent arg0
) {
471 int intCurrentWidth
= this.getJContentPane().getWidth();
472 int intCurrentHeight
= this.getJContentPane().getHeight();
473 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
474 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
476 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
478 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
479 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
480 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
481 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
482 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
483 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
484 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
485 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
486 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);