Remove empty FfsFileNameGuid element under ModuleSaBuildOptions if user input empty...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFrameworkModules.java
CommitLineData
a13899c5 1package org.tianocore.frameworkwizard.platform.ui;\r
2\r
3import java.awt.BorderLayout;\r
4\r
5import javax.swing.JFrame;\r
6import javax.swing.JOptionPane;\r
7import javax.swing.JPanel;\r
a13899c5 8import javax.swing.JSplitPane;\r
9import javax.swing.JLabel;\r
10import javax.swing.JScrollPane;\r
11import javax.swing.JTable;\r
12import javax.swing.JButton;\r
13import javax.swing.ListSelectionModel;\r
14import javax.swing.table.DefaultTableModel;\r
15\r
16import org.tianocore.PlatformSurfaceAreaDocument;\r
d6d24759 17import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformType;\r
a13899c5 18import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r
19import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;\r
20import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;\r
21import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;\r
22\r
23import java.awt.FlowLayout;\r
24import java.io.File;\r
25import java.util.ArrayList;\r
26import java.util.HashMap;\r
27import java.util.Iterator;\r
28import java.util.Map;\r
29import java.util.Set;\r
bf5abaff 30import java.util.Vector;\r
a13899c5 31\r
32public class FpdFrameworkModules extends IInternalFrame {\r
33\r
44053733 34 /**\r
35 * \r
36 */\r
37 private static final long serialVersionUID = 1L;\r
a13899c5 38 static JFrame frame;\r
39 private JSplitPane jSplitPane = null;\r
40 private JPanel jPanel = null;\r
41 private JPanel jPanel1 = null;\r
42 private JLabel jLabel = null;\r
43 private JScrollPane jScrollPane = null;\r
44 private JTable jTable = null;\r
45 private JPanel jPanel2 = null;\r
46 private JButton jButton = null;\r
47 private JLabel jLabel1 = null;\r
48 private JPanel jPanel3 = null;\r
49 private JScrollPane jScrollPane1 = null;\r
50 private JTable jTable1 = null;\r
51 private JButton jButton1 = null;\r
52 private JButton jButton2 = null;\r
53 private NonEditableTableModel model = null;\r
54 private NonEditableTableModel model1 = null;\r
55 \r
56 private FpdModuleSA settingDlg = null;\r
57 \r
58 private FpdFileContents ffc = null;\r
d6d24759 59 private OpeningPlatformType docConsole = null;\r
bf5abaff 60 private Map<String, ArrayList<String>> fpdMsa = null;\r
a13899c5 61 \r
62 private ArrayList<ModuleIdentification> miList = null;\r
63\r
64 /**\r
65 * This method initializes jSplitPane \r
66 * \r
67 * @return javax.swing.JSplitPane \r
68 */\r
69 private JSplitPane getJSplitPane() {\r
70 if (jSplitPane == null) {\r
71 jSplitPane = new JSplitPane();\r
72 jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);\r
73 jSplitPane.setDividerLocation(250);\r
74 jSplitPane.setBottomComponent(getJPanel1());\r
75 jSplitPane.setTopComponent(getJPanel());\r
76 }\r
77 return jSplitPane;\r
78 }\r
79\r
80 /**\r
81 * This method initializes jPanel \r
82 * \r
83 * @return javax.swing.JPanel \r
84 */\r
85 private JPanel getJPanel() {\r
86 if (jPanel == null) {\r
87 jLabel = new JLabel();\r
88 jLabel.setText("Modules in Workspace");\r
89 jPanel = new JPanel();\r
90 jPanel.setLayout(new BorderLayout());\r
91 jPanel.add(jLabel, java.awt.BorderLayout.NORTH);\r
92 jPanel.add(getJScrollPane(), java.awt.BorderLayout.CENTER);\r
93 jPanel.add(getJPanel2(), java.awt.BorderLayout.SOUTH);\r
94 }\r
95 return jPanel;\r
96 }\r
97\r
98 /**\r
99 * This method initializes jPanel1 \r
100 * \r
101 * @return javax.swing.JPanel \r
102 */\r
103 private JPanel getJPanel1() {\r
104 if (jPanel1 == null) {\r
105 jLabel1 = new JLabel();\r
106 jLabel1.setText("Modules Added");\r
107 jPanel1 = new JPanel();\r
108 jPanel1.setLayout(new BorderLayout());\r
109 jPanel1.add(jLabel1, java.awt.BorderLayout.NORTH);\r
110 jPanel1.add(getJPanel3(), java.awt.BorderLayout.SOUTH);\r
111 jPanel1.add(getJScrollPane1(), java.awt.BorderLayout.CENTER);\r
112 }\r
113 return jPanel1;\r
114 }\r
115\r
116 /**\r
117 * This method initializes jScrollPane \r
118 * \r
119 * @return javax.swing.JScrollPane \r
120 */\r
121 private JScrollPane getJScrollPane() {\r
122 if (jScrollPane == null) {\r
123 jScrollPane = new JScrollPane();\r
124 jScrollPane.setPreferredSize(new java.awt.Dimension(600,200));\r
125 jScrollPane.setViewportView(getJTable());\r
126 }\r
127 return jScrollPane;\r
128 }\r
129\r
130 /**\r
131 * This method initializes jTable \r
132 * \r
133 * @return javax.swing.JTable \r
134 */\r
135 private JTable getJTable() {\r
136 if (jTable == null) {\r
137 model = new NonEditableTableModel();\r
138 jTable = new JTable(model);\r
f3b0ed9a 139 jTable.setRowHeight(20);\r
a13899c5 140 model.addColumn("ModuleName");\r
a13899c5 141 model.addColumn("ModuleVersion");\r
bf5abaff 142 model.addColumn("PackageName");\r
a13899c5 143 model.addColumn("PackageVersion");\r
bf5abaff 144 model.addColumn("Path");\r
a13899c5 145 \r
146 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
147 }\r
148 return jTable;\r
149 }\r
150\r
151 /**\r
152 * This method initializes jPanel2 \r
153 * \r
154 * @return javax.swing.JPanel \r
155 */\r
156 private JPanel getJPanel2() {\r
157 if (jPanel2 == null) {\r
158 FlowLayout flowLayout = new FlowLayout();\r
159 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);\r
160 jPanel2 = new JPanel();\r
161 jPanel2.setLayout(flowLayout);\r
162 jPanel2.add(getJButton(), null);\r
163 }\r
164 return jPanel2;\r
165 }\r
166\r
167 /**\r
168 * This method initializes jButton \r
169 * \r
170 * @return javax.swing.JButton \r
171 */\r
172 private JButton getJButton() {\r
173 if (jButton == null) {\r
174 jButton = new JButton();\r
175 jButton.setPreferredSize(new java.awt.Dimension(130,20));\r
176 jButton.setText("Add a Module");\r
177 jButton.addActionListener(new java.awt.event.ActionListener() {\r
178 public void actionPerformed(java.awt.event.ActionEvent e) {\r
179 int selectedRow = jTable.getSelectedRow();\r
180 if (selectedRow < 0){\r
181 return;\r
182 }\r
183 \r
bf5abaff 184 String path = model.getValueAt(selectedRow, 4)+"";\r
185 ModuleIdentification mi = miList.get(selectedRow);\r
186 Vector<String> vArchs = null;\r
187 try {\r
188 vArchs = GlobalData.getModuleSupArchs(mi);\r
189 }\r
190 catch (Exception exp) {\r
191 JOptionPane.showMessageDialog(frame, exp.getMessage());\r
a13899c5 192 }\r
a13899c5 193 \r
bf5abaff 194 if (vArchs == null) {\r
195 JOptionPane.showMessageDialog(frame, "No supported Archs specified in MSA file.");\r
196 return;\r
a13899c5 197 }\r
af25df16 198 \r
bf5abaff 199 String archsAdded = "";\r
200 String mg = mi.getGuid();\r
201 String mv = mi.getVersion();\r
202 String pg = mi.getPackage().getGuid();\r
203 String pv = mi.getPackage().getVersion();\r
204 \r
205 ArrayList<String> al = fpdMsa.get(mg + mv + pg + pv);\r
206 if (al == null) {\r
207 al = new ArrayList<String>();\r
208 fpdMsa.put(mg + mv + pg + pv, al);\r
209 }\r
210 for (int i = 0; i < al.size(); ++i) {\r
211 vArchs.remove(al.get(i));\r
212 }\r
213 //\r
214 // Archs this Module supported have already been added.\r
215 //\r
216 if (vArchs.size() == 0) {\r
217 JOptionPane.showMessageDialog(frame, "This Module Already Added.");\r
218 return;\r
af25df16 219 }\r
bf5abaff 220 //ToDo put Arch instead of null\r
221 for (int i = 0; i < vArchs.size(); ++i) {\r
222 String arch = vArchs.get(i);\r
223 al.add(arch);\r
224 archsAdded += arch + " ";\r
225 String[] row = {"", mv, "", pv, arch, path};\r
226 \r
227 if (mi != null) {\r
228 row[0] = mi.getName();\r
229 row[2] = mi.getPackage().getName();\r
230 \r
231 }\r
232 model1.addRow(row);\r
233 \r
234 docConsole.setSaved(false);\r
235 try{\r
236 //ToDo : specify archs need to add.\r
237 ffc.addFrameworkModulesPcdBuildDefs(mi, arch, null);\r
238 }\r
239 catch (Exception exception) {\r
240 JOptionPane.showMessageDialog(frame, "PCD Insertion Fail. " + exception.getMessage());\r
241 }\r
82961247 242 }\r
bf5abaff 243 \r
244 \r
245 JOptionPane.showMessageDialog(frame, "This Module with Arch "+ archsAdded +" Added Successfully.");\r
af25df16 246 jTable1.changeSelection(model1.getRowCount()-1, 0, false, false);\r
82961247 247 }\r
a13899c5 248 });\r
249 }\r
250 return jButton;\r
251 }\r
252\r
253 /**\r
254 * This method initializes jPanel3 \r
255 * \r
256 * @return javax.swing.JPanel \r
257 */\r
258 private JPanel getJPanel3() {\r
259 if (jPanel3 == null) {\r
260 FlowLayout flowLayout1 = new FlowLayout();\r
261 flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);\r
262 jPanel3 = new JPanel();\r
263 jPanel3.setLayout(flowLayout1);\r
264 jPanel3.add(getJButton1(), null);\r
265 jPanel3.add(getJButton2(), null);\r
266 }\r
267 return jPanel3;\r
268 }\r
269\r
270 /**\r
271 * This method initializes jScrollPane1 \r
272 * \r
273 * @return javax.swing.JScrollPane \r
274 */\r
275 private JScrollPane getJScrollPane1() {\r
276 if (jScrollPane1 == null) {\r
277 jScrollPane1 = new JScrollPane();\r
278 jScrollPane1.setPreferredSize(new java.awt.Dimension(453,200));\r
279 jScrollPane1.setViewportView(getJTable1());\r
280 }\r
281 return jScrollPane1;\r
282 }\r
283\r
284 /**\r
285 * This method initializes jTable1 \r
286 * \r
287 * @return javax.swing.JTable \r
288 */\r
289 private JTable getJTable1() {\r
290 if (jTable1 == null) {\r
291 model1 = new NonEditableTableModel();\r
292 jTable1 = new JTable(model1);\r
f3b0ed9a 293 jTable1.setRowHeight(20);\r
a13899c5 294 model1.addColumn("ModuleName");\r
a13899c5 295 model1.addColumn("ModuleVersion"); \r
bf5abaff 296 model1.addColumn("PackageName");\r
a13899c5 297 model1.addColumn("PackageVersion");\r
bf5abaff 298 model1.addColumn("SupportedArch");\r
299 model1.addColumn("Path");\r
a13899c5 300 \r
301 jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
302 }\r
303 return jTable1;\r
304 }\r
305\r
306 /**\r
307 * This method initializes jButton1 \r
308 * \r
309 * @return javax.swing.JButton \r
310 */\r
311 private JButton getJButton1() {\r
312 if (jButton1 == null) {\r
313 jButton1 = new JButton();\r
314 jButton1.setPreferredSize(new java.awt.Dimension(130,20));\r
315 jButton1.setText("Settings");\r
316 jButton1.addActionListener(new java.awt.event.ActionListener() {\r
317 public void actionPerformed(java.awt.event.ActionEvent e) {\r
318 int selectedRow = jTable1.getSelectedRow();\r
319 if (selectedRow < 0){\r
320 return;\r
321 }\r
322 if (settingDlg == null) {\r
323 settingDlg = new FpdModuleSA(ffc);\r
324 }\r
8f55ea73 325 \r
bf5abaff 326 String[] sa = new String[5];\r
327 ffc.getFrameworkModuleInfo(selectedRow, sa);\r
328 String mg = sa[0];\r
329 String mv = sa[1];\r
330 String pg = sa[2];\r
331 String pv = sa[3];\r
332 String arch = sa[4];\r
8f55ea73 333 settingDlg.setKey(mg + " " + mv + " " + pg + " " + pv + " " + arch, selectedRow, docConsole);\r
a13899c5 334 settingDlg.setVisible(true);\r
335 }\r
336 });\r
337 }\r
338 return jButton1;\r
339 }\r
340\r
341 /**\r
342 * This method initializes jButton2 \r
343 * \r
344 * @return javax.swing.JButton \r
345 */\r
346 private JButton getJButton2() {\r
347 if (jButton2 == null) {\r
348 jButton2 = new JButton();\r
349 jButton2.setPreferredSize(new java.awt.Dimension(130,20));\r
350 jButton2.setText("Remove Module");\r
351 jButton2.addActionListener(new java.awt.event.ActionListener() {\r
352 public void actionPerformed(java.awt.event.ActionEvent e) {\r
353 int selectedRow = jTable1.getSelectedRow();\r
354 if (selectedRow < 0){\r
355 return;\r
356 }\r
bf5abaff 357 String[] sa = new String[5];\r
358 ffc.getFrameworkModuleInfo(selectedRow, sa);\r
359 String mg = sa[0];\r
360 String mv = sa[1];\r
361 String pg = sa[2];\r
362 String pv = sa[3];\r
363 String arch = sa[4];\r
364 ModuleIdentification mi = getModuleId(sa[0] + " " + sa[1] + " " + sa[2] + " " + sa[3] + " " + sa[4]);\r
365 mv = mi.getVersion();\r
366 pv = mi.getPackage().getVersion();\r
a13899c5 367 model1.removeRow(selectedRow);\r
bf5abaff 368 if (arch == null) {\r
369 // if no arch specified in ModuleSA\r
370 fpdMsa.remove(mg+mv+pg+pv);\r
371 }\r
372 else {\r
373 ArrayList<String> al = fpdMsa.get(mg+mv+pg+pv);\r
374 al.remove(arch);\r
375 if (al.size() == 0) {\r
376 fpdMsa.remove(mg+mv+pg+pv);\r
377 }\r
378 }\r
379 \r
380 \r
d6d24759 381 docConsole.setSaved(false);\r
a13899c5 382 ffc.removeModuleSA(selectedRow);\r
383 }\r
384 });\r
385 }\r
386 return jButton2;\r
387 }\r
388\r
389 /**\r
390 * @param args\r
391 */\r
392 public static void main(String[] args) {\r
393 // TODO Auto-generated method stub\r
394 new FpdFrameworkModules().setVisible(true);\r
395 }\r
396\r
397 /**\r
398 * This is the default constructor\r
399 */\r
400 public FpdFrameworkModules() {\r
401 super();\r
402 initialize();\r
403 }\r
404\r
405 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd){\r
406 this();\r
407 init(fpd);\r
408 \r
409 }\r
410 \r
d6d24759 411 public FpdFrameworkModules(OpeningPlatformType opt) {\r
412 this(opt.getXmlFpd());\r
413 docConsole = opt;\r
414 }\r
415 \r
a13899c5 416 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {\r
417 try {\r
418 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", System.getenv("WORKSPACE"));\r
419 }\r
420 catch(Exception e){\r
410e0e9f 421 JOptionPane.showMessageDialog(frame, "Error occurred when getting module data.");\r
a13899c5 422 }\r
423 \r
424 if (ffc == null){\r
425 ffc = new FpdFileContents(fpd);\r
426 ffc.initDynPcdMap();\r
427 }\r
428 \r
429 if (fpdMsa == null) {\r
bf5abaff 430 fpdMsa = new HashMap<String, ArrayList<String>>();\r
a13899c5 431 }\r
432 \r
433 if (ffc.getFrameworkModulesCount() > 0) {\r
434 String[][] saa = new String[ffc.getFrameworkModulesCount()][5];\r
435 ffc.getFrameworkModulesInfo(saa);\r
436 for (int i = 0; i < saa.length; ++i) {\r
bf5abaff 437 ModuleIdentification mi = getModuleId(saa[i][0]+ " "+saa[i][1]+" "+saa[i][2]+" "+saa[i][3]);\r
438 String[] row = {"", "", "", "", "", ""};\r
f3b0ed9a 439 if (mi != null) {\r
bf5abaff 440 row[0] = mi.getName();\r
441 row[1] = mi.getVersion();\r
442 row[2] = mi.getPackage().getName();\r
443 row[3] = mi.getPackage().getVersion();\r
444 row[4] = saa[i][4];\r
445 try{\r
446 row[5] = GlobalData.getMsaFile(mi).getPath().substring(System.getenv("WORKSPACE").length() + 1);\r
447 }\r
448 catch (Exception e) {\r
449 JOptionPane.showMessageDialog(frame, "ShowFPDModules:" + e.getMessage());\r
450 }\r
451 }\r
452 model1.addRow(row);\r
453 ArrayList<String> al = fpdMsa.get(saa[i][0]+row[1]+saa[i][2]+row[3]);\r
454 if (al == null) {\r
455 al = new ArrayList<String>();\r
456 fpdMsa.put(saa[i][0]+row[1]+saa[i][2]+row[3], al);\r
a13899c5 457 }\r
bf5abaff 458 al.add(saa[i][4]);\r
459 \r
a13899c5 460 }\r
461 }\r
462 \r
463 showAllModules();\r
464 \r
465 }\r
466 \r
467 private void showAllModules() {\r
468 \r
469 if (miList == null) {\r
470 miList = new ArrayList<ModuleIdentification>();\r
471 }\r
472 Set<PackageIdentification> spi = GlobalData.getPackageList();\r
473 Iterator ispi = spi.iterator();\r
474 \r
475 while(ispi.hasNext()) {\r
476 PackageIdentification pi = (PackageIdentification)ispi.next();\r
477 String[] s = {"", "", "", "", ""};\r
bf5abaff 478 \r
a13899c5 479 Set<ModuleIdentification> smi = GlobalData.getModules(pi);\r
480 Iterator ismi = smi.iterator();\r
481 while(ismi.hasNext()) {\r
482 ModuleIdentification mi = (ModuleIdentification)ismi.next();\r
483 s[0] = mi.getName();\r
bf5abaff 484 s[1] = mi.getVersion();\r
485 s[2] = pi.getName();\r
486 s[3] = pi.getVersion();\r
487 try {\r
488 s[4] = GlobalData.getMsaFile(mi).getPath().substring(System.getenv("WORKSPACE").length() + 1);\r
489 }\r
490 catch (Exception e) {\r
491 JOptionPane.showMessageDialog(frame, "ShowAllModules:" + e.getMessage());\r
492 }\r
a13899c5 493 model.addRow(s);\r
494 miList.add(mi);\r
495 }\r
496 }\r
497 }\r
498 /**\r
499 * This method initializes this\r
500 * \r
501 * @return void\r
502 */\r
503 private void initialize() {\r
504 this.setSize(633, 533);\r
505 this.setTitle("Framework Modules");\r
506 this.setContentPane(getJSplitPane());\r
507 this.setVisible(true);\r
508 \r
509 }\r
510 \r
511 private ModuleIdentification getModuleId(String key){\r
512 //\r
bf5abaff 513 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion, Arch into string array.\r
a13899c5 514 //\r
515 String[] keyPart = key.split(" ");\r
516 Set<PackageIdentification> spi = GlobalData.getPackageList();\r
517 Iterator ispi = spi.iterator();\r
518 \r
519 while(ispi.hasNext()) {\r
520 PackageIdentification pi = (PackageIdentification)ispi.next();\r
f3b0ed9a 521 if ( !pi.getGuid().equals(keyPart[2])){ \r
12e17a0a 522\r
523 continue;\r
524 }\r
525 if (keyPart[3] != null && keyPart[3].length() > 0 && !keyPart[3].equals("null")){\r
526 if(!pi.getVersion().equals(keyPart[3])){\r
410e0e9f 527 continue;\r
528 }\r
12e17a0a 529 }\r
a13899c5 530 Set<ModuleIdentification> smi = GlobalData.getModules(pi);\r
531 Iterator ismi = smi.iterator();\r
532 while(ismi.hasNext()) {\r
533 ModuleIdentification mi = (ModuleIdentification)ismi.next();\r
f3b0ed9a 534 if (mi.getGuid().equals(keyPart[0])){\r
12e17a0a 535 if (keyPart[1] != null && keyPart[1].length() > 0 && !keyPart[1].equals("null")){\r
536 if(!mi.getVersion().equals(keyPart[1])){\r
537 continue;\r
538 }\r
539 }\r
f3b0ed9a 540\r
a13899c5 541 return mi;\r
542 }\r
543 }\r
544 }\r
545 return null;\r
546 }\r
547\r
548} // @jve:decl-index=0:visual-constraint="10,10"\r
549\r
550class NonEditableTableModel extends DefaultTableModel {\r
44053733 551 /**\r
552 * \r
553 */\r
554 private static final long serialVersionUID = 1L;\r
555\r
a13899c5 556 public boolean isCellEditable(int row, int col) {\r
557 return false;\r
558 }\r
559}\r