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
.JDialog
;
9 import javax
.swing
.JSplitPane
;
10 import javax
.swing
.JLabel
;
11 import javax
.swing
.JScrollPane
;
12 import javax
.swing
.JTable
;
13 import javax
.swing
.JButton
;
14 import javax
.swing
.ListSelectionModel
;
15 import javax
.swing
.table
.DefaultTableModel
;
17 import org
.tianocore
.PlatformSurfaceAreaDocument
;
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
{
34 private JSplitPane jSplitPane
= null;
35 private JPanel jPanel
= null;
36 private JPanel jPanel1
= null;
37 private JLabel jLabel
= null;
38 private JScrollPane jScrollPane
= null;
39 private JTable jTable
= null;
40 private JPanel jPanel2
= null;
41 private JButton jButton
= null;
42 private JLabel jLabel1
= null;
43 private JPanel jPanel3
= null;
44 private JScrollPane jScrollPane1
= null;
45 private JTable jTable1
= null;
46 private JButton jButton1
= null;
47 private JButton jButton2
= null;
48 private NonEditableTableModel model
= null;
49 private NonEditableTableModel model1
= null;
51 private FpdModuleSA settingDlg
= null;
53 private FpdFileContents ffc
= null;
55 private Map
<String
, String
> fpdMsa
= null;
57 private ArrayList
<ModuleIdentification
> miList
= null;
60 * This method initializes jSplitPane
62 * @return javax.swing.JSplitPane
64 private JSplitPane
getJSplitPane() {
65 if (jSplitPane
== null) {
66 jSplitPane
= new JSplitPane();
67 jSplitPane
.setOrientation(javax
.swing
.JSplitPane
.VERTICAL_SPLIT
);
68 jSplitPane
.setDividerLocation(250);
69 jSplitPane
.setBottomComponent(getJPanel1());
70 jSplitPane
.setTopComponent(getJPanel());
76 * This method initializes jPanel
78 * @return javax.swing.JPanel
80 private JPanel
getJPanel() {
82 jLabel
= new JLabel();
83 jLabel
.setText("Modules in Workspace");
84 jPanel
= new JPanel();
85 jPanel
.setLayout(new BorderLayout());
86 jPanel
.add(jLabel
, java
.awt
.BorderLayout
.NORTH
);
87 jPanel
.add(getJScrollPane(), java
.awt
.BorderLayout
.CENTER
);
88 jPanel
.add(getJPanel2(), java
.awt
.BorderLayout
.SOUTH
);
94 * This method initializes jPanel1
96 * @return javax.swing.JPanel
98 private JPanel
getJPanel1() {
99 if (jPanel1
== null) {
100 jLabel1
= new JLabel();
101 jLabel1
.setText("Modules Added");
102 jPanel1
= new JPanel();
103 jPanel1
.setLayout(new BorderLayout());
104 jPanel1
.add(jLabel1
, java
.awt
.BorderLayout
.NORTH
);
105 jPanel1
.add(getJPanel3(), java
.awt
.BorderLayout
.SOUTH
);
106 jPanel1
.add(getJScrollPane1(), java
.awt
.BorderLayout
.CENTER
);
112 * This method initializes jScrollPane
114 * @return javax.swing.JScrollPane
116 private JScrollPane
getJScrollPane() {
117 if (jScrollPane
== null) {
118 jScrollPane
= new JScrollPane();
119 jScrollPane
.setPreferredSize(new java
.awt
.Dimension(600,200));
120 jScrollPane
.setViewportView(getJTable());
126 * This method initializes jTable
128 * @return javax.swing.JTable
130 private JTable
getJTable() {
131 if (jTable
== null) {
132 model
= new NonEditableTableModel();
133 jTable
= new JTable(model
);
134 model
.addColumn("ModuleName");
135 model
.addColumn("ModuleGUID");
136 model
.addColumn("ModuleVersion");
137 model
.addColumn("PackageGUID");
138 model
.addColumn("PackageVersion");
140 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
146 * This method initializes jPanel2
148 * @return javax.swing.JPanel
150 private JPanel
getJPanel2() {
151 if (jPanel2
== null) {
152 FlowLayout flowLayout
= new FlowLayout();
153 flowLayout
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
154 jPanel2
= new JPanel();
155 jPanel2
.setLayout(flowLayout
);
156 jPanel2
.add(getJButton(), null);
162 * This method initializes jButton
164 * @return javax.swing.JButton
166 private JButton
getJButton() {
167 if (jButton
== null) {
168 jButton
= new JButton();
169 jButton
.setPreferredSize(new java
.awt
.Dimension(130,20));
170 jButton
.setText("Add a Module");
171 jButton
.addActionListener(new java
.awt
.event
.ActionListener() {
172 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
173 int selectedRow
= jTable
.getSelectedRow();
174 if (selectedRow
< 0){
178 String mg
= (String
)model
.getValueAt(selectedRow
, 1);
179 String mv
= (String
)model
.getValueAt(selectedRow
, 2);
180 String pg
= (String
)model
.getValueAt(selectedRow
, 3);
181 String pv
= (String
)model
.getValueAt(selectedRow
, 4);
182 if (fpdMsa
.containsKey(mg
+ mv
+ pg
+ pv
)) {
183 JOptionPane
.showMessageDialog(frame
, "This Module Already Added.");
186 //ToDo put Arch instead of null
187 fpdMsa
.put(mg
+ mv
+ pg
+ pv
, null);
189 String
[] row
= {" ", mg
, mv
, pg
, pv
};
190 if (getModuleId(mg
+ " " + mv
+ " " + pg
+ " " + pv
) != null) {
191 row
[0] = getModuleId(mg
+ " " + mv
+ " " + pg
+ " " + pv
).getName();
194 ffc
.addFrameworkModulesPcdBuildDefs(miList
.get(selectedRow
), null);
202 * This method initializes jPanel3
204 * @return javax.swing.JPanel
206 private JPanel
getJPanel3() {
207 if (jPanel3
== null) {
208 FlowLayout flowLayout1
= new FlowLayout();
209 flowLayout1
.setAlignment(java
.awt
.FlowLayout
.RIGHT
);
210 jPanel3
= new JPanel();
211 jPanel3
.setLayout(flowLayout1
);
212 jPanel3
.add(getJButton1(), null);
213 jPanel3
.add(getJButton2(), null);
219 * This method initializes jScrollPane1
221 * @return javax.swing.JScrollPane
223 private JScrollPane
getJScrollPane1() {
224 if (jScrollPane1
== null) {
225 jScrollPane1
= new JScrollPane();
226 jScrollPane1
.setPreferredSize(new java
.awt
.Dimension(453,200));
227 jScrollPane1
.setViewportView(getJTable1());
233 * This method initializes jTable1
235 * @return javax.swing.JTable
237 private JTable
getJTable1() {
238 if (jTable1
== null) {
239 model1
= new NonEditableTableModel();
240 jTable1
= new JTable(model1
);
241 model1
.addColumn("ModuleName");
242 model1
.addColumn("ModuleGUID");
243 model1
.addColumn("ModuleVersion");
244 model1
.addColumn("PackageGUID");
245 model1
.addColumn("PackageVersion");
246 // model1.addColumn("SupportedArch");
248 jTable1
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
254 * This method initializes jButton1
256 * @return javax.swing.JButton
258 private JButton
getJButton1() {
259 if (jButton1
== null) {
260 jButton1
= new JButton();
261 jButton1
.setPreferredSize(new java
.awt
.Dimension(130,20));
262 jButton1
.setText("Settings");
263 jButton1
.addActionListener(new java
.awt
.event
.ActionListener() {
264 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
265 int selectedRow
= jTable1
.getSelectedRow();
266 if (selectedRow
< 0){
269 if (settingDlg
== null) {
270 settingDlg
= new FpdModuleSA(ffc
);
273 String mg
= model1
.getValueAt(selectedRow
, 1).toString();
274 String mv
= model1
.getValueAt(selectedRow
, 2).toString();
275 String pg
= model1
.getValueAt(selectedRow
, 3).toString();
276 String pv
= model1
.getValueAt(selectedRow
, 4).toString();
277 settingDlg
.setKey(mg
+ " " + mv
+ " " + pg
+ " " + pv
);
278 settingDlg
.setVisible(true);
286 * This method initializes jButton2
288 * @return javax.swing.JButton
290 private JButton
getJButton2() {
291 if (jButton2
== null) {
292 jButton2
= new JButton();
293 jButton2
.setPreferredSize(new java
.awt
.Dimension(130,20));
294 jButton2
.setText("Remove Module");
295 jButton2
.addActionListener(new java
.awt
.event
.ActionListener() {
296 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
297 int selectedRow
= jTable1
.getSelectedRow();
298 if (selectedRow
< 0){
301 String mg
= model1
.getValueAt(selectedRow
, 1).toString();
302 String mv
= model1
.getValueAt(selectedRow
, 2).toString();
303 String pg
= model1
.getValueAt(selectedRow
, 3).toString();
304 String pv
= model1
.getValueAt(selectedRow
, 4).toString();
305 model1
.removeRow(selectedRow
);
306 fpdMsa
.remove(mg
+mv
+pg
+pv
);
307 ffc
.removeModuleSA(selectedRow
);
317 public static void main(String
[] args
) {
318 // TODO Auto-generated method stub
319 new FpdFrameworkModules().setVisible(true);
323 * This is the default constructor
325 public FpdFrameworkModules() {
330 public FpdFrameworkModules(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
){
336 private void init(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
338 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db", System
.getenv("WORKSPACE"));
341 JOptionPane
.showMessageDialog(frame
, "FrameworkDatabase Corrupted.");
345 ffc
= new FpdFileContents(fpd
);
349 if (fpdMsa
== null) {
350 fpdMsa
= new HashMap
<String
, String
>();
353 if (ffc
.getFrameworkModulesCount() > 0) {
354 String
[][] saa
= new String
[ffc
.getFrameworkModulesCount()][5];
355 ffc
.getFrameworkModulesInfo(saa
);
356 for (int i
= 0; i
< saa
.length
; ++i
) {
357 if (getModuleId(saa
[i
][1]+ " "+saa
[i
][2]+" "+saa
[i
][3]+" "+saa
[i
][4]) != null) {
358 saa
[i
][0] = getModuleId(saa
[i
][1]+ " "+saa
[i
][2]+" "+saa
[i
][3]+" "+saa
[i
][4]).getName();
360 model1
.addRow(saa
[i
]);
361 fpdMsa
.put(saa
[i
][1]+saa
[i
][2]+saa
[i
][3]+saa
[i
][4], saa
[i
][0]);
369 private void showAllModules() {
371 if (miList
== null) {
372 miList
= new ArrayList
<ModuleIdentification
>();
374 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
375 Iterator ispi
= spi
.iterator();
377 while(ispi
.hasNext()) {
378 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
379 String
[] s
= {"", "", "", "", ""};
381 s
[4] = pi
.getVersion();
382 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
383 Iterator ismi
= smi
.iterator();
384 while(ismi
.hasNext()) {
385 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
388 s
[2] = mi
.getVersion();
395 * This method initializes this
399 private void initialize() {
400 this.setSize(633, 533);
401 this.setTitle("Framework Modules");
402 this.setContentPane(getJSplitPane());
403 this.setVisible(true);
407 private ModuleIdentification
getModuleId(String key
){
409 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.
411 String
[] keyPart
= key
.split(" ");
412 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
413 Iterator ispi
= spi
.iterator();
415 while(ispi
.hasNext()) {
416 PackageIdentification pi
= (PackageIdentification
)ispi
.next();
417 if ( !pi
.getGuid().equals(keyPart
[2]) || !pi
.getVersion().equals(keyPart
[3])){
420 Set
<ModuleIdentification
> smi
= GlobalData
.getModules(pi
);
421 Iterator ismi
= smi
.iterator();
422 while(ismi
.hasNext()) {
423 ModuleIdentification mi
= (ModuleIdentification
)ismi
.next();
424 if (mi
.getGuid().equals(keyPart
[0]) && mi
.getVersion().equals(keyPart
[1])){
432 } // @jve:decl-index=0:visual-constraint="10,10"
434 class NonEditableTableModel
extends DefaultTableModel
{
435 public boolean isCellEditable(int row
, int col
) {