]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java
Adapt to new Main UI interface.
[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
30\r
31public class FpdFrameworkModules extends IInternalFrame {\r
32\r
44053733 33 /**\r
34 * \r
35 */\r
36 private static final long serialVersionUID = 1L;\r
a13899c5 37 static JFrame frame;\r
38 private JSplitPane jSplitPane = null;\r
39 private JPanel jPanel = null;\r
40 private JPanel jPanel1 = null;\r
41 private JLabel jLabel = null;\r
42 private JScrollPane jScrollPane = null;\r
43 private JTable jTable = null;\r
44 private JPanel jPanel2 = null;\r
45 private JButton jButton = null;\r
46 private JLabel jLabel1 = null;\r
47 private JPanel jPanel3 = null;\r
48 private JScrollPane jScrollPane1 = null;\r
49 private JTable jTable1 = null;\r
50 private JButton jButton1 = null;\r
51 private JButton jButton2 = null;\r
52 private NonEditableTableModel model = null;\r
53 private NonEditableTableModel model1 = null;\r
54 \r
55 private FpdModuleSA settingDlg = null;\r
56 \r
57 private FpdFileContents ffc = null;\r
d6d24759 58 private OpeningPlatformType docConsole = null;\r
a13899c5 59 private Map<String, String> fpdMsa = null;\r
60 \r
61 private ArrayList<ModuleIdentification> miList = null;\r
62\r
63 /**\r
64 * This method initializes jSplitPane \r
65 * \r
66 * @return javax.swing.JSplitPane \r
67 */\r
68 private JSplitPane getJSplitPane() {\r
69 if (jSplitPane == null) {\r
70 jSplitPane = new JSplitPane();\r
71 jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);\r
72 jSplitPane.setDividerLocation(250);\r
73 jSplitPane.setBottomComponent(getJPanel1());\r
74 jSplitPane.setTopComponent(getJPanel());\r
75 }\r
76 return jSplitPane;\r
77 }\r
78\r
79 /**\r
80 * This method initializes jPanel \r
81 * \r
82 * @return javax.swing.JPanel \r
83 */\r
84 private JPanel getJPanel() {\r
85 if (jPanel == null) {\r
86 jLabel = new JLabel();\r
87 jLabel.setText("Modules in Workspace");\r
88 jPanel = new JPanel();\r
89 jPanel.setLayout(new BorderLayout());\r
90 jPanel.add(jLabel, java.awt.BorderLayout.NORTH);\r
91 jPanel.add(getJScrollPane(), java.awt.BorderLayout.CENTER);\r
92 jPanel.add(getJPanel2(), java.awt.BorderLayout.SOUTH);\r
93 }\r
94 return jPanel;\r
95 }\r
96\r
97 /**\r
98 * This method initializes jPanel1 \r
99 * \r
100 * @return javax.swing.JPanel \r
101 */\r
102 private JPanel getJPanel1() {\r
103 if (jPanel1 == null) {\r
104 jLabel1 = new JLabel();\r
105 jLabel1.setText("Modules Added");\r
106 jPanel1 = new JPanel();\r
107 jPanel1.setLayout(new BorderLayout());\r
108 jPanel1.add(jLabel1, java.awt.BorderLayout.NORTH);\r
109 jPanel1.add(getJPanel3(), java.awt.BorderLayout.SOUTH);\r
110 jPanel1.add(getJScrollPane1(), java.awt.BorderLayout.CENTER);\r
111 }\r
112 return jPanel1;\r
113 }\r
114\r
115 /**\r
116 * This method initializes jScrollPane \r
117 * \r
118 * @return javax.swing.JScrollPane \r
119 */\r
120 private JScrollPane getJScrollPane() {\r
121 if (jScrollPane == null) {\r
122 jScrollPane = new JScrollPane();\r
123 jScrollPane.setPreferredSize(new java.awt.Dimension(600,200));\r
124 jScrollPane.setViewportView(getJTable());\r
125 }\r
126 return jScrollPane;\r
127 }\r
128\r
129 /**\r
130 * This method initializes jTable \r
131 * \r
132 * @return javax.swing.JTable \r
133 */\r
134 private JTable getJTable() {\r
135 if (jTable == null) {\r
136 model = new NonEditableTableModel();\r
137 jTable = new JTable(model);\r
f3b0ed9a 138 jTable.setRowHeight(20);\r
a13899c5 139 model.addColumn("ModuleName");\r
140 model.addColumn("ModuleGUID");\r
141 model.addColumn("ModuleVersion");\r
142 model.addColumn("PackageGUID");\r
143 model.addColumn("PackageVersion");\r
144 \r
145 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
146 }\r
147 return jTable;\r
148 }\r
149\r
150 /**\r
151 * This method initializes jPanel2 \r
152 * \r
153 * @return javax.swing.JPanel \r
154 */\r
155 private JPanel getJPanel2() {\r
156 if (jPanel2 == null) {\r
157 FlowLayout flowLayout = new FlowLayout();\r
158 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);\r
159 jPanel2 = new JPanel();\r
160 jPanel2.setLayout(flowLayout);\r
161 jPanel2.add(getJButton(), null);\r
162 }\r
163 return jPanel2;\r
164 }\r
165\r
166 /**\r
167 * This method initializes jButton \r
168 * \r
169 * @return javax.swing.JButton \r
170 */\r
171 private JButton getJButton() {\r
172 if (jButton == null) {\r
173 jButton = new JButton();\r
174 jButton.setPreferredSize(new java.awt.Dimension(130,20));\r
175 jButton.setText("Add a Module");\r
176 jButton.addActionListener(new java.awt.event.ActionListener() {\r
177 public void actionPerformed(java.awt.event.ActionEvent e) {\r
178 int selectedRow = jTable.getSelectedRow();\r
179 if (selectedRow < 0){\r
180 return;\r
181 }\r
182 \r
183 String mg = (String)model.getValueAt(selectedRow, 1);\r
184 String mv = (String)model.getValueAt(selectedRow, 2);\r
185 String pg = (String)model.getValueAt(selectedRow, 3);\r
186 String pv = (String)model.getValueAt(selectedRow, 4);\r
187 if (fpdMsa.containsKey(mg + mv + pg + pv)) {\r
188 JOptionPane.showMessageDialog(frame, "This Module Already Added.");\r
189 return;\r
190 }\r
191 //ToDo put Arch instead of null\r
192 fpdMsa.put(mg + mv + pg + pv, null);\r
193 \r
194 String[] row = {" ", mg, mv, pg, pv};\r
f3b0ed9a 195 ModuleIdentification mi = getModuleId(mg + " " + mv + " " + pg + " " + pv);\r
196 if (mi != null) {\r
197 row[0] = mi.getName();\r
198 row[2] = mi.getVersion();\r
199 row[4] = mi.getPackage().getVersion();\r
a13899c5 200 }\r
201 model1.addRow(row);\r
d6d24759 202 docConsole.setSaved(false);\r
a13899c5 203 ffc.addFrameworkModulesPcdBuildDefs(miList.get(selectedRow), null);\r
204 }\r
205 });\r
206 }\r
207 return jButton;\r
208 }\r
209\r
210 /**\r
211 * This method initializes jPanel3 \r
212 * \r
213 * @return javax.swing.JPanel \r
214 */\r
215 private JPanel getJPanel3() {\r
216 if (jPanel3 == null) {\r
217 FlowLayout flowLayout1 = new FlowLayout();\r
218 flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);\r
219 jPanel3 = new JPanel();\r
220 jPanel3.setLayout(flowLayout1);\r
221 jPanel3.add(getJButton1(), null);\r
222 jPanel3.add(getJButton2(), null);\r
223 }\r
224 return jPanel3;\r
225 }\r
226\r
227 /**\r
228 * This method initializes jScrollPane1 \r
229 * \r
230 * @return javax.swing.JScrollPane \r
231 */\r
232 private JScrollPane getJScrollPane1() {\r
233 if (jScrollPane1 == null) {\r
234 jScrollPane1 = new JScrollPane();\r
235 jScrollPane1.setPreferredSize(new java.awt.Dimension(453,200));\r
236 jScrollPane1.setViewportView(getJTable1());\r
237 }\r
238 return jScrollPane1;\r
239 }\r
240\r
241 /**\r
242 * This method initializes jTable1 \r
243 * \r
244 * @return javax.swing.JTable \r
245 */\r
246 private JTable getJTable1() {\r
247 if (jTable1 == null) {\r
248 model1 = new NonEditableTableModel();\r
249 jTable1 = new JTable(model1);\r
f3b0ed9a 250 jTable1.setRowHeight(20);\r
a13899c5 251 model1.addColumn("ModuleName");\r
252 model1.addColumn("ModuleGUID");\r
253 model1.addColumn("ModuleVersion"); \r
254 model1.addColumn("PackageGUID");\r
255 model1.addColumn("PackageVersion");\r
256// model1.addColumn("SupportedArch");\r
257 \r
258 jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
259 }\r
260 return jTable1;\r
261 }\r
262\r
263 /**\r
264 * This method initializes jButton1 \r
265 * \r
266 * @return javax.swing.JButton \r
267 */\r
268 private JButton getJButton1() {\r
269 if (jButton1 == null) {\r
270 jButton1 = new JButton();\r
271 jButton1.setPreferredSize(new java.awt.Dimension(130,20));\r
272 jButton1.setText("Settings");\r
273 jButton1.addActionListener(new java.awt.event.ActionListener() {\r
274 public void actionPerformed(java.awt.event.ActionEvent e) {\r
275 int selectedRow = jTable1.getSelectedRow();\r
276 if (selectedRow < 0){\r
277 return;\r
278 }\r
279 if (settingDlg == null) {\r
280 settingDlg = new FpdModuleSA(ffc);\r
281 }\r
d6d24759 282 docConsole.setSaved(false);\r
f3b0ed9a 283 String mg = model1.getValueAt(selectedRow, 1)+"";\r
284 String mv = model1.getValueAt(selectedRow, 2)+"";\r
285 String pg = model1.getValueAt(selectedRow, 3)+"";\r
286 String pv = model1.getValueAt(selectedRow, 4)+"";\r
a13899c5 287 settingDlg.setKey(mg + " " + mv + " " + pg + " " + pv);\r
288 settingDlg.setVisible(true);\r
289 }\r
290 });\r
291 }\r
292 return jButton1;\r
293 }\r
294\r
295 /**\r
296 * This method initializes jButton2 \r
297 * \r
298 * @return javax.swing.JButton \r
299 */\r
300 private JButton getJButton2() {\r
301 if (jButton2 == null) {\r
302 jButton2 = new JButton();\r
303 jButton2.setPreferredSize(new java.awt.Dimension(130,20));\r
304 jButton2.setText("Remove Module");\r
305 jButton2.addActionListener(new java.awt.event.ActionListener() {\r
306 public void actionPerformed(java.awt.event.ActionEvent e) {\r
307 int selectedRow = jTable1.getSelectedRow();\r
308 if (selectedRow < 0){\r
309 return;\r
310 }\r
311 String mg = model1.getValueAt(selectedRow, 1).toString();\r
312 String mv = model1.getValueAt(selectedRow, 2).toString();\r
313 String pg = model1.getValueAt(selectedRow, 3).toString();\r
314 String pv = model1.getValueAt(selectedRow, 4).toString();\r
315 model1.removeRow(selectedRow);\r
316 fpdMsa.remove(mg+mv+pg+pv);\r
d6d24759 317 docConsole.setSaved(false);\r
a13899c5 318 ffc.removeModuleSA(selectedRow);\r
319 }\r
320 });\r
321 }\r
322 return jButton2;\r
323 }\r
324\r
325 /**\r
326 * @param args\r
327 */\r
328 public static void main(String[] args) {\r
329 // TODO Auto-generated method stub\r
330 new FpdFrameworkModules().setVisible(true);\r
331 }\r
332\r
333 /**\r
334 * This is the default constructor\r
335 */\r
336 public FpdFrameworkModules() {\r
337 super();\r
338 initialize();\r
339 }\r
340\r
341 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd){\r
342 this();\r
343 init(fpd);\r
344 \r
345 }\r
346 \r
d6d24759 347 public FpdFrameworkModules(OpeningPlatformType opt) {\r
348 this(opt.getXmlFpd());\r
349 docConsole = opt;\r
350 }\r
351 \r
a13899c5 352 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {\r
353 try {\r
354 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", System.getenv("WORKSPACE"));\r
355 }\r
356 catch(Exception e){\r
357 JOptionPane.showMessageDialog(frame, "FrameworkDatabase Corrupted.");\r
358 }\r
359 \r
360 if (ffc == null){\r
361 ffc = new FpdFileContents(fpd);\r
362 ffc.initDynPcdMap();\r
363 }\r
364 \r
365 if (fpdMsa == null) {\r
366 fpdMsa = new HashMap<String, String>();\r
367 }\r
368 \r
369 if (ffc.getFrameworkModulesCount() > 0) {\r
370 String[][] saa = new String[ffc.getFrameworkModulesCount()][5];\r
371 ffc.getFrameworkModulesInfo(saa);\r
372 for (int i = 0; i < saa.length; ++i) {\r
f3b0ed9a 373 ModuleIdentification mi = getModuleId(saa[i][1]+ " "+saa[i][2]+" "+saa[i][3]+" "+saa[i][4]);\r
374 if (mi != null) {\r
375 saa[i][0] = mi.getName();\r
376 saa[i][2] = mi.getVersion();\r
377 saa[i][4] = mi.getPackage().getVersion();\r
a13899c5 378 }\r
379 model1.addRow(saa[i]);\r
380 fpdMsa.put(saa[i][1]+saa[i][2]+saa[i][3]+saa[i][4], saa[i][0]);\r
381 }\r
382 }\r
383 \r
384 showAllModules();\r
385 \r
386 }\r
387 \r
388 private void showAllModules() {\r
389 \r
390 if (miList == null) {\r
391 miList = new ArrayList<ModuleIdentification>();\r
392 }\r
393 Set<PackageIdentification> spi = GlobalData.getPackageList();\r
394 Iterator ispi = spi.iterator();\r
395 \r
396 while(ispi.hasNext()) {\r
397 PackageIdentification pi = (PackageIdentification)ispi.next();\r
398 String[] s = {"", "", "", "", ""};\r
399 s[3] = pi.getGuid();\r
400 s[4] = pi.getVersion();\r
401 Set<ModuleIdentification> smi = GlobalData.getModules(pi);\r
402 Iterator ismi = smi.iterator();\r
403 while(ismi.hasNext()) {\r
404 ModuleIdentification mi = (ModuleIdentification)ismi.next();\r
405 s[0] = mi.getName();\r
406 s[1] = mi.getGuid();\r
407 s[2] = mi.getVersion();\r
408 model.addRow(s);\r
409 miList.add(mi);\r
410 }\r
411 }\r
412 }\r
413 /**\r
414 * This method initializes this\r
415 * \r
416 * @return void\r
417 */\r
418 private void initialize() {\r
419 this.setSize(633, 533);\r
420 this.setTitle("Framework Modules");\r
421 this.setContentPane(getJSplitPane());\r
422 this.setVisible(true);\r
423 \r
424 }\r
425 \r
426 private ModuleIdentification getModuleId(String key){\r
427 //\r
428 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.\r
429 //\r
430 String[] keyPart = key.split(" ");\r
431 Set<PackageIdentification> spi = GlobalData.getPackageList();\r
432 Iterator ispi = spi.iterator();\r
433 \r
434 while(ispi.hasNext()) {\r
435 PackageIdentification pi = (PackageIdentification)ispi.next();\r
f3b0ed9a 436 if ( !pi.getGuid().equals(keyPart[2])){ \r
437// || !pi.getVersion().equals(keyPart[3])){\r
a13899c5 438 continue;\r
439 }\r
440 Set<ModuleIdentification> smi = GlobalData.getModules(pi);\r
441 Iterator ismi = smi.iterator();\r
442 while(ismi.hasNext()) {\r
443 ModuleIdentification mi = (ModuleIdentification)ismi.next();\r
f3b0ed9a 444 if (mi.getGuid().equals(keyPart[0])){\r
445// && mi.getVersion().equals(keyPart[1])){\r
446\r
a13899c5 447 return mi;\r
448 }\r
449 }\r
450 }\r
451 return null;\r
452 }\r
453\r
454} // @jve:decl-index=0:visual-constraint="10,10"\r
455\r
456class NonEditableTableModel extends DefaultTableModel {\r
44053733 457 /**\r
458 * \r
459 */\r
460 private static final long serialVersionUID = 1L;\r
461\r
a13899c5 462 public boolean isCellEditable(int row, int col) {\r
463 return false;\r
464 }\r
465}\r