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 ModNameCol
= 0;
85 private final int ModVerCol
= 1;
87 private final int PkgNameCol
= 2;
89 private final int PkgVerCol
= 3;
91 private final int ArchCol
= 4;
93 private final int Path4Col
= 4;
95 private final int Path5Col
= 5;
97 private final int ModNameMinWidth
= 168;
99 private final int ModNamePrefWidth
= 200;
101 private final int PkgNameMinWidth
= 100;
103 private final int PkgNamePrefWidth
= 110;
105 private final int PkgNameMaxWidth
= 150;
107 private final int VerMinWidth
= 50;
109 private final int VerMaxWidth
= 80;
111 private final int VerPrefWidth
= 60;
113 private final int PathPrefWidth
= 320;
115 private final int PathMinWidth
= 280;
117 private final int ArchPrefWidth
= 80;
119 private final int ArchMinWidth
= 60;
121 private final int ArchMaxWidth
= 100;
124 * This method initializes jSplitPane
126 * @return javax.swing.JSplitPane
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());
140 * This method initializes jPanel
142 * @return javax.swing.JPanel
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
);
158 * This method initializes jPanel1
160 * @return javax.swing.JPanel
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
);
176 * This method initializes jScrollPane
178 * @return javax.swing.JScrollPane
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());
186 return jScrollPaneAllModules
;
190 * This method initializes jTable
192 * @return javax.swing.JTable
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
);
226 jTableAllModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
228 return jTableAllModules
;
232 * This method initializes jPanel2
234 * @return javax.swing.JPanel
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);
244 return jPanelTopSouth
;
248 * This method initializes jButton
250 * @return javax.swing.JButton
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) {
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;
270 vArchs
= GlobalData
.getModuleSupArchs(mi
);
272 catch (Exception exp
) {
273 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
276 if (vArchs
== null) {
277 JOptionPane
.showMessageDialog(frame
, "No Supported Architectures specified in MSA file.");
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();
287 ArrayList
<String
> al
= fpdMsa
.get(mg
+ mv
+ pg
+ pv
);
289 al
= new ArrayList
<String
>();
290 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, al
);
292 for (int i
= 0; i
< al
.size(); ++i
) {
293 vArchs
.remove(al
.get(i
));
296 // Archs this Module supported have already been added.
298 if (vArchs
.size() == 0) {
299 JOptionPane
.showMessageDialog(frame
, "This Module has already been added.");
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
);
307 archsAdded
+= arch
+ " ";
308 String
[] row
= { "", mv
, "", pv
, arch
, path
};
311 row
[ModNameCol
] = mi
.getName();
312 row
[PkgNameCol
] = mi
.getPackage().getName();
315 modelFpdModules
.addRow(row
);
317 docConsole
.setSaved(false);
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;
328 String s
= "This Module with Architecture " + archsAdded
;
330 s
+= " was added with Error. Platform may NOT Build.";
332 s
+= " was added Successfully.";
334 JOptionPane
.showMessageDialog(frame
, s
);
335 jTableFpdModules
.changeSelection(modelFpdModules
.getRowCount() - 1, 0, false, false);
339 return jButtonAddModule
;
343 * This method initializes jPanel3
345 * @return javax.swing.JPanel
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);
356 return jPanelBottomSouth
;
360 * This method initializes jScrollPane1
362 * @return javax.swing.JScrollPane
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());
370 return jScrollPaneFpdModules
;
374 * This method initializes jTable1
376 * @return javax.swing.JTable
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
);
415 jTableFpdModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
417 return jTableFpdModules
;
421 * This method initializes jButton1
423 * @return javax.swing.JButton
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) {
437 TableSorter sorter
= (TableSorter
) jTableFpdModules
.getModel();
438 selectedRow
= sorter
.modelIndex(selectedRow
);
440 if (ffc
.adjustPcd(selectedRow
)) {
441 docConsole
.setSaved(false);
444 catch (Exception exp
) {
445 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
449 if (settingDlg
== null) {
450 settingDlg
= new FpdModuleSA(ffc
);
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);
465 return jButtonSettings
;
469 * This method initializes jButton2
471 * @return javax.swing.JButton
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) {
485 TableSorter sorter
= (TableSorter
) jTableFpdModules
.getModel();
486 selectedRow
= sorter
.modelIndex(selectedRow
);
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
] + " "
498 mv
= mi
.getVersion();
499 pv
= mi
.getPackage().getVersion();
500 modelFpdModules
.removeRow(selectedRow
);
502 // if no arch specified in ModuleSA
503 fpdMsa
.remove(mg
+ mv
+ pg
+ pv
);
505 ArrayList
<String
> al
= fpdMsa
.get(mg
+ mv
+ pg
+ pv
);
507 if (al
.size() == 0) {
508 fpdMsa
.remove(mg
+ mv
+ pg
+ pv
);
512 docConsole
.setSaved(false);
513 ffc
.removeModuleSA(selectedRow
);
517 return jButtonRemoveModule
;
523 public static void main(String
[] args
) {
524 // TODO Auto-generated method stub
525 new FpdFrameworkModules().setVisible(true);
529 * This is the default constructor
531 public FpdFrameworkModules() {
536 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
542 public FpdFrameworkModules(OpeningPlatformType opt
) {
543 this(opt
.getXmlFpd());
547 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
549 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
552 JOptionPane
.showMessageDialog(frame
, "Error occurred when getting module data.");
556 ffc
= new FpdFileContents(fpd
);
560 if (fpdMsa
== null) {
561 fpdMsa
= new HashMap
<String
, ArrayList
<String
>>();
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
= { "", "", "", "", "", "" };
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
];
578 row
[Path5Col
] = GlobalData
.getMsaFile(mi
).getPath().substring(
579 System
.getenv("WORKSPACE")
581 } catch (Exception e
) {
582 JOptionPane
.showMessageDialog(frame
, "Show FPD Modules:" + e
.getMessage());
585 modelFpdModules
.addRow(row
);
586 ArrayList
<String
> al
= fpdMsa
.get(saa
[i
][ModNameCol
] + row
[ModVerCol
] + saa
[i
][PkgNameCol
]
589 al
= new ArrayList
<String
>();
590 fpdMsa
.put(saa
[i
][ModNameCol
] + row
[ModVerCol
] + saa
[i
][PkgNameCol
] + row
[PkgVerCol
], al
);
592 al
.add(saa
[i
][Path4Col
]);
601 private void showAllModules() {
603 if (miList
== null) {
604 miList
= new ArrayList
<ModuleIdentification
>();
606 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
607 Iterator ispi
= spi
.iterator();
609 while (ispi
.hasNext()) {
610 PackageIdentification pi
= (PackageIdentification
) ispi
.next();
611 String
[] s
= { "", "", "", "", "" };
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();
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());
627 modelAllModules
.addRow(s
);
634 * This method initializes this
638 private void initialize() {
639 this.setSize(633, 533);
640 this.setTitle("Framework Modules");
641 this.setContentPane(getJSplitPane());
642 this.setVisible(true);
646 } // @jve:decl-index=0:visual-constraint="10,10"
648 class NonEditableTableModel
extends DefaultTableModel
{
652 private static final long serialVersionUID
= 1L;
654 public boolean isCellEditable(int row
, int col
) {