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 ModNameMinWidth
= 168;
107 private final int ModNamePrefWidth
= 200;
109 private final int PkgNameMinWidth
= 100;
111 private final int PkgNamePrefWidth
= 110;
113 private final int PkgNameMaxWidth
= 150;
115 private final int VerMinWidth
= 50;
117 private final int VerMaxWidth
= 80;
119 private final int VerPrefWidth
= 60;
121 private final int PathPrefWidth
= 320;
123 private final int PathMinWidth
= 280;
125 private final int ArchPrefWidth
= 80;
127 private final int ArchMinWidth
= 60;
129 private final int ArchMaxWidth
= 100;
132 * This method initializes jSplitPane
134 * @return javax.swing.JSplitPane
136 private JSplitPane
getJSplitPane() {
137 if (jSplitPane
== null) {
138 jSplitPane
= new JSplitPane();
139 jSplitPane
.setOrientation(javax
.swing
.JSplitPane
.VERTICAL_SPLIT
);
140 jSplitPane
.setDividerLocation(250);
141 jSplitPane
.setBottomComponent(getJPanelBottom());
142 jSplitPane
.setTopComponent(getJPanelTop());
148 * This method initializes jPanel
150 * @return javax.swing.JPanel
152 private JPanel
getJPanelTop() {
153 if (jPanelTop
== null) {
154 jLabel
= new JLabel();
155 jLabel
.setText("Modules in Workspace");
156 jPanelTop
= new JPanel();
157 jPanelTop
.setLayout(new BorderLayout());
158 jPanelTop
.add(jLabel
, java
.awt
.BorderLayout
.NORTH
);
159 jPanelTop
.add(getJScrollPaneAllModules(), java
.awt
.BorderLayout
.CENTER
);
160 jPanelTop
.add(getJPanelTopSouth(), java
.awt
.BorderLayout
.SOUTH
);
166 * This method initializes jPanel1
168 * @return javax.swing.JPanel
170 private JPanel
getJPanelBottom() {
171 if (jPanelBottom
== null) {
172 jLabelModulesAdded
= new JLabel();
173 jLabelModulesAdded
.setText("Modules Added");
174 jPanelBottom
= new JPanel();
175 jPanelBottom
.setLayout(new BorderLayout());
176 jPanelBottom
.add(jLabelModulesAdded
, java
.awt
.BorderLayout
.NORTH
);
177 jPanelBottom
.add(getJPanelBottomSouth(), java
.awt
.BorderLayout
.SOUTH
);
178 jPanelBottom
.add(getJScrollPaneFpdModules(), java
.awt
.BorderLayout
.CENTER
);
184 * This method initializes jScrollPane
186 * @return javax.swing.JScrollPane
188 private JScrollPane
getJScrollPaneAllModules() {
189 if (jScrollPaneAllModules
== null) {
190 jScrollPaneAllModules
= new JScrollPane();
191 jScrollPaneAllModules
.setPreferredSize(new java
.awt
.Dimension(600, 200));
192 jScrollPaneAllModules
.setViewportView(getJTableAllModules());
194 return jScrollPaneAllModules
;
198 * This method initializes jTable
200 * @return javax.swing.JTable
202 private JTable
getJTableAllModules() {
203 if (jTableAllModules
== null) {
204 modelAllModules
= new NonEditableTableModel();
205 TableSorter sorter
= new TableSorter(modelAllModules
);
206 jTableAllModules
= new JTable(sorter
);
207 sorter
.setTableHeader(jTableAllModules
.getTableHeader());
208 jTableAllModules
.setRowHeight(20);
209 modelAllModules
.addColumn("<html>Module<br>Name</html>");
210 modelAllModules
.addColumn("<html>Package<br>Name</html>");
211 modelAllModules
.addColumn("Path");
212 modelAllModules
.addColumn("<html>Package<br>Version</html>");
213 modelAllModules
.addColumn("<html>Module<br>Version</html>");
215 javax
.swing
.table
.TableColumn column
= null;
216 column
= jTableAllModules
.getColumnModel().getColumn(ModNameColForAllModTable
);
217 column
.setPreferredWidth(ModNamePrefWidth
);
218 column
.setMinWidth(ModNameMinWidth
);
219 column
= jTableAllModules
.getColumnModel().getColumn(ModVerColForAllModTable
);
220 column
.setPreferredWidth(VerPrefWidth
);
221 column
.setMaxWidth(VerMaxWidth
);
222 column
.setMinWidth(VerMinWidth
);
223 column
= jTableAllModules
.getColumnModel().getColumn(PkgNameColForAllModTable
);
224 column
.setPreferredWidth(PkgNamePrefWidth
);
225 column
.setMinWidth(PkgNameMinWidth
);
226 column
.setMaxWidth(PkgNameMaxWidth
);
227 column
= jTableAllModules
.getColumnModel().getColumn(PkgVerColForAllModTable
);
228 column
.setPreferredWidth(VerPrefWidth
);
229 column
.setMaxWidth(VerMaxWidth
);
230 column
.setMinWidth(VerMinWidth
);
231 column
= jTableAllModules
.getColumnModel().getColumn(PathColForAllModTable
);
232 column
.setPreferredWidth(PathPrefWidth
);
233 column
.setMinWidth(PathMinWidth
);
235 jTableAllModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
236 jTableAllModules
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_OFF
);
238 return jTableAllModules
;
242 * This method initializes jPanel2
244 * @return javax.swing.JPanel
246 private JPanel
getJPanelTopSouth() {
247 if (jPanelTopSouth
== null) {
248 FlowLayout flowLayout
= new FlowLayout();
249 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
250 jPanelTopSouth
= new JPanel();
251 jPanelTopSouth
.setLayout(flowLayout
);
252 jPanelTopSouth
.add(getJButtonAddModule(), null);
254 return jPanelTopSouth
;
258 * This method initializes jButton
260 * @return javax.swing.JButton
262 private JButton
getJButtonAddModule() {
263 if (jButtonAddModule
== null) {
264 jButtonAddModule
= new JButton();
265 jButtonAddModule
.setPreferredSize(new java
.awt
.Dimension(130, 20));
266 jButtonAddModule
.setText("Add a Module");
267 jButtonAddModule
.addActionListener(new java
.awt
.event
.ActionListener() {
268 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
269 int selectedRow
= jTableAllModules
.getSelectedRow();
270 if (selectedRow
< 0) {
274 TableSorter sorter
= (TableSorter
) jTableAllModules
.getModel();
275 selectedRow
= sorter
.modelIndex(selectedRow
);
276 String path
= modelAllModules
.getValueAt(selectedRow
, PathColForAllModTable
) + "";
277 ModuleIdentification mi
= miList
.get(selectedRow
);
278 Vector
<String
> vArchs
= null;
280 vArchs
= GlobalData
.getModuleSupArchs(mi
);
282 catch (Exception exp
) {
283 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
286 if (vArchs
== null) {
287 JOptionPane
.showMessageDialog(frame
, "No Supported Architectures specified in MSA file.");
291 String archsAdded
= "";
292 String mg
= mi
.getGuid();
293 String mv
= mi
.getVersion();
294 String pg
= mi
.getPackage().getGuid();
295 String pv
= mi
.getPackage().getVersion();
297 ArrayList
<String
> al
= fpdMsa
.get(mg
+ mv
+ pg
+ pv
);
299 al
= new ArrayList
<String
>();
300 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, al
);
302 for (int i
= 0; i
< al
.size(); ++i
) {
303 vArchs
.remove(al
.get(i
));
306 // Archs this Module supported have already been added.
308 if (vArchs
.size() == 0) {
309 JOptionPane
.showMessageDialog(frame
, "This Module has already been added.");
312 //ToDo put Arch instead of null
313 boolean errorOccurred
= false;
314 for (int i
= 0; i
< vArchs
.size(); ++i
) {
315 String arch
= vArchs
.get(i
);
317 archsAdded
+= arch
+ " ";
318 String
[] row
= { "", "", "", "", "", "" };
321 row
[ModNameColForFpdModTable
] = mi
.getName();
322 row
[PkgNameColForFpdModTable
] = mi
.getPackage().getName();
323 row
[PathColForFpdModTable
] = path
;
324 row
[ArchColForFpdModTable
] = arch
;
325 row
[PkgVerColForFpdModTable
] = pv
;
326 row
[ModVerColForFpdModTable
] = mv
;
329 modelFpdModules
.addRow(row
);
331 docConsole
.setSaved(false);
333 //ToDo : specify archs need to add.
334 ffc
.addFrameworkModulesPcdBuildDefs(mi
, arch
, null);
335 } catch (Exception exception
) {
336 JOptionPane
.showMessageDialog(frame
, "Adding " + row
[ModNameColForFpdModTable
] + " with SupArch " + arch
337 + ": " + exception
.getMessage());
338 errorOccurred
= true;
342 String s
= "This Module with Architecture " + archsAdded
;
344 s
+= " was added with Error. Platform may NOT Build.";
346 s
+= " was added Successfully.";
348 JOptionPane
.showMessageDialog(frame
, s
);
349 jTableFpdModules
.changeSelection(modelFpdModules
.getRowCount() - 1, 0, false, false);
353 return jButtonAddModule
;
357 * This method initializes jPanel3
359 * @return javax.swing.JPanel
361 private JPanel
getJPanelBottomSouth() {
362 if (jPanelBottomSouth
== null) {
363 FlowLayout flowLayout1
= new FlowLayout();
364 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
365 jPanelBottomSouth
= new JPanel();
366 jPanelBottomSouth
.setLayout(flowLayout1
);
367 jPanelBottomSouth
.add(getJButtonSettings(), null);
368 jPanelBottomSouth
.add(getJButtonRemoveModule(), null);
370 return jPanelBottomSouth
;
374 * This method initializes jScrollPane1
376 * @return javax.swing.JScrollPane
378 private JScrollPane
getJScrollPaneFpdModules() {
379 if (jScrollPaneFpdModules
== null) {
380 jScrollPaneFpdModules
= new JScrollPane();
381 jScrollPaneFpdModules
.setPreferredSize(new java
.awt
.Dimension(453, 200));
382 jScrollPaneFpdModules
.setViewportView(getJTableFpdModules());
384 return jScrollPaneFpdModules
;
388 * This method initializes jTable1
390 * @return javax.swing.JTable
392 private JTable
getJTableFpdModules() {
393 if (jTableFpdModules
== null) {
394 modelFpdModules
= new NonEditableTableModel();
395 TableSorter sorter
= new TableSorter(modelFpdModules
);
396 jTableFpdModules
= new JTable(sorter
);
397 sorter
.setTableHeader(jTableFpdModules
.getTableHeader());
398 jTableFpdModules
.setRowHeight(20);
399 modelFpdModules
.addColumn("<html>Module<br>Name</html>");
400 modelFpdModules
.addColumn("<html>Package<br>Name</html>");
401 modelFpdModules
.addColumn("Path");
402 modelFpdModules
.addColumn("<html>Supported<br>Architectures</html>");
403 modelFpdModules
.addColumn("<html>Package<br>Version</html>");
404 modelFpdModules
.addColumn("<html>Module<br>Version</html>");
406 javax
.swing
.table
.TableColumn column
= null;
407 column
= jTableFpdModules
.getColumnModel().getColumn(ModNameColForFpdModTable
);
408 column
.setPreferredWidth(ModNamePrefWidth
);
409 column
.setMinWidth(ModNameMinWidth
);
410 column
= jTableFpdModules
.getColumnModel().getColumn(ModVerColForFpdModTable
);
411 column
.setPreferredWidth(VerPrefWidth
);
412 column
.setMaxWidth(VerMaxWidth
);
413 column
.setMinWidth(VerMinWidth
);
414 column
= jTableFpdModules
.getColumnModel().getColumn(PkgNameColForFpdModTable
);
415 column
.setPreferredWidth(PkgNamePrefWidth
);
416 column
.setMinWidth(PkgNameMinWidth
);
417 column
.setMaxWidth(PkgNameMaxWidth
);
418 column
= jTableFpdModules
.getColumnModel().getColumn(PkgVerColForFpdModTable
);
419 column
.setPreferredWidth(VerPrefWidth
);
420 column
.setMaxWidth(VerMaxWidth
);
421 column
.setMinWidth(VerMinWidth
);
422 column
= jTableFpdModules
.getColumnModel().getColumn(ArchColForFpdModTable
);
423 column
.setPreferredWidth(ArchPrefWidth
);
424 column
.setMaxWidth(ArchMaxWidth
);
425 column
.setMinWidth(ArchMinWidth
);
426 column
= jTableFpdModules
.getColumnModel().getColumn(PathColForFpdModTable
);
427 column
.setPreferredWidth(PathPrefWidth
);
428 column
.setMinWidth(PathMinWidth
);
430 jTableFpdModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
431 jTableFpdModules
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_OFF
);
433 return jTableFpdModules
;
437 * This method initializes jButton1
439 * @return javax.swing.JButton
441 private JButton
getJButtonSettings() {
442 if (jButtonSettings
== null) {
443 jButtonSettings
= new JButton();
444 jButtonSettings
.setPreferredSize(new java
.awt
.Dimension(130,20));
445 jButtonSettings
.setText("Settings");
446 jButtonSettings
.addActionListener(new java
.awt
.event
.ActionListener() {
447 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
448 int selectedRow
= jTableFpdModules
.getSelectedRow();
449 if (selectedRow
< 0) {
453 TableSorter sorter
= (TableSorter
) jTableFpdModules
.getModel();
454 selectedRow
= sorter
.modelIndex(selectedRow
);
456 if (ffc
.adjustPcd(selectedRow
)) {
457 docConsole
.setSaved(false);
460 catch (Exception exp
) {
461 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
465 if (settingDlg
== null) {
466 settingDlg
= new FpdModuleSA(ffc
);
469 String
[] sa
= new String
[5];
470 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
476 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
, selectedRow
, docConsole
);
477 settingDlg
.setVisible(true);
481 return jButtonSettings
;
485 * This method initializes jButton2
487 * @return javax.swing.JButton
489 private JButton
getJButtonRemoveModule() {
490 if (jButtonRemoveModule
== null) {
491 jButtonRemoveModule
= new JButton();
492 jButtonRemoveModule
.setPreferredSize(new java
.awt
.Dimension(130, 20));
493 jButtonRemoveModule
.setText("Remove Module");
494 jButtonRemoveModule
.addActionListener(new java
.awt
.event
.ActionListener() {
495 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
496 int selectedRow
= jTableFpdModules
.getSelectedRow();
497 if (selectedRow
< 0) {
501 TableSorter sorter
= (TableSorter
) jTableFpdModules
.getModel();
502 selectedRow
= sorter
.modelIndex(selectedRow
);
504 String
[] sa
= new String
[5];
505 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
511 ModuleIdentification mi
= GlobalData
.getModuleId(sa
[0] + " " + sa
[1] + " "
512 + sa
[2] + " " + sa
[3] + " "
514 mv
= mi
.getVersion();
515 pv
= mi
.getPackage().getVersion();
516 modelFpdModules
.removeRow(selectedRow
);
518 // if no arch specified in ModuleSA
519 fpdMsa
.remove(mg
+ mv
+ pg
+ pv
);
521 ArrayList
<String
> al
= fpdMsa
.get(mg
+ mv
+ pg
+ pv
);
523 if (al
.size() == 0) {
524 fpdMsa
.remove(mg
+ mv
+ pg
+ pv
);
528 docConsole
.setSaved(false);
529 ffc
.removeModuleSA(selectedRow
);
533 return jButtonRemoveModule
;
539 public static void main(String
[] args
) {
540 // TODO Auto-generated method stub
541 new FpdFrameworkModules().setVisible(true);
545 * This is the default constructor
547 public FpdFrameworkModules() {
552 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
558 public FpdFrameworkModules(OpeningPlatformType opt
) {
559 this(opt
.getXmlFpd());
563 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
565 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
568 JOptionPane
.showMessageDialog(frame
, "Error occurred when getting module data.");
572 ffc
= new FpdFileContents(fpd
);
576 if (fpdMsa
== null) {
577 fpdMsa
= new HashMap
<String
, ArrayList
<String
>>();
580 if (ffc
.getFrameworkModulesCount() > 0) {
581 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
582 ffc
.getFrameworkModulesInfo(saa
);
583 for (int i
= 0; i
< saa
.length
; ++i
) {
584 ModuleIdentification mi
= GlobalData
.getModuleId(saa
[i
][0] + " " + saa
[i
][1] + " "
585 + saa
[i
][2] + " " + saa
[i
][3]);
586 String
[] row
= { "", "", "", "", "", "" };
588 row
[ModNameColForFpdModTable
] = mi
.getName();
589 row
[ModVerColForFpdModTable
] = mi
.getVersion();
590 row
[PkgNameColForFpdModTable
] = mi
.getPackage().getName();
591 row
[PkgVerColForFpdModTable
] = mi
.getPackage().getVersion();
592 row
[ArchColForFpdModTable
] = saa
[i
][4];
594 row
[PathColForFpdModTable
] = GlobalData
.getMsaFile(mi
).getPath().substring(
595 System
.getenv("WORKSPACE")
597 } catch (Exception e
) {
598 JOptionPane
.showMessageDialog(frame
, "Show FPD Modules:" + e
.getMessage());
601 modelFpdModules
.addRow(row
);
602 ArrayList
<String
> al
= fpdMsa
.get(saa
[i
][0] + saa
[i
][1]
603 + saa
[i
][2] + saa
[i
][3]);
605 al
= new ArrayList
<String
>();
606 fpdMsa
.put(saa
[i
][0] + saa
[i
][1] + saa
[i
][2] + saa
[i
][3], al
);
617 private void showAllModules() {
619 if (miList
== null) {
620 miList
= new ArrayList
<ModuleIdentification
>();
622 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
623 Iterator ispi
= spi
.iterator();
625 while (ispi
.hasNext()) {
626 PackageIdentification pi
= (PackageIdentification
) ispi
.next();
627 String
[] s
= { "", "", "", "", "" };
629 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
630 Iterator ismi
= smi
.iterator();
631 while (ismi
.hasNext()) {
632 ModuleIdentification mi
= (ModuleIdentification
) ismi
.next();
633 s
[ModNameColForAllModTable
] = mi
.getName();
634 s
[ModVerColForAllModTable
] = mi
.getVersion();
635 s
[PkgNameColForAllModTable
] = pi
.getName();
636 s
[PkgVerColForAllModTable
] = pi
.getVersion();
638 s
[PathColForAllModTable
] = GlobalData
.getMsaFile(mi
).getPath()
639 .substring(System
.getenv("WORKSPACE").length() + 1);
640 } catch (Exception e
) {
641 JOptionPane
.showMessageDialog(frame
, "Show All Modules:" + e
.getMessage());
643 modelAllModules
.addRow(s
);
650 * This method initializes this
654 private void initialize() {
655 this.setSize(633, 533);
656 this.setTitle("Framework Modules");
657 this.setContentPane(getJSplitPane());
658 this.setVisible(true);
662 } // @jve:decl-index=0:visual-constraint="10,10"
664 class NonEditableTableModel
extends DefaultTableModel
{
668 private static final long serialVersionUID
= 1L;
670 public boolean isCellEditable(int row
, int col
) {