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 jPanel
= null;
41 private JPanel jPanel1
= null;
42 private JLabel jLabel
= null;
43 private JScrollPane jScrollPane
= null;
44 private JTable jTable
= null;
45 private JPanel jPanel2
= null;
46 private JButton jButton
= null;
47 private JLabel jLabel1
= null;
48 private JPanel jPanel3
= null;
49 private JScrollPane jScrollPane1
= null;
50 private JTable jTable1
= null;
51 private JButton jButton1
= null;
52 private JButton jButton2
= null;
53 private NonEditableTableModel model
= null;
54 private NonEditableTableModel model1
= 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(getJPanel1());
75 jSplitPane
.setTopComponent(getJPanel());
81 * This method initializes jPanel
83 * @return javax.swing.JPanel
85 private JPanel
getJPanel() {
87 jLabel
= new JLabel();
88 jLabel
.setText("Modules in Workspace");
89 jPanel
= new JPanel();
90 jPanel
.setLayout(new BorderLayout());
91 jPanel
.add(jLabel
, java
.awt
.BorderLayout
.NORTH
);
92 jPanel
.add(getJScrollPane(), java
.awt
.BorderLayout
.CENTER
);
93 jPanel
.add(getJPanel2(), java
.awt
.BorderLayout
.SOUTH
);
99 * This method initializes jPanel1
101 * @return javax.swing.JPanel
103 private JPanel
getJPanel1() {
104 if (jPanel1
== null) {
105 jLabel1
= new JLabel();
106 jLabel1
.setText("Modules Added");
107 jPanel1
= new JPanel();
108 jPanel1
.setLayout(new BorderLayout());
109 jPanel1
.add(jLabel1
, java
.awt
.BorderLayout
.NORTH
);
110 jPanel1
.add(getJPanel3(), java
.awt
.BorderLayout
.SOUTH
);
111 jPanel1
.add(getJScrollPane1(), java
.awt
.BorderLayout
.CENTER
);
117 * This method initializes jScrollPane
119 * @return javax.swing.JScrollPane
121 private JScrollPane
getJScrollPane() {
122 if (jScrollPane
== null) {
123 jScrollPane
= new JScrollPane();
124 jScrollPane
.setPreferredSize(new java
.awt
.Dimension(600,200));
125 jScrollPane
.setViewportView(getJTable());
131 * This method initializes jTable
133 * @return javax.swing.JTable
135 private JTable
getJTable() {
136 if (jTable
== null) {
137 model
= new NonEditableTableModel();
138 jTable
= new JTable(model
);
139 jTable
.setRowHeight(20);
140 model
.addColumn("ModuleName");
141 model
.addColumn("ModuleVersion");
142 model
.addColumn("PackageName");
143 model
.addColumn("PackageVersion");
144 model
.addColumn("Path");
146 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
152 * This method initializes jPanel2
154 * @return javax.swing.JPanel
156 private JPanel
getJPanel2() {
157 if (jPanel2
== null) {
158 FlowLayout flowLayout
= new FlowLayout();
159 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
160 jPanel2
= new JPanel();
161 jPanel2
.setLayout(flowLayout
);
162 jPanel2
.add(getJButton(), null);
168 * This method initializes jButton
170 * @return javax.swing.JButton
172 private JButton
getJButton() {
173 if (jButton
== null) {
174 jButton
= new JButton();
175 jButton
.setPreferredSize(new java
.awt
.Dimension(130,20));
176 jButton
.setText("Add a Module");
177 jButton
.addActionListener(new java
.awt
.event
.ActionListener() {
178 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
179 int selectedRow
= jTable
.getSelectedRow();
180 if (selectedRow
< 0){
184 String path
= model
.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 for (int i
= 0; i
< vArchs
.size(); ++i
) {
222 String arch
= vArchs
.get(i
);
224 archsAdded
+= arch
+ " ";
225 String
[] row
= {"", mv
, "", pv
, arch
, path
};
228 row
[0] = mi
.getName();
229 row
[2] = mi
.getPackage().getName();
234 docConsole
.setSaved(false);
236 //ToDo : specify archs need to add.
237 ffc
.addFrameworkModulesPcdBuildDefs(mi
, arch
, null);
239 catch (Exception exception
) {
240 JOptionPane
.showMessageDialog(frame
, "PCD Insertion Fail. " + exception
.getMessage());
245 JOptionPane
.showMessageDialog(frame
, "This Module with Arch "+ archsAdded
+" Added Successfully.");
246 jTable1
.changeSelection(model1
.getRowCount()-1, 0, false, false);
254 * This method initializes jPanel3
256 * @return javax.swing.JPanel
258 private JPanel
getJPanel3() {
259 if (jPanel3
== null) {
260 FlowLayout flowLayout1
= new FlowLayout();
261 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
262 jPanel3
= new JPanel();
263 jPanel3
.setLayout(flowLayout1
);
264 jPanel3
.add(getJButton1(), null);
265 jPanel3
.add(getJButton2(), null);
271 * This method initializes jScrollPane1
273 * @return javax.swing.JScrollPane
275 private JScrollPane
getJScrollPane1() {
276 if (jScrollPane1
== null) {
277 jScrollPane1
= new JScrollPane();
278 jScrollPane1
.setPreferredSize(new java
.awt
.Dimension(453,200));
279 jScrollPane1
.setViewportView(getJTable1());
285 * This method initializes jTable1
287 * @return javax.swing.JTable
289 private JTable
getJTable1() {
290 if (jTable1
== null) {
291 model1
= new NonEditableTableModel();
292 jTable1
= new JTable(model1
);
293 jTable1
.setRowHeight(20);
294 model1
.addColumn("ModuleName");
295 model1
.addColumn("ModuleVersion");
296 model1
.addColumn("PackageName");
297 model1
.addColumn("PackageVersion");
298 model1
.addColumn("SupportedArch");
299 model1
.addColumn("Path");
301 jTable1
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
307 * This method initializes jButton1
309 * @return javax.swing.JButton
311 private JButton
getJButton1() {
312 if (jButton1
== null) {
313 jButton1
= new JButton();
314 jButton1
.setPreferredSize(new java
.awt
.Dimension(130,20));
315 jButton1
.setText("Settings");
316 jButton1
.addActionListener(new java
.awt
.event
.ActionListener() {
317 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
318 int selectedRow
= jTable1
.getSelectedRow();
319 if (selectedRow
< 0){
322 if (settingDlg
== null) {
323 settingDlg
= new FpdModuleSA(ffc
);
326 String
[] sa
= new String
[5];
327 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
333 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
, selectedRow
, docConsole
);
334 settingDlg
.setVisible(true);
342 * This method initializes jButton2
344 * @return javax.swing.JButton
346 private JButton
getJButton2() {
347 if (jButton2
== null) {
348 jButton2
= new JButton();
349 jButton2
.setPreferredSize(new java
.awt
.Dimension(130,20));
350 jButton2
.setText("Remove Module");
351 jButton2
.addActionListener(new java
.awt
.event
.ActionListener() {
352 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
353 int selectedRow
= jTable1
.getSelectedRow();
354 if (selectedRow
< 0){
357 String
[] sa
= new String
[5];
358 ffc
.getFrameworkModuleInfo(selectedRow
, sa
);
364 ModuleIdentification mi
= getModuleId(sa
[0] + " " + sa
[1] + " " + sa
[2] + " " + sa
[3] + " " + sa
[4]);
365 mv
= mi
.getVersion();
366 pv
= mi
.getPackage().getVersion();
367 model1
.removeRow(selectedRow
);
369 // if no arch specified in ModuleSA
370 fpdMsa
.remove(mg
+mv
+pg
+pv
);
373 ArrayList
<String
> al
= fpdMsa
.get(mg
+mv
+pg
+pv
);
375 if (al
.size() == 0) {
376 fpdMsa
.remove(mg
+mv
+pg
+pv
);
381 docConsole
.setSaved(false);
382 ffc
.removeModuleSA(selectedRow
);
392 public static void main(String
[] args
) {
393 // TODO Auto-generated method stub
394 new FpdFrameworkModules().setVisible(true);
398 * This is the default constructor
400 public FpdFrameworkModules() {
405 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
){
411 public FpdFrameworkModules(OpeningPlatformType opt
) {
412 this(opt
.getXmlFpd());
416 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
418 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
421 JOptionPane
.showMessageDialog(frame
, "Error occurred when getting module data.");
425 ffc
= new FpdFileContents(fpd
);
429 if (fpdMsa
== null) {
430 fpdMsa
= new HashMap
<String
, ArrayList
<String
>>();
433 if (ffc
.getFrameworkModulesCount() > 0) {
434 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
435 ffc
.getFrameworkModulesInfo(saa
);
436 for (int i
= 0; i
< saa
.length
; ++i
) {
437 ModuleIdentification mi
= getModuleId(saa
[i
][0]+ " "+saa
[i
][1]+" "+saa
[i
][2]+" "+saa
[i
][3]);
438 String
[] row
= {"", "", "", "", "", ""};
440 row
[0] = mi
.getName();
441 row
[1] = mi
.getVersion();
442 row
[2] = mi
.getPackage().getName();
443 row
[3] = mi
.getPackage().getVersion();
446 row
[5] = GlobalData
.getMsaFile(mi
).getPath().substring(System
.getenv("WORKSPACE").length() + 1);
448 catch (Exception e
) {
449 JOptionPane
.showMessageDialog(frame
, "ShowFPDModules:" + e
.getMessage());
453 ArrayList
<String
> al
= fpdMsa
.get(saa
[i
][0]+row
[1]+saa
[i
][2]+row
[3]);
455 al
= new ArrayList
<String
>();
456 fpdMsa
.put(saa
[i
][0]+row
[1]+saa
[i
][2]+row
[3], al
);
467 private void showAllModules() {
469 if (miList
== null) {
470 miList
= new ArrayList
<ModuleIdentification
>();
472 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
473 Iterator ispi
= spi
.iterator();
475 while(ispi
.hasNext()) {
476 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
477 String
[] s
= {"", "", "", "", ""};
479 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
480 Iterator ismi
= smi
.iterator();
481 while(ismi
.hasNext()) {
482 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
484 s
[1] = mi
.getVersion();
486 s
[3] = pi
.getVersion();
488 s
[4] = GlobalData
.getMsaFile(mi
).getPath().substring(System
.getenv("WORKSPACE").length() + 1);
490 catch (Exception e
) {
491 JOptionPane
.showMessageDialog(frame
, "ShowAllModules:" + e
.getMessage());
499 * This method initializes this
503 private void initialize() {
504 this.setSize(633, 533);
505 this.setTitle("Framework Modules");
506 this.setContentPane(getJSplitPane());
507 this.setVisible(true);
511 private ModuleIdentification
getModuleId(String key
){
513 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion, Arch into string array.
515 String
[] keyPart
= key
.split(" ");
516 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
517 Iterator ispi
= spi
.iterator();
519 while(ispi
.hasNext()) {
520 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
521 if ( !pi
.getGuid().equalsIgnoreCase(keyPart
[2])){
525 if (keyPart
[3] != null && keyPart
[3].length() > 0 && !keyPart
[3].equals("null")){
526 if(!pi
.getVersion().equals(keyPart
[3])){
530 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
531 Iterator ismi
= smi
.iterator();
532 while(ismi
.hasNext()) {
533 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
534 if (mi
.getGuid().equalsIgnoreCase(keyPart
[0])){
535 if (keyPart
[1] != null && keyPart
[1].length() > 0 && !keyPart
[1].equals("null")){
536 if(!mi
.getVersion().equals(keyPart
[1])){
548 } // @jve:decl-index=0:visual-constraint="10,10"
550 class NonEditableTableModel
extends DefaultTableModel
{
554 private static final long serialVersionUID
= 1L;
556 public boolean isCellEditable(int row
, int col
) {