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