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