]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleBuildOptions.java
1. Fix EDKT461 [Framework Wizard] Can't change ModuleBuildOptions for MSA file
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / ModuleBuildOptions.java
CommitLineData
b3cb8ee7 1/** @file\r
2 \r
3 The file is used to create, update BuildOptions of MSA/MBD file\r
4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15\r
16package org.tianocore.frameworkwizard.module.ui;\r
17\r
18import java.awt.Dimension;\r
19import java.awt.event.ActionEvent;\r
20import java.awt.event.ComponentEvent;\r
21import java.awt.event.MouseEvent;\r
22import java.util.List;\r
23import java.util.Vector;\r
24\r
25import javax.swing.JButton;\r
26import javax.swing.JPanel;\r
27import javax.swing.JScrollPane;\r
28import javax.swing.JTable;\r
29import javax.swing.ListSelectionModel;\r
30import javax.swing.event.ListSelectionEvent;\r
31\r
32import org.tianocore.ModuleBuildOptionsDocument;\r
33import org.tianocore.UserExtensionsDocument;\r
34import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
35import org.tianocore.OptionDocument.Option;\r
36import org.tianocore.frameworkwizard.common.DataType;\r
37import org.tianocore.frameworkwizard.common.IDefaultTableModel;\r
38import org.tianocore.frameworkwizard.common.Log;\r
39import org.tianocore.frameworkwizard.common.Tools;\r
40import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r
41import org.tianocore.frameworkwizard.common.ui.IFrame;\r
42import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r
43import org.tianocore.frameworkwizard.module.Identifications.BuildOptions.BuildOptionsIdentification;\r
44import org.tianocore.frameworkwizard.module.Identifications.BuildOptions.BuildOptionsVector;\r
45import org.tianocore.frameworkwizard.module.ui.dialog.BuildOptionsDlg;\r
46\r
47/**\r
48 The class is used to create, update BuildOptions of MSA/MBD file\r
49 It extends IInternalFrame\r
50 \r
51\r
52\r
53 **/\r
54public class ModuleBuildOptions extends IInternalFrame {\r
55\r
56 ///\r
57 /// Define class Serial Version UID\r
58 ///\r
59 private static final long serialVersionUID = -3888558623432442561L;\r
60\r
61 //\r
62 //Define class members\r
63 //\r
64 private JPanel jContentPane = null;\r
65\r
66 private JButton jButtonAdd = null;\r
67\r
68 private JButton jButtonRemove = null;\r
69\r
70 private JButton jButtonUpdate = null;\r
71\r
72 private JScrollPane jScrollPane = null;\r
73\r
74 private JScrollPane jScrollPaneTable = null;\r
75\r
76 private JTable jTable = null;\r
77\r
78 //\r
79 // Not used by UI\r
80 //\r
81 private OpeningModuleType omt = null;\r
82\r
83 private ModuleSurfaceArea msa = null;\r
84\r
85 private ModuleBuildOptionsDocument.ModuleBuildOptions mbo = null;\r
86\r
87 private List<UserExtensionsDocument.UserExtensions> ue = null;\r
88\r
89 private BuildOptionsIdentification id = null;\r
90\r
91 private BuildOptionsVector vid = new BuildOptionsVector();\r
92\r
93 private IDefaultTableModel model = null;\r
94\r
95 private int selectedRow = -1;\r
96\r
97 /**\r
98 This method initializes jButtonAdd \r
99 \r
100 @return javax.swing.JButton jButtonAdd\r
101 \r
102 **/\r
103 private JButton getJButtonAdd() {\r
104 if (jButtonAdd == null) {\r
105 jButtonAdd = new JButton();\r
106 jButtonAdd.setBounds(new java.awt.Rectangle(210, 195, 90, 20));\r
107 jButtonAdd.setText("Add");\r
108 jButtonAdd.addActionListener(this);\r
109 jButtonAdd.setPreferredSize(new java.awt.Dimension(90, 20));\r
110 }\r
111 return jButtonAdd;\r
112 }\r
113\r
114 /**\r
115 This method initializes jButtonRemove \r
116 \r
117 @return javax.swing.JButton jButtonRemove\r
118 \r
119 **/\r
120 private JButton getJButtonRemove() {\r
121 if (jButtonRemove == null) {\r
122 jButtonRemove = new JButton();\r
123 jButtonRemove.setBounds(new java.awt.Rectangle(390, 195, 90, 20));\r
124 jButtonRemove.setText("Remove");\r
125 jButtonRemove.addActionListener(this);\r
126 jButtonRemove.setPreferredSize(new java.awt.Dimension(90, 20));\r
127 }\r
128 return jButtonRemove;\r
129 }\r
130\r
131 /**\r
132 This method initializes jButtonUpdate \r
133 \r
134 @return javax.swing.JButton jButtonUpdate\r
135 \r
136 **/\r
137 private JButton getJButtonUpdate() {\r
138 if (jButtonUpdate == null) {\r
139 jButtonUpdate = new JButton();\r
140 jButtonUpdate.setBounds(new java.awt.Rectangle(315, 195, 90, 20));\r
141 jButtonUpdate.setPreferredSize(new java.awt.Dimension(90, 20));\r
142 jButtonUpdate.setText("Edit");\r
143 jButtonUpdate.addActionListener(this);\r
144 }\r
145 return jButtonUpdate;\r
146 }\r
147\r
148 /**\r
149 This method initializes jScrollPane \r
150 \r
151 @return javax.swing.JScrollPane \r
152 */\r
153 private JScrollPane getJScrollPane() {\r
154 if (jScrollPane == null) {\r
155 jScrollPane = new JScrollPane();\r
156 jScrollPane.setViewportView(getJContentPane());\r
157 }\r
158 return jScrollPane;\r
159 }\r
160\r
161 /**\r
162 This method initializes jScrollPaneTable \r
163 \r
164 @return javax.swing.JScrollPane \r
165 **/\r
166 private JScrollPane getJScrollPaneTable() {\r
167 if (jScrollPaneTable == null) {\r
168 jScrollPaneTable = new JScrollPane();\r
169 jScrollPaneTable.setBounds(new java.awt.Rectangle(15, 10, 470, 420));\r
170 jScrollPaneTable.setPreferredSize(new Dimension(470, 420));\r
171 jScrollPaneTable.setViewportView(getJTable());\r
172 }\r
173 return jScrollPaneTable;\r
174 }\r
175\r
176 /**\r
177 This method initializes jTable \r
178 \r
179 @return javax.swing.JTable \r
180 **/\r
181 private JTable getJTable() {\r
182 if (jTable == null) {\r
183 jTable = new JTable();\r
184 model = new IDefaultTableModel();\r
185 jTable = new JTable(model);\r
186 jTable.setRowHeight(20);\r
187\r
188 model.addColumn("Option String Value");\r
189\r
190 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
191 jTable.getSelectionModel().addListSelectionListener(this);\r
192 jTable.getModel().addTableModelListener(this);\r
193 jTable.addMouseListener(this);\r
194 }\r
195 return jTable;\r
196 }\r
197\r
198 public static void main(String[] args) {\r
199 }\r
200\r
201 /**\r
202 This method initializes this\r
203 \r
204 **/\r
205 private void init() {\r
206 this.setSize(500, 515);\r
207 this.setContentPane(getJScrollPane());\r
208 this.setTitle("Boot Modes");\r
209 }\r
210\r
211 /**\r
212 This method initializes this\r
213 Fill values to all fields if these values are not empty\r
214 \r
215 @param inBuildOptions\r
216\r
217 **/\r
218 private void init(ModuleBuildOptionsDocument.ModuleBuildOptions inModuleBuildOptions) {\r
219 init();\r
220 this.mbo = inModuleBuildOptions;\r
221\r
222 if (this.mbo != null) {\r
223 //\r
224 // Save User Extensitions\r
225 //\r
226 if (this.mbo.getUserExtensionsList() != null) {\r
227 this.ue = this.mbo.getUserExtensionsList();\r
228 }\r
229\r
230 if (this.mbo.getOptions() != null) {\r
231 if (this.mbo.getOptions().getOptionList() != null) {\r
232 for (int index = 0; index < this.mbo.getOptions().getOptionList().size(); index++) {\r
233 Option o = this.mbo.getOptions().getOptionList().get(index);\r
234 if (o != null) {\r
235 String arg0 = o.getStringValue();\r
236 Vector<String> arg1 = Tools.convertListToVector(o.getBuildTargets());\r
237 String arg2 = o.getToolChainFamily();\r
238 String arg3 = o.getTagName();\r
239 String arg4 = o.getToolCode();\r
240 Vector<String> arg5 = Tools.convertListToVector(o.getSupArchList());\r
241\r
242 id = new BuildOptionsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
243 vid.addBuildOptions(id);\r
244 }\r
245 }\r
246 }\r
247 }\r
248 }\r
249 showTable();\r
250 }\r
251\r
252 /**\r
253 This is the default constructor\r
254 \r
255 **/\r
256 public ModuleBuildOptions() {\r
257 super();\r
258 init();\r
259 this.setVisible(true);\r
260 }\r
261\r
262 /**\r
263 This is the override edit constructor\r
264 \r
265 @param inBuildOptions The input BuildOptionsDocument.BuildOptions\r
266 \r
267 **/\r
268 public ModuleBuildOptions(OpeningModuleType inOmt) {\r
269 super();\r
270 this.omt = inOmt;\r
271 this.msa = omt.getXmlMsa();\r
272 init(msa.getModuleBuildOptions());\r
273 this.setVisible(true);\r
274 }\r
275\r
276 /**\r
277 This method initializes jContentPane\r
278 \r
279 @return javax.swing.JPanel jContentPane\r
280 \r
281 **/\r
282 private JPanel getJContentPane() {\r
283 if (jContentPane == null) {\r
284 jContentPane = new JPanel();\r
285 jContentPane.setLayout(null);\r
286 jContentPane.setPreferredSize(new java.awt.Dimension(490, 490));\r
287\r
288 jContentPane.add(getJButtonAdd(), null);\r
289 jContentPane.add(getJButtonRemove(), null);\r
290 jContentPane.add(getJButtonUpdate(), null);\r
291 jContentPane.add(getJScrollPaneTable(), null);\r
292 }\r
293 return jContentPane;\r
294 }\r
295\r
296 private void showEdit(int index) {\r
297 BuildOptionsDlg dlg = new BuildOptionsDlg(vid.getBuildOptions(index), new IFrame(), omt.getId());\r
298 int result = dlg.showDialog();\r
299 if (result == DataType.RETURN_TYPE_OK) {\r
300 if (index == -1) {\r
301 this.vid.addBuildOptions(dlg.getId());\r
302 } else {\r
303 this.vid.setBuildOptions(dlg.getId(), index);\r
304 }\r
305 this.showTable();\r
306 this.save();\r
307 dlg.dispose();\r
308 }\r
309 if (result == DataType.RETURN_TYPE_CANCEL) {\r
310 dlg.dispose();\r
311 }\r
312 }\r
313\r
314 /**\r
315 Clear all table rows\r
316 \r
317 **/\r
318 private void clearAll() {\r
319 if (model != null) {\r
320 for (int index = model.getRowCount() - 1; index >= 0; index--) {\r
321 model.removeRow(index);\r
322 }\r
323 }\r
324 }\r
325\r
326 /**\r
327 Read content of vector and put then into table\r
328 \r
329 **/\r
330 private void showTable() {\r
331 clearAll();\r
332\r
333 if (vid.size() > 0) {\r
334 for (int index = 0; index < vid.size(); index++) {\r
335 model.addRow(vid.toStringVector(index));\r
336 }\r
337 }\r
338 this.jTable.repaint();\r
339 this.jTable.updateUI();\r
340 }\r
341\r
342 /* (non-Javadoc)\r
343 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
344 *\r
345 * Override actionPerformed to listen all actions\r
346 * \r
347 */\r
348 public void actionPerformed(ActionEvent arg0) {\r
349 if (arg0.getSource() == jButtonAdd) {\r
350 showEdit(-1);\r
351 }\r
352 if (arg0.getSource() == jButtonUpdate) {\r
353 if (this.selectedRow < 0) {\r
354 Log.wrn("Update Boot Modes", "Please select one record first.");\r
355 return;\r
356 }\r
357 showEdit(selectedRow);\r
358 }\r
359\r
360 if (arg0.getSource() == jButtonRemove) {\r
361 if (jTable.isEditing()) {\r
362 jTable.getCellEditor().stopCellEditing();\r
363 }\r
364 if (selectedRow > -1) {\r
365 this.model.removeRow(selectedRow);\r
366 this.vid.removeBuildOptions(selectedRow);\r
367 selectedRow = -1;\r
368 this.save();\r
369 }\r
370 }\r
371 }\r
372\r
373 /**\r
374 Save all components of Mbd Header\r
375 if exists BuildOptions, set the value directly\r
376 if not exists BuildOptions, new an instance first\r
377 \r
378 **/\r
379 public void save() {\r
380 try {\r
381 int count = this.vid.size();\r
382\r
383 this.mbo = ModuleBuildOptionsDocument.ModuleBuildOptions.Factory.newInstance();\r
384 this.mbo.addNewOptions();\r
385 //\r
386 // Restore User Extensions Data\r
387 //\r
388 if (this.ue != null) {\r
389 for (int index = 0; index < this.ue.size(); index++) {\r
390 this.mbo.addNewUserExtensions();\r
391 this.mbo.setUserExtensionsArray(index, ue.get(index));\r
392 }\r
393 }\r
394\r
395 if (count > 0) {\r
396 for (int index = 0; index < count; index++) {\r
397 Option o = Option.Factory.newInstance();\r
398 if (!isEmpty(vid.getBuildOptions(index).getOption())) {\r
399 o.setStringValue(vid.getBuildOptions(index).getOption());\r
400 }\r
401 if (vid.getBuildOptions(index).getBuildTargets() != null\r
402 && vid.getBuildOptions(index).getBuildTargets().size() > 0) {\r
403 o.setBuildTargets(vid.getBuildOptions(index).getBuildTargets());\r
404 }\r
405 if (!isEmpty(vid.getBuildOptions(index).getToolChainFamily())) {\r
406 o.setToolChainFamily(vid.getBuildOptions(index).getToolChainFamily());\r
407 }\r
408 if (!isEmpty(vid.getBuildOptions(index).getTagName())) {\r
409 o.setTagName(vid.getBuildOptions(index).getTagName());\r
410 }\r
411 if (!isEmpty(vid.getBuildOptions(index).getToolCode())) {\r
412 o.setToolCode(vid.getBuildOptions(index).getToolCode());\r
413 }\r
414 if (vid.getBuildOptions(index).getSupArchList() != null\r
415 && vid.getBuildOptions(index).getSupArchList().size() > 0) {\r
416 o.setSupArchList(vid.getBuildOptions(index).getSupArchList());\r
417 }\r
418\r
419 this.mbo.getOptions().addNewOption();\r
420 this.mbo.getOptions().setOptionArray(this.mbo.getOptions().getOptionList().size() - 1, o);\r
421 }\r
422 }\r
423\r
424 this.msa.setModuleBuildOptions(this.mbo);\r
425 this.omt.setSaved(false);\r
426 } catch (Exception e) {\r
427 Log.wrn("Update Module Build Options", e.getMessage());\r
428 Log.err("Update Module Build Options", e.getMessage());\r
429 }\r
430 }\r
431\r
432 /* (non-Javadoc)\r
433 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r
434 *\r
435 */\r
436 public void valueChanged(ListSelectionEvent arg0) {\r
437 if (arg0.getValueIsAdjusting()) {\r
438 return;\r
439 }\r
440 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r
441 if (lsm.isSelectionEmpty()) {\r
442 return;\r
443 } else {\r
444 selectedRow = lsm.getMinSelectionIndex();\r
445 }\r
446 }\r
447\r
448 /* (non-Javadoc)\r
449 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r
450 *\r
451 */\r
452 public void mouseClicked(MouseEvent arg0) {\r
453 if (arg0.getClickCount() == 2) {\r
454 if (this.selectedRow < 0) {\r
455 return;\r
456 } else {\r
457 showEdit(selectedRow);\r
458 }\r
459 }\r
460 }\r
461\r
462 /* (non-Javadoc)\r
463 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r
464 * \r
465 * Override componentResized to resize all components when frame's size is changed\r
466 */\r
467 public void componentResized(ComponentEvent arg0) {\r
468 int intCurrentWidth = this.getJContentPane().getWidth();\r
469 int intCurrentHeight = this.getJContentPane().getHeight();\r
470 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r
471 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r
472\r
473 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
474 intPreferredHeight);\r
475 Tools.relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
476 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON,\r
477 DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r
478 Tools.relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
479 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON,\r
480 DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r
481 Tools.relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
482 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON,\r
483 DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r
484 }\r
485}\r