]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleBuildOptions.java
1. Finish Enhancement EDKT345: Support deleting multiple rows together when remove...
[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
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
ff7bc6c4 192 jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);\r
b3cb8ee7 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
ff7bc6c4 367\r
368 int selectedRows[] = this.jTable.getSelectedRows();\r
369 \r
370 if (selectedRows != null) {\r
371 for (int index = selectedRows.length - 1; index > -1; index--) {\r
372 this.model.removeRow(selectedRows[index]);\r
373 this.vid.removeBuildOptions(selectedRows[index]);\r
374 }\r
b3cb8ee7 375 selectedRow = -1;\r
376 this.save();\r
377 }\r
378 }\r
379 }\r
380\r
381 /**\r
382 Save all components of Mbd Header\r
383 if exists BuildOptions, set the value directly\r
384 if not exists BuildOptions, new an instance first\r
385 \r
386 **/\r
387 public void save() {\r
388 try {\r
389 int count = this.vid.size();\r
390\r
391 this.mbo = ModuleBuildOptionsDocument.ModuleBuildOptions.Factory.newInstance();\r
392 this.mbo.addNewOptions();\r
393 //\r
394 // Restore User Extensions Data\r
395 //\r
396 if (this.ue != null) {\r
397 for (int index = 0; index < this.ue.size(); index++) {\r
398 this.mbo.addNewUserExtensions();\r
399 this.mbo.setUserExtensionsArray(index, ue.get(index));\r
400 }\r
401 }\r
402\r
403 if (count > 0) {\r
404 for (int index = 0; index < count; index++) {\r
405 Option o = Option.Factory.newInstance();\r
406 if (!isEmpty(vid.getBuildOptions(index).getOption())) {\r
407 o.setStringValue(vid.getBuildOptions(index).getOption());\r
408 }\r
409 if (vid.getBuildOptions(index).getBuildTargets() != null\r
410 && vid.getBuildOptions(index).getBuildTargets().size() > 0) {\r
411 o.setBuildTargets(vid.getBuildOptions(index).getBuildTargets());\r
412 }\r
413 if (!isEmpty(vid.getBuildOptions(index).getToolChainFamily())) {\r
414 o.setToolChainFamily(vid.getBuildOptions(index).getToolChainFamily());\r
415 }\r
416 if (!isEmpty(vid.getBuildOptions(index).getTagName())) {\r
417 o.setTagName(vid.getBuildOptions(index).getTagName());\r
418 }\r
419 if (!isEmpty(vid.getBuildOptions(index).getToolCode())) {\r
420 o.setToolCode(vid.getBuildOptions(index).getToolCode());\r
421 }\r
422 if (vid.getBuildOptions(index).getSupArchList() != null\r
423 && vid.getBuildOptions(index).getSupArchList().size() > 0) {\r
424 o.setSupArchList(vid.getBuildOptions(index).getSupArchList());\r
425 }\r
426\r
427 this.mbo.getOptions().addNewOption();\r
428 this.mbo.getOptions().setOptionArray(this.mbo.getOptions().getOptionList().size() - 1, o);\r
429 }\r
430 }\r
431\r
432 this.msa.setModuleBuildOptions(this.mbo);\r
433 this.omt.setSaved(false);\r
434 } catch (Exception e) {\r
435 Log.wrn("Update Module Build Options", e.getMessage());\r
436 Log.err("Update Module Build Options", e.getMessage());\r
437 }\r
438 }\r
439\r
440 /* (non-Javadoc)\r
441 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r
442 *\r
443 */\r
444 public void valueChanged(ListSelectionEvent arg0) {\r
445 if (arg0.getValueIsAdjusting()) {\r
446 return;\r
447 }\r
448 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r
449 if (lsm.isSelectionEmpty()) {\r
450 return;\r
451 } else {\r
452 selectedRow = lsm.getMinSelectionIndex();\r
453 }\r
454 }\r
455\r
456 /* (non-Javadoc)\r
457 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r
458 *\r
459 */\r
460 public void mouseClicked(MouseEvent arg0) {\r
461 if (arg0.getClickCount() == 2) {\r
462 if (this.selectedRow < 0) {\r
463 return;\r
464 } else {\r
465 showEdit(selectedRow);\r
466 }\r
467 }\r
468 }\r
469\r
470 /* (non-Javadoc)\r
471 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r
472 * \r
473 * Override componentResized to resize all components when frame's size is changed\r
474 */\r
475 public void componentResized(ComponentEvent arg0) {\r
476 int intCurrentWidth = this.getJContentPane().getWidth();\r
477 int intCurrentHeight = this.getJContentPane().getHeight();\r
478 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r
479 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r
480\r
481 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
482 intPreferredHeight);\r
483 Tools.relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
484 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON,\r
485 DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r
486 Tools.relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
487 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON,\r
488 DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r
489 Tools.relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r
490 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON,\r
491 DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r
492 }\r
493}\r