]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java
auto adjust pcd settings when display existing ModuleSA settings. if new PCD added...
[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.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;
22
23 import java.awt.FlowLayout;
24 import java.io.File;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.Vector;
31
32 public class FpdFrameworkModules extends IInternalFrame {
33
34 /**
35 *
36 */
37 private static final long serialVersionUID = 1L;
38 static JFrame frame;
39 private JSplitPane jSplitPane = null;
40 private JPanel jPanelTop = null;
41 private JPanel jPanelBottom = null;
42 private JLabel jLabel = null;
43 private JScrollPane jScrollPaneAllModules = null;
44 private JTable jTableAllModules = null;
45 private JPanel jPanelTopSouth = null;
46 private JButton jButtonAddModule = null;
47 private JLabel jLabelModulesAdded = null;
48 private JPanel jPanelBottomSouth = null;
49 private JScrollPane jScrollPaneFpdModules = null;
50 private JTable jTableFpdModules = null;
51 private JButton jButtonSettings = null;
52 private JButton jButtonRemoveModule = null;
53 private NonEditableTableModel modelAllModules = null;
54 private NonEditableTableModel modelFpdModules = null;
55
56 private FpdModuleSA settingDlg = null;
57
58 private FpdFileContents ffc = null;
59 private OpeningPlatformType docConsole = null;
60 private Map<String, ArrayList<String>> fpdMsa = null;
61
62 private ArrayList<ModuleIdentification> miList = null;
63
64 /**
65 * This method initializes jSplitPane
66 *
67 * @return javax.swing.JSplitPane
68 */
69 private JSplitPane getJSplitPane() {
70 if (jSplitPane == null) {
71 jSplitPane = new JSplitPane();
72 jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
73 jSplitPane.setDividerLocation(250);
74 jSplitPane.setBottomComponent(getJPanelBottom());
75 jSplitPane.setTopComponent(getJPanelTop());
76 }
77 return jSplitPane;
78 }
79
80 /**
81 * This method initializes jPanel
82 *
83 * @return javax.swing.JPanel
84 */
85 private JPanel getJPanelTop() {
86 if (jPanelTop == null) {
87 jLabel = new JLabel();
88 jLabel.setText("Modules in Workspace");
89 jPanelTop = new JPanel();
90 jPanelTop.setLayout(new BorderLayout());
91 jPanelTop.add(jLabel, java.awt.BorderLayout.NORTH);
92 jPanelTop.add(getJScrollPaneAllModules(), java.awt.BorderLayout.CENTER);
93 jPanelTop.add(getJPanelTopSouth(), java.awt.BorderLayout.SOUTH);
94 }
95 return jPanelTop;
96 }
97
98 /**
99 * This method initializes jPanel1
100 *
101 * @return javax.swing.JPanel
102 */
103 private JPanel getJPanelBottom() {
104 if (jPanelBottom == null) {
105 jLabelModulesAdded = new JLabel();
106 jLabelModulesAdded.setText("Modules Added");
107 jPanelBottom = new JPanel();
108 jPanelBottom.setLayout(new BorderLayout());
109 jPanelBottom.add(jLabelModulesAdded, java.awt.BorderLayout.NORTH);
110 jPanelBottom.add(getJPanelBottomSouth(), java.awt.BorderLayout.SOUTH);
111 jPanelBottom.add(getJScrollPaneFpdModules(), java.awt.BorderLayout.CENTER);
112 }
113 return jPanelBottom;
114 }
115
116 /**
117 * This method initializes jScrollPane
118 *
119 * @return javax.swing.JScrollPane
120 */
121 private JScrollPane getJScrollPaneAllModules() {
122 if (jScrollPaneAllModules == null) {
123 jScrollPaneAllModules = new JScrollPane();
124 jScrollPaneAllModules.setPreferredSize(new java.awt.Dimension(600,200));
125 jScrollPaneAllModules.setViewportView(getJTableAllModules());
126 }
127 return jScrollPaneAllModules;
128 }
129
130 /**
131 * This method initializes jTable
132 *
133 * @return javax.swing.JTable
134 */
135 private JTable getJTableAllModules() {
136 if (jTableAllModules == null) {
137 modelAllModules = new NonEditableTableModel();
138 TableSorter sorter = new TableSorter(modelAllModules);
139 jTableAllModules = new JTable(sorter);
140 sorter.setTableHeader(jTableAllModules.getTableHeader());
141 jTableAllModules.setRowHeight(20);
142 modelAllModules.addColumn("ModuleName");
143 modelAllModules.addColumn("ModuleVersion");
144 modelAllModules.addColumn("PackageName");
145 modelAllModules.addColumn("PackageVersion");
146 modelAllModules.addColumn("Path");
147
148 jTableAllModules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
149 }
150 return jTableAllModules;
151 }
152
153 /**
154 * This method initializes jPanel2
155 *
156 * @return javax.swing.JPanel
157 */
158 private JPanel getJPanelTopSouth() {
159 if (jPanelTopSouth == null) {
160 FlowLayout flowLayout = new FlowLayout();
161 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
162 jPanelTopSouth = new JPanel();
163 jPanelTopSouth.setLayout(flowLayout);
164 jPanelTopSouth.add(getJButtonAddModule(), null);
165 }
166 return jPanelTopSouth;
167 }
168
169 /**
170 * This method initializes jButton
171 *
172 * @return javax.swing.JButton
173 */
174 private JButton getJButtonAddModule() {
175 if (jButtonAddModule == null) {
176 jButtonAddModule = new JButton();
177 jButtonAddModule.setPreferredSize(new java.awt.Dimension(130,20));
178 jButtonAddModule.setText("Add a Module");
179 jButtonAddModule.addActionListener(new java.awt.event.ActionListener() {
180 public void actionPerformed(java.awt.event.ActionEvent e) {
181 int selectedRow = jTableAllModules.getSelectedRow();
182 if (selectedRow < 0){
183 return;
184 }
185
186 TableSorter sorter = (TableSorter)jTableAllModules.getModel();
187 selectedRow = sorter.modelIndex(selectedRow);
188 String path = modelAllModules.getValueAt(selectedRow, 4)+"";
189 ModuleIdentification mi = miList.get(selectedRow);
190 Vector<String> vArchs = null;
191 try {
192 vArchs = GlobalData.getModuleSupArchs(mi);
193 }
194 catch (Exception exp) {
195 JOptionPane.showMessageDialog(frame, exp.getMessage());
196 }
197
198 if (vArchs == null) {
199 JOptionPane.showMessageDialog(frame, "No supported Archs specified in MSA file.");
200 return;
201 }
202
203 String archsAdded = "";
204 String mg = mi.getGuid();
205 String mv = mi.getVersion();
206 String pg = mi.getPackage().getGuid();
207 String pv = mi.getPackage().getVersion();
208
209 ArrayList<String> al = fpdMsa.get(mg + mv + pg + pv);
210 if (al == null) {
211 al = new ArrayList<String>();
212 fpdMsa.put(mg + mv + pg + pv, al);
213 }
214 for (int i = 0; i < al.size(); ++i) {
215 vArchs.remove(al.get(i));
216 }
217 //
218 // Archs this Module supported have already been added.
219 //
220 if (vArchs.size() == 0) {
221 JOptionPane.showMessageDialog(frame, "This Module Already Added.");
222 return;
223 }
224 //ToDo put Arch instead of null
225 boolean errorOccurred = false;
226 for (int i = 0; i < vArchs.size(); ++i) {
227 String arch = vArchs.get(i);
228 al.add(arch);
229 archsAdded += arch + " ";
230 String[] row = {"", mv, "", pv, arch, path};
231
232 if (mi != null) {
233 row[0] = mi.getName();
234 row[2] = mi.getPackage().getName();
235
236 }
237 modelFpdModules.addRow(row);
238
239 docConsole.setSaved(false);
240 try{
241 //ToDo : specify archs need to add.
242 ffc.addFrameworkModulesPcdBuildDefs(mi, arch, null);
243 }
244 catch (Exception exception) {
245 JOptionPane.showMessageDialog(frame, "Adding " + row[0] + " with SupArch " + arch + ": "+ exception.getMessage());
246 errorOccurred = true;
247 }
248 }
249
250 String s = "This Module with Arch "+ archsAdded;
251 if (errorOccurred) {
252 s += " Added with Error. Platform may NOT Be Built.";
253 }
254 else {
255 s += " Added Successfully.";
256 }
257 JOptionPane.showMessageDialog(frame, s);
258 jTableFpdModules.changeSelection(modelFpdModules.getRowCount()-1, 0, false, false);
259 }
260 });
261 }
262 return jButtonAddModule;
263 }
264
265 /**
266 * This method initializes jPanel3
267 *
268 * @return javax.swing.JPanel
269 */
270 private JPanel getJPanelBottomSouth() {
271 if (jPanelBottomSouth == null) {
272 FlowLayout flowLayout1 = new FlowLayout();
273 flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
274 jPanelBottomSouth = new JPanel();
275 jPanelBottomSouth.setLayout(flowLayout1);
276 jPanelBottomSouth.add(getJButtonSettings(), null);
277 jPanelBottomSouth.add(getJButtonRemoveModule(), null);
278 }
279 return jPanelBottomSouth;
280 }
281
282 /**
283 * This method initializes jScrollPane1
284 *
285 * @return javax.swing.JScrollPane
286 */
287 private JScrollPane getJScrollPaneFpdModules() {
288 if (jScrollPaneFpdModules == null) {
289 jScrollPaneFpdModules = new JScrollPane();
290 jScrollPaneFpdModules.setPreferredSize(new java.awt.Dimension(453,200));
291 jScrollPaneFpdModules.setViewportView(getJTableFpdModules());
292 }
293 return jScrollPaneFpdModules;
294 }
295
296 /**
297 * This method initializes jTable1
298 *
299 * @return javax.swing.JTable
300 */
301 private JTable getJTableFpdModules() {
302 if (jTableFpdModules == null) {
303 modelFpdModules = new NonEditableTableModel();
304 TableSorter sorter = new TableSorter(modelFpdModules);
305 jTableFpdModules = new JTable(sorter);
306 sorter.setTableHeader(jTableFpdModules.getTableHeader());
307 jTableFpdModules.setRowHeight(20);
308 modelFpdModules.addColumn("ModuleName");
309 modelFpdModules.addColumn("ModuleVersion");
310 modelFpdModules.addColumn("PackageName");
311 modelFpdModules.addColumn("PackageVersion");
312 modelFpdModules.addColumn("SupportedArch");
313 modelFpdModules.addColumn("Path");
314
315 jTableFpdModules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
316 }
317 return jTableFpdModules;
318 }
319
320 /**
321 * This method initializes jButton1
322 *
323 * @return javax.swing.JButton
324 */
325 private JButton getJButtonSettings() {
326 if (jButtonSettings == null) {
327 jButtonSettings = new JButton();
328 jButtonSettings.setPreferredSize(new java.awt.Dimension(130,20));
329 jButtonSettings.setText("Settings");
330 jButtonSettings.addActionListener(new java.awt.event.ActionListener() {
331 public void actionPerformed(java.awt.event.ActionEvent e) {
332 int selectedRow = jTableFpdModules.getSelectedRow();
333 if (selectedRow < 0){
334 return;
335 }
336
337 TableSorter sorter = (TableSorter)jTableFpdModules.getModel();
338 selectedRow = sorter.modelIndex(selectedRow);
339 try {
340 if (ffc.adjustPcd(selectedRow)) {
341 docConsole.setSaved(false);
342 }
343 }
344 catch (Exception exp) {
345 JOptionPane.showMessageDialog(frame, exp.getMessage());
346 return;
347 }
348
349 if (settingDlg == null) {
350 settingDlg = new FpdModuleSA(ffc);
351 }
352
353 String[] sa = new String[5];
354 ffc.getFrameworkModuleInfo(selectedRow, sa);
355 String mg = sa[0];
356 String mv = sa[1];
357 String pg = sa[2];
358 String pv = sa[3];
359 String arch = sa[4];
360 settingDlg.setKey(mg + " " + mv + " " + pg + " " + pv + " " + arch, selectedRow, docConsole);
361 settingDlg.setVisible(true);
362 }
363 });
364 }
365 return jButtonSettings;
366 }
367
368
369 /**
370 * This method initializes jButton2
371 *
372 * @return javax.swing.JButton
373 */
374 private JButton getJButtonRemoveModule() {
375 if (jButtonRemoveModule == null) {
376 jButtonRemoveModule = new JButton();
377 jButtonRemoveModule.setPreferredSize(new java.awt.Dimension(130,20));
378 jButtonRemoveModule.setText("Remove Module");
379 jButtonRemoveModule.addActionListener(new java.awt.event.ActionListener() {
380 public void actionPerformed(java.awt.event.ActionEvent e) {
381 int selectedRow = jTableFpdModules.getSelectedRow();
382 if (selectedRow < 0){
383 return;
384 }
385
386 TableSorter sorter = (TableSorter)jTableFpdModules.getModel();
387 selectedRow = sorter.modelIndex(selectedRow);
388
389 String[] sa = new String[5];
390 ffc.getFrameworkModuleInfo(selectedRow, sa);
391 String mg = sa[0];
392 String mv = sa[1];
393 String pg = sa[2];
394 String pv = sa[3];
395 String arch = sa[4];
396 ModuleIdentification mi = GlobalData.getModuleId(sa[0] + " " + sa[1] + " " + sa[2] + " " + sa[3] + " " + sa[4]);
397 mv = mi.getVersion();
398 pv = mi.getPackage().getVersion();
399 modelFpdModules.removeRow(selectedRow);
400 if (arch == null) {
401 // if no arch specified in ModuleSA
402 fpdMsa.remove(mg+mv+pg+pv);
403 }
404 else {
405 ArrayList<String> al = fpdMsa.get(mg+mv+pg+pv);
406 al.remove(arch);
407 if (al.size() == 0) {
408 fpdMsa.remove(mg+mv+pg+pv);
409 }
410 }
411
412
413 docConsole.setSaved(false);
414 ffc.removeModuleSA(selectedRow);
415 }
416 });
417 }
418 return jButtonRemoveModule;
419 }
420
421 /**
422 * @param args
423 */
424 public static void main(String[] args) {
425 // TODO Auto-generated method stub
426 new FpdFrameworkModules().setVisible(true);
427 }
428
429 /**
430 * This is the default constructor
431 */
432 public FpdFrameworkModules() {
433 super();
434 initialize();
435 }
436
437 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd){
438 this();
439 init(fpd);
440
441 }
442
443 public FpdFrameworkModules(OpeningPlatformType opt) {
444 this(opt.getXmlFpd());
445 docConsole = opt;
446 }
447
448 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
449 try {
450 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db", System.getenv("WORKSPACE"));
451 }
452 catch(Exception e){
453 JOptionPane.showMessageDialog(frame, "Error occurred when getting module data.");
454 }
455
456 if (ffc == null){
457 ffc = new FpdFileContents(fpd);
458 ffc.initDynPcdMap();
459 }
460
461 if (fpdMsa == null) {
462 fpdMsa = new HashMap<String, ArrayList<String>>();
463 }
464
465 if (ffc.getFrameworkModulesCount() > 0) {
466 String[][] saa = new String[ffc.getFrameworkModulesCount()][5];
467 ffc.getFrameworkModulesInfo(saa);
468 for (int i = 0; i < saa.length; ++i) {
469 ModuleIdentification mi = GlobalData.getModuleId(saa[i][0]+ " "+saa[i][1]+" "+saa[i][2]+" "+saa[i][3]);
470 String[] row = {"", "", "", "", "", ""};
471 if (mi != null) {
472 row[0] = mi.getName();
473 row[1] = mi.getVersion();
474 row[2] = mi.getPackage().getName();
475 row[3] = mi.getPackage().getVersion();
476 row[4] = saa[i][4];
477 try{
478 row[5] = GlobalData.getMsaFile(mi).getPath().substring(System.getenv("WORKSPACE").length() + 1);
479 }
480 catch (Exception e) {
481 JOptionPane.showMessageDialog(frame, "ShowFPDModules:" + e.getMessage());
482 }
483 }
484 modelFpdModules.addRow(row);
485 ArrayList<String> al = fpdMsa.get(saa[i][0]+row[1]+saa[i][2]+row[3]);
486 if (al == null) {
487 al = new ArrayList<String>();
488 fpdMsa.put(saa[i][0]+row[1]+saa[i][2]+row[3], al);
489 }
490 al.add(saa[i][4]);
491
492 }
493 }
494
495 showAllModules();
496
497 }
498
499 private void showAllModules() {
500
501 if (miList == null) {
502 miList = new ArrayList<ModuleIdentification>();
503 }
504 Set<PackageIdentification> spi = GlobalData.getPackageList();
505 Iterator ispi = spi.iterator();
506
507 while(ispi.hasNext()) {
508 PackageIdentification pi = (PackageIdentification)ispi.next();
509 String[] s = {"", "", "", "", ""};
510
511 Set<ModuleIdentification> smi = GlobalData.getModules(pi);
512 Iterator ismi = smi.iterator();
513 while(ismi.hasNext()) {
514 ModuleIdentification mi = (ModuleIdentification)ismi.next();
515 s[0] = mi.getName();
516 s[1] = mi.getVersion();
517 s[2] = pi.getName();
518 s[3] = pi.getVersion();
519 try {
520 s[4] = GlobalData.getMsaFile(mi).getPath().substring(System.getenv("WORKSPACE").length() + 1);
521 }
522 catch (Exception e) {
523 JOptionPane.showMessageDialog(frame, "ShowAllModules:" + e.getMessage());
524 }
525 modelAllModules.addRow(s);
526 miList.add(mi);
527 }
528 }
529 }
530 /**
531 * This method initializes this
532 *
533 * @return void
534 */
535 private void initialize() {
536 this.setSize(633, 533);
537 this.setTitle("Framework Modules");
538 this.setContentPane(getJSplitPane());
539 this.setVisible(true);
540
541 }
542
543 } // @jve:decl-index=0:visual-constraint="10,10"
544
545 class NonEditableTableModel extends DefaultTableModel {
546 /**
547 *
548 */
549 private static final long serialVersionUID = 1L;
550
551 public boolean isCellEditable(int row, int col) {
552 return false;
553 }
554 }