1 package org
.tianocore
.frameworkwizard
.platform
.ui
;
3 import java
.awt
.BorderLayout
;
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
;
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
;
23 import java
.awt
.FlowLayout
;
25 import java
.util
.ArrayList
;
26 import java
.util
.HashMap
;
27 import java
.util
.Iterator
;
30 import java
.util
.Vector
;
32 public class FpdFrameworkModules
extends IInternalFrame
{
37 private static final long serialVersionUID
= 1L;
41 private JSplitPane jSplitPane
= null;
43 private JPanel jPanelTop
= null;
45 private JPanel jPanelBottom
= null;
47 private JLabel jLabel
= null;
49 private JScrollPane jScrollPaneAllModules
= null;
51 private JTable jTableAllModules
= null;
53 private JPanel jPanelTopSouth
= null;
55 private JButton jButtonAddModule
= null;
57 private JLabel jLabelModulesAdded
= null;
59 private JPanel jPanelBottomSouth
= null;
61 private JScrollPane jScrollPaneFpdModules
= null;
63 private JTable jTableFpdModules
= null;
65 private JButton jButtonSettings
= null;
67 private JButton jButtonRemoveModule
= null;
69 private NonEditableTableModel modelAllModules
= null;
71 private NonEditableTableModel modelFpdModules
= null;
73 private FpdModuleSA settingDlg
= null;
75 private FpdFileContents ffc
= null;
77 private OpeningPlatformType docConsole
= null;
79 private Map
<String
, ArrayList
<String
>> fpdMsa
= null;
81 private ArrayList
<ModuleIdentification
> miList
= null;
83 private final int modNameColForAllModTable
= 0;
85 private final int pkgNameColForAllModTable
= 1;
87 private final int pathColForAllModTable
= 2;
89 private final int pkgVerColForAllModTable
= 3;
91 private final int modVerColForAllModTable
= 4;
93 private final int modNameColForFpdModTable
= 0;
95 private final int pkgNameColForFpdModTable
= 1;
97 private final int pathColForFpdModTable
= 2;
99 private final int archColForFpdModTable
= 3;
101 private final int pkgVerColForFpdModTable
= 4;
103 private final int modVerColForFpdModTable
= 5;
105 private final int ffcModGuid
= 0;
107 private final int ffcModVer
= 1;
109 private final int ffcPkgGuid
= 2;
111 private final int ffcPkgVer
= 3;
113 private final int ffcModArch
= 4;
115 private final int modNameMinWidth
= 168;
117 private final int modNamePrefWidth
= 200;
119 private final int pkgNameMinWidth
= 100;
121 private final int pkgNamePrefWidth
= 110;
123 private final int pkgNameMaxWidth
= 150;
125 private final int verMinWidth
= 50;
127 private final int verMaxWidth
= 80;
129 private final int verPrefWidth
= 60;
131 private final int pathPrefWidth
= 320;
133 private final int pathMinWidth
= 280;
135 private final int archPrefWidth
= 80;
137 private final int archMinWidth
= 60;
139 private final int archMaxWidth
= 100;
142 * This method initializes jSplitPane
144 * @return javax.swing.JSplitPane
146 private JSplitPane
getJSplitPane() {
147 if (jSplitPane
== null) {
148 jSplitPane
= new JSplitPane();
149 jSplitPane
.setOrientation(javax
.swing
.JSplitPane
.VERTICAL_SPLIT
);
150 jSplitPane
.setDividerLocation(250);
151 jSplitPane
.setBottomComponent(getJPanelBottom());
152 jSplitPane
.setTopComponent(getJPanelTop());
158 * This method initializes jPanel
160 * @return javax.swing.JPanel
162 private JPanel
getJPanelTop() {
163 if (jPanelTop
== null) {
164 jLabel
= new JLabel();
165 jLabel
.setText("Modules in Workspace");
166 jPanelTop
= new JPanel();
167 jPanelTop
.setLayout(new BorderLayout());
168 jPanelTop
.add(jLabel
, java
.awt
.BorderLayout
.NORTH
);
169 jPanelTop
.add(getJScrollPaneAllModules(), java
.awt
.BorderLayout
.CENTER
);
170 jPanelTop
.add(getJPanelTopSouth(), java
.awt
.BorderLayout
.SOUTH
);
176 * This method initializes jPanel1
178 * @return javax.swing.JPanel
180 private JPanel
getJPanelBottom() {
181 if (jPanelBottom
== null) {
182 jLabelModulesAdded
= new JLabel();
183 jLabelModulesAdded
.setText("Modules Added");
184 jPanelBottom
= new JPanel();
185 jPanelBottom
.setLayout(new BorderLayout());
186 jPanelBottom
.add(jLabelModulesAdded
, java
.awt
.BorderLayout
.NORTH
);
187 jPanelBottom
.add(getJPanelBottomSouth(), java
.awt
.BorderLayout
.SOUTH
);
188 jPanelBottom
.add(getJScrollPaneFpdModules(), java
.awt
.BorderLayout
.CENTER
);
194 * This method initializes jScrollPane
196 * @return javax.swing.JScrollPane
198 private JScrollPane
getJScrollPaneAllModules() {
199 if (jScrollPaneAllModules
== null) {
200 jScrollPaneAllModules
= new JScrollPane();
201 jScrollPaneAllModules
.setPreferredSize(new java
.awt
.Dimension(600, 200));
202 jScrollPaneAllModules
.setViewportView(getJTableAllModules());
204 return jScrollPaneAllModules
;
208 * This method initializes jTable
210 * @return javax.swing.JTable
212 private JTable
getJTableAllModules() {
213 if (jTableAllModules
== null) {
214 modelAllModules
= new NonEditableTableModel();
215 TableSorter sorter
= new TableSorter(modelAllModules
);
216 jTableAllModules
= new JTable(sorter
);
217 sorter
.setTableHeader(jTableAllModules
.getTableHeader());
218 jTableAllModules
.setRowHeight(20);
219 modelAllModules
.addColumn("<html>Module<br>Name</html>");
220 modelAllModules
.addColumn("<html>Package<br>Name</html>");
221 modelAllModules
.addColumn("Path");
222 modelAllModules
.addColumn("<html>Package<br>Version</html>");
223 modelAllModules
.addColumn("<html>Module<br>Version</html>");
225 javax
.swing
.table
.TableColumn column
= null;
226 column
= jTableAllModules
.getColumnModel().getColumn(modNameColForAllModTable
);
227 column
.setPreferredWidth(modNamePrefWidth
);
228 column
.setMinWidth(modNameMinWidth
);
229 column
= jTableAllModules
.getColumnModel().getColumn(modVerColForAllModTable
);
230 column
.setPreferredWidth(verPrefWidth
);
231 column
.setMaxWidth(verMaxWidth
);
232 column
.setMinWidth(verMinWidth
);
233 column
= jTableAllModules
.getColumnModel().getColumn(pkgNameColForAllModTable
);
234 column
.setPreferredWidth(pkgNamePrefWidth
);
235 column
.setMinWidth(pkgNameMinWidth
);
236 column
.setMaxWidth(pkgNameMaxWidth
);
237 column
= jTableAllModules
.getColumnModel().getColumn(pkgVerColForAllModTable
);
238 column
.setPreferredWidth(verPrefWidth
);
239 column
.setMaxWidth(verMaxWidth
);
240 column
.setMinWidth(verMinWidth
);
241 column
= jTableAllModules
.getColumnModel().getColumn(pathColForAllModTable
);
242 column
.setPreferredWidth(pathPrefWidth
);
243 column
.setMinWidth(pathMinWidth
);
245 jTableAllModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
246 jTableAllModules
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_OFF
);
248 return jTableAllModules
;
252 * This method initializes jPanel2
254 * @return javax.swing.JPanel
256 private JPanel
getJPanelTopSouth() {
257 if (jPanelTopSouth
== null) {
258 FlowLayout flowLayout
= new FlowLayout();
259 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
260 jPanelTopSouth
= new JPanel();
261 jPanelTopSouth
.setLayout(flowLayout
);
262 jPanelTopSouth
.add(getJButtonAddModule(), null);
264 return jPanelTopSouth
;
268 * This method initializes jButton
270 * @return javax.swing.JButton
272 private JButton
getJButtonAddModule() {
273 if (jButtonAddModule
== null) {
274 jButtonAddModule
= new JButton();
275 jButtonAddModule
.setPreferredSize(new java
.awt
.Dimension(130, 20));
276 jButtonAddModule
.setText("Add a Module");
277 jButtonAddModule
.addActionListener(new java
.awt
.event
.ActionListener() {
278 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
279 int selectedRow
= jTableAllModules
.getSelectedRow();
280 if (selectedRow
< 0) {
284 TableSorter sorter
= (TableSorter
) jTableAllModules
.getModel();
285 selectedRow
= sorter
.modelIndex(selectedRow
);
286 String path
= modelAllModules
.getValueAt(selectedRow
, pathColForAllModTable
) + "";
287 ModuleIdentification mi
= miList
.get(selectedRow
);
288 Vector
<String
> vArchs
= null;
290 vArchs
= GlobalData
.getModuleSupArchs(mi
);
292 catch (Exception exp
) {
293 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
296 if (vArchs
== null) {
297 JOptionPane
.showMessageDialog(frame
, "No Supported Architectures specified in MSA file.");
301 String archsAdded
= "";
302 String mg
= mi
.getGuid();
303 String mv
= mi
.getVersion();
304 String pg
= mi
.getPackage().getGuid();
305 String pv
= mi
.getPackage().getVersion();
307 ArrayList
<String
> al
= fpdMsa
.get(mg
+ mv
+ pg
+ pv
);
309 al
= new ArrayList
<String
>();
310 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, al
);
312 for (int i
= 0; i
< al
.size(); ++i
) {
313 vArchs
.remove(al
.get(i
));
316 // Archs this Module supported have already been added.
318 if (vArchs
.size() == 0) {
319 JOptionPane
.showMessageDialog(frame
, "This Module has already been added.");
322 //ToDo put Arch instead of null
323 boolean errorOccurred
= false;
324 for (int i
= 0; i
< vArchs
.size(); ++i
) {
325 String arch
= vArchs
.get(i
);
327 archsAdded
+= arch
+ " ";
328 String
[] row
= { "", "", "", "", "", "" };
331 row
[modNameColForFpdModTable
] = mi
.getName();
332 row
[pkgNameColForFpdModTable
] = mi
.getPackage().getName();
333 row
[pathColForFpdModTable
] = path
;
334 row
[archColForFpdModTable
] = arch
;
335 row
[pkgVerColForFpdModTable
] = pv
;
336 row
[modVerColForFpdModTable
] = mv
;
339 modelFpdModules
.addRow(row
);
341 docConsole
.setSaved(false);
343 //ToDo : specify archs need to add.
344 ffc
.addFrameworkModulesPcdBuildDefs(mi
, arch
, null);
345 } catch (Exception exception
) {
346 JOptionPane
.showMessageDialog(frame
, "Adding " + row
[modNameColForFpdModTable
] + " with SupArch " + arch
347 + ": " + exception
.getMessage());
348 errorOccurred
= true;
352 String s
= "This Module with Architecture " + archsAdded
;
354 s
+= " was added with Error. Platform may NOT Build.";
356 s
+= " was added Successfully.";
358 JOptionPane
.showMessageDialog(frame
, s
);
359 jTableFpdModules
.changeSelection(modelFpdModules
.getRowCount() - 1, 0, false, false);
363 return jButtonAddModule
;
367 * This method initializes jPanel3
369 * @return javax.swing.JPanel
371 private JPanel
getJPanelBottomSouth() {
372 if (jPanelBottomSouth
== null) {
373 FlowLayout flowLayout1
= new FlowLayout();
374 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
375 jPanelBottomSouth
= new JPanel();
376 jPanelBottomSouth
.setLayout(flowLayout1
);
377 jPanelBottomSouth
.add(getJButtonSettings(), null);
378 jPanelBottomSouth
.add(getJButtonRemoveModule(), null);
380 return jPanelBottomSouth
;
384 * This method initializes jScrollPane1
386 * @return javax.swing.JScrollPane
388 private JScrollPane
getJScrollPaneFpdModules() {
389 if (jScrollPaneFpdModules
== null) {
390 jScrollPaneFpdModules
= new JScrollPane();
391 jScrollPaneFpdModules
.setPreferredSize(new java
.awt
.Dimension(453, 200));
392 jScrollPaneFpdModules
.setViewportView(getJTableFpdModules());
394 return jScrollPaneFpdModules
;
398 * This method initializes jTable1
400 * @return javax.swing.JTable
402 private JTable
getJTableFpdModules() {
403 if (jTableFpdModules
== null) {
404 modelFpdModules
= new NonEditableTableModel();
405 TableSorter sorter
= new TableSorter(modelFpdModules
);
406 jTableFpdModules
= new JTable(sorter
);
407 sorter
.setTableHeader(jTableFpdModules
.getTableHeader());
408 jTableFpdModules
.setRowHeight(20);
409 modelFpdModules
.addColumn("<html>Module<br>Name</html>");
410 modelFpdModules
.addColumn("<html>Package<br>Name</html>");
411 modelFpdModules
.addColumn("Path");
412 modelFpdModules
.addColumn("<html>Supported<br>Architectures</html>");
413 modelFpdModules
.addColumn("<html>Package<br>Version</html>");
414 modelFpdModules
.addColumn("<html>Module<br>Version</html>");
416 javax
.swing
.table
.TableColumn column
= null;
417 column
= jTableFpdModules
.getColumnModel().getColumn(modNameColForFpdModTable
);
418 column
.setPreferredWidth(modNamePrefWidth
);
419 column
.setMinWidth(modNameMinWidth
);
420 column
= jTableFpdModules
.getColumnModel().getColumn(modVerColForFpdModTable
);
421 column
.setPreferredWidth(verPrefWidth
);
422 column
.setMaxWidth(verMaxWidth
);
423 column
.setMinWidth(verMinWidth
);
424 column
= jTableFpdModules
.getColumnModel().getColumn(pkgNameColForFpdModTable
);
425 column
.setPreferredWidth(pkgNamePrefWidth
);
426 column
.setMinWidth(pkgNameMinWidth
);
427 column
.setMaxWidth(pkgNameMaxWidth
);
428 column
= jTableFpdModules
.getColumnModel().getColumn(pkgVerColForFpdModTable
);
429 column
.setPreferredWidth(verPrefWidth
);
430 column
.setMaxWidth(verMaxWidth
);
431 column
.setMinWidth(verMinWidth
);
432 column
= jTableFpdModules
.getColumnModel().getColumn(archColForFpdModTable
);
433 column
.setPreferredWidth(archPrefWidth
);
434 column
.setMaxWidth(archMaxWidth
);
435 column
.setMinWidth(archMinWidth
);
436 column
= jTableFpdModules
.getColumnModel().getColumn(pathColForFpdModTable
);
437 column
.setPreferredWidth(pathPrefWidth
);
438 column
.setMinWidth(pathMinWidth
);
440 jTableFpdModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
441 jTableFpdModules
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_OFF
);
443 return jTableFpdModules
;
447 * This method initializes jButton1
449 * @return javax.swing.JButton
451 private JButton
getJButtonSettings() {
452 if (jButtonSettings
== null) {
453 jButtonSettings
= new JButton();
454 jButtonSettings
.setPreferredSize(new java
.awt
.Dimension(130,20));
455 jButtonSettings
.setText("Settings");
456 jButtonSettings
.addActionListener(new java
.awt
.event
.ActionListener() {
457 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
458 int selectedRow
= jTableFpdModules
.getSelectedRow();
459 if (selectedRow
< 0) {
463 TableSorter sorter
= (TableSorter
) jTableFpdModules
.getModel();
464 selectedRow
= sorter
.modelIndex(selectedRow
);
466 if (ffc
.adjustPcd(selectedRow
)) {
467 docConsole
.setSaved(false);
470 catch (Exception exp
) {
471 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
475 if (settingDlg
== null) {
476 settingDlg
= new FpdModuleSA(ffc
);
479 String
[] sa
= new String
[5];
480 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
481 String mg
= sa
[ffcModGuid
];
482 String mv
= sa
[ffcModVer
];
483 String pg
= sa
[ffcPkgGuid
];
484 String pv
= sa
[ffcPkgVer
];
485 String arch
= sa
[ffcModArch
];
486 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
, selectedRow
, docConsole
);
487 settingDlg
.setVisible(true);
491 return jButtonSettings
;
495 * This method initializes jButton2
497 * @return javax.swing.JButton
499 private JButton
getJButtonRemoveModule() {
500 if (jButtonRemoveModule
== null) {
501 jButtonRemoveModule
= new JButton();
502 jButtonRemoveModule
.setPreferredSize(new java
.awt
.Dimension(130, 20));
503 jButtonRemoveModule
.setText("Remove Module");
504 jButtonRemoveModule
.addActionListener(new java
.awt
.event
.ActionListener() {
505 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
506 int selectedRow
= jTableFpdModules
.getSelectedRow();
507 if (selectedRow
< 0) {
511 TableSorter sorter
= (TableSorter
) jTableFpdModules
.getModel();
512 selectedRow
= sorter
.modelIndex(selectedRow
);
514 String
[] sa
= new String
[5];
515 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
516 String mg
= sa
[ffcModGuid
];
517 String mv
= sa
[ffcModVer
];
518 String pg
= sa
[ffcPkgGuid
];
519 String pv
= sa
[ffcPkgVer
];
520 String arch
= sa
[ffcModArch
];
521 ModuleIdentification mi
= GlobalData
.getModuleId(mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
);
522 mv
= mi
.getVersion();
523 pv
= mi
.getPackage().getVersion();
524 modelFpdModules
.removeRow(selectedRow
);
526 // if no arch specified in ModuleSA
527 fpdMsa
.remove(mg
+ mv
+ pg
+ pv
);
529 ArrayList
<String
> al
= fpdMsa
.get(mg
+ mv
+ pg
+ pv
);
531 if (al
.size() == 0) {
532 fpdMsa
.remove(mg
+ mv
+ pg
+ pv
);
536 docConsole
.setSaved(false);
537 ffc
.removeModuleSA(selectedRow
);
541 return jButtonRemoveModule
;
547 public static void main(String
[] args
) {
548 // TODO Auto-generated method stub
549 new FpdFrameworkModules().setVisible(true);
553 * This is the default constructor
555 public FpdFrameworkModules() {
560 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
566 public FpdFrameworkModules(OpeningPlatformType opt
) {
567 this(opt
.getXmlFpd());
571 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
573 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
576 JOptionPane
.showMessageDialog(frame
, "Error occurred when getting module data.");
580 ffc
= new FpdFileContents(fpd
);
584 if (fpdMsa
== null) {
585 fpdMsa
= new HashMap
<String
, ArrayList
<String
>>();
588 if (ffc
.getFrameworkModulesCount() > 0) {
589 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
590 ffc
.getFrameworkModulesInfo(saa
);
591 for (int i
= 0; i
< saa
.length
; ++i
) {
592 ModuleIdentification mi
= GlobalData
.getModuleId(saa
[i
][ffcModGuid
] + " " + saa
[i
][ffcModVer
] + " "
593 + saa
[i
][ffcPkgGuid
] + " " + saa
[i
][ffcPkgVer
]);
594 String
[] row
= { "", "", "", "", "", "" };
596 row
[modNameColForFpdModTable
] = mi
.getName();
597 row
[modVerColForFpdModTable
] = mi
.getVersion();
598 row
[pkgNameColForFpdModTable
] = mi
.getPackage().getName();
599 row
[pkgVerColForFpdModTable
] = mi
.getPackage().getVersion();
600 row
[archColForFpdModTable
] = saa
[i
][4];
602 row
[pathColForFpdModTable
] = GlobalData
.getMsaFile(mi
).getPath().substring(
603 System
.getenv("WORKSPACE")
605 } catch (Exception e
) {
606 JOptionPane
.showMessageDialog(frame
, "Show FPD Modules:" + e
.getMessage());
609 modelFpdModules
.addRow(row
);
610 ArrayList
<String
> al
= fpdMsa
.get(saa
[i
][ffcModGuid
] + saa
[i
][ffcModVer
]
611 + saa
[i
][ffcPkgGuid
] + saa
[i
][ffcPkgVer
]);
613 al
= new ArrayList
<String
>();
614 fpdMsa
.put(saa
[i
][ffcModGuid
] + saa
[i
][ffcModVer
] + saa
[i
][ffcPkgGuid
] + saa
[i
][ffcPkgVer
], al
);
616 al
.add(saa
[i
][ffcModArch
]);
625 private void showAllModules() {
627 if (miList
== null) {
628 miList
= new ArrayList
<ModuleIdentification
>();
630 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
631 Iterator ispi
= spi
.iterator();
633 while (ispi
.hasNext()) {
634 PackageIdentification pi
= (PackageIdentification
) ispi
.next();
635 String
[] s
= { "", "", "", "", "" };
637 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
638 Iterator ismi
= smi
.iterator();
639 while (ismi
.hasNext()) {
640 ModuleIdentification mi
= (ModuleIdentification
) ismi
.next();
641 s
[modNameColForAllModTable
] = mi
.getName();
642 s
[modVerColForAllModTable
] = mi
.getVersion();
643 s
[pkgNameColForAllModTable
] = pi
.getName();
644 s
[pkgVerColForAllModTable
] = pi
.getVersion();
646 s
[pathColForAllModTable
] = GlobalData
.getMsaFile(mi
).getPath()
647 .substring(System
.getenv("WORKSPACE").length() + 1);
648 } catch (Exception e
) {
649 JOptionPane
.showMessageDialog(frame
, "Show All Modules:" + e
.getMessage());
651 modelAllModules
.addRow(s
);
658 * This method initializes this
662 private void initialize() {
663 this.setSize(633, 533);
664 this.setTitle("Framework Modules");
665 this.setContentPane(getJSplitPane());
666 this.setVisible(true);
670 } // @jve:decl-index=0:visual-constraint="10,10"
672 class NonEditableTableModel
extends DefaultTableModel
{
676 private static final long serialVersionUID
= 1L;
678 public boolean isCellEditable(int row
, int col
) {