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 model
.addColumn("ModuleName");
138 model
.addColumn("ModuleGUID");
139 model
.addColumn("ModuleVersion");
140 model
.addColumn("PackageGUID");
141 model
.addColumn("PackageVersion");
143 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
149 * This method initializes jPanel2
151 * @return javax.swing.JPanel
153 private JPanel
getJPanel2() {
154 if (jPanel2
== null) {
155 FlowLayout flowLayout
= new FlowLayout();
156 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
157 jPanel2
= new JPanel();
158 jPanel2
.setLayout(flowLayout
);
159 jPanel2
.add(getJButton(), null);
165 * This method initializes jButton
167 * @return javax.swing.JButton
169 private JButton
getJButton() {
170 if (jButton
== null) {
171 jButton
= new JButton();
172 jButton
.setPreferredSize(new java
.awt
.Dimension(130,20));
173 jButton
.setText("Add a Module");
174 jButton
.addActionListener(new java
.awt
.event
.ActionListener() {
175 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
176 int selectedRow
= jTable
.getSelectedRow();
177 if (selectedRow
< 0){
181 String mg
= (String
)model
.getValueAt(selectedRow
, 1);
182 String mv
= (String
)model
.getValueAt(selectedRow
, 2);
183 String pg
= (String
)model
.getValueAt(selectedRow
, 3);
184 String pv
= (String
)model
.getValueAt(selectedRow
, 4);
185 if (fpdMsa
.containsKey(mg
+ mv
+ pg
+ pv
)) {
186 JOptionPane
.showMessageDialog(frame
, "This Module Already Added.");
189 //ToDo put Arch instead of null
190 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, null);
192 String
[] row
= {" ", mg
, mv
, pg
, pv
};
193 if (getModuleId(mg
+ " " + mv
+ " " + pg
+ " " + pv
) != null) {
194 row
[0] = getModuleId(mg
+ " " + mv
+ " " + pg
+ " " + pv
).getName();
197 ffc
.addFrameworkModulesPcdBuildDefs(miList
.get(selectedRow
), null);
205 * This method initializes jPanel3
207 * @return javax.swing.JPanel
209 private JPanel
getJPanel3() {
210 if (jPanel3
== null) {
211 FlowLayout flowLayout1
= new FlowLayout();
212 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
213 jPanel3
= new JPanel();
214 jPanel3
.setLayout(flowLayout1
);
215 jPanel3
.add(getJButton1(), null);
216 jPanel3
.add(getJButton2(), null);
222 * This method initializes jScrollPane1
224 * @return javax.swing.JScrollPane
226 private JScrollPane
getJScrollPane1() {
227 if (jScrollPane1
== null) {
228 jScrollPane1
= new JScrollPane();
229 jScrollPane1
.setPreferredSize(new java
.awt
.Dimension(453,200));
230 jScrollPane1
.setViewportView(getJTable1());
236 * This method initializes jTable1
238 * @return javax.swing.JTable
240 private JTable
getJTable1() {
241 if (jTable1
== null) {
242 model1
= new NonEditableTableModel();
243 jTable1
= new JTable(model1
);
244 model1
.addColumn("ModuleName");
245 model1
.addColumn("ModuleGUID");
246 model1
.addColumn("ModuleVersion");
247 model1
.addColumn("PackageGUID");
248 model1
.addColumn("PackageVersion");
249 // model1.addColumn("SupportedArch");
251 jTable1
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
257 * This method initializes jButton1
259 * @return javax.swing.JButton
261 private JButton
getJButton1() {
262 if (jButton1
== null) {
263 jButton1
= new JButton();
264 jButton1
.setPreferredSize(new java
.awt
.Dimension(130,20));
265 jButton1
.setText("Settings");
266 jButton1
.addActionListener(new java
.awt
.event
.ActionListener() {
267 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
268 int selectedRow
= jTable1
.getSelectedRow();
269 if (selectedRow
< 0){
272 if (settingDlg
== null) {
273 settingDlg
= new FpdModuleSA(ffc
);
276 String mg
= model1
.getValueAt(selectedRow
, 1).toString();
277 String mv
= model1
.getValueAt(selectedRow
, 2).toString();
278 String pg
= model1
.getValueAt(selectedRow
, 3).toString();
279 String pv
= model1
.getValueAt(selectedRow
, 4).toString();
280 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
);
281 settingDlg
.setVisible(true);
289 * This method initializes jButton2
291 * @return javax.swing.JButton
293 private JButton
getJButton2() {
294 if (jButton2
== null) {
295 jButton2
= new JButton();
296 jButton2
.setPreferredSize(new java
.awt
.Dimension(130,20));
297 jButton2
.setText("Remove Module");
298 jButton2
.addActionListener(new java
.awt
.event
.ActionListener() {
299 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
300 int selectedRow
= jTable1
.getSelectedRow();
301 if (selectedRow
< 0){
304 String mg
= model1
.getValueAt(selectedRow
, 1).toString();
305 String mv
= model1
.getValueAt(selectedRow
, 2).toString();
306 String pg
= model1
.getValueAt(selectedRow
, 3).toString();
307 String pv
= model1
.getValueAt(selectedRow
, 4).toString();
308 model1
.removeRow(selectedRow
);
309 fpdMsa
.remove(mg
+mv
+pg
+pv
);
310 ffc
.removeModuleSA(selectedRow
);
320 public static void main(String
[] args
) {
321 // TODO Auto-generated method stub
322 new FpdFrameworkModules().setVisible(true);
326 * This is the default constructor
328 public FpdFrameworkModules() {
333 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
){
339 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
341 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
344 JOptionPane
.showMessageDialog(frame
, "FrameworkDatabase Corrupted.");
348 ffc
= new FpdFileContents(fpd
);
352 if (fpdMsa
== null) {
353 fpdMsa
= new HashMap
<String
, String
>();
356 if (ffc
.getFrameworkModulesCount() > 0) {
357 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
358 ffc
.getFrameworkModulesInfo(saa
);
359 for (int i
= 0; i
< saa
.length
; ++i
) {
360 if (getModuleId(saa
[i
][1]+ " "+saa
[i
][2]+" "+saa
[i
][3]+" "+saa
[i
][4]) != null) {
361 saa
[i
][0] = getModuleId(saa
[i
][1]+ " "+saa
[i
][2]+" "+saa
[i
][3]+" "+saa
[i
][4]).getName();
363 model1
.addRow(saa
[i
]);
364 fpdMsa
.put(saa
[i
][1]+saa
[i
][2]+saa
[i
][3]+saa
[i
][4], saa
[i
][0]);
372 private void showAllModules() {
374 if (miList
== null) {
375 miList
= new ArrayList
<ModuleIdentification
>();
377 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
378 Iterator ispi
= spi
.iterator();
380 while(ispi
.hasNext()) {
381 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
382 String
[] s
= {"", "", "", "", ""};
384 s
[4] = pi
.getVersion();
385 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
386 Iterator ismi
= smi
.iterator();
387 while(ismi
.hasNext()) {
388 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
391 s
[2] = mi
.getVersion();
398 * This method initializes this
402 private void initialize() {
403 this.setSize(633, 533);
404 this.setTitle("Framework Modules");
405 this.setContentPane(getJSplitPane());
406 this.setVisible(true);
410 private ModuleIdentification
getModuleId(String key
){
412 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.
414 String
[] keyPart
= key
.split(" ");
415 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
416 Iterator ispi
= spi
.iterator();
418 while(ispi
.hasNext()) {
419 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
420 if ( !pi
.getGuid().equals(keyPart
[2]) || !pi
.getVersion().equals(keyPart
[3])){
423 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
424 Iterator ismi
= smi
.iterator();
425 while(ismi
.hasNext()) {
426 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
427 if (mi
.getGuid().equals(keyPart
[0]) && mi
.getVersion().equals(keyPart
[1])){
435 } // @jve:decl-index=0:visual-constraint="10,10"
437 class NonEditableTableModel
extends DefaultTableModel
{
441 private static final long serialVersionUID
= 1L;
443 public boolean isCellEditable(int row
, int col
) {