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
;
31 public class FpdFrameworkModules
extends IInternalFrame
{
36 private static final long serialVersionUID
= 1L;
38 private JSplitPane jSplitPane
= null;
39 private JPanel jPanel
= null;
40 private JPanel jPanel1
= null;
41 private JLabel jLabel
= null;
42 private JScrollPane jScrollPane
= null;
43 private JTable jTable
= null;
44 private JPanel jPanel2
= null;
45 private JButton jButton
= null;
46 private JLabel jLabel1
= null;
47 private JPanel jPanel3
= null;
48 private JScrollPane jScrollPane1
= null;
49 private JTable jTable1
= null;
50 private JButton jButton1
= null;
51 private JButton jButton2
= null;
52 private NonEditableTableModel model
= null;
53 private NonEditableTableModel model1
= null;
55 private FpdModuleSA settingDlg
= null;
57 private FpdFileContents ffc
= null;
58 private OpeningPlatformType docConsole
= null;
59 private Map
<String
, String
> fpdMsa
= null;
61 private ArrayList
<ModuleIdentification
> miList
= null;
64 * This method initializes jSplitPane
66 * @return javax.swing.JSplitPane
68 private JSplitPane
getJSplitPane() {
69 if (jSplitPane
== null) {
70 jSplitPane
= new JSplitPane();
71 jSplitPane
.setOrientation(javax
.swing
.JSplitPane
.VERTICAL_SPLIT
);
72 jSplitPane
.setDividerLocation(250);
73 jSplitPane
.setBottomComponent(getJPanel1());
74 jSplitPane
.setTopComponent(getJPanel());
80 * This method initializes jPanel
82 * @return javax.swing.JPanel
84 private JPanel
getJPanel() {
86 jLabel
= new JLabel();
87 jLabel
.setText("Modules in Workspace");
88 jPanel
= new JPanel();
89 jPanel
.setLayout(new BorderLayout());
90 jPanel
.add(jLabel
, java
.awt
.BorderLayout
.NORTH
);
91 jPanel
.add(getJScrollPane(), java
.awt
.BorderLayout
.CENTER
);
92 jPanel
.add(getJPanel2(), java
.awt
.BorderLayout
.SOUTH
);
98 * This method initializes jPanel1
100 * @return javax.swing.JPanel
102 private JPanel
getJPanel1() {
103 if (jPanel1
== null) {
104 jLabel1
= new JLabel();
105 jLabel1
.setText("Modules Added");
106 jPanel1
= new JPanel();
107 jPanel1
.setLayout(new BorderLayout());
108 jPanel1
.add(jLabel1
, java
.awt
.BorderLayout
.NORTH
);
109 jPanel1
.add(getJPanel3(), java
.awt
.BorderLayout
.SOUTH
);
110 jPanel1
.add(getJScrollPane1(), java
.awt
.BorderLayout
.CENTER
);
116 * This method initializes jScrollPane
118 * @return javax.swing.JScrollPane
120 private JScrollPane
getJScrollPane() {
121 if (jScrollPane
== null) {
122 jScrollPane
= new JScrollPane();
123 jScrollPane
.setPreferredSize(new java
.awt
.Dimension(600,200));
124 jScrollPane
.setViewportView(getJTable());
130 * This method initializes jTable
132 * @return javax.swing.JTable
134 private JTable
getJTable() {
135 if (jTable
== null) {
136 model
= new NonEditableTableModel();
137 jTable
= new JTable(model
);
138 jTable
.setRowHeight(20);
139 model
.addColumn("ModuleName");
140 model
.addColumn("ModuleGUID");
141 model
.addColumn("ModuleVersion");
142 model
.addColumn("PackageGUID");
143 model
.addColumn("PackageVersion");
145 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
151 * This method initializes jPanel2
153 * @return javax.swing.JPanel
155 private JPanel
getJPanel2() {
156 if (jPanel2
== null) {
157 FlowLayout flowLayout
= new FlowLayout();
158 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
159 jPanel2
= new JPanel();
160 jPanel2
.setLayout(flowLayout
);
161 jPanel2
.add(getJButton(), null);
167 * This method initializes jButton
169 * @return javax.swing.JButton
171 private JButton
getJButton() {
172 if (jButton
== null) {
173 jButton
= new JButton();
174 jButton
.setPreferredSize(new java
.awt
.Dimension(130,20));
175 jButton
.setText("Add a Module");
176 jButton
.addActionListener(new java
.awt
.event
.ActionListener() {
177 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
178 int selectedRow
= jTable
.getSelectedRow();
179 if (selectedRow
< 0){
183 String mg
= (String
)model
.getValueAt(selectedRow
, 1);
184 String mv
= (String
)model
.getValueAt(selectedRow
, 2);
185 String pg
= (String
)model
.getValueAt(selectedRow
, 3);
186 String pv
= (String
)model
.getValueAt(selectedRow
, 4);
187 if (fpdMsa
.containsKey(mg
+ mv
+ pg
+ pv
)) {
188 JOptionPane
.showMessageDialog(frame
, "This Module Already Added.");
191 //ToDo put Arch instead of null
192 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, null);
194 String
[] row
= {" ", mg
, mv
, pg
, pv
};
195 ModuleIdentification mi
= getModuleId(mg
+ " " + mv
+ " " + pg
+ " " + pv
);
197 row
[0] = mi
.getName();
198 row
[2] = mi
.getVersion();
199 row
[4] = mi
.getPackage().getVersion();
203 docConsole
.setSaved(false);
205 ffc
.addFrameworkModulesPcdBuildDefs(miList
.get(selectedRow
), null);
207 catch (Exception exception
) {
208 JOptionPane
.showMessageDialog(frame
, "PCD Insertion Fail. " + exception
.getMessage());
210 JOptionPane
.showMessageDialog(frame
, "This Module Added Successfully.");
211 jTable1
.changeSelection(model1
.getRowCount()-1, 0, false, false);
219 * This method initializes jPanel3
221 * @return javax.swing.JPanel
223 private JPanel
getJPanel3() {
224 if (jPanel3
== null) {
225 FlowLayout flowLayout1
= new FlowLayout();
226 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
227 jPanel3
= new JPanel();
228 jPanel3
.setLayout(flowLayout1
);
229 jPanel3
.add(getJButton1(), null);
230 jPanel3
.add(getJButton2(), null);
236 * This method initializes jScrollPane1
238 * @return javax.swing.JScrollPane
240 private JScrollPane
getJScrollPane1() {
241 if (jScrollPane1
== null) {
242 jScrollPane1
= new JScrollPane();
243 jScrollPane1
.setPreferredSize(new java
.awt
.Dimension(453,200));
244 jScrollPane1
.setViewportView(getJTable1());
250 * This method initializes jTable1
252 * @return javax.swing.JTable
254 private JTable
getJTable1() {
255 if (jTable1
== null) {
256 model1
= new NonEditableTableModel();
257 jTable1
= new JTable(model1
);
258 jTable1
.setRowHeight(20);
259 model1
.addColumn("ModuleName");
260 model1
.addColumn("ModuleGUID");
261 model1
.addColumn("ModuleVersion");
262 model1
.addColumn("PackageGUID");
263 model1
.addColumn("PackageVersion");
264 // model1.addColumn("SupportedArch");
266 jTable1
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
272 * This method initializes jButton1
274 * @return javax.swing.JButton
276 private JButton
getJButton1() {
277 if (jButton1
== null) {
278 jButton1
= new JButton();
279 jButton1
.setPreferredSize(new java
.awt
.Dimension(130,20));
280 jButton1
.setText("Settings");
281 jButton1
.addActionListener(new java
.awt
.event
.ActionListener() {
282 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
283 int selectedRow
= jTable1
.getSelectedRow();
284 if (selectedRow
< 0){
287 if (settingDlg
== null) {
288 settingDlg
= new FpdModuleSA(ffc
);
290 docConsole
.setSaved(false);
291 String mg
= model1
.getValueAt(selectedRow
, 1)+"";
292 String mv
= model1
.getValueAt(selectedRow
, 2)+"";
293 String pg
= model1
.getValueAt(selectedRow
, 3)+"";
294 String pv
= model1
.getValueAt(selectedRow
, 4)+"";
295 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
);
296 settingDlg
.setVisible(true);
304 * This method initializes jButton2
306 * @return javax.swing.JButton
308 private JButton
getJButton2() {
309 if (jButton2
== null) {
310 jButton2
= new JButton();
311 jButton2
.setPreferredSize(new java
.awt
.Dimension(130,20));
312 jButton2
.setText("Remove Module");
313 jButton2
.addActionListener(new java
.awt
.event
.ActionListener() {
314 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
315 int selectedRow
= jTable1
.getSelectedRow();
316 if (selectedRow
< 0){
319 String mg
= model1
.getValueAt(selectedRow
, 1).toString();
320 String mv
= model1
.getValueAt(selectedRow
, 2).toString();
321 String pg
= model1
.getValueAt(selectedRow
, 3).toString();
322 String pv
= model1
.getValueAt(selectedRow
, 4).toString();
323 model1
.removeRow(selectedRow
);
324 fpdMsa
.remove(mg
+mv
+pg
+pv
);
325 docConsole
.setSaved(false);
326 ffc
.removeModuleSA(selectedRow
);
336 public static void main(String
[] args
) {
337 // TODO Auto-generated method stub
338 new FpdFrameworkModules().setVisible(true);
342 * This is the default constructor
344 public FpdFrameworkModules() {
349 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
){
355 public FpdFrameworkModules(OpeningPlatformType opt
) {
356 this(opt
.getXmlFpd());
360 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
362 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
365 JOptionPane
.showMessageDialog(frame
, "FrameworkDatabase Corrupted.");
369 ffc
= new FpdFileContents(fpd
);
373 if (fpdMsa
== null) {
374 fpdMsa
= new HashMap
<String
, String
>();
377 if (ffc
.getFrameworkModulesCount() > 0) {
378 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
379 ffc
.getFrameworkModulesInfo(saa
);
380 for (int i
= 0; i
< saa
.length
; ++i
) {
381 ModuleIdentification mi
= getModuleId(saa
[i
][1]+ " "+saa
[i
][2]+" "+saa
[i
][3]+" "+saa
[i
][4]);
383 saa
[i
][0] = mi
.getName();
384 saa
[i
][2] = mi
.getVersion();
385 saa
[i
][4] = mi
.getPackage().getVersion();
387 model1
.addRow(saa
[i
]);
388 fpdMsa
.put(saa
[i
][1]+saa
[i
][2]+saa
[i
][3]+saa
[i
][4], saa
[i
][0]);
396 private void showAllModules() {
398 if (miList
== null) {
399 miList
= new ArrayList
<ModuleIdentification
>();
401 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
402 Iterator ispi
= spi
.iterator();
404 while(ispi
.hasNext()) {
405 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
406 String
[] s
= {"", "", "", "", ""};
408 s
[4] = pi
.getVersion();
409 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
410 Iterator ismi
= smi
.iterator();
411 while(ismi
.hasNext()) {
412 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
415 s
[2] = mi
.getVersion();
422 * This method initializes this
426 private void initialize() {
427 this.setSize(633, 533);
428 this.setTitle("Framework Modules");
429 this.setContentPane(getJSplitPane());
430 this.setVisible(true);
434 private ModuleIdentification
getModuleId(String key
){
436 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.
438 String
[] keyPart
= key
.split(" ");
439 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
440 Iterator ispi
= spi
.iterator();
442 while(ispi
.hasNext()) {
443 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
444 if ( !pi
.getGuid().equals(keyPart
[2])){
448 if (keyPart
[3] != null && keyPart
[3].length() > 0 && !keyPart
[3].equals("null")){
449 if(!pi
.getVersion().equals(keyPart
[3])){
453 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
454 Iterator ismi
= smi
.iterator();
455 while(ismi
.hasNext()) {
456 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
457 if (mi
.getGuid().equals(keyPart
[0])){
458 if (keyPart
[1] != null && keyPart
[1].length() > 0 && !keyPart
[1].equals("null")){
459 if(!mi
.getVersion().equals(keyPart
[1])){
471 } // @jve:decl-index=0:visual-constraint="10,10"
473 class NonEditableTableModel
extends DefaultTableModel
{
477 private static final long serialVersionUID
= 1L;
479 public boolean isCellEditable(int row
, int col
) {