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 jTableAllModules
= new JTable(modelAllModules
);
139 jTableAllModules
.setRowHeight(20);
140 modelAllModules
.addColumn("ModuleName");
141 modelAllModules
.addColumn("ModuleVersion");
142 modelAllModules
.addColumn("PackageName");
143 modelAllModules
.addColumn("PackageVersion");
144 modelAllModules
.addColumn("Path");
146 jTableAllModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
148 return jTableAllModules
;
152 * This method initializes jPanel2
154 * @return javax.swing.JPanel
156 private JPanel
getJPanelTopSouth() {
157 if (jPanelTopSouth
== null) {
158 FlowLayout flowLayout
= new FlowLayout();
159 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
160 jPanelTopSouth
= new JPanel();
161 jPanelTopSouth
.setLayout(flowLayout
);
162 jPanelTopSouth
.add(getJButtonAddModule(), null);
164 return jPanelTopSouth
;
168 * This method initializes jButton
170 * @return javax.swing.JButton
172 private JButton
getJButtonAddModule() {
173 if (jButtonAddModule
== null) {
174 jButtonAddModule
= new JButton();
175 jButtonAddModule
.setPreferredSize(new java
.awt
.Dimension(130,20));
176 jButtonAddModule
.setText("Add a Module");
177 jButtonAddModule
.addActionListener(new java
.awt
.event
.ActionListener() {
178 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
179 int selectedRow
= jTableAllModules
.getSelectedRow();
180 if (selectedRow
< 0){
184 String path
= modelAllModules
.getValueAt(selectedRow
, 4)+"";
185 ModuleIdentification mi
= miList
.get(selectedRow
);
186 Vector
<String
> vArchs
= null;
188 vArchs
= GlobalData
.getModuleSupArchs(mi
);
190 catch (Exception exp
) {
191 JOptionPane
.showMessageDialog(frame
, exp
.getMessage());
194 if (vArchs
== null) {
195 JOptionPane
.showMessageDialog(frame
, "No supported Archs specified in MSA file.");
199 String archsAdded
= "";
200 String mg
= mi
.getGuid();
201 String mv
= mi
.getVersion();
202 String pg
= mi
.getPackage().getGuid();
203 String pv
= mi
.getPackage().getVersion();
205 ArrayList
<String
> al
= fpdMsa
.get(mg
+ mv
+ pg
+ pv
);
207 al
= new ArrayList
<String
>();
208 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, al
);
210 for (int i
= 0; i
< al
.size(); ++i
) {
211 vArchs
.remove(al
.get(i
));
214 // Archs this Module supported have already been added.
216 if (vArchs
.size() == 0) {
217 JOptionPane
.showMessageDialog(frame
, "This Module Already Added.");
220 //ToDo put Arch instead of null
221 boolean errorOccurred
= false;
222 for (int i
= 0; i
< vArchs
.size(); ++i
) {
223 String arch
= vArchs
.get(i
);
225 archsAdded
+= arch
+ " ";
226 String
[] row
= {"", mv
, "", pv
, arch
, path
};
229 row
[0] = mi
.getName();
230 row
[2] = mi
.getPackage().getName();
233 modelFpdModules
.addRow(row
);
235 docConsole
.setSaved(false);
237 //ToDo : specify archs need to add.
238 ffc
.addFrameworkModulesPcdBuildDefs(mi
, arch
, null);
240 catch (Exception exception
) {
241 JOptionPane
.showMessageDialog(frame
, "Adding " + row
[0] + " with SupArch " + arch
+ ": "+ exception
.getMessage());
242 errorOccurred
= true;
246 String s
= "This Module with Arch "+ archsAdded
;
248 s
+= " Added with Error. Platform may NOT Be Built.";
251 s
+= " Added Successfully.";
253 JOptionPane
.showMessageDialog(frame
, s
);
254 jTableFpdModules
.changeSelection(modelFpdModules
.getRowCount()-1, 0, false, false);
258 return jButtonAddModule
;
262 * This method initializes jPanel3
264 * @return javax.swing.JPanel
266 private JPanel
getJPanelBottomSouth() {
267 if (jPanelBottomSouth
== null) {
268 FlowLayout flowLayout1
= new FlowLayout();
269 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
270 jPanelBottomSouth
= new JPanel();
271 jPanelBottomSouth
.setLayout(flowLayout1
);
272 jPanelBottomSouth
.add(getJButtonSettings(), null);
273 jPanelBottomSouth
.add(getJButtonRemoveModule(), null);
275 return jPanelBottomSouth
;
279 * This method initializes jScrollPane1
281 * @return javax.swing.JScrollPane
283 private JScrollPane
getJScrollPaneFpdModules() {
284 if (jScrollPaneFpdModules
== null) {
285 jScrollPaneFpdModules
= new JScrollPane();
286 jScrollPaneFpdModules
.setPreferredSize(new java
.awt
.Dimension(453,200));
287 jScrollPaneFpdModules
.setViewportView(getJTableFpdModules());
289 return jScrollPaneFpdModules
;
293 * This method initializes jTable1
295 * @return javax.swing.JTable
297 private JTable
getJTableFpdModules() {
298 if (jTableFpdModules
== null) {
299 modelFpdModules
= new NonEditableTableModel();
300 jTableFpdModules
= new JTable(modelFpdModules
);
301 jTableFpdModules
.setRowHeight(20);
302 modelFpdModules
.addColumn("ModuleName");
303 modelFpdModules
.addColumn("ModuleVersion");
304 modelFpdModules
.addColumn("PackageName");
305 modelFpdModules
.addColumn("PackageVersion");
306 modelFpdModules
.addColumn("SupportedArch");
307 modelFpdModules
.addColumn("Path");
309 jTableFpdModules
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
311 return jTableFpdModules
;
315 * This method initializes jButton1
317 * @return javax.swing.JButton
319 private JButton
getJButtonSettings() {
320 if (jButtonSettings
== null) {
321 jButtonSettings
= new JButton();
322 jButtonSettings
.setPreferredSize(new java
.awt
.Dimension(130,20));
323 jButtonSettings
.setText("Settings");
324 jButtonSettings
.addActionListener(new java
.awt
.event
.ActionListener() {
325 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
326 int selectedRow
= jTableFpdModules
.getSelectedRow();
327 if (selectedRow
< 0){
330 if (settingDlg
== null) {
331 settingDlg
= new FpdModuleSA(ffc
);
334 String
[] sa
= new String
[5];
335 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
341 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
, selectedRow
, docConsole
);
342 settingDlg
.setVisible(true);
346 return jButtonSettings
;
350 * This method initializes jButton2
352 * @return javax.swing.JButton
354 private JButton
getJButtonRemoveModule() {
355 if (jButtonRemoveModule
== null) {
356 jButtonRemoveModule
= new JButton();
357 jButtonRemoveModule
.setPreferredSize(new java
.awt
.Dimension(130,20));
358 jButtonRemoveModule
.setText("Remove Module");
359 jButtonRemoveModule
.addActionListener(new java
.awt
.event
.ActionListener() {
360 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
361 int selectedRow
= jTableFpdModules
.getSelectedRow();
362 if (selectedRow
< 0){
365 String
[] sa
= new String
[5];
366 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
372 ModuleIdentification mi
= GlobalData
.getModuleId(sa
[0] + " " + sa
[1] + " " + sa
[2] + " " + sa
[3] + " " + sa
[4]);
373 mv
= mi
.getVersion();
374 pv
= mi
.getPackage().getVersion();
375 modelFpdModules
.removeRow(selectedRow
);
377 // if no arch specified in ModuleSA
378 fpdMsa
.remove(mg
+mv
+pg
+pv
);
381 ArrayList
<String
> al
= fpdMsa
.get(mg
+mv
+pg
+pv
);
383 if (al
.size() == 0) {
384 fpdMsa
.remove(mg
+mv
+pg
+pv
);
389 docConsole
.setSaved(false);
390 ffc
.removeModuleSA(selectedRow
);
394 return jButtonRemoveModule
;
400 public static void main(String
[] args
) {
401 // TODO Auto-generated method stub
402 new FpdFrameworkModules().setVisible(true);
406 * This is the default constructor
408 public FpdFrameworkModules() {
413 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
){
419 public FpdFrameworkModules(OpeningPlatformType opt
) {
420 this(opt
.getXmlFpd());
424 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
426 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
429 JOptionPane
.showMessageDialog(frame
, "Error occurred when getting module data.");
433 ffc
= new FpdFileContents(fpd
);
437 if (fpdMsa
== null) {
438 fpdMsa
= new HashMap
<String
, ArrayList
<String
>>();
441 if (ffc
.getFrameworkModulesCount() > 0) {
442 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
443 ffc
.getFrameworkModulesInfo(saa
);
444 for (int i
= 0; i
< saa
.length
; ++i
) {
445 ModuleIdentification mi
= GlobalData
.getModuleId(saa
[i
][0]+ " "+saa
[i
][1]+" "+saa
[i
][2]+" "+saa
[i
][3]);
446 String
[] row
= {"", "", "", "", "", ""};
448 row
[0] = mi
.getName();
449 row
[1] = mi
.getVersion();
450 row
[2] = mi
.getPackage().getName();
451 row
[3] = mi
.getPackage().getVersion();
454 row
[5] = GlobalData
.getMsaFile(mi
).getPath().substring(System
.getenv("WORKSPACE").length() + 1);
456 catch (Exception e
) {
457 JOptionPane
.showMessageDialog(frame
, "ShowFPDModules:" + e
.getMessage());
460 modelFpdModules
.addRow(row
);
461 ArrayList
<String
> al
= fpdMsa
.get(saa
[i
][0]+row
[1]+saa
[i
][2]+row
[3]);
463 al
= new ArrayList
<String
>();
464 fpdMsa
.put(saa
[i
][0]+row
[1]+saa
[i
][2]+row
[3], al
);
475 private void showAllModules() {
477 if (miList
== null) {
478 miList
= new ArrayList
<ModuleIdentification
>();
480 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
481 Iterator ispi
= spi
.iterator();
483 while(ispi
.hasNext()) {
484 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
485 String
[] s
= {"", "", "", "", ""};
487 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
488 Iterator ismi
= smi
.iterator();
489 while(ismi
.hasNext()) {
490 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
492 s
[1] = mi
.getVersion();
494 s
[3] = pi
.getVersion();
496 s
[4] = GlobalData
.getMsaFile(mi
).getPath().substring(System
.getenv("WORKSPACE").length() + 1);
498 catch (Exception e
) {
499 JOptionPane
.showMessageDialog(frame
, "ShowAllModules:" + e
.getMessage());
501 modelAllModules
.addRow(s
);
507 * This method initializes this
511 private void initialize() {
512 this.setSize(633, 533);
513 this.setTitle("Framework Modules");
514 this.setContentPane(getJSplitPane());
515 this.setVisible(true);
519 } // @jve:decl-index=0:visual-constraint="10,10"
521 class NonEditableTableModel
extends DefaultTableModel
{
525 private static final long serialVersionUID
= 1L;
527 public boolean isCellEditable(int row
, int col
) {