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
.ui
.IInternalFrame
;
18 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.GlobalData
;
19 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
20 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
22 import java
.awt
.FlowLayout
;
24 import java
.util
.ArrayList
;
25 import java
.util
.HashMap
;
26 import java
.util
.Iterator
;
30 public class FpdFrameworkModules
extends IInternalFrame
{
35 private static final long serialVersionUID
= 1L;
37 private JSplitPane jSplitPane
= null;
38 private JPanel jPanel
= null;
39 private JPanel jPanel1
= null;
40 private JLabel jLabel
= null;
41 private JScrollPane jScrollPane
= null;
42 private JTable jTable
= null;
43 private JPanel jPanel2
= null;
44 private JButton jButton
= null;
45 private JLabel jLabel1
= null;
46 private JPanel jPanel3
= null;
47 private JScrollPane jScrollPane1
= null;
48 private JTable jTable1
= null;
49 private JButton jButton1
= null;
50 private JButton jButton2
= null;
51 private NonEditableTableModel model
= null;
52 private NonEditableTableModel model1
= null;
54 private FpdModuleSA settingDlg
= null;
56 private FpdFileContents ffc
= null;
58 private Map
<String
, String
> fpdMsa
= null;
60 private ArrayList
<ModuleIdentification
> miList
= null;
63 * This method initializes jSplitPane
65 * @return javax.swing.JSplitPane
67 private JSplitPane
getJSplitPane() {
68 if (jSplitPane
== null) {
69 jSplitPane
= new JSplitPane();
70 jSplitPane
.setOrientation(javax
.swing
.JSplitPane
.VERTICAL_SPLIT
);
71 jSplitPane
.setDividerLocation(250);
72 jSplitPane
.setBottomComponent(getJPanel1());
73 jSplitPane
.setTopComponent(getJPanel());
79 * This method initializes jPanel
81 * @return javax.swing.JPanel
83 private JPanel
getJPanel() {
85 jLabel
= new JLabel();
86 jLabel
.setText("Modules in Workspace");
87 jPanel
= new JPanel();
88 jPanel
.setLayout(new BorderLayout());
89 jPanel
.add(jLabel
, java
.awt
.BorderLayout
.NORTH
);
90 jPanel
.add(getJScrollPane(), java
.awt
.BorderLayout
.CENTER
);
91 jPanel
.add(getJPanel2(), java
.awt
.BorderLayout
.SOUTH
);
97 * This method initializes jPanel1
99 * @return javax.swing.JPanel
101 private JPanel
getJPanel1() {
102 if (jPanel1
== null) {
103 jLabel1
= new JLabel();
104 jLabel1
.setText("Modules Added");
105 jPanel1
= new JPanel();
106 jPanel1
.setLayout(new BorderLayout());
107 jPanel1
.add(jLabel1
, java
.awt
.BorderLayout
.NORTH
);
108 jPanel1
.add(getJPanel3(), java
.awt
.BorderLayout
.SOUTH
);
109 jPanel1
.add(getJScrollPane1(), java
.awt
.BorderLayout
.CENTER
);
115 * This method initializes jScrollPane
117 * @return javax.swing.JScrollPane
119 private JScrollPane
getJScrollPane() {
120 if (jScrollPane
== null) {
121 jScrollPane
= new JScrollPane();
122 jScrollPane
.setPreferredSize(new java
.awt
.Dimension(600,200));
123 jScrollPane
.setViewportView(getJTable());
129 * This method initializes jTable
131 * @return javax.swing.JTable
133 private JTable
getJTable() {
134 if (jTable
== null) {
135 model
= new NonEditableTableModel();
136 jTable
= new JTable(model
);
137 jTable
.setRowHeight(20);
138 model
.addColumn("ModuleName");
139 model
.addColumn("ModuleGUID");
140 model
.addColumn("ModuleVersion");
141 model
.addColumn("PackageGUID");
142 model
.addColumn("PackageVersion");
144 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
150 * This method initializes jPanel2
152 * @return javax.swing.JPanel
154 private JPanel
getJPanel2() {
155 if (jPanel2
== null) {
156 FlowLayout flowLayout
= new FlowLayout();
157 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
158 jPanel2
= new JPanel();
159 jPanel2
.setLayout(flowLayout
);
160 jPanel2
.add(getJButton(), null);
166 * This method initializes jButton
168 * @return javax.swing.JButton
170 private JButton
getJButton() {
171 if (jButton
== null) {
172 jButton
= new JButton();
173 jButton
.setPreferredSize(new java
.awt
.Dimension(130,20));
174 jButton
.setText("Add a Module");
175 jButton
.addActionListener(new java
.awt
.event
.ActionListener() {
176 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
177 int selectedRow
= jTable
.getSelectedRow();
178 if (selectedRow
< 0){
182 String mg
= (String
)model
.getValueAt(selectedRow
, 1);
183 String mv
= (String
)model
.getValueAt(selectedRow
, 2);
184 String pg
= (String
)model
.getValueAt(selectedRow
, 3);
185 String pv
= (String
)model
.getValueAt(selectedRow
, 4);
186 if (fpdMsa
.containsKey(mg
+ mv
+ pg
+ pv
)) {
187 JOptionPane
.showMessageDialog(frame
, "This Module Already Added.");
190 //ToDo put Arch instead of null
191 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, null);
193 String
[] row
= {" ", mg
, mv
, pg
, pv
};
194 ModuleIdentification mi
= getModuleId(mg
+ " " + mv
+ " " + pg
+ " " + pv
);
196 row
[0] = mi
.getName();
197 row
[2] = mi
.getVersion();
198 row
[4] = mi
.getPackage().getVersion();
201 ffc
.addFrameworkModulesPcdBuildDefs(miList
.get(selectedRow
), null);
209 * This method initializes jPanel3
211 * @return javax.swing.JPanel
213 private JPanel
getJPanel3() {
214 if (jPanel3
== null) {
215 FlowLayout flowLayout1
= new FlowLayout();
216 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
217 jPanel3
= new JPanel();
218 jPanel3
.setLayout(flowLayout1
);
219 jPanel3
.add(getJButton1(), null);
220 jPanel3
.add(getJButton2(), null);
226 * This method initializes jScrollPane1
228 * @return javax.swing.JScrollPane
230 private JScrollPane
getJScrollPane1() {
231 if (jScrollPane1
== null) {
232 jScrollPane1
= new JScrollPane();
233 jScrollPane1
.setPreferredSize(new java
.awt
.Dimension(453,200));
234 jScrollPane1
.setViewportView(getJTable1());
240 * This method initializes jTable1
242 * @return javax.swing.JTable
244 private JTable
getJTable1() {
245 if (jTable1
== null) {
246 model1
= new NonEditableTableModel();
247 jTable1
= new JTable(model1
);
248 jTable1
.setRowHeight(20);
249 model1
.addColumn("ModuleName");
250 model1
.addColumn("ModuleGUID");
251 model1
.addColumn("ModuleVersion");
252 model1
.addColumn("PackageGUID");
253 model1
.addColumn("PackageVersion");
254 // model1.addColumn("SupportedArch");
256 jTable1
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
262 * This method initializes jButton1
264 * @return javax.swing.JButton
266 private JButton
getJButton1() {
267 if (jButton1
== null) {
268 jButton1
= new JButton();
269 jButton1
.setPreferredSize(new java
.awt
.Dimension(130,20));
270 jButton1
.setText("Settings");
271 jButton1
.addActionListener(new java
.awt
.event
.ActionListener() {
272 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
273 int selectedRow
= jTable1
.getSelectedRow();
274 if (selectedRow
< 0){
277 if (settingDlg
== null) {
278 settingDlg
= new FpdModuleSA(ffc
);
281 String mg
= model1
.getValueAt(selectedRow
, 1)+"";
282 String mv
= model1
.getValueAt(selectedRow
, 2)+"";
283 String pg
= model1
.getValueAt(selectedRow
, 3)+"";
284 String pv
= model1
.getValueAt(selectedRow
, 4)+"";
285 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
);
286 settingDlg
.setVisible(true);
294 * This method initializes jButton2
296 * @return javax.swing.JButton
298 private JButton
getJButton2() {
299 if (jButton2
== null) {
300 jButton2
= new JButton();
301 jButton2
.setPreferredSize(new java
.awt
.Dimension(130,20));
302 jButton2
.setText("Remove Module");
303 jButton2
.addActionListener(new java
.awt
.event
.ActionListener() {
304 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
305 int selectedRow
= jTable1
.getSelectedRow();
306 if (selectedRow
< 0){
309 String mg
= model1
.getValueAt(selectedRow
, 1).toString();
310 String mv
= model1
.getValueAt(selectedRow
, 2).toString();
311 String pg
= model1
.getValueAt(selectedRow
, 3).toString();
312 String pv
= model1
.getValueAt(selectedRow
, 4).toString();
313 model1
.removeRow(selectedRow
);
314 fpdMsa
.remove(mg
+mv
+pg
+pv
);
315 ffc
.removeModuleSA(selectedRow
);
325 public static void main(String
[] args
) {
326 // TODO Auto-generated method stub
327 new FpdFrameworkModules().setVisible(true);
331 * This is the default constructor
333 public FpdFrameworkModules() {
338 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
){
344 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
346 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
349 JOptionPane
.showMessageDialog(frame
, "FrameworkDatabase Corrupted.");
353 ffc
= new FpdFileContents(fpd
);
357 if (fpdMsa
== null) {
358 fpdMsa
= new HashMap
<String
, String
>();
361 if (ffc
.getFrameworkModulesCount() > 0) {
362 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
363 ffc
.getFrameworkModulesInfo(saa
);
364 for (int i
= 0; i
< saa
.length
; ++i
) {
365 ModuleIdentification mi
= getModuleId(saa
[i
][1]+ " "+saa
[i
][2]+" "+saa
[i
][3]+" "+saa
[i
][4]);
367 saa
[i
][0] = mi
.getName();
368 saa
[i
][2] = mi
.getVersion();
369 saa
[i
][4] = mi
.getPackage().getVersion();
371 model1
.addRow(saa
[i
]);
372 fpdMsa
.put(saa
[i
][1]+saa
[i
][2]+saa
[i
][3]+saa
[i
][4], saa
[i
][0]);
380 private void showAllModules() {
382 if (miList
== null) {
383 miList
= new ArrayList
<ModuleIdentification
>();
385 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
386 Iterator ispi
= spi
.iterator();
388 while(ispi
.hasNext()) {
389 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
390 String
[] s
= {"", "", "", "", ""};
392 s
[4] = pi
.getVersion();
393 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
394 Iterator ismi
= smi
.iterator();
395 while(ismi
.hasNext()) {
396 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
399 s
[2] = mi
.getVersion();
406 * This method initializes this
410 private void initialize() {
411 this.setSize(633, 533);
412 this.setTitle("Framework Modules");
413 this.setContentPane(getJSplitPane());
414 this.setVisible(true);
418 private ModuleIdentification
getModuleId(String key
){
420 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.
422 String
[] keyPart
= key
.split(" ");
423 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
424 Iterator ispi
= spi
.iterator();
426 while(ispi
.hasNext()) {
427 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
428 if ( !pi
.getGuid().equals(keyPart
[2])){
429 // || !pi.getVersion().equals(keyPart[3])){
432 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
433 Iterator ismi
= smi
.iterator();
434 while(ismi
.hasNext()) {
435 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
436 if (mi
.getGuid().equals(keyPart
[0])){
437 // && mi.getVersion().equals(keyPart[1])){
446 } // @jve:decl-index=0:visual-constraint="10,10"
448 class NonEditableTableModel
extends DefaultTableModel
{
452 private static final long serialVersionUID
= 1L;
454 public boolean isCellEditable(int row
, int col
) {