]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleBuildOptions.java
076f820ae8e44b1f56d6b134b9990c23f0f7c1af
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / ModuleBuildOptions.java
1 /** @file
2
3 The file is used to create, update BuildOptions of MSA/MBD file
4
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
10
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.
13
14 **/
15
16 package org.tianocore.frameworkwizard.module.ui;
17
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;
24
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;
31
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;
46
47 /**
48 The class is used to create, update BuildOptions of MSA/MBD file
49 It extends IInternalFrame
50
51
52
53 **/
54 public class ModuleBuildOptions extends IInternalFrame {
55
56 ///
57 /// Define class Serial Version UID
58 ///
59 private static final long serialVersionUID = -3888558623432442561L;
60
61 //
62 //Define class members
63 //
64 private JPanel jContentPane = null;
65
66 private JButton jButtonAdd = null;
67
68 private JButton jButtonRemove = null;
69
70 private JButton jButtonUpdate = null;
71
72 private JScrollPane jScrollPane = null;
73
74 private JScrollPane jScrollPaneTable = null;
75
76 private JTable jTable = null;
77
78 //
79 // Not used by UI
80 //
81 private OpeningModuleType omt = null;
82
83 private ModuleSurfaceArea msa = null;
84
85 private ModuleBuildOptionsDocument.ModuleBuildOptions mbo = null;
86
87 private List<UserExtensionsDocument.UserExtensions> ue = null;
88
89 private BuildOptionsIdentification id = null;
90
91 private BuildOptionsVector vid = new BuildOptionsVector();
92
93 private IDefaultTableModel model = null;
94
95 private int selectedRow = -1;
96
97 /**
98 This method initializes jButtonAdd
99
100 @return javax.swing.JButton jButtonAdd
101
102 **/
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));
110 }
111 return jButtonAdd;
112 }
113
114 /**
115 This method initializes jButtonRemove
116
117 @return javax.swing.JButton jButtonRemove
118
119 **/
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));
127 }
128 return jButtonRemove;
129 }
130
131 /**
132 This method initializes jButtonUpdate
133
134 @return javax.swing.JButton jButtonUpdate
135
136 **/
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);
144 }
145 return jButtonUpdate;
146 }
147
148 /**
149 This method initializes jScrollPane
150
151 @return javax.swing.JScrollPane
152 */
153 private JScrollPane getJScrollPane() {
154 if (jScrollPane == null) {
155 jScrollPane = new JScrollPane();
156 jScrollPane.setViewportView(getJContentPane());
157 }
158 return jScrollPane;
159 }
160
161 /**
162 This method initializes jScrollPaneTable
163
164 @return javax.swing.JScrollPane
165 **/
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());
172 }
173 return jScrollPaneTable;
174 }
175
176 /**
177 This method initializes jTable
178
179 @return javax.swing.JTable
180 **/
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);
187
188 model.addColumn("Option String Value");
189
190 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
191 jTable.getSelectionModel().addListSelectionListener(this);
192 jTable.getModel().addTableModelListener(this);
193 jTable.addMouseListener(this);
194 }
195 return jTable;
196 }
197
198 public static void main(String[] args) {
199 }
200
201 /**
202 This method initializes this
203
204 **/
205 private void init() {
206 this.setSize(500, 515);
207 this.setContentPane(getJScrollPane());
208 this.setTitle("Boot Modes");
209 }
210
211 /**
212 This method initializes this
213 Fill values to all fields if these values are not empty
214
215 @param inBuildOptions
216
217 **/
218 private void init(ModuleBuildOptionsDocument.ModuleBuildOptions inModuleBuildOptions) {
219 init();
220 this.mbo = inModuleBuildOptions;
221
222 if (this.mbo != null) {
223 //
224 // Save User Extensitions
225 //
226 if (this.mbo.getUserExtensionsList() != null) {
227 this.ue = this.mbo.getUserExtensionsList();
228 }
229
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);
234 if (o != null) {
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());
241
242 id = new BuildOptionsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
243 vid.addBuildOptions(id);
244 }
245 }
246 }
247 }
248 }
249 showTable();
250 }
251
252 /**
253 This is the default constructor
254
255 **/
256 public ModuleBuildOptions() {
257 super();
258 init();
259 this.setVisible(true);
260 }
261
262 /**
263 This is the override edit constructor
264
265 @param inBuildOptions The input BuildOptionsDocument.BuildOptions
266
267 **/
268 public ModuleBuildOptions(OpeningModuleType inOmt) {
269 super();
270 this.omt = inOmt;
271 this.msa = omt.getXmlMsa();
272 init(msa.getModuleBuildOptions());
273 this.setVisible(true);
274 }
275
276 /**
277 This method initializes jContentPane
278
279 @return javax.swing.JPanel jContentPane
280
281 **/
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));
287
288 jContentPane.add(getJButtonAdd(), null);
289 jContentPane.add(getJButtonRemove(), null);
290 jContentPane.add(getJButtonUpdate(), null);
291 jContentPane.add(getJScrollPaneTable(), null);
292 }
293 return jContentPane;
294 }
295
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) {
300 if (index == -1) {
301 this.vid.addBuildOptions(dlg.getId());
302 } else {
303 this.vid.setBuildOptions(dlg.getId(), index);
304 }
305 this.showTable();
306 this.save();
307 dlg.dispose();
308 }
309 if (result == DataType.RETURN_TYPE_CANCEL) {
310 dlg.dispose();
311 }
312 }
313
314 /**
315 Clear all table rows
316
317 **/
318 private void clearAll() {
319 if (model != null) {
320 for (int index = model.getRowCount() - 1; index >= 0; index--) {
321 model.removeRow(index);
322 }
323 }
324 }
325
326 /**
327 Read content of vector and put then into table
328
329 **/
330 private void showTable() {
331 clearAll();
332
333 if (vid.size() > 0) {
334 for (int index = 0; index < vid.size(); index++) {
335 model.addRow(vid.toStringVector(index));
336 }
337 }
338 this.jTable.repaint();
339 this.jTable.updateUI();
340 }
341
342 /* (non-Javadoc)
343 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
344 *
345 * Override actionPerformed to listen all actions
346 *
347 */
348 public void actionPerformed(ActionEvent arg0) {
349 if (arg0.getSource() == jButtonAdd) {
350 showEdit(-1);
351 }
352 if (arg0.getSource() == jButtonUpdate) {
353 if (this.selectedRow < 0) {
354 Log.wrn("Update Boot Modes", "Please select one record first.");
355 return;
356 }
357 showEdit(selectedRow);
358 }
359
360 if (arg0.getSource() == jButtonRemove) {
361 if (jTable.isEditing()) {
362 jTable.getCellEditor().stopCellEditing();
363 }
364 if (selectedRow > -1) {
365 this.model.removeRow(selectedRow);
366 this.vid.removeBuildOptions(selectedRow);
367 selectedRow = -1;
368 this.save();
369 }
370 }
371 }
372
373 /**
374 Save all components of Mbd Header
375 if exists BuildOptions, set the value directly
376 if not exists BuildOptions, new an instance first
377
378 **/
379 public void save() {
380 try {
381 int count = this.vid.size();
382
383 this.mbo = ModuleBuildOptionsDocument.ModuleBuildOptions.Factory.newInstance();
384 this.mbo.addNewOptions();
385 //
386 // Restore User Extensions Data
387 //
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));
392 }
393 }
394
395 if (count > 0) {
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());
400 }
401 if (vid.getBuildOptions(index).getBuildTargets() != null
402 && vid.getBuildOptions(index).getBuildTargets().size() > 0) {
403 o.setBuildTargets(vid.getBuildOptions(index).getBuildTargets());
404 }
405 if (!isEmpty(vid.getBuildOptions(index).getToolChainFamily())) {
406 o.setToolChainFamily(vid.getBuildOptions(index).getToolChainFamily());
407 }
408 if (!isEmpty(vid.getBuildOptions(index).getTagName())) {
409 o.setTagName(vid.getBuildOptions(index).getTagName());
410 }
411 if (!isEmpty(vid.getBuildOptions(index).getToolCode())) {
412 o.setToolCode(vid.getBuildOptions(index).getToolCode());
413 }
414 if (vid.getBuildOptions(index).getSupArchList() != null
415 && vid.getBuildOptions(index).getSupArchList().size() > 0) {
416 o.setSupArchList(vid.getBuildOptions(index).getSupArchList());
417 }
418
419 this.mbo.getOptions().addNewOption();
420 this.mbo.getOptions().setOptionArray(this.mbo.getOptions().getOptionList().size() - 1, o);
421 }
422 }
423
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());
429 }
430 }
431
432 /* (non-Javadoc)
433 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
434 *
435 */
436 public void valueChanged(ListSelectionEvent arg0) {
437 if (arg0.getValueIsAdjusting()) {
438 return;
439 }
440 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();
441 if (lsm.isSelectionEmpty()) {
442 return;
443 } else {
444 selectedRow = lsm.getMinSelectionIndex();
445 }
446 }
447
448 /* (non-Javadoc)
449 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
450 *
451 */
452 public void mouseClicked(MouseEvent arg0) {
453 if (arg0.getClickCount() == 2) {
454 if (this.selectedRow < 0) {
455 return;
456 } else {
457 showEdit(selectedRow);
458 }
459 }
460 }
461
462 /* (non-Javadoc)
463 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
464 *
465 * Override componentResized to resize all components when frame's size is changed
466 */
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;
472
473 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,
474 intPreferredHeight);
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);
484 }
485 }