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 |
15 | package org.tianocore.frameworkwizard.module.ui;\r |
16 | \r |
06a19cee |
17 | import java.awt.Dimension;\r |
a13899c5 |
18 | import java.awt.event.ActionEvent;\r |
19 | import java.awt.event.ComponentEvent;\r |
06a19cee |
20 | import java.awt.event.MouseEvent;\r |
a13899c5 |
21 | import java.util.Vector;\r |
22 | \r |
23 | import javax.swing.JButton;\r |
a13899c5 |
24 | import javax.swing.JPanel;\r |
25 | import javax.swing.JScrollPane;\r |
06a19cee |
26 | import javax.swing.JTable;\r |
27 | import javax.swing.ListSelectionModel;\r |
28 | import javax.swing.event.ListSelectionEvent;\r |
a13899c5 |
29 | \r |
30 | import org.tianocore.PPIsDocument;\r |
31 | import org.tianocore.PpiNotifyUsage;\r |
32 | import org.tianocore.PpiUsage;\r |
33 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r |
34 | import org.tianocore.PPIsDocument.PPIs;\r |
35 | import org.tianocore.PPIsDocument.PPIs.Ppi;\r |
36 | import org.tianocore.PPIsDocument.PPIs.PpiNotify;\r |
37 | import org.tianocore.frameworkwizard.common.DataType;\r |
a13899c5 |
38 | import org.tianocore.frameworkwizard.common.EnumerationData;\r |
06a19cee |
39 | import org.tianocore.frameworkwizard.common.IDefaultTableModel;\r |
a13899c5 |
40 | import org.tianocore.frameworkwizard.common.Log;\r |
a13899c5 |
41 | import org.tianocore.frameworkwizard.common.Tools;\r |
79cb6fdb |
42 | import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r |
06a19cee |
43 | import org.tianocore.frameworkwizard.common.ui.IFrame;\r |
a13899c5 |
44 | import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r |
79cb6fdb |
45 | import org.tianocore.frameworkwizard.module.Identifications.Ppis.PpisIdentification;\r |
46 | import org.tianocore.frameworkwizard.module.Identifications.Ppis.PpisVector;\r |
06a19cee |
47 | import 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 |
54 | public 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 |
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 |
107 | jButtonAdd.setBounds(new java.awt.Rectangle(230, 220, 80, 20));\r |
108 | jButtonAdd.setText("Add");\r |
109 | jButtonAdd.addActionListener(this);\r |
110 | jButtonAdd.setPreferredSize(new java.awt.Dimension(80, 20));\r |
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 |
124 | jButtonRemove.setBounds(new java.awt.Rectangle(400, 220, 80, 20));\r |
125 | jButtonRemove.setText("Remove");\r |
126 | jButtonRemove.addActionListener(this);\r |
127 | jButtonRemove.setPreferredSize(new java.awt.Dimension(80, 20));\r |
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 |
141 | jButtonUpdate.setBounds(new java.awt.Rectangle(315, 220, 80, 20));\r |
142 | jButtonUpdate.setPreferredSize(new java.awt.Dimension(80, 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 |
a13899c5 |
179 | \r |
06a19cee |
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("Guid C_Name");\r |
190 | model.addColumn("Type");\r |
191 | model.addColumn("Usage");\r |
192 | \r |
193 | jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r |
194 | jTable.getSelectionModel().addListSelectionListener(this);\r |
195 | jTable.getModel().addTableModelListener(this);\r |
196 | jTable.addMouseListener(this);\r |
a13899c5 |
197 | }\r |
06a19cee |
198 | return jTable;\r |
199 | }\r |
200 | \r |
201 | public static void main(String[] args) {\r |
202 | \r |
a13899c5 |
203 | }\r |
204 | \r |
205 | /**\r |
06a19cee |
206 | This method initializes this\r |
a13899c5 |
207 | \r |
208 | **/\r |
06a19cee |
209 | private void init() {\r |
210 | this.setSize(500, 515);\r |
211 | this.setContentPane(getJScrollPane());\r |
212 | this.setTitle("Ppis");\r |
a13899c5 |
213 | }\r |
06a19cee |
214 | \r |
a13899c5 |
215 | /**\r |
06a19cee |
216 | This method initializes this\r |
217 | Fill values to all fields if these values are not empty\r |
218 | \r |
219 | @param inPackageDependencies\r |
a13899c5 |
220 | \r |
06a19cee |
221 | **/\r |
222 | private void init(PPIs inPpis) {\r |
223 | init();\r |
224 | this.ppis = inPpis;\r |
225 | \r |
226 | if (this.ppis != null) {\r |
227 | if (this.ppis.getPpiList().size() > 0) {\r |
228 | for (int index = 0; index < this.ppis.getPpiList().size(); index++) {\r |
229 | String arg0 = ppis.getPpiList().get(index).getPpiCName();\r |
230 | String arg1 = ed.getVPpiType().get(0);\r |
231 | String arg2 = null;\r |
232 | if (ppis.getPpiList().get(index).getUsage() != null) {\r |
233 | arg2 = ppis.getPpiList().get(index).getUsage().toString();\r |
234 | }\r |
235 | \r |
236 | String arg3 = ppis.getPpiList().get(index).getFeatureFlag();\r |
237 | Vector<String> arg4 = Tools.convertListToVector(ppis.getPpiList().get(index).getSupArchList());\r |
238 | String arg5 = ppis.getPpiList().get(index).getHelpText();\r |
239 | \r |
240 | id = new PpisIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r |
241 | vid.addPpis(id);\r |
242 | }\r |
243 | }\r |
244 | if (this.ppis.getPpiNotifyList().size() > 0) {\r |
245 | for (int index = 0; index < this.ppis.getPpiNotifyList().size(); index++) {\r |
246 | String arg0 = ppis.getPpiNotifyList().get(index).getPpiNotifyCName();\r |
247 | String arg1 = ed.getVPpiType().get(1);\r |
248 | String arg2 = null;\r |
249 | if (ppis.getPpiNotifyList().get(index).getUsage() != null) {\r |
250 | arg2 = ppis.getPpiNotifyList().get(index).getUsage().toString();\r |
251 | }\r |
252 | \r |
253 | String arg3 = ppis.getPpiNotifyList().get(index).getFeatureFlag();\r |
254 | Vector<String> arg4 = Tools\r |
255 | .convertListToVector(ppis.getPpiNotifyList().get(index).getSupArchList());\r |
256 | String arg5 = ppis.getPpiNotifyList().get(index).getHelpText();\r |
a13899c5 |
257 | \r |
06a19cee |
258 | id = new PpisIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r |
259 | vid.addPpis(id);\r |
260 | }\r |
261 | }\r |
262 | }\r |
263 | showTable();\r |
a13899c5 |
264 | }\r |
a13899c5 |
265 | \r |
266 | /**\r |
267 | This is the default constructor\r |
268 | \r |
269 | **/\r |
270 | public ModulePpis() {\r |
271 | super();\r |
272 | init();\r |
273 | this.setVisible(true);\r |
274 | }\r |
275 | \r |
276 | /**\r |
277 | This is the override edit constructor\r |
278 | \r |
279 | @param inPpis The input data of PPIsDocument.PPIs\r |
280 | \r |
281 | **/\r |
282 | public ModulePpis(OpeningModuleType inOmt) {\r |
283 | super();\r |
284 | this.omt = inOmt;\r |
285 | this.msa = omt.getXmlMsa();\r |
286 | init(msa.getPPIs());\r |
287 | this.setVisible(true);\r |
288 | }\r |
289 | \r |
a13899c5 |
290 | /**\r |
291 | This method initializes jContentPane\r |
292 | \r |
293 | @return javax.swing.JPanel jContentPane\r |
294 | \r |
295 | **/\r |
296 | private JPanel getJContentPane() {\r |
297 | if (jContentPane == null) {\r |
a13899c5 |
298 | jContentPane = new JPanel();\r |
299 | jContentPane.setLayout(null);\r |
06a19cee |
300 | jContentPane.setPreferredSize(new java.awt.Dimension(490, 490));\r |
301 | \r |
a13899c5 |
302 | jContentPane.add(getJButtonAdd(), null);\r |
303 | jContentPane.add(getJButtonRemove(), null);\r |
304 | jContentPane.add(getJButtonUpdate(), null);\r |
06a19cee |
305 | jContentPane.add(getJScrollPaneTable(), null);\r |
a13899c5 |
306 | }\r |
307 | return jContentPane;\r |
308 | }\r |
309 | \r |
06a19cee |
310 | private void showEdit(int index) {\r |
c25ad66c |
311 | PpisDlg dlg = new PpisDlg(vid.getPpis(index), new IFrame(), omt.getId());\r |
06a19cee |
312 | int result = dlg.showDialog();\r |
313 | if (result == DataType.RETURN_TYPE_OK) {\r |
314 | if (index == -1) {\r |
315 | this.vid.addPpis(dlg.getId());\r |
316 | } else {\r |
317 | this.vid.setPpis(dlg.getId(), index);\r |
318 | }\r |
319 | this.showTable();\r |
320 | this.save();\r |
321 | dlg.dispose();\r |
322 | }\r |
323 | if (result == DataType.RETURN_TYPE_CANCEL) {\r |
324 | dlg.dispose();\r |
325 | }\r |
326 | }\r |
327 | \r |
328 | /**\r |
329 | Clear all table rows\r |
330 | \r |
331 | **/\r |
332 | private void clearAll() {\r |
333 | if (model != null) {\r |
334 | for (int index = model.getRowCount() - 1; index >= 0; index--) {\r |
335 | model.removeRow(index);\r |
336 | }\r |
337 | }\r |
338 | }\r |
339 | \r |
a13899c5 |
340 | /**\r |
06a19cee |
341 | Read content of vector and put then into table\r |
a13899c5 |
342 | \r |
343 | **/\r |
06a19cee |
344 | private void showTable() {\r |
345 | clearAll();\r |
346 | \r |
347 | if (vid.size() > 0) {\r |
348 | for (int index = 0; index < vid.size(); index++) {\r |
349 | model.addRow(vid.toStringVector(index));\r |
350 | }\r |
351 | }\r |
352 | this.jTable.repaint();\r |
353 | this.jTable.updateUI();\r |
a13899c5 |
354 | }\r |
355 | \r |
356 | /* (non-Javadoc)\r |
357 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r |
358 | *\r |
359 | * Override actionPerformed to listen all actions\r |
360 | * \r |
361 | */\r |
362 | public void actionPerformed(ActionEvent arg0) {\r |
363 | if (arg0.getSource() == jButtonAdd) {\r |
06a19cee |
364 | showEdit(-1);\r |
a13899c5 |
365 | }\r |
366 | if (arg0.getSource() == jButtonUpdate) {\r |
06a19cee |
367 | if (this.selectedRow < 0) {\r |
ed1665f2 |
368 | Log.wrn("Update Ppis", "Please select one record first.");\r |
a13899c5 |
369 | return;\r |
370 | }\r |
06a19cee |
371 | showEdit(selectedRow);\r |
a13899c5 |
372 | }\r |
a13899c5 |
373 | \r |
06a19cee |
374 | if (arg0.getSource() == jButtonRemove) {\r |
375 | if (jTable.isEditing()) {\r |
376 | jTable.getCellEditor().stopCellEditing();\r |
a13899c5 |
377 | }\r |
06a19cee |
378 | if (selectedRow > -1) {\r |
379 | this.model.removeRow(selectedRow);\r |
380 | this.vid.removePpis(selectedRow);\r |
381 | selectedRow = -1;\r |
382 | this.save();\r |
a13899c5 |
383 | }\r |
384 | }\r |
a13899c5 |
385 | }\r |
386 | \r |
387 | /**\r |
388 | Save all components of PPIs\r |
389 | if exists ppis, set the value directly\r |
390 | if not exists ppis, new an instance first\r |
391 | \r |
392 | **/\r |
393 | public void save() {\r |
394 | try {\r |
395 | int count = this.vid.size();\r |
396 | \r |
397 | this.ppis = PPIs.Factory.newInstance();\r |
398 | if (count > 0) {\r |
399 | for (int index = 0; index < count; index++) {\r |
400 | if (vid.getPpis(index).getType().equals(ed.getVPpiType().get(0))) {\r |
401 | Ppi p = Ppi.Factory.newInstance();\r |
402 | if (!isEmpty(vid.getPpis(index).getName())) {\r |
403 | p.setPpiCName(vid.getPpis(index).getName());\r |
404 | }\r |
405 | if (!isEmpty(vid.getPpis(index).getUsage())) {\r |
406 | p.setUsage(PpiUsage.Enum.forString(vid.getPpis(index).getUsage()));\r |
407 | }\r |
408 | if (!isEmpty(vid.getPpis(index).getFeatureFlag())) {\r |
409 | p.setFeatureFlag(vid.getPpis(index).getFeatureFlag());\r |
410 | }\r |
411 | if (vid.getPpis(index).getSupArchList() != null\r |
412 | && vid.getPpis(index).getSupArchList().size() > 0) {\r |
413 | p.setSupArchList(vid.getPpis(index).getSupArchList());\r |
414 | }\r |
415 | if (!isEmpty(vid.getPpis(index).getHelp())) {\r |
416 | p.setHelpText(vid.getPpis(index).getHelp());\r |
417 | }\r |
418 | this.ppis.addNewPpi();\r |
419 | this.ppis.setPpiArray(ppis.getPpiList().size() - 1, p);\r |
420 | }\r |
421 | if (vid.getPpis(index).getType().equals(ed.getVPpiType().get(1))) {\r |
422 | PpiNotify p = PpiNotify.Factory.newInstance();\r |
423 | if (!isEmpty(vid.getPpis(index).getName())) {\r |
424 | p.setPpiNotifyCName(vid.getPpis(index).getName());\r |
425 | }\r |
426 | if (!isEmpty(vid.getPpis(index).getUsage())) {\r |
427 | p.setUsage(PpiNotifyUsage.Enum.forString(vid.getPpis(index).getUsage()));\r |
428 | }\r |
429 | if (!isEmpty(vid.getPpis(index).getFeatureFlag())) {\r |
430 | p.setFeatureFlag(vid.getPpis(index).getFeatureFlag());\r |
431 | }\r |
432 | if (vid.getPpis(index).getSupArchList() != null\r |
433 | && vid.getPpis(index).getSupArchList().size() > 0) {\r |
434 | p.setSupArchList(vid.getPpis(index).getSupArchList());\r |
435 | }\r |
436 | if (!isEmpty(vid.getPpis(index).getHelp())) {\r |
437 | p.setHelpText(vid.getPpis(index).getHelp());\r |
438 | }\r |
439 | this.ppis.addNewPpiNotify();\r |
440 | this.ppis.setPpiNotifyArray(ppis.getPpiNotifyList().size() - 1, p);\r |
441 | }\r |
442 | }\r |
443 | }\r |
444 | \r |
445 | this.msa.setPPIs(ppis);\r |
446 | this.omt.setSaved(false);\r |
447 | } catch (Exception e) {\r |
ed1665f2 |
448 | Log.wrn("Update Ppis", e.getMessage());\r |
a13899c5 |
449 | Log.err("Update Ppis", e.getMessage());\r |
450 | }\r |
451 | }\r |
452 | \r |
06a19cee |
453 | /* (non-Javadoc)\r |
454 | * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r |
455 | *\r |
456 | */\r |
457 | public void valueChanged(ListSelectionEvent arg0) {\r |
458 | if (arg0.getValueIsAdjusting()) {\r |
459 | return;\r |
460 | }\r |
461 | ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r |
462 | if (lsm.isSelectionEmpty()) {\r |
463 | return;\r |
464 | } else {\r |
465 | selectedRow = lsm.getMinSelectionIndex();\r |
466 | }\r |
467 | }\r |
468 | \r |
469 | /* (non-Javadoc)\r |
470 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r |
471 | *\r |
472 | */\r |
473 | public void mouseClicked(MouseEvent arg0) {\r |
474 | if (arg0.getClickCount() == 2) {\r |
475 | if (this.selectedRow < 0) {\r |
476 | return;\r |
477 | } else {\r |
478 | showEdit(selectedRow);\r |
479 | }\r |
480 | }\r |
481 | }\r |
482 | \r |
a13899c5 |
483 | /* (non-Javadoc)\r |
484 | * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r |
485 | * \r |
486 | * Override componentResized to resize all components when frame's size is changed\r |
487 | */\r |
488 | public void componentResized(ComponentEvent arg0) {\r |
489 | int intCurrentWidth = this.getJContentPane().getWidth();\r |
490 | int intCurrentHeight = this.getJContentPane().getHeight();\r |
491 | int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r |
492 | int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r |
493 | \r |
8792f60f |
494 | Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r |
495 | intPreferredHeight);\r |
496 | Tools.relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r |
497 | intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON,\r |
498 | DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r |
499 | Tools.relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r |
500 | intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON,\r |
501 | DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r |
502 | Tools.relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth,\r |
503 | intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON,\r |
504 | DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r |
a13899c5 |
505 | }\r |
a13899c5 |
506 | }\r |