]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java
some bug fixing for FpdFrameworkModules
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFrameworkModules.java
1 package org.tianocore.frameworkwizard.platform.ui;
2
3 import java.awt.BorderLayout;
4
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;
15
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;
21
22 import java.awt.FlowLayout;
23 import java.io.File;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.Map;
28 import java.util.Set;
29
30 public class FpdFrameworkModules extends IInternalFrame {
31
32 /**
33 *
34 */
35 private static final long serialVersionUID = 1L;
36 static JFrame frame;
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;
53
54 private FpdModuleSA settingDlg = null;
55
56 private FpdFileContents ffc = null;
57
58 private Map<String, String> fpdMsa = null;
59
60 private ArrayList<ModuleIdentification> miList = null;
61
62 /**
63 * This method initializes jSplitPane
64 *
65 * @return javax.swing.JSplitPane
66 */
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());
74 }
75 return jSplitPane;
76 }
77
78 /**
79 * This method initializes jPanel
80 *
81 * @return javax.swing.JPanel
82 */
83 private JPanel getJPanel() {
84 if (jPanel == null) {
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);
92 }
93 return jPanel;
94 }
95
96 /**
97 * This method initializes jPanel1
98 *
99 * @return javax.swing.JPanel
100 */
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);
110 }
111 return jPanel1;
112 }
113
114 /**
115 * This method initializes jScrollPane
116 *
117 * @return javax.swing.JScrollPane
118 */
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());
124 }
125 return jScrollPane;
126 }
127
128 /**
129 * This method initializes jTable
130 *
131 * @return javax.swing.JTable
132 */
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");
143
144 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
145 }
146 return jTable;
147 }
148
149 /**
150 * This method initializes jPanel2
151 *
152 * @return javax.swing.JPanel
153 */
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);
161 }
162 return jPanel2;
163 }
164
165 /**
166 * This method initializes jButton
167 *
168 * @return javax.swing.JButton
169 */
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){
179 return;
180 }
181
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.");
188 return;
189 }
190 //ToDo put Arch instead of null
191 fpdMsa.put(mg + mv + pg + pv, null);
192
193 String[] row = {" ", mg, mv, pg, pv};
194 ModuleIdentification mi = getModuleId(mg + " " + mv + " " + pg + " " + pv);
195 if (mi != null) {
196 row[0] = mi.getName();
197 row[2] = mi.getVersion();
198 row[4] = mi.getPackage().getVersion();
199 }
200 model1.addRow(row);
201 ffc.addFrameworkModulesPcdBuildDefs(miList.get(selectedRow), null);
202 }
203 });
204 }
205 return jButton;
206 }
207
208 /**
209 * This method initializes jPanel3
210 *
211 * @return javax.swing.JPanel
212 */
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);
221 }
222 return jPanel3;
223 }
224
225 /**
226 * This method initializes jScrollPane1
227 *
228 * @return javax.swing.JScrollPane
229 */
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());
235 }
236 return jScrollPane1;
237 }
238
239 /**
240 * This method initializes jTable1
241 *
242 * @return javax.swing.JTable
243 */
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");
255
256 jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
257 }
258 return jTable1;
259 }
260
261 /**
262 * This method initializes jButton1
263 *
264 * @return javax.swing.JButton
265 */
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){
275 return;
276 }
277 if (settingDlg == null) {
278 settingDlg = new FpdModuleSA(ffc);
279 }
280
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);
287 }
288 });
289 }
290 return jButton1;
291 }
292
293 /**
294 * This method initializes jButton2
295 *
296 * @return javax.swing.JButton
297 */
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){
307 return;
308 }
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);
316 }
317 });
318 }
319 return jButton2;
320 }
321
322 /**
323 * @param args
324 */
325 public static void main(String[] args) {
326 // TODO Auto-generated method stub
327 new FpdFrameworkModules().setVisible(true);
328 }
329
330 /**
331 * This is the default constructor
332 */
333 public FpdFrameworkModules() {
334 super();
335 initialize();
336 }
337
338 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd){
339 this();
340 init(fpd);
341
342 }
343
344 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
345 try {
346 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", System.getenv("WORKSPACE"));
347 }
348 catch(Exception e){
349 JOptionPane.showMessageDialog(frame, "FrameworkDatabase Corrupted.");
350 }
351
352 if (ffc == null){
353 ffc = new FpdFileContents(fpd);
354 ffc.initDynPcdMap();
355 }
356
357 if (fpdMsa == null) {
358 fpdMsa = new HashMap<String, String>();
359 }
360
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]);
366 if (mi != null) {
367 saa[i][0] = mi.getName();
368 saa[i][2] = mi.getVersion();
369 saa[i][4] = mi.getPackage().getVersion();
370 }
371 model1.addRow(saa[i]);
372 fpdMsa.put(saa[i][1]+saa[i][2]+saa[i][3]+saa[i][4], saa[i][0]);
373 }
374 }
375
376 showAllModules();
377
378 }
379
380 private void showAllModules() {
381
382 if (miList == null) {
383 miList = new ArrayList<ModuleIdentification>();
384 }
385 Set<PackageIdentification> spi = GlobalData.getPackageList();
386 Iterator ispi = spi.iterator();
387
388 while(ispi.hasNext()) {
389 PackageIdentification pi = (PackageIdentification)ispi.next();
390 String[] s = {"", "", "", "", ""};
391 s[3] = pi.getGuid();
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();
397 s[0] = mi.getName();
398 s[1] = mi.getGuid();
399 s[2] = mi.getVersion();
400 model.addRow(s);
401 miList.add(mi);
402 }
403 }
404 }
405 /**
406 * This method initializes this
407 *
408 * @return void
409 */
410 private void initialize() {
411 this.setSize(633, 533);
412 this.setTitle("Framework Modules");
413 this.setContentPane(getJSplitPane());
414 this.setVisible(true);
415
416 }
417
418 private ModuleIdentification getModuleId(String key){
419 //
420 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.
421 //
422 String[] keyPart = key.split(" ");
423 Set<PackageIdentification> spi = GlobalData.getPackageList();
424 Iterator ispi = spi.iterator();
425
426 while(ispi.hasNext()) {
427 PackageIdentification pi = (PackageIdentification)ispi.next();
428 if ( !pi.getGuid().equals(keyPart[2])){
429 // || !pi.getVersion().equals(keyPart[3])){
430 continue;
431 }
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])){
438
439 return mi;
440 }
441 }
442 }
443 return null;
444 }
445
446 } // @jve:decl-index=0:visual-constraint="10,10"
447
448 class NonEditableTableModel extends DefaultTableModel {
449 /**
450 *
451 */
452 private static final long serialVersionUID = 1L;
453
454 public boolean isCellEditable(int row, int col) {
455 return false;
456 }
457 }