]>
Commit | Line | Data |
---|---|---|
a13899c5 | 1 | /** @file\r |
2 | \r | |
3 | The file is used to create, update BootModes 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 | |
06a19cee | 18 | import java.awt.Dimension;\r |
a13899c5 | 19 | import java.awt.event.ActionEvent;\r |
20 | import java.awt.event.ComponentEvent;\r | |
06a19cee | 21 | import java.awt.event.MouseEvent;\r |
a13899c5 | 22 | import java.util.Vector;\r |
23 | \r | |
24 | import javax.swing.JButton;\r | |
a13899c5 | 25 | import javax.swing.JPanel;\r |
26 | import javax.swing.JScrollPane;\r | |
06a19cee | 27 | import javax.swing.JTable;\r |
28 | import javax.swing.ListSelectionModel;\r | |
29 | import javax.swing.event.ListSelectionEvent;\r | |
a13899c5 | 30 | \r |
31 | import org.tianocore.BootModeNames;\r | |
32 | import org.tianocore.BootModeUsage;\r | |
33 | import org.tianocore.BootModesDocument;\r | |
34 | import org.tianocore.BootModesDocument.BootModes;\r | |
35 | import org.tianocore.BootModesDocument.BootModes.BootMode;\r | |
36 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r | |
37 | import org.tianocore.frameworkwizard.common.DataType;\r | |
06a19cee | 38 | import org.tianocore.frameworkwizard.common.IDefaultTableModel;\r |
a13899c5 | 39 | import org.tianocore.frameworkwizard.common.Log;\r |
a13899c5 | 40 | import org.tianocore.frameworkwizard.common.Tools;\r |
79cb6fdb | 41 | import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r |
06a19cee | 42 | import org.tianocore.frameworkwizard.common.ui.IFrame;\r |
a13899c5 | 43 | import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r |
79cb6fdb | 44 | import org.tianocore.frameworkwizard.module.Identifications.BootModes.BootModesIdentification;\r |
45 | import org.tianocore.frameworkwizard.module.Identifications.BootModes.BootModesVector;\r | |
06a19cee | 46 | import org.tianocore.frameworkwizard.module.ui.dialog.BootModesDlg;\r |
a13899c5 | 47 | \r |
48 | /**\r | |
49 | The class is used to create, update BootModes of MSA/MBD file\r | |
50 | It extends IInternalFrame\r | |
51 | \r | |
52 | \r | |
53 | \r | |
54 | **/\r | |
55 | public class ModuleBootModes extends IInternalFrame {\r | |
56 | \r | |
57 | ///\r | |
58 | /// Define class Serial Version UID\r | |
59 | ///\r | |
60 | private static final long serialVersionUID = -3888558623432442561L;\r | |
61 | \r | |
62 | //\r | |
63 | //Define class members\r | |
64 | //\r | |
65 | private JPanel jContentPane = null;\r | |
66 | \r | |
a13899c5 | 67 | private JButton jButtonAdd = null;\r |
68 | \r | |
69 | private JButton jButtonRemove = null;\r | |
70 | \r | |
71 | private JButton jButtonUpdate = null;\r | |
72 | \r | |
73 | private JScrollPane jScrollPane = null;\r | |
74 | \r | |
06a19cee | 75 | private JScrollPane jScrollPaneTable = null;\r |
a13899c5 | 76 | \r |
06a19cee | 77 | private JTable jTable = null;\r |
a9e882c9 | 78 | \r |
79 | private IFrame parentFrame = null;\r | |
a13899c5 | 80 | \r |
81 | //\r | |
82 | // Not used by UI\r | |
83 | //\r | |
a13899c5 | 84 | private OpeningModuleType omt = null;\r |
85 | \r | |
86 | private ModuleSurfaceArea msa = null;\r | |
87 | \r | |
88 | private BootModesDocument.BootModes bootModes = null;\r | |
89 | \r | |
90 | private BootModesIdentification id = null;\r | |
91 | \r | |
92 | private BootModesVector vid = new BootModesVector();\r | |
93 | \r | |
06a19cee | 94 | private IDefaultTableModel model = null;\r |
a13899c5 | 95 | \r |
06a19cee | 96 | private int selectedRow = -1;\r |
a13899c5 | 97 | \r |
98 | /**\r | |
99 | This method initializes jButtonAdd \r | |
100 | \r | |
101 | @return javax.swing.JButton jButtonAdd\r | |
102 | \r | |
103 | **/\r | |
104 | private JButton getJButtonAdd() {\r | |
105 | if (jButtonAdd == null) {\r | |
106 | jButtonAdd = new JButton();\r | |
3767c118 | 107 | jButtonAdd.setBounds(new java.awt.Rectangle(210, 195, 90, 20));\r |
a13899c5 | 108 | jButtonAdd.setText("Add");\r |
109 | jButtonAdd.addActionListener(this);\r | |
3767c118 | 110 | jButtonAdd.setPreferredSize(new java.awt.Dimension(90, 20));\r |
a13899c5 | 111 | }\r |
112 | return jButtonAdd;\r | |
113 | }\r | |
114 | \r | |
115 | /**\r | |
116 | This method initializes jButtonRemove \r | |
117 | \r | |
118 | @return javax.swing.JButton jButtonRemove\r | |
119 | \r | |
120 | **/\r | |
121 | private JButton getJButtonRemove() {\r | |
122 | if (jButtonRemove == null) {\r | |
123 | jButtonRemove = new JButton();\r | |
3767c118 | 124 | jButtonRemove.setBounds(new java.awt.Rectangle(390, 195, 90, 20));\r |
a13899c5 | 125 | jButtonRemove.setText("Remove");\r |
126 | jButtonRemove.addActionListener(this);\r | |
3767c118 | 127 | jButtonRemove.setPreferredSize(new java.awt.Dimension(90, 20));\r |
a13899c5 | 128 | }\r |
129 | return jButtonRemove;\r | |
130 | }\r | |
131 | \r | |
132 | /**\r | |
133 | This method initializes jButtonUpdate \r | |
134 | \r | |
135 | @return javax.swing.JButton jButtonUpdate\r | |
136 | \r | |
137 | **/\r | |
138 | private JButton getJButtonUpdate() {\r | |
139 | if (jButtonUpdate == null) {\r | |
140 | jButtonUpdate = new JButton();\r | |
3767c118 | 141 | jButtonUpdate.setBounds(new java.awt.Rectangle(315, 195, 90, 20));\r |
142 | jButtonUpdate.setPreferredSize(new java.awt.Dimension(90, 20));\r | |
06a19cee | 143 | jButtonUpdate.setText("Edit");\r |
a13899c5 | 144 | jButtonUpdate.addActionListener(this);\r |
145 | }\r | |
146 | return jButtonUpdate;\r | |
147 | }\r | |
148 | \r | |
a13899c5 | 149 | /**\r |
150 | This method initializes jScrollPane \r | |
151 | \r | |
152 | @return javax.swing.JScrollPane \r | |
153 | */\r | |
154 | private JScrollPane getJScrollPane() {\r | |
155 | if (jScrollPane == null) {\r | |
156 | jScrollPane = new JScrollPane();\r | |
157 | jScrollPane.setViewportView(getJContentPane());\r | |
158 | }\r | |
159 | return jScrollPane;\r | |
160 | }\r | |
161 | \r | |
162 | /**\r | |
06a19cee | 163 | This method initializes jScrollPaneTable \r |
164 | \r | |
165 | @return javax.swing.JScrollPane \r | |
166 | **/\r | |
167 | private JScrollPane getJScrollPaneTable() {\r | |
168 | if (jScrollPaneTable == null) {\r | |
169 | jScrollPaneTable = new JScrollPane();\r | |
170 | jScrollPaneTable.setBounds(new java.awt.Rectangle(15, 10, 470, 420));\r | |
171 | jScrollPaneTable.setPreferredSize(new Dimension(470, 420));\r | |
172 | jScrollPaneTable.setViewportView(getJTable());\r | |
a13899c5 | 173 | }\r |
06a19cee | 174 | return jScrollPaneTable;\r |
a13899c5 | 175 | }\r |
176 | \r | |
177 | /**\r | |
06a19cee | 178 | This method initializes jTable \r |
179 | \r | |
180 | @return javax.swing.JTable \r | |
a13899c5 | 181 | **/\r |
06a19cee | 182 | private JTable getJTable() {\r |
183 | if (jTable == null) {\r | |
184 | jTable = new JTable();\r | |
185 | model = new IDefaultTableModel();\r | |
186 | jTable = new JTable(model);\r | |
187 | jTable.setRowHeight(20);\r | |
188 | \r | |
189 | model.addColumn("Name");\r | |
190 | model.addColumn("Usage");\r | |
191 | \r | |
ff7bc6c4 | 192 | jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);\r |
06a19cee | 193 | jTable.getSelectionModel().addListSelectionListener(this);\r |
194 | jTable.getModel().addTableModelListener(this);\r | |
195 | jTable.addMouseListener(this);\r | |
a13899c5 | 196 | }\r |
06a19cee | 197 | return jTable;\r |
a13899c5 | 198 | }\r |
199 | \r | |
06a19cee | 200 | public static void main(String[] args) {\r |
201 | }\r | |
a13899c5 | 202 | \r |
06a19cee | 203 | /**\r |
204 | This method initializes this\r | |
205 | \r | |
a13899c5 | 206 | **/\r |
06a19cee | 207 | private void init() {\r |
208 | this.setSize(500, 515);\r | |
209 | this.setContentPane(getJScrollPane());\r | |
210 | this.setTitle("Boot Modes");\r | |
a13899c5 | 211 | }\r |
06a19cee | 212 | \r |
a13899c5 | 213 | /**\r |
06a19cee | 214 | This method initializes this\r |
215 | Fill values to all fields if these values are not empty\r | |
216 | \r | |
217 | @param inBootModes\r | |
a13899c5 | 218 | \r |
06a19cee | 219 | **/\r |
220 | private void init(BootModes inBootModes) {\r | |
221 | init();\r | |
222 | this.bootModes = inBootModes;\r | |
223 | \r | |
224 | if (this.bootModes != null) {\r | |
225 | if (this.bootModes.getBootModeList().size() > 0) {\r | |
226 | for (int index = 0; index < this.bootModes.getBootModeList().size(); index++) {\r | |
227 | String arg0 = null;\r | |
228 | if (bootModes.getBootModeList().get(index).getBootModeName() != null) {\r | |
229 | arg0 = bootModes.getBootModeList().get(index).getBootModeName().toString();\r | |
230 | }\r | |
231 | String arg1 = null;\r | |
232 | if (bootModes.getBootModeList().get(index).getUsage() != null) {\r | |
233 | arg1 = bootModes.getBootModeList().get(index).getUsage().toString();\r | |
234 | }\r | |
235 | \r | |
236 | String arg2 = bootModes.getBootModeList().get(index).getFeatureFlag();\r | |
237 | Vector<String> arg3 = Tools.convertListToVector(bootModes.getBootModeList().get(index)\r | |
238 | .getSupArchList());\r | |
239 | String arg4 = bootModes.getBootModeList().get(index).getHelpText();\r | |
240 | \r | |
241 | id = new BootModesIdentification(arg0, arg1, arg2, arg3, arg4);\r | |
242 | vid.addBootModes(id);\r | |
243 | }\r | |
244 | }\r | |
245 | }\r | |
246 | showTable();\r | |
a13899c5 | 247 | }\r |
a13899c5 | 248 | \r |
249 | /**\r | |
250 | This is the default constructor\r | |
251 | \r | |
252 | **/\r | |
253 | public ModuleBootModes() {\r | |
254 | super();\r | |
255 | init();\r | |
256 | this.setVisible(true);\r | |
257 | }\r | |
258 | \r | |
259 | /**\r | |
260 | This is the override edit constructor\r | |
261 | \r | |
262 | @param inBootModes The input BootModesDocument.BootModes\r | |
263 | \r | |
264 | **/\r | |
a9e882c9 | 265 | public ModuleBootModes(OpeningModuleType inOmt, IFrame iFrame) {\r |
a13899c5 | 266 | super();\r |
267 | this.omt = inOmt;\r | |
268 | this.msa = omt.getXmlMsa();\r | |
a9e882c9 | 269 | this.parentFrame = iFrame;\r |
a13899c5 | 270 | init(msa.getBootModes());\r |
271 | this.setVisible(true);\r | |
272 | }\r | |
a13899c5 | 273 | \r |
274 | /**\r | |
275 | This method initializes jContentPane\r | |
276 | \r | |
277 | @return javax.swing.JPanel jContentPane\r | |
278 | \r | |
279 | **/\r | |
280 | private JPanel getJContentPane() {\r | |
281 | if (jContentPane == null) {\r | |
a13899c5 | 282 | jContentPane = new JPanel();\r |
283 | jContentPane.setLayout(null);\r | |
06a19cee | 284 | jContentPane.setPreferredSize(new java.awt.Dimension(490, 490));\r |
285 | \r | |
a13899c5 | 286 | jContentPane.add(getJButtonAdd(), null);\r |
287 | jContentPane.add(getJButtonRemove(), null);\r | |
288 | jContentPane.add(getJButtonUpdate(), null);\r | |
06a19cee | 289 | jContentPane.add(getJScrollPaneTable(), null);\r |
a13899c5 | 290 | }\r |
291 | return jContentPane;\r | |
292 | }\r | |
293 | \r | |
06a19cee | 294 | private void showEdit(int index) {\r |
a9e882c9 | 295 | BootModesDlg dlg = new BootModesDlg(vid.getBootModes(index), this.parentFrame, omt.getId());\r |
06a19cee | 296 | int result = dlg.showDialog();\r |
297 | if (result == DataType.RETURN_TYPE_OK) {\r | |
298 | if (index == -1) {\r | |
299 | this.vid.addBootModes(dlg.getId());\r | |
300 | } else {\r | |
301 | this.vid.setBootModes(dlg.getId(), index);\r | |
302 | }\r | |
303 | this.showTable();\r | |
304 | this.save();\r | |
305 | dlg.dispose();\r | |
306 | }\r | |
307 | if (result == DataType.RETURN_TYPE_CANCEL) {\r | |
308 | dlg.dispose();\r | |
309 | }\r | |
310 | }\r | |
311 | \r | |
312 | /**\r | |
313 | Clear all table rows\r | |
314 | \r | |
315 | **/\r | |
316 | private void clearAll() {\r | |
317 | if (model != null) {\r | |
318 | for (int index = model.getRowCount() - 1; index >= 0; index--) {\r | |
319 | model.removeRow(index);\r | |
320 | }\r | |
321 | }\r | |
322 | }\r | |
323 | \r | |
a13899c5 | 324 | /**\r |
06a19cee | 325 | Read content of vector and put then into table\r |
a13899c5 | 326 | \r |
327 | **/\r | |
06a19cee | 328 | private void showTable() {\r |
329 | clearAll();\r | |
330 | \r | |
331 | if (vid.size() > 0) {\r | |
332 | for (int index = 0; index < vid.size(); index++) {\r | |
333 | model.addRow(vid.toStringVector(index));\r | |
334 | }\r | |
335 | }\r | |
336 | this.jTable.repaint();\r | |
337 | this.jTable.updateUI();\r | |
a13899c5 | 338 | }\r |
339 | \r | |
340 | /* (non-Javadoc)\r | |
341 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
342 | *\r | |
343 | * Override actionPerformed to listen all actions\r | |
344 | * \r | |
345 | */\r | |
346 | public void actionPerformed(ActionEvent arg0) {\r | |
347 | if (arg0.getSource() == jButtonAdd) {\r | |
06a19cee | 348 | showEdit(-1);\r |
a13899c5 | 349 | }\r |
350 | if (arg0.getSource() == jButtonUpdate) {\r | |
06a19cee | 351 | if (this.selectedRow < 0) {\r |
ed1665f2 | 352 | Log.wrn("Update Boot Modes", "Please select one record first.");\r |
a13899c5 | 353 | return;\r |
354 | }\r | |
06a19cee | 355 | showEdit(selectedRow);\r |
a13899c5 | 356 | }\r |
a13899c5 | 357 | \r |
06a19cee | 358 | if (arg0.getSource() == jButtonRemove) {\r |
359 | if (jTable.isEditing()) {\r | |
360 | jTable.getCellEditor().stopCellEditing();\r | |
361 | }\r | |
ff7bc6c4 | 362 | \r |
363 | int selectedRows[] = this.jTable.getSelectedRows();\r | |
364 | \r | |
365 | if (selectedRows != null) {\r | |
366 | for (int index = selectedRows.length - 1; index > -1; index--) {\r | |
367 | this.model.removeRow(selectedRows[index]);\r | |
368 | this.vid.removeBootModes(selectedRows[index]);\r | |
369 | }\r | |
06a19cee | 370 | selectedRow = -1;\r |
371 | this.save();\r | |
a13899c5 | 372 | }\r |
373 | }\r | |
a13899c5 | 374 | }\r |
375 | \r | |
376 | /**\r | |
377 | Save all components of Mbd Header\r | |
378 | if exists bootModes, set the value directly\r | |
379 | if not exists bootModes, 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.bootModes = BootModes.Factory.newInstance();\r | |
387 | if (count > 0) {\r | |
388 | for (int index = 0; index < count; index++) {\r | |
389 | BootMode p = BootMode.Factory.newInstance();\r | |
390 | if (!isEmpty(vid.getBootModes(index).getName())) {\r | |
391 | p.setBootModeName(BootModeNames.Enum.forString(vid.getBootModes(index).getName()));\r | |
392 | }\r | |
393 | if (!isEmpty(vid.getBootModes(index).getUsage())) {\r | |
394 | p.setUsage(BootModeUsage.Enum.forString(vid.getBootModes(index).getUsage()));\r | |
395 | }\r | |
396 | if (!isEmpty(vid.getBootModes(index).getFeatureFlag())) {\r | |
397 | p.setFeatureFlag(vid.getBootModes(index).getFeatureFlag());\r | |
398 | }\r | |
06a19cee | 399 | if (vid.getBootModes(index).getSupArchList() != null\r |
400 | && vid.getBootModes(index).getSupArchList().size() > 0) {\r | |
a13899c5 | 401 | p.setSupArchList(vid.getBootModes(index).getSupArchList());\r |
402 | }\r | |
403 | if (!isEmpty(vid.getBootModes(index).getHelp())) {\r | |
404 | p.setHelpText(vid.getBootModes(index).getHelp());\r | |
405 | }\r | |
406 | this.bootModes.addNewBootMode();\r | |
407 | this.bootModes.setBootModeArray(bootModes.getBootModeList().size() - 1, p);\r | |
408 | }\r | |
409 | }\r | |
410 | \r | |
411 | this.msa.setBootModes(bootModes);\r | |
412 | this.omt.setSaved(false);\r | |
413 | } catch (Exception e) {\r | |
ed1665f2 | 414 | Log.wrn("Update Boot Modes", e.getMessage());\r |
a13899c5 | 415 | Log.err("Update Boot Modes", e.getMessage());\r |
416 | }\r | |
417 | }\r | |
418 | \r | |
06a19cee | 419 | /* (non-Javadoc)\r |
420 | * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r | |
421 | *\r | |
422 | */\r | |
423 | public void valueChanged(ListSelectionEvent arg0) {\r | |
424 | if (arg0.getValueIsAdjusting()) {\r | |
425 | return;\r | |
426 | }\r | |
427 | ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r | |
428 | if (lsm.isSelectionEmpty()) {\r | |
429 | return;\r | |
430 | } else {\r | |
431 | selectedRow = lsm.getMinSelectionIndex();\r | |
432 | }\r | |
433 | }\r | |
434 | \r | |
435 | /* (non-Javadoc)\r | |
436 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r | |
437 | *\r | |
438 | */\r | |
439 | public void mouseClicked(MouseEvent arg0) {\r | |
440 | if (arg0.getClickCount() == 2) {\r | |
441 | if (this.selectedRow < 0) {\r | |
442 | return;\r | |
443 | } else {\r | |
444 | showEdit(selectedRow);\r | |
445 | }\r | |
446 | }\r | |
447 | }\r | |
448 | \r | |
a13899c5 | 449 | /* (non-Javadoc)\r |
450 | * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r | |
451 | * \r | |
452 | * Override componentResized to resize all components when frame's size is changed\r | |
453 | */\r | |
454 | public void componentResized(ComponentEvent arg0) {\r | |
455 | int intCurrentWidth = this.getJContentPane().getWidth();\r | |
456 | int intCurrentHeight = this.getJContentPane().getHeight();\r | |
457 | int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r | |
458 | int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r | |
459 | \r | |
8792f60f | 460 | Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r |
461 | intPreferredHeight);\r | |
462 | Tools.relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r | |
463 | intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON,\r | |
464 | DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r | |
465 | Tools.relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r | |
466 | intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON,\r | |
467 | DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r | |
468 | Tools.relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r | |
469 | intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON,\r | |
470 | DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r | |
a13899c5 | 471 | }\r |
a13899c5 | 472 | }\r |