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