Fixed grammar and column widths (set min, preferred and max widths for version and...
[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
39 static JFrame frame;
40
41 private JSplitPane jSplitPane = null;
42
43 private JPanel jPanelTop = null;
44
45 private JPanel jPanelBottom = null;
46
47 private JLabel jLabel = null;
48
49 private JScrollPane jScrollPaneAllModules = null;
50
51 private JTable jTableAllModules = null;
52
53 private JPanel jPanelTopSouth = null;
54
55 private JButton jButtonAddModule = null;
56
57 private JLabel jLabelModulesAdded = null;
58
59 private JPanel jPanelBottomSouth = null;
60
61 private JScrollPane jScrollPaneFpdModules = null;
62
63 private JTable jTableFpdModules = null;
64
65 private JButton jButtonSettings = null;
66
67 private JButton jButtonRemoveModule = null;
68
69 private NonEditableTableModel modelAllModules = null;
70
71 private NonEditableTableModel modelFpdModules = null;
72
73 private FpdModuleSA settingDlg = null;
74
75 private FpdFileContents ffc = null;
76
77 private OpeningPlatformType docConsole = null;
78
79 private Map<String, ArrayList<String>> fpdMsa = null;
80
81 private ArrayList<ModuleIdentification> miList = null;
82
83 private final int ModNameCol = 0;
84
85 private final int ModVerCol = 1;
86
87 private final int PkgNameCol = 2;
88
89 private final int PkgVerCol = 3;
90
91 private final int ArchCol = 4;
92
93 private final int Path4Col = 4;
94
95 private final int Path5Col = 5;
96
97 private final int ModNameMinWidth = 168;
98
99 private final int ModNamePrefWidth = 200;
100
101 private final int PkgNameMinWidth = 100;
102
103 private final int PkgNamePrefWidth = 110;
104
105 private final int PkgNameMaxWidth = 150;
106
107 private final int VerMinWidth = 50;
108
109 private final int VerMaxWidth = 80;
110
111 private final int VerPrefWidth = 60;
112
113 private final int PathPrefWidth = 320;
114
115 private final int PathMinWidth = 280;
116
117 private final int ArchPrefWidth = 80;
118
119 private final int ArchMinWidth = 60;
120
121 private final int ArchMaxWidth = 100;
122
123 /**
124 * This method initializes jSplitPane
125 *
126 * @return javax.swing.JSplitPane
127 */
128 private JSplitPane getJSplitPane() {
129 if (jSplitPane == null) {
130 jSplitPane = new JSplitPane();
131 jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
132 jSplitPane.setDividerLocation(250);
133 jSplitPane.setBottomComponent(getJPanelBottom());
134 jSplitPane.setTopComponent(getJPanelTop());
135 }
136 return jSplitPane;
137 }
138
139 /**
140 * This method initializes jPanel
141 *
142 * @return javax.swing.JPanel
143 */
144 private JPanel getJPanelTop() {
145 if (jPanelTop == null) {
146 jLabel = new JLabel();
147 jLabel.setText("Modules in Workspace");
148 jPanelTop = new JPanel();
149 jPanelTop.setLayout(new BorderLayout());
150 jPanelTop.add(jLabel, java.awt.BorderLayout.NORTH);
151 jPanelTop.add(getJScrollPaneAllModules(), java.awt.BorderLayout.CENTER);
152 jPanelTop.add(getJPanelTopSouth(), java.awt.BorderLayout.SOUTH);
153 }
154 return jPanelTop;
155 }
156
157 /**
158 * This method initializes jPanel1
159 *
160 * @return javax.swing.JPanel
161 */
162 private JPanel getJPanelBottom() {
163 if (jPanelBottom == null) {
164 jLabelModulesAdded = new JLabel();
165 jLabelModulesAdded.setText("Modules Added");
166 jPanelBottom = new JPanel();
167 jPanelBottom.setLayout(new BorderLayout());
168 jPanelBottom.add(jLabelModulesAdded, java.awt.BorderLayout.NORTH);
169 jPanelBottom.add(getJPanelBottomSouth(), java.awt.BorderLayout.SOUTH);
170 jPanelBottom.add(getJScrollPaneFpdModules(), java.awt.BorderLayout.CENTER);
171 }
172 return jPanelBottom;
173 }
174
175 /**
176 * This method initializes jScrollPane
177 *
178 * @return javax.swing.JScrollPane
179 */
180 private JScrollPane getJScrollPaneAllModules() {
181 if (jScrollPaneAllModules == null) {
182 jScrollPaneAllModules = new JScrollPane();
183 jScrollPaneAllModules.setPreferredSize(new java.awt.Dimension(600, 200));
184 jScrollPaneAllModules.setViewportView(getJTableAllModules());
185 }
186 return jScrollPaneAllModules;
187 }
188
189 /**
190 * This method initializes jTable
191 *
192 * @return javax.swing.JTable
193 */
194 private JTable getJTableAllModules() {
195 if (jTableAllModules == null) {
196 modelAllModules = new NonEditableTableModel();
197 TableSorter sorter = new TableSorter(modelAllModules);
198 jTableAllModules = new JTable(sorter);
199 sorter.setTableHeader(jTableAllModules.getTableHeader());
200 jTableAllModules.setRowHeight(20);
201 modelAllModules.addColumn("<html>Module<br>Name</html>");
202 modelAllModules.addColumn("<html>Module<br>Version</html>");
203 modelAllModules.addColumn("<html>Package<br>Name</html>");
204 modelAllModules.addColumn("<html>Package<br>Version</html>");
205 modelAllModules.addColumn("Path");
206 javax.swing.table.TableColumn column = null;
207 column = jTableAllModules.getColumnModel().getColumn(ModNameCol);
208 column.setPreferredWidth(ModNamePrefWidth);
209 column.setMinWidth(ModNameMinWidth);
210 column = jTableAllModules.getColumnModel().getColumn(ModVerCol);
211 column.setPreferredWidth(VerPrefWidth);
212 column.setMaxWidth(VerMaxWidth);
213 column.setMinWidth(VerMinWidth);
214 column = jTableAllModules.getColumnModel().getColumn(PkgNameCol);
215 column.setPreferredWidth(PkgNamePrefWidth);
216 column.setMinWidth(PkgNameMinWidth);
217 column.setMaxWidth(PkgNameMaxWidth);
218 column = jTableAllModules.getColumnModel().getColumn(PkgVerCol);
219 column.setPreferredWidth(VerPrefWidth);
220 column.setMaxWidth(VerMaxWidth);
221 column.setMinWidth(VerMinWidth);
222 column = jTableAllModules.getColumnModel().getColumn(Path4Col);
223 column.setPreferredWidth(PathPrefWidth);
224 column.setMinWidth(PathMinWidth);
225
226 jTableAllModules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
227 }
228 return jTableAllModules;
229 }
230
231 /**
232 * This method initializes jPanel2
233 *
234 * @return javax.swing.JPanel
235 */
236 private JPanel getJPanelTopSouth() {
237 if (jPanelTopSouth == null) {
238 FlowLayout flowLayout = new FlowLayout();
239 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
240 jPanelTopSouth = new JPanel();
241 jPanelTopSouth.setLayout(flowLayout);
242 jPanelTopSouth.add(getJButtonAddModule(), null);
243 }
244 return jPanelTopSouth;
245 }
246
247 /**
248 * This method initializes jButton
249 *
250 * @return javax.swing.JButton
251 */
252 private JButton getJButtonAddModule() {
253 if (jButtonAddModule == null) {
254 jButtonAddModule = new JButton();
255 jButtonAddModule.setPreferredSize(new java.awt.Dimension(130, 20));
256 jButtonAddModule.setText("Add a Module");
257 jButtonAddModule.addActionListener(new java.awt.event.ActionListener() {
258 public void actionPerformed(java.awt.event.ActionEvent e) {
259 int selectedRow = jTableAllModules.getSelectedRow();
260 if (selectedRow < 0) {
261 return;
262 }
263
264 TableSorter sorter = (TableSorter) jTableAllModules.getModel();
265 selectedRow = sorter.modelIndex(selectedRow);
266 String path = modelAllModules.getValueAt(selectedRow, Path4Col) + "";
267 ModuleIdentification mi = miList.get(selectedRow);
268 Vector<String> vArchs = null;
269 try {
270 vArchs = GlobalData.getModuleSupArchs(mi);
271 }
272 catch (Exception exp) {
273 JOptionPane.showMessageDialog(frame, exp.getMessage());
274 }
275
276 if (vArchs == null) {
277 JOptionPane.showMessageDialog(frame, "No Supported Architectures specified in MSA file.");
278 return;
279 }
280
281 String archsAdded = "";
282 String mg = mi.getGuid();
283 String mv = mi.getVersion();
284 String pg = mi.getPackage().getGuid();
285 String pv = mi.getPackage().getVersion();
286
287 ArrayList<String> al = fpdMsa.get(mg + mv + pg + pv);
288 if (al == null) {
289 al = new ArrayList<String>();
290 fpdMsa.put(mg + mv + pg + pv, al);
291 }
292 for (int i = 0; i < al.size(); ++i) {
293 vArchs.remove(al.get(i));
294 }
295 //
296 // Archs this Module supported have already been added.
297 //
298 if (vArchs.size() == 0) {
299 JOptionPane.showMessageDialog(frame, "This Module has already been added.");
300 return;
301 }
302 //ToDo put Arch instead of null
303 boolean errorOccurred = false;
304 for (int i = 0; i < vArchs.size(); ++i) {
305 String arch = vArchs.get(i);
306 al.add(arch);
307 archsAdded += arch + " ";
308 String[] row = { "", mv, "", pv, arch, path };
309
310 if (mi != null) {
311 row[ModNameCol] = mi.getName();
312 row[PkgNameCol] = mi.getPackage().getName();
313
314 }
315 modelFpdModules.addRow(row);
316
317 docConsole.setSaved(false);
318 try {
319 //ToDo : specify archs need to add.
320 ffc.addFrameworkModulesPcdBuildDefs(mi, arch, null);
321 } catch (Exception exception) {
322 JOptionPane.showMessageDialog(frame, "Adding " + row[ModNameCol] + " with SupArch " + arch
323 + ": " + exception.getMessage());
324 errorOccurred = true;
325 }
326 }
327
328 String s = "This Module with Architecture " + archsAdded;
329 if (errorOccurred) {
330 s += " was added with Error. Platform may NOT Build.";
331 } else {
332 s += " was added Successfully.";
333 }
334 JOptionPane.showMessageDialog(frame, s);
335 jTableFpdModules.changeSelection(modelFpdModules.getRowCount() - 1, 0, false, false);
336 }
337 });
338 }
339 return jButtonAddModule;
340 }
341
342 /**
343 * This method initializes jPanel3
344 *
345 * @return javax.swing.JPanel
346 */
347 private JPanel getJPanelBottomSouth() {
348 if (jPanelBottomSouth == null) {
349 FlowLayout flowLayout1 = new FlowLayout();
350 flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
351 jPanelBottomSouth = new JPanel();
352 jPanelBottomSouth.setLayout(flowLayout1);
353 jPanelBottomSouth.add(getJButtonSettings(), null);
354 jPanelBottomSouth.add(getJButtonRemoveModule(), null);
355 }
356 return jPanelBottomSouth;
357 }
358
359 /**
360 * This method initializes jScrollPane1
361 *
362 * @return javax.swing.JScrollPane
363 */
364 private JScrollPane getJScrollPaneFpdModules() {
365 if (jScrollPaneFpdModules == null) {
366 jScrollPaneFpdModules = new JScrollPane();
367 jScrollPaneFpdModules.setPreferredSize(new java.awt.Dimension(453, 200));
368 jScrollPaneFpdModules.setViewportView(getJTableFpdModules());
369 }
370 return jScrollPaneFpdModules;
371 }
372
373 /**
374 * This method initializes jTable1
375 *
376 * @return javax.swing.JTable
377 */
378 private JTable getJTableFpdModules() {
379 if (jTableFpdModules == null) {
380 modelFpdModules = new NonEditableTableModel();
381 TableSorter sorter = new TableSorter(modelFpdModules);
382 jTableFpdModules = new JTable(sorter);
383 sorter.setTableHeader(jTableFpdModules.getTableHeader());
384 jTableFpdModules.setRowHeight(20);
385 modelFpdModules.addColumn("<html>Module<br>Name</html>");
386 modelFpdModules.addColumn("<html>Module<br>Version</html>");
387 modelFpdModules.addColumn("<html>Package<br>Name</html>");
388 modelFpdModules.addColumn("<html>Package<br>Version</html>");
389 modelFpdModules.addColumn("<html>Supported<br>Architectures</html>");
390 modelFpdModules.addColumn("Path");
391 javax.swing.table.TableColumn column = null;
392 column = jTableFpdModules.getColumnModel().getColumn(ModNameCol);
393 column.setPreferredWidth(ModNamePrefWidth);
394 column.setMinWidth(ModNameMinWidth);
395 column = jTableFpdModules.getColumnModel().getColumn(ModVerCol);
396 column.setPreferredWidth(VerPrefWidth);
397 column.setMaxWidth(VerMaxWidth);
398 column.setMinWidth(VerMinWidth);
399 column = jTableFpdModules.getColumnModel().getColumn(PkgNameCol);
400 column.setPreferredWidth(PkgNamePrefWidth);
401 column.setMinWidth(PkgNameMinWidth);
402 column.setMaxWidth(PkgNameMaxWidth);
403 column = jTableFpdModules.getColumnModel().getColumn(PkgVerCol);
404 column.setPreferredWidth(VerPrefWidth);
405 column.setMaxWidth(VerMaxWidth);
406 column.setMinWidth(VerMinWidth);
407 column = jTableFpdModules.getColumnModel().getColumn(ArchCol);
408 column.setPreferredWidth(ArchPrefWidth);
409 column.setMaxWidth(ArchMaxWidth);
410 column.setMinWidth(ArchMinWidth);
411 column = jTableFpdModules.getColumnModel().getColumn(Path5Col);
412 column.setPreferredWidth(PathPrefWidth);
413 column.setMinWidth(PathMinWidth);
414
415 jTableFpdModules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
416 }
417 return jTableFpdModules;
418 }
419
420 /**
421 * This method initializes jButton1
422 *
423 * @return javax.swing.JButton
424 */
425 private JButton getJButtonSettings() {
426 if (jButtonSettings == null) {
427 jButtonSettings = new JButton();
428 jButtonSettings.setPreferredSize(new java.awt.Dimension(130,20));
429 jButtonSettings.setText("Settings");
430 jButtonSettings.addActionListener(new java.awt.event.ActionListener() {
431 public void actionPerformed(java.awt.event.ActionEvent e) {
432 int selectedRow = jTableFpdModules.getSelectedRow();
433 if (selectedRow < 0) {
434 return;
435 }
436
437 TableSorter sorter = (TableSorter) jTableFpdModules.getModel();
438 selectedRow = sorter.modelIndex(selectedRow);
439 try {
440 if (ffc.adjustPcd(selectedRow)) {
441 docConsole.setSaved(false);
442 }
443 }
444 catch (Exception exp) {
445 JOptionPane.showMessageDialog(frame, exp.getMessage());
446 return;
447 }
448
449 if (settingDlg == null) {
450 settingDlg = new FpdModuleSA(ffc);
451 }
452
453 String[] sa = new String[5];
454 ffc.getFrameworkModuleInfo(selectedRow, sa);
455 String mg = sa[ModNameCol];
456 String mv = sa[ModVerCol];
457 String pg = sa[PkgNameCol];
458 String pv = sa[PkgVerCol];
459 String arch = sa[ArchCol];
460 settingDlg.setKey(mg + " " + mv + " " + pg + " " + pv + " " + arch, selectedRow, docConsole);
461 settingDlg.setVisible(true);
462 }
463 });
464 }
465 return jButtonSettings;
466 }
467
468 /**
469 * This method initializes jButton2
470 *
471 * @return javax.swing.JButton
472 */
473 private JButton getJButtonRemoveModule() {
474 if (jButtonRemoveModule == null) {
475 jButtonRemoveModule = new JButton();
476 jButtonRemoveModule.setPreferredSize(new java.awt.Dimension(130, 20));
477 jButtonRemoveModule.setText("Remove Module");
478 jButtonRemoveModule.addActionListener(new java.awt.event.ActionListener() {
479 public void actionPerformed(java.awt.event.ActionEvent e) {
480 int selectedRow = jTableFpdModules.getSelectedRow();
481 if (selectedRow < 0) {
482 return;
483 }
484
485 TableSorter sorter = (TableSorter) jTableFpdModules.getModel();
486 selectedRow = sorter.modelIndex(selectedRow);
487
488 String[] sa = new String[5];
489 ffc.getFrameworkModuleInfo(selectedRow, sa);
490 String mg = sa[ModNameCol];
491 String mv = sa[ModVerCol];
492 String pg = sa[PkgNameCol];
493 String pv = sa[PkgVerCol];
494 String arch = sa[ArchCol];
495 ModuleIdentification mi = GlobalData.getModuleId(sa[ModNameCol] + " " + sa[ModVerCol] + " "
496 + sa[PkgNameCol] + " " + sa[PkgVerCol] + " "
497 + sa[ArchCol]);
498 mv = mi.getVersion();
499 pv = mi.getPackage().getVersion();
500 modelFpdModules.removeRow(selectedRow);
501 if (arch == null) {
502 // if no arch specified in ModuleSA
503 fpdMsa.remove(mg + mv + pg + pv);
504 } else {
505 ArrayList<String> al = fpdMsa.get(mg + mv + pg + pv);
506 al.remove(arch);
507 if (al.size() == 0) {
508 fpdMsa.remove(mg + mv + pg + pv);
509 }
510 }
511
512 docConsole.setSaved(false);
513 ffc.removeModuleSA(selectedRow);
514 }
515 });
516 }
517 return jButtonRemoveModule;
518 }
519
520 /**
521 * @param args
522 */
523 public static void main(String[] args) {
524 // TODO Auto-generated method stub
525 new FpdFrameworkModules().setVisible(true);
526 }
527
528 /**
529 * This is the default constructor
530 */
531 public FpdFrameworkModules() {
532 super();
533 initialize();
534 }
535
536 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
537 this();
538 init(fpd);
539
540 }
541
542 public FpdFrameworkModules(OpeningPlatformType opt) {
543 this(opt.getXmlFpd());
544 docConsole = opt;
545 }
546
547 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
548 try {
549 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", System.getenv("WORKSPACE"));
550 }
551 catch(Exception e){
552 JOptionPane.showMessageDialog(frame, "Error occurred when getting module data.");
553 }
554
555 if (ffc == null) {
556 ffc = new FpdFileContents(fpd);
557 ffc.initDynPcdMap();
558 }
559
560 if (fpdMsa == null) {
561 fpdMsa = new HashMap<String, ArrayList<String>>();
562 }
563
564 if (ffc.getFrameworkModulesCount() > 0) {
565 String[][] saa = new String[ffc.getFrameworkModulesCount()][5];
566 ffc.getFrameworkModulesInfo(saa);
567 for (int i = 0; i < saa.length; ++i) {
568 ModuleIdentification mi = GlobalData.getModuleId(saa[i][ModNameCol] + " " + saa[i][ModVerCol] + " "
569 + saa[i][PkgNameCol] + " " + saa[i][PkgVerCol]);
570 String[] row = { "", "", "", "", "", "" };
571 if (mi != null) {
572 row[ModNameCol] = mi.getName();
573 row[ModVerCol] = mi.getVersion();
574 row[PkgNameCol] = mi.getPackage().getName();
575 row[PkgVerCol] = mi.getPackage().getVersion();
576 row[ArchCol] = saa[i][ArchCol];
577 try {
578 row[Path5Col] = GlobalData.getMsaFile(mi).getPath().substring(
579 System.getenv("WORKSPACE")
580 .length() + 1);
581 } catch (Exception e) {
582 JOptionPane.showMessageDialog(frame, "Show FPD Modules:" + e.getMessage());
583 }
584 }
585 modelFpdModules.addRow(row);
586 ArrayList<String> al = fpdMsa.get(saa[i][ModNameCol] + row[ModVerCol] + saa[i][PkgNameCol]
587 + row[PkgVerCol]);
588 if (al == null) {
589 al = new ArrayList<String>();
590 fpdMsa.put(saa[i][ModNameCol] + row[ModVerCol] + saa[i][PkgNameCol] + row[PkgVerCol], al);
591 }
592 al.add(saa[i][Path4Col]);
593
594 }
595 }
596
597 showAllModules();
598
599 }
600
601 private void showAllModules() {
602
603 if (miList == null) {
604 miList = new ArrayList<ModuleIdentification>();
605 }
606 Set<PackageIdentification> spi = GlobalData.getPackageList();
607 Iterator ispi = spi.iterator();
608
609 while (ispi.hasNext()) {
610 PackageIdentification pi = (PackageIdentification) ispi.next();
611 String[] s = { "", "", "", "", "" };
612
613 Set<ModuleIdentification> smi = GlobalData.getModules(pi);
614 Iterator ismi = smi.iterator();
615 while (ismi.hasNext()) {
616 ModuleIdentification mi = (ModuleIdentification) ismi.next();
617 s[ModNameCol] = mi.getName();
618 s[ModVerCol] = mi.getVersion();
619 s[PkgNameCol] = pi.getName();
620 s[PkgVerCol] = pi.getVersion();
621 try {
622 s[Path4Col] = GlobalData.getMsaFile(mi).getPath()
623 .substring(System.getenv("WORKSPACE").length() + 1);
624 } catch (Exception e) {
625 JOptionPane.showMessageDialog(frame, "Show All Modules:" + e.getMessage());
626 }
627 modelAllModules.addRow(s);
628 miList.add(mi);
629 }
630 }
631 }
632
633 /**
634 * This method initializes this
635 *
636 * @return void
637 */
638 private void initialize() {
639 this.setSize(633, 533);
640 this.setTitle("Framework Modules");
641 this.setContentPane(getJSplitPane());
642 this.setVisible(true);
643
644 }
645
646 } // @jve:decl-index=0:visual-constraint="10,10"
647
648 class NonEditableTableModel extends DefaultTableModel {
649 /**
650 *
651 */
652 private static final long serialVersionUID = 1L;
653
654 public boolean isCellEditable(int row, int col) {
655 return false;
656 }
657 }