]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleBuildOptions.java
178ae39981e035ef1710cd6b7b70da851eae26f0
[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 private IFrame parentFrame = null;
98
99 /**
100 This method initializes jButtonAdd
101
102 @return javax.swing.JButton jButtonAdd
103
104 **/
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));
112 }
113 return jButtonAdd;
114 }
115
116 /**
117 This method initializes jButtonRemove
118
119 @return javax.swing.JButton jButtonRemove
120
121 **/
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));
129 }
130 return jButtonRemove;
131 }
132
133 /**
134 This method initializes jButtonUpdate
135
136 @return javax.swing.JButton jButtonUpdate
137
138 **/
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);
146 }
147 return jButtonUpdate;
148 }
149
150 /**
151 This method initializes jScrollPane
152
153 @return javax.swing.JScrollPane
154 */
155 private JScrollPane getJScrollPane() {
156 if (jScrollPane == null) {
157 jScrollPane = new JScrollPane();
158 jScrollPane.setViewportView(getJContentPane());
159 }
160 return jScrollPane;
161 }
162
163 /**
164 This method initializes jScrollPaneTable
165
166 @return javax.swing.JScrollPane
167 **/
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());
174 }
175 return jScrollPaneTable;
176 }
177
178 /**
179 This method initializes jTable
180
181 @return javax.swing.JTable
182 **/
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);
189
190 model.addColumn("Option String Value");
191
192 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
193 jTable.getSelectionModel().addListSelectionListener(this);
194 jTable.getModel().addTableModelListener(this);
195 jTable.addMouseListener(this);
196 }
197 return jTable;
198 }
199
200 public static void main(String[] args) {
201 }
202
203 /**
204 This method initializes this
205
206 **/
207 private void init() {
208 this.setSize(500, 515);
209 this.setContentPane(getJScrollPane());
210 this.setTitle("Boot Modes");
211 }
212
213 /**
214 This method initializes this
215 Fill values to all fields if these values are not empty
216
217 @param inBuildOptions
218
219 **/
220 private void init(ModuleBuildOptionsDocument.ModuleBuildOptions inModuleBuildOptions) {
221 init();
222 this.mbo = inModuleBuildOptions;
223
224 if (this.mbo != null) {
225 //
226 // Save User Extensitions
227 //
228 if (this.mbo.getUserExtensionsList() != null) {
229 this.ue = this.mbo.getUserExtensionsList();
230 }
231
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);
236 if (o != null) {
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());
243
244 id = new BuildOptionsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
245 vid.addBuildOptions(id);
246 }
247 }
248 }
249 }
250 }
251 showTable();
252 }
253
254 /**
255 This is the default constructor
256
257 **/
258 public ModuleBuildOptions() {
259 super();
260 init();
261 this.setVisible(true);
262 }
263
264 /**
265 This is the override edit constructor
266
267 @param inBuildOptions The input BuildOptionsDocument.BuildOptions
268
269 **/
270 public ModuleBuildOptions(OpeningModuleType inOmt, IFrame iFrame) {
271 super();
272 this.omt = inOmt;
273 this.msa = omt.getXmlMsa();
274 this.parentFrame = iFrame;
275 init(msa.getModuleBuildOptions());
276 this.setVisible(true);
277 }
278
279 /**
280 This method initializes jContentPane
281
282 @return javax.swing.JPanel jContentPane
283
284 **/
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));
290
291 jContentPane.add(getJButtonAdd(), null);
292 jContentPane.add(getJButtonRemove(), null);
293 jContentPane.add(getJButtonUpdate(), null);
294 jContentPane.add(getJScrollPaneTable(), null);
295 }
296 return jContentPane;
297 }
298
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) {
303 if (index == -1) {
304 this.vid.addBuildOptions(dlg.getId());
305 } else {
306 this.vid.setBuildOptions(dlg.getId(), index);
307 }
308 this.showTable();
309 this.save();
310 dlg.dispose();
311 }
312 if (result == DataType.RETURN_TYPE_CANCEL) {
313 dlg.dispose();
314 }
315 }
316
317 /**
318 Clear all table rows
319
320 **/
321 private void clearAll() {
322 if (model != null) {
323 for (int index = model.getRowCount() - 1; index >= 0; index--) {
324 model.removeRow(index);
325 }
326 }
327 }
328
329 /**
330 Read content of vector and put then into table
331
332 **/
333 private void showTable() {
334 clearAll();
335
336 if (vid.size() > 0) {
337 for (int index = 0; index < vid.size(); index++) {
338 model.addRow(vid.toStringVector(index));
339 }
340 }
341 this.jTable.repaint();
342 this.jTable.updateUI();
343 }
344
345 /* (non-Javadoc)
346 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
347 *
348 * Override actionPerformed to listen all actions
349 *
350 */
351 public void actionPerformed(ActionEvent arg0) {
352 if (arg0.getSource() == jButtonAdd) {
353 showEdit(-1);
354 }
355 if (arg0.getSource() == jButtonUpdate) {
356 if (this.selectedRow < 0) {
357 Log.wrn("Update Boot Modes", "Please select one record first.");
358 return;
359 }
360 showEdit(selectedRow);
361 }
362
363 if (arg0.getSource() == jButtonRemove) {
364 if (jTable.isEditing()) {
365 jTable.getCellEditor().stopCellEditing();
366 }
367 if (selectedRow > -1) {
368 this.model.removeRow(selectedRow);
369 this.vid.removeBuildOptions(selectedRow);
370 selectedRow = -1;
371 this.save();
372 }
373 }
374 }
375
376 /**
377 Save all components of Mbd Header
378 if exists BuildOptions, set the value directly
379 if not exists BuildOptions, new an instance first
380
381 **/
382 public void save() {
383 try {
384 int count = this.vid.size();
385
386 this.mbo = ModuleBuildOptionsDocument.ModuleBuildOptions.Factory.newInstance();
387 this.mbo.addNewOptions();
388 //
389 // Restore User Extensions Data
390 //
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));
395 }
396 }
397
398 if (count > 0) {
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());
403 }
404 if (vid.getBuildOptions(index).getBuildTargets() != null
405 && vid.getBuildOptions(index).getBuildTargets().size() > 0) {
406 o.setBuildTargets(vid.getBuildOptions(index).getBuildTargets());
407 }
408 if (!isEmpty(vid.getBuildOptions(index).getToolChainFamily())) {
409 o.setToolChainFamily(vid.getBuildOptions(index).getToolChainFamily());
410 }
411 if (!isEmpty(vid.getBuildOptions(index).getTagName())) {
412 o.setTagName(vid.getBuildOptions(index).getTagName());
413 }
414 if (!isEmpty(vid.getBuildOptions(index).getToolCode())) {
415 o.setToolCode(vid.getBuildOptions(index).getToolCode());
416 }
417 if (vid.getBuildOptions(index).getSupArchList() != null
418 && vid.getBuildOptions(index).getSupArchList().size() > 0) {
419 o.setSupArchList(vid.getBuildOptions(index).getSupArchList());
420 }
421
422 this.mbo.getOptions().addNewOption();
423 this.mbo.getOptions().setOptionArray(this.mbo.getOptions().getOptionList().size() - 1, o);
424 }
425 }
426
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());
432 }
433 }
434
435 /* (non-Javadoc)
436 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
437 *
438 */
439 public void valueChanged(ListSelectionEvent arg0) {
440 if (arg0.getValueIsAdjusting()) {
441 return;
442 }
443 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();
444 if (lsm.isSelectionEmpty()) {
445 return;
446 } else {
447 selectedRow = lsm.getMinSelectionIndex();
448 }
449 }
450
451 /* (non-Javadoc)
452 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
453 *
454 */
455 public void mouseClicked(MouseEvent arg0) {
456 if (arg0.getClickCount() == 2) {
457 if (this.selectedRow < 0) {
458 return;
459 } else {
460 showEdit(selectedRow);
461 }
462 }
463 }
464
465 /* (non-Javadoc)
466 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
467 *
468 * Override componentResized to resize all components when frame's size is changed
469 */
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;
475
476 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,
477 intPreferredHeight);
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);
487 }
488 }