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;
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;
56 private FpdModuleSA settingDlg
= null;
58 private FpdFileContents ffc
= null;
59 private OpeningPlatformType docConsole
= null;
60 private Map
<String
, ArrayList
<String
>> fpdMsa
= null;
62 private ArrayList
<ModuleIdentification
> miList
= null;
65 * This method initializes jSplitPane
67 * @return javax.swing.JSplitPane
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());
81 * This method initializes jPanel
83 * @return javax.swing.JPanel
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
);
99 * This method initializes jPanel1
101 * @return javax.swing.JPanel
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
);
117 * This method initializes jScrollPane
119 * @return javax.swing.JScrollPane
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());
127 return jScrollPaneAllModules
;
131 * This method initializes jTable
133 * @return javax.swing.JTable
135 private JTable
getJTableAllModules() {
136 if (jTableAllModules
== null) {
137 modelAllModules
= new NonEditableTableModel();
138 TableSorter sorter
= new TableSorter(modelAllModules
);
139 jTableAllModules
= new JTable(sorter
);
140 sorter
.setTableHeader(jTableAllModules
.getTableHeader());
141 jTableAllModules
.setRowHeight(20);
142 modelAllModules
.addColumn("ModuleName");
143 modelAllModules
.addColumn("ModuleVersion");
144 modelAllModules
.addColumn("PackageName");
145 modelAllModules
.addColumn("PackageVersion");
146 modelAllModules
.addColumn("Path");
148 jTableAllModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
150 return jTableAllModules
;
154 * This method initializes jPanel2
156 * @return javax.swing.JPanel
158 private JPanel
getJPanelTopSouth() {
159 if (jPanelTopSouth
== null) {
160 FlowLayout flowLayout
= new FlowLayout();
161 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
162 jPanelTopSouth
= new JPanel();
163 jPanelTopSouth
.setLayout(flowLayout
);
164 jPanelTopSouth
.add(getJButtonAddModule(), null);
166 return jPanelTopSouth
;
170 * This method initializes jButton
172 * @return javax.swing.JButton
174 private JButton
getJButtonAddModule() {
175 if (jButtonAddModule
== null) {
176 jButtonAddModule
= new JButton();
177 jButtonAddModule
.setPreferredSize(new java
.awt
.Dimension(130,20));
178 jButtonAddModule
.setText("Add a Module");
179 jButtonAddModule
.addActionListener(new java
.awt
.event
.ActionListener() {
180 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
181 int selectedRow
= jTableAllModules
.getSelectedRow();
182 if (selectedRow
< 0){
186 TableSorter sorter
= (TableSorter
)jTableAllModules
.getModel();
187 selectedRow
= sorter
.modelIndex(selectedRow
);
188 String path
= modelAllModules
.getValueAt(selectedRow
, 4)+"";
189 ModuleIdentification mi
= miList
.get(selectedRow
);
190 Vector
<String
> vArchs
= null;
192 vArchs
= GlobalData
.getModuleSupArchs(mi
);
194 catch (Exception exp
) {
195 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
198 if (vArchs
== null) {
199 JOptionPane
.showMessageDialog(frame
, "No supported Archs specified in MSA file.");
203 String archsAdded
= "";
204 String mg
= mi
.getGuid();
205 String mv
= mi
.getVersion();
206 String pg
= mi
.getPackage().getGuid();
207 String pv
= mi
.getPackage().getVersion();
209 ArrayList
<String
> al
= fpdMsa
.get(mg
+ mv
+ pg
+ pv
);
211 al
= new ArrayList
<String
>();
212 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, al
);
214 for (int i
= 0; i
< al
.size(); ++i
) {
215 vArchs
.remove(al
.get(i
));
218 // Archs this Module supported have already been added.
220 if (vArchs
.size() == 0) {
221 JOptionPane
.showMessageDialog(frame
, "This Module Already Added.");
224 //ToDo put Arch instead of null
225 boolean errorOccurred
= false;
226 for (int i
= 0; i
< vArchs
.size(); ++i
) {
227 String arch
= vArchs
.get(i
);
229 archsAdded
+= arch
+ " ";
230 String
[] row
= {"", mv
, "", pv
, arch
, path
};
233 row
[0] = mi
.getName();
234 row
[2] = mi
.getPackage().getName();
237 modelFpdModules
.addRow(row
);
239 docConsole
.setSaved(false);
241 //ToDo : specify archs need to add.
242 ffc
.addFrameworkModulesPcdBuildDefs(mi
, arch
, null);
244 catch (Exception exception
) {
245 JOptionPane
.showMessageDialog(frame
, "Adding " + row
[0] + " with SupArch " + arch
+ ": "+ exception
.getMessage());
246 errorOccurred
= true;
250 String s
= "This Module with Arch "+ archsAdded
;
252 s
+= " Added with Error. Platform may NOT Be Built.";
255 s
+= " Added Successfully.";
257 JOptionPane
.showMessageDialog(frame
, s
);
258 jTableFpdModules
.changeSelection(modelFpdModules
.getRowCount()-1, 0, false, false);
262 return jButtonAddModule
;
266 * This method initializes jPanel3
268 * @return javax.swing.JPanel
270 private JPanel
getJPanelBottomSouth() {
271 if (jPanelBottomSouth
== null) {
272 FlowLayout flowLayout1
= new FlowLayout();
273 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
274 jPanelBottomSouth
= new JPanel();
275 jPanelBottomSouth
.setLayout(flowLayout1
);
276 jPanelBottomSouth
.add(getJButtonSettings(), null);
277 jPanelBottomSouth
.add(getJButtonRemoveModule(), null);
279 return jPanelBottomSouth
;
283 * This method initializes jScrollPane1
285 * @return javax.swing.JScrollPane
287 private JScrollPane
getJScrollPaneFpdModules() {
288 if (jScrollPaneFpdModules
== null) {
289 jScrollPaneFpdModules
= new JScrollPane();
290 jScrollPaneFpdModules
.setPreferredSize(new java
.awt
.Dimension(453,200));
291 jScrollPaneFpdModules
.setViewportView(getJTableFpdModules());
293 return jScrollPaneFpdModules
;
297 * This method initializes jTable1
299 * @return javax.swing.JTable
301 private JTable
getJTableFpdModules() {
302 if (jTableFpdModules
== null) {
303 modelFpdModules
= new NonEditableTableModel();
304 TableSorter sorter
= new TableSorter(modelFpdModules
);
305 jTableFpdModules
= new JTable(sorter
);
306 sorter
.setTableHeader(jTableFpdModules
.getTableHeader());
307 jTableFpdModules
.setRowHeight(20);
308 modelFpdModules
.addColumn("ModuleName");
309 modelFpdModules
.addColumn("ModuleVersion");
310 modelFpdModules
.addColumn("PackageName");
311 modelFpdModules
.addColumn("PackageVersion");
312 modelFpdModules
.addColumn("SupportedArch");
313 modelFpdModules
.addColumn("Path");
315 jTableFpdModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
317 return jTableFpdModules
;
321 * This method initializes jButton1
323 * @return javax.swing.JButton
325 private JButton
getJButtonSettings() {
326 if (jButtonSettings
== null) {
327 jButtonSettings
= new JButton();
328 jButtonSettings
.setPreferredSize(new java
.awt
.Dimension(130,20));
329 jButtonSettings
.setText("Settings");
330 jButtonSettings
.addActionListener(new java
.awt
.event
.ActionListener() {
331 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
332 int selectedRow
= jTableFpdModules
.getSelectedRow();
333 if (selectedRow
< 0){
337 TableSorter sorter
= (TableSorter
)jTableFpdModules
.getModel();
338 selectedRow
= sorter
.modelIndex(selectedRow
);
340 if (ffc
.adjustPcd(selectedRow
)) {
341 docConsole
.setSaved(false);
344 catch (Exception exp
) {
345 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
349 if (settingDlg
== null) {
350 settingDlg
= new FpdModuleSA(ffc
);
353 String
[] sa
= new String
[5];
354 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
360 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
, selectedRow
, docConsole
);
361 settingDlg
.setVisible(true);
365 return jButtonSettings
;
370 * This method initializes jButton2
372 * @return javax.swing.JButton
374 private JButton
getJButtonRemoveModule() {
375 if (jButtonRemoveModule
== null) {
376 jButtonRemoveModule
= new JButton();
377 jButtonRemoveModule
.setPreferredSize(new java
.awt
.Dimension(130,20));
378 jButtonRemoveModule
.setText("Remove Module");
379 jButtonRemoveModule
.addActionListener(new java
.awt
.event
.ActionListener() {
380 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
381 int selectedRow
= jTableFpdModules
.getSelectedRow();
382 if (selectedRow
< 0){
386 TableSorter sorter
= (TableSorter
)jTableFpdModules
.getModel();
387 selectedRow
= sorter
.modelIndex(selectedRow
);
389 String
[] sa
= new String
[5];
390 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
396 ModuleIdentification mi
= GlobalData
.getModuleId(sa
[0] + " " + sa
[1] + " " + sa
[2] + " " + sa
[3] + " " + sa
[4]);
397 mv
= mi
.getVersion();
398 pv
= mi
.getPackage().getVersion();
399 modelFpdModules
.removeRow(selectedRow
);
401 // if no arch specified in ModuleSA
402 fpdMsa
.remove(mg
+mv
+pg
+pv
);
405 ArrayList
<String
> al
= fpdMsa
.get(mg
+mv
+pg
+pv
);
407 if (al
.size() == 0) {
408 fpdMsa
.remove(mg
+mv
+pg
+pv
);
413 docConsole
.setSaved(false);
414 ffc
.removeModuleSA(selectedRow
);
418 return jButtonRemoveModule
;
424 public static void main(String
[] args
) {
425 // TODO Auto-generated method stub
426 new FpdFrameworkModules().setVisible(true);
430 * This is the default constructor
432 public FpdFrameworkModules() {
437 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
){
443 public FpdFrameworkModules(OpeningPlatformType opt
) {
444 this(opt
.getXmlFpd());
448 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
450 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
453 JOptionPane
.showMessageDialog(frame
, "Error occurred when getting module data.");
457 ffc
= new FpdFileContents(fpd
);
461 if (fpdMsa
== null) {
462 fpdMsa
= new HashMap
<String
, ArrayList
<String
>>();
465 if (ffc
.getFrameworkModulesCount() > 0) {
466 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
467 ffc
.getFrameworkModulesInfo(saa
);
468 for (int i
= 0; i
< saa
.length
; ++i
) {
469 ModuleIdentification mi
= GlobalData
.getModuleId(saa
[i
][0]+ " "+saa
[i
][1]+" "+saa
[i
][2]+" "+saa
[i
][3]);
470 String
[] row
= {"", "", "", "", "", ""};
472 row
[0] = mi
.getName();
473 row
[1] = mi
.getVersion();
474 row
[2] = mi
.getPackage().getName();
475 row
[3] = mi
.getPackage().getVersion();
478 row
[5] = GlobalData
.getMsaFile(mi
).getPath().substring(System
.getenv("WORKSPACE").length() + 1);
480 catch (Exception e
) {
481 JOptionPane
.showMessageDialog(frame
, "ShowFPDModules:" + e
.getMessage());
484 modelFpdModules
.addRow(row
);
485 ArrayList
<String
> al
= fpdMsa
.get(saa
[i
][0]+row
[1]+saa
[i
][2]+row
[3]);
487 al
= new ArrayList
<String
>();
488 fpdMsa
.put(saa
[i
][0]+row
[1]+saa
[i
][2]+row
[3], al
);
499 private void showAllModules() {
501 if (miList
== null) {
502 miList
= new ArrayList
<ModuleIdentification
>();
504 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
505 Iterator ispi
= spi
.iterator();
507 while(ispi
.hasNext()) {
508 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
509 String
[] s
= {"", "", "", "", ""};
511 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
512 Iterator ismi
= smi
.iterator();
513 while(ismi
.hasNext()) {
514 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
516 s
[1] = mi
.getVersion();
518 s
[3] = pi
.getVersion();
520 s
[4] = GlobalData
.getMsaFile(mi
).getPath().substring(System
.getenv("WORKSPACE").length() + 1);
522 catch (Exception e
) {
523 JOptionPane
.showMessageDialog(frame
, "ShowAllModules:" + e
.getMessage());
525 modelAllModules
.addRow(s
);
531 * This method initializes this
535 private void initialize() {
536 this.setSize(633, 533);
537 this.setTitle("Framework Modules");
538 this.setContentPane(getJSplitPane());
539 this.setVisible(true);
543 } // @jve:decl-index=0:visual-constraint="10,10"
545 class NonEditableTableModel
extends DefaultTableModel
{
549 private static final long serialVersionUID
= 1L;
551 public boolean isCellEditable(int row
, int col
) {