Fix EDKT337,Double click on modules in "Framework Modules" of Platforms should be...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFrameworkModules.java
1 /** @file
2
3 The file is used to create, update FrameworkModules of Fpd file
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 package org.tianocore.frameworkwizard.platform.ui;
16
17 import java.awt.BorderLayout;
18
19 import javax.swing.JFrame;
20 import javax.swing.JOptionPane;
21 import javax.swing.JPanel;
22 import javax.swing.JSplitPane;
23 import javax.swing.JLabel;
24 import javax.swing.JScrollPane;
25 import javax.swing.JTable;
26 import javax.swing.JButton;
27 import javax.swing.ListSelectionModel;
28 import javax.swing.event.TableModelEvent;
29 import javax.swing.table.DefaultTableModel;
30 import javax.swing.table.TableModel;
31
32 import org.tianocore.PlatformSurfaceAreaDocument;
33 import org.tianocore.frameworkwizard.common.GlobalData;
34 import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformType;
35 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
36 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
37 import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;
38 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
39
40 import java.awt.FlowLayout;
41 import java.awt.event.MouseEvent;
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.Iterator;
45 import java.util.Map;
46 import java.util.Vector;
47
48 public class FpdFrameworkModules extends IInternalFrame {
49
50 /**
51 * Initialize Globals
52 */
53 private static final long serialVersionUID = 1L;
54
55 public static final int forceDbgColForFpdModTable = 7;
56
57 static JFrame frame;
58
59 private JSplitPane jSplitPane = null;
60
61 private JPanel jPanelTop = null;
62
63 private JPanel jPanelBottom = null;
64
65 private JLabel jLabel = null;
66
67 private JScrollPane jScrollPaneAllModules = null;
68
69 private JTable jTableAllModules = null;
70
71 private JPanel jPanelTopSouth = null;
72
73 private JButton jButtonAddModule = null;
74
75 private JLabel jLabelModulesAdded = null;
76
77 private JPanel jPanelBottomSouth = null;
78
79 private JScrollPane jScrollPaneFpdModules = null;
80
81 private JTable jTableFpdModules = null;
82
83 private JButton jButtonSettings = null;
84
85 private JButton jButtonRemoveModule = null;
86
87 private NonEditableTableModel modelAllModules = null;
88
89 private FpdModulesTableModel modelFpdModules = null;
90
91 private FpdModuleSA settingDlg = null;
92
93 private FpdFileContents ffc = null;
94
95 private OpeningPlatformType docConsole = null;
96
97 private Map<String, ArrayList<String>> fpdMsa = null;
98
99 private ArrayList<ModuleIdentification> miList = null;
100
101 /**
102 * Column settings for displaying all modules in workspace
103 */
104 private final int modNameColForAllModTable = 0;
105
106 private final int pkgNameColForAllModTable = 1;
107
108 private final int pathColForAllModTable = 2;
109
110 private final int typeColForAllModTable = 3;
111
112 private final int pkgVerColForAllModTable = 5;
113
114 private final int modVerColForAllModTable = 4;
115
116 /**
117 * Column settings for display modules in the FPD file
118 */
119 private final int modNameColForFpdModTable = 0;
120
121 private final int pkgNameColForFpdModTable = 1;
122
123 private final int pathColForFpdModTable = 2;
124
125 private final int archColForFpdModTable = 3;
126
127 private final int pkgVerColForFpdModTable = 6;
128
129 private final int modVerColForFpdModTable = 5;
130
131 private final int typeColForFpdModTable = 4;
132
133 /**
134 * FpdFileContents structure
135 */
136 private final int ffcModGuid = 0;
137
138 private final int ffcModVer = 1;
139
140 private final int ffcPkgGuid = 2;
141
142 private final int ffcPkgVer = 3;
143
144 private final int ffcModArch = 4;
145
146 /**
147 * Set Column Widths, Only the PATH should not have a max width.
148 */
149 private final int modNameMinWidth = 168;
150
151 private final int modNamePrefWidth = 200;
152
153 private final int modNameMaxWidth = 350;
154
155 private final int pkgNameMinWidth = 100;
156
157 private final int pkgNamePrefWidth = 130;
158
159 private final int pkgNameMaxWidth = 150;
160
161 private final int verMinWidth = 60;
162
163 private final int verMaxWidth = 80;
164
165 private final int verPrefWidth = 70;
166
167 private final int pathPrefWidth = 600;
168
169 private final int pathMinWidth = 280;
170
171 private final int archPrefWidth = 80;
172
173 private final int archMinWidth = 60;
174
175 private final int archMaxWidth = 100;
176
177 private final int typePrefWidth = 145;
178
179 private final int typeMinWidth = 100;
180
181 private final int typeMaxWidth = 155;
182
183 /**
184 * This method initializes jSplitPane
185 *
186 * This is the main edit window
187 *
188 * @return javax.swing.JSplitPane jSplitPane
189 */
190 private JSplitPane getJSplitPane() {
191 if (jSplitPane == null) {
192 jSplitPane = new JSplitPane();
193 jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
194 jSplitPane.setDividerLocation(250);
195 jSplitPane.setBottomComponent(getJPanelBottom());
196 jSplitPane.setTopComponent(getJPanelTop());
197 }
198 return jSplitPane;
199 }
200
201 /**
202 * This method initializes jPanelTop
203 *
204 * This panel contains the All Modules Table
205 *
206 * @return javax.swing.JPanel jPanelTop
207 */
208 private JPanel getJPanelTop() {
209 if (jPanelTop == null) {
210 jLabel = new JLabel();
211 jLabel.setText(" Modules in Workspace");
212 jPanelTop = new JPanel();
213 jPanelTop.setLayout(new BorderLayout());
214 jPanelTop.add(jLabel, java.awt.BorderLayout.NORTH);
215 jPanelTop.add(getJScrollPaneAllModules(), java.awt.BorderLayout.CENTER);
216 jPanelTop.add(getJPanelTopSouth(), java.awt.BorderLayout.SOUTH);
217 }
218 return jPanelTop;
219 }
220
221 /**
222 * This method initializes jPanelBottom
223 *
224 * This panel contains the FPD Modules Table
225 *
226 * @return javax.swing.JPanel jPanelBottom
227 */
228 private JPanel getJPanelBottom() {
229 if (jPanelBottom == null) {
230 jLabelModulesAdded = new JLabel();
231 jLabelModulesAdded.setText(" Modules Added into Platform");
232 jPanelBottom = new JPanel();
233 jPanelBottom.setLayout(new BorderLayout());
234 jPanelBottom.add(jLabelModulesAdded, java.awt.BorderLayout.NORTH);
235 jPanelBottom.add(getJPanelBottomSouth(), java.awt.BorderLayout.SOUTH);
236 jPanelBottom.add(getJScrollPaneFpdModules(), java.awt.BorderLayout.CENTER);
237 }
238 return jPanelBottom;
239 }
240
241 /**
242 * This method initializes jScrollPaneAllModules
243 *
244 * @return javax.swing.JScrollPane jScrollPaneAllModules
245 */
246 private JScrollPane getJScrollPaneAllModules() {
247 if (jScrollPaneAllModules == null) {
248 jScrollPaneAllModules = new JScrollPane();
249 jScrollPaneAllModules.setPreferredSize(new java.awt.Dimension(600, 200));
250 jScrollPaneAllModules.setViewportView(getJTableAllModules());
251 }
252 return jScrollPaneAllModules;
253 }
254
255 /**
256 * This method initializes jTableAllModules
257 *
258 * @return javax.swing.JTable jTableAllModules
259 */
260 private JTable getJTableAllModules() {
261 if (jTableAllModules == null) {
262 modelAllModules = new NonEditableTableModel();
263 TableSorter sorter = new TableSorter(modelAllModules);
264 jTableAllModules = new JTable(sorter);
265 sorter.setTableHeader(jTableAllModules.getTableHeader());
266 jTableAllModules.setRowHeight(20);
267 modelAllModules.addColumn("<html>Module<br>Name</html>");
268 modelAllModules.addColumn("<html>Package<br>Name</html>");
269 modelAllModules.addColumn("Path");
270 modelAllModules.addColumn("<html>Module<br>Type</html>");
271 modelAllModules.addColumn("<html>Module<br>Version</html>");
272 modelAllModules.addColumn("<html>Package<br>Version</html>");
273
274 javax.swing.table.TableColumn column = null;
275 column = jTableAllModules.getColumnModel().getColumn(modNameColForAllModTable);
276 column.setPreferredWidth(modNamePrefWidth);
277 column.setMinWidth(modNameMinWidth);
278 column.setMaxWidth(modNameMaxWidth);
279 column = jTableAllModules.getColumnModel().getColumn(modVerColForAllModTable);
280 column.setPreferredWidth(verPrefWidth);
281 column.setMaxWidth(verMaxWidth);
282 column.setMinWidth(verMinWidth);
283 column = jTableAllModules.getColumnModel().getColumn(pkgNameColForAllModTable);
284 column.setPreferredWidth(pkgNamePrefWidth);
285 column.setMinWidth(pkgNameMinWidth);
286 column.setMaxWidth(pkgNameMaxWidth);
287 column = jTableAllModules.getColumnModel().getColumn(pkgVerColForAllModTable);
288 column.setPreferredWidth(verPrefWidth);
289 column.setMaxWidth(verMaxWidth);
290 column.setMinWidth(verMinWidth);
291 column = jTableAllModules.getColumnModel().getColumn(typeColForAllModTable);
292 column.setPreferredWidth(typePrefWidth);
293 column.setMaxWidth(typeMaxWidth);
294 column.setMinWidth(typeMinWidth);
295 column = jTableAllModules.getColumnModel().getColumn(pathColForAllModTable);
296 column.setPreferredWidth(pathPrefWidth);
297 column.setMinWidth(pathMinWidth);
298
299 jTableAllModules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
300 jTableAllModules.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
301 jTableAllModules.addMouseListener(new java.awt.event.MouseAdapter() {
302 public void mouseClicked(java.awt.event.MouseEvent e) {
303 if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
304 java.awt.Point p = e.getPoint();
305 int rowIndex = jTableAllModules.rowAtPoint(p);
306 TableSorter sorter = (TableSorter) jTableAllModules.getModel();
307 rowIndex = sorter.getModelRowIndex(rowIndex);
308 addModuleIntoPlatform (rowIndex);
309 }
310 }
311 });
312
313
314 }
315 return jTableAllModules;
316 }
317
318 /**
319 * This method initializes jPanelTopSouth
320 *
321 * This panel contains the ADD button
322 *
323 * @return javax.swing.JPanel jPanelTopSouth
324 */
325 private JPanel getJPanelTopSouth() {
326 if (jPanelTopSouth == null) {
327 FlowLayout flowLayout = new FlowLayout();
328 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
329 jPanelTopSouth = new JPanel();
330 jPanelTopSouth.setLayout(flowLayout);
331 jPanelTopSouth.add(getJButtonAddModule(), null);
332 }
333 return jPanelTopSouth;
334 }
335
336 private void addModuleIntoPlatform (int selectedRow) {
337 String path = modelAllModules.getValueAt(selectedRow, pathColForAllModTable) + "";
338 ModuleIdentification mi = miList.get(selectedRow);
339 Vector<String> vArchs = null;
340 try {
341 vArchs = WorkspaceProfile.getModuleSupArchs(mi);
342 }
343 catch (Exception exp) {
344 JOptionPane.showMessageDialog(frame, exp.getMessage());
345 }
346
347 if (vArchs == null) {
348 JOptionPane.showMessageDialog(frame, "No Supported Architectures specified in MSA file.");
349 return;
350 }
351
352 String archsAdded = "";
353 String mg = mi.getGuid();
354 String mv = mi.getVersion();
355 String pg = mi.getPackageId().getGuid();
356 String pv = mi.getPackageId().getVersion();
357 String mType = SurfaceAreaQuery.getModuleType(mi);
358
359 ArrayList<String> al = fpdMsa.get(mg + mv + pg + pv);
360 if (al == null) {
361 //
362 // if existing ModuleSA does not specify version info.
363 //
364 al = fpdMsa.get(mg + "null" + pg + "null");
365 if (al == null) {
366 al = fpdMsa.get(mg + "null" + pg + pv);
367 if (al == null){
368 al = fpdMsa.get(mg + mv + pg + "null");
369 if (al == null) {
370 al = new ArrayList<String>();
371 fpdMsa.put(mg + mv + pg + pv, al);
372 }
373 }
374 }
375 }
376 //
377 // filter from module SupArchs what archs has been added.
378 //
379 for (int i = 0; i < al.size(); ++i) {
380 vArchs.remove(al.get(i));
381 }
382 //
383 // check whether archs conform to SupArch of platform.
384 //
385 Vector<Object> platformSupArch = new Vector<Object>();
386 ffc.getPlatformDefsSupportedArchs(platformSupArch);
387 vArchs.retainAll(platformSupArch);
388 //
389 // Archs this Module supported have already been added.
390 //
391 if (vArchs.size() == 0) {
392 JOptionPane.showMessageDialog(frame, "This Module has already been added.");
393 return;
394 }
395 //ToDo put Arch instead of null
396 boolean errorOccurred = false;
397 for (int i = 0; i < vArchs.size(); ++i) {
398 String arch = vArchs.get(i);
399 al.add(arch);
400 archsAdded += arch + " ";
401 String[] row = { "", "", "", "", "", "", "" };
402
403 if (mi != null) {
404 row[modNameColForFpdModTable] = mi.getName();
405 row[pkgNameColForFpdModTable] = mi.getPackageId().getName();
406 row[pathColForFpdModTable] = path;
407 row[archColForFpdModTable] = arch;
408 row[pkgVerColForFpdModTable] = pv;
409 row[modVerColForFpdModTable] = mv;
410 row[typeColForFpdModTable] = mType;
411
412 }
413 modelFpdModules.addRow(row);
414
415 docConsole.setSaved(false);
416 try {
417 //ToDo : specify archs need to add.
418 ffc.addFrameworkModulesPcdBuildDefs(mi, arch, null);
419 } catch (Exception exception) {
420 JOptionPane.showMessageDialog(frame, "Adding " + row[modNameColForFpdModTable] + " with Supporting Architectures: " + arch
421 + ": " + exception.getMessage());
422 errorOccurred = true;
423 }
424 }
425
426 String s = "This Module with Architecture " + archsAdded;
427 if (errorOccurred) {
428 s += " was added with Error. Platform may NOT Build.";
429 } else {
430 s += " was added Successfully.";
431 }
432 JOptionPane.showMessageDialog(frame, s);
433 TableSorter sorterFpdModules = (TableSorter)jTableFpdModules.getModel();
434 int viewIndex = sorterFpdModules.getViewIndexArray()[modelFpdModules.getRowCount() - 1];
435 jTableFpdModules.changeSelection(viewIndex, 0, false, false);
436
437 }
438
439 /**
440 * This method initializes jButtonAddModule
441 *
442 * @return javax.swing.JButton jButtonAddModule
443 */
444 private JButton getJButtonAddModule() {
445 if (jButtonAddModule == null) {
446 jButtonAddModule = new JButton();
447 jButtonAddModule.setPreferredSize(new java.awt.Dimension(130, 20));
448 jButtonAddModule.setText("Add a Module");
449 jButtonAddModule.addActionListener(new java.awt.event.ActionListener() {
450 public void actionPerformed(java.awt.event.ActionEvent e) {
451 int selectedRow = jTableAllModules.getSelectedRow();
452 if (selectedRow < 0) {
453 return;
454 }
455
456 TableSorter sorter = (TableSorter) jTableAllModules.getModel();
457 selectedRow = sorter.getModelRowIndex(selectedRow);
458 addModuleIntoPlatform (selectedRow);
459 }
460 });
461 }
462 return jButtonAddModule;
463 }
464
465 /**
466 * This method initializes jPanelBottomSouth
467 *
468 * This panel contains the Settings and Remove Buttons
469 *
470 * @return javax.swing.JPanel jPanelBottomSouth
471 */
472 private JPanel getJPanelBottomSouth() {
473 if (jPanelBottomSouth == null) {
474 FlowLayout flowLayout1 = new FlowLayout();
475 flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
476 jPanelBottomSouth = new JPanel();
477 jPanelBottomSouth.setLayout(flowLayout1);
478 jPanelBottomSouth.add(getJButtonSettings(), null);
479 jPanelBottomSouth.add(getJButtonRemoveModule(), null);
480 }
481 return jPanelBottomSouth;
482 }
483
484 /**
485 * This method initializes jScrollPaneFpdModules
486 *
487 * @return javax.swing.JScrollPane jScrollPaneFpdModules
488 */
489 private JScrollPane getJScrollPaneFpdModules() {
490 if (jScrollPaneFpdModules == null) {
491 jScrollPaneFpdModules = new JScrollPane();
492 jScrollPaneFpdModules.setPreferredSize(new java.awt.Dimension(453, 200));
493 jScrollPaneFpdModules.setViewportView(getJTableFpdModules());
494 }
495 return jScrollPaneFpdModules;
496 }
497
498 /**
499 * This method initializes jTableFpdModules
500 *
501 * @return javax.swing.JTable jTableFpdModules
502 */
503 private JTable getJTableFpdModules() {
504 if (jTableFpdModules == null) {
505 modelFpdModules = new FpdModulesTableModel();
506 TableSorter sorter = new TableSorter(modelFpdModules);
507 jTableFpdModules = new JTable(sorter);
508 sorter.setTableHeader(jTableFpdModules.getTableHeader());
509 jTableFpdModules.setRowHeight(20);
510 modelFpdModules.addColumn("<html>Module<br>Name</html>");
511 modelFpdModules.addColumn("<html>Package<br>Name</html>");
512 modelFpdModules.addColumn("Path");
513 modelFpdModules.addColumn("<html>Supported<br>Architectures</html>");
514 modelFpdModules.addColumn("<html>Module<br>Type</html>");
515 modelFpdModules.addColumn("<html>Module<br>Version</html>");
516 modelFpdModules.addColumn("<html>Package<br>Version</html>");
517 modelFpdModules.addColumn("<html>Force<br>Debug</html>");
518
519 javax.swing.table.TableColumn column = null;
520 column = jTableFpdModules.getColumnModel().getColumn(modNameColForFpdModTable);
521 column.setPreferredWidth(modNamePrefWidth);
522 column.setMinWidth(modNameMinWidth);
523 column.setMaxWidth(modNameMaxWidth);
524 column = jTableFpdModules.getColumnModel().getColumn(modVerColForFpdModTable);
525 column.setPreferredWidth(verPrefWidth);
526 column.setMaxWidth(verMaxWidth);
527 column.setMinWidth(verMinWidth);
528 column = jTableFpdModules.getColumnModel().getColumn(pkgNameColForFpdModTable);
529 column.setPreferredWidth(pkgNamePrefWidth);
530 column.setMinWidth(pkgNameMinWidth);
531 column.setMaxWidth(pkgNameMaxWidth);
532 column = jTableFpdModules.getColumnModel().getColumn(pkgVerColForFpdModTable);
533 column.setPreferredWidth(verPrefWidth);
534 column.setMaxWidth(verMaxWidth);
535 column.setMinWidth(verMinWidth);
536 column = jTableFpdModules.getColumnModel().getColumn(archColForFpdModTable);
537 column.setPreferredWidth(archPrefWidth);
538 column.setMaxWidth(archMaxWidth);
539 column.setMinWidth(archMinWidth);
540 column = jTableFpdModules.getColumnModel().getColumn(pathColForFpdModTable);
541 column.setPreferredWidth(pathPrefWidth);
542 column.setMinWidth(pathMinWidth);
543 column = jTableFpdModules.getColumnModel().getColumn(typeColForFpdModTable);
544 column.setPreferredWidth(typePrefWidth);
545 column.setMaxWidth(typeMaxWidth);
546 column.setMinWidth(typeMinWidth);
547
548 jTableFpdModules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
549 jTableFpdModules.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
550
551 jTableFpdModules.addMouseListener(new java.awt.event.MouseAdapter() {
552 public void mouseClicked(java.awt.event.MouseEvent e) {
553 if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
554 java.awt.Point p = e.getPoint();
555 int rowIndex = jTableFpdModules.rowAtPoint(p);
556 TableSorter sorter = (TableSorter) jTableFpdModules.getModel();
557 rowIndex = sorter.getModelRowIndex(rowIndex);
558 showSettingsDlg (rowIndex);
559 }
560 }
561 });
562
563 jTableFpdModules.getModel().addTableModelListener(this);
564 }
565 return jTableFpdModules;
566 }
567
568 public void tableChanged(TableModelEvent arg0) {
569 if (arg0.getType() == TableModelEvent.UPDATE){
570 int row = arg0.getFirstRow();
571 int column = arg0.getColumn();
572 TableModel m = (TableModel)arg0.getSource();
573
574 if (column != forceDbgColForFpdModTable) {
575 return;
576 }
577 String s = m.getValueAt(row, column)+"";
578 boolean dbgEnable = new Boolean(s);
579 ffc.setModuleSAForceDebug(row, dbgEnable);
580 docConsole.setSaved(false);
581 }
582 }
583
584 private void showSettingsDlg (int row) {
585 try {
586 if (ffc.adjustPcd(row)) {
587 docConsole.setSaved(false);
588 }
589 }
590 catch (Exception exp) {
591 JOptionPane.showMessageDialog(frame, exp.getMessage());
592 return;
593 }
594
595 if (settingDlg == null) {
596 settingDlg = new FpdModuleSA(ffc);
597 }
598
599 String[] sa = new String[5];
600 ffc.getFrameworkModuleInfo(row, sa);
601 String mg = sa[ffcModGuid];
602 String mv = sa[ffcModVer];
603 String pg = sa[ffcPkgGuid];
604 String pv = sa[ffcPkgVer];
605 String arch = sa[ffcModArch];
606 settingDlg.setKey(mg + " " + mv + " " + pg + " " + pv + " " + arch, row, docConsole);
607 settingDlg.setVisible(true);
608 }
609 /**
610 * This method initializes jButtonSettings
611 *
612 * @return javax.swing.JButton jButtonSettings
613 */
614 private JButton getJButtonSettings() {
615 if (jButtonSettings == null) {
616 jButtonSettings = new JButton();
617 jButtonSettings.setPreferredSize(new java.awt.Dimension(130,20));
618 jButtonSettings.setText("Settings");
619 jButtonSettings.addActionListener(new java.awt.event.ActionListener() {
620 public void actionPerformed(java.awt.event.ActionEvent e) {
621 int selectedRow = jTableFpdModules.getSelectedRow();
622 if (selectedRow < 0) {
623 return;
624 }
625
626 TableSorter sorter = (TableSorter) jTableFpdModules.getModel();
627 selectedRow = sorter.getModelRowIndex(selectedRow);
628 showSettingsDlg (selectedRow);
629 }
630 });
631 }
632 return jButtonSettings;
633 }
634
635 /**
636 * This method initializes jButtonRemoveModule
637 *
638 * @return javax.swing.JButton jButtonRemoveModule
639 */
640 private JButton getJButtonRemoveModule() {
641 if (jButtonRemoveModule == null) {
642 jButtonRemoveModule = new JButton();
643 jButtonRemoveModule.setPreferredSize(new java.awt.Dimension(130, 20));
644 jButtonRemoveModule.setText("Remove Module");
645 jButtonRemoveModule.addActionListener(new java.awt.event.ActionListener() {
646 public void actionPerformed(java.awt.event.ActionEvent e) {
647 int selectedRow = jTableFpdModules.getSelectedRow();
648 if (selectedRow < 0) {
649 return;
650 }
651
652
653 TableSorter sorter = (TableSorter) jTableFpdModules.getModel();
654 selectedRow = sorter.getModelRowIndex(selectedRow);
655
656 String[] sa = new String[5];
657 ffc.getFrameworkModuleInfo(selectedRow, sa);
658 String mg = sa[ffcModGuid];
659 String mv = sa[ffcModVer];
660 String pg = sa[ffcPkgGuid];
661 String pv = sa[ffcPkgVer];
662 String arch = sa[ffcModArch];
663 //
664 // sync. module order list in BuildOptions-UserExtensions.
665 //
666 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
667 String fvBindings = ffc.getFvBinding(moduleKey);
668 if (fvBindings != null) {
669 String[] fvArray = fvBindings.split(" ");
670 for (int i = 0; i < fvArray.length; ++i) {
671 ffc.removeModuleInBuildOptionsUserExtensions(fvArray[i].trim(), mg, mv, pg, pv, arch);
672 }
673 }
674
675 ModuleIdentification mi = WorkspaceProfile.getModuleId(mg + " " + mv + " " + pg + " " + pv + " " + arch);
676 if (mi != null) {
677 mv = mi.getVersion();
678 pv = mi.getPackageId().getVersion();
679 }
680
681 try {
682 ffc.removeModuleSA(selectedRow);
683 }
684 catch (Exception exp) {
685 JOptionPane.showMessageDialog(frame, exp.getCause() + exp.getMessage());
686 return;
687 }
688
689 if (arch == null) {
690 // if no arch specified in ModuleSA
691 fpdMsa.remove(mg + mv + pg + pv);
692
693 } else {
694 ArrayList<String> al = fpdMsa.get(mg + mv + pg + pv);
695 if (al != null) {
696 al.remove(arch);
697 if (al.size() == 0) {
698 fpdMsa.remove(mg + mv + pg + pv);
699 }
700 }
701 }
702
703 modelFpdModules.removeRow(selectedRow);
704 docConsole.setSaved(false);
705 }
706 });
707 }
708 return jButtonRemoveModule;
709 }
710
711 /**
712 *
713 * @param args
714 */
715 public static void main(String[] args) {
716 // Set the pane visable
717 new FpdFrameworkModules().setVisible(true);
718 }
719
720 /**
721 * This is the default constructor
722 */
723 public FpdFrameworkModules() {
724 super();
725 initialize();
726 }
727
728 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
729 this();
730 init(fpd);
731
732 }
733
734 public FpdFrameworkModules(OpeningPlatformType opt) {
735 this(opt.getXmlFpd());
736 docConsole = opt;
737 }
738
739 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
740
741 if (ffc == null) {
742 ffc = new FpdFileContents(fpd);
743 ffc.initDynPcdMap();
744 }
745
746 if (fpdMsa == null) {
747 fpdMsa = new HashMap<String, ArrayList<String>>();
748 }
749
750 if (ffc.getFrameworkModulesCount() > 0) {
751 String[][] saa = new String[ffc.getFrameworkModulesCount()][5];
752 ffc.getFrameworkModulesInfo(saa);
753 for (int i = 0; i < saa.length; ++i) {
754 ModuleIdentification mi = WorkspaceProfile.getModuleId(saa[i][ffcModGuid] + " " + saa[i][ffcModVer] + " "
755 + saa[i][ffcPkgGuid] + " " + saa[i][ffcPkgVer]);
756 Object[] row = { "", "", "", "", "", "", "", "" };
757 if (mi != null) {
758 row[modNameColForFpdModTable] = mi.getName();
759 row[modVerColForFpdModTable] = mi.getVersion();
760 row[typeColForFpdModTable] = SurfaceAreaQuery.getModuleType(mi);
761 row[pkgNameColForFpdModTable] = mi.getPackageId().getName();
762 row[pkgVerColForFpdModTable] = mi.getPackageId().getVersion();
763 row[archColForFpdModTable] = saa[i][ffcModArch];
764 try {
765 row[pathColForFpdModTable] = mi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
766 } catch (Exception e) {
767 JOptionPane.showMessageDialog(frame, "Show FPD Modules:" + e.getMessage());
768 }
769
770 String fpdMsaKey = saa[i][ffcModGuid] + row[modVerColForFpdModTable]
771 + saa[i][ffcPkgGuid] + row[pkgVerColForFpdModTable];
772 ArrayList<String> al = fpdMsa.get(fpdMsaKey);
773 if (al == null) {
774 al = new ArrayList<String>();
775 fpdMsa.put(fpdMsaKey, al);
776 }
777 al.add(saa[i][ffcModArch]);
778 }
779 else {
780 row[modNameColForFpdModTable] = saa[i][ffcModGuid];
781 row[modVerColForFpdModTable] = saa[i][ffcModVer];
782 row[pkgNameColForFpdModTable] = saa[i][ffcPkgGuid];
783 row[pkgVerColForFpdModTable] = saa[i][ffcPkgVer];
784 row[archColForFpdModTable] = saa[i][ffcModArch];
785 }
786 row[forceDbgColForFpdModTable] = ffc.getModuleSAForceDebug(i);
787 modelFpdModules.addRow(row);
788
789 }
790 TableSorter sorter = (TableSorter)jTableFpdModules.getModel();
791 sorter.setSortState(modNameColForFpdModTable, TableSorter.ASCENDING);
792 }
793
794 showAllModules();
795
796 }
797
798 private void showAllModules() {
799
800 if (miList == null) {
801 miList = new ArrayList<ModuleIdentification>();
802 }
803
804 String[] s = { "", "", "", "", "", "" };
805
806 Iterator ismi = GlobalData.vModuleList.iterator();
807 while (ismi.hasNext()) {
808 ModuleIdentification mi = (ModuleIdentification) ismi.next();
809 s[modNameColForAllModTable] = mi.getName();
810 s[modVerColForAllModTable] = mi.getVersion();
811 s[typeColForAllModTable] = SurfaceAreaQuery.getModuleType(mi);
812 s[pkgNameColForAllModTable] = mi.getPackageId().getName();
813 s[pkgVerColForAllModTable] = mi.getPackageId().getVersion();
814 try {
815 s[pathColForAllModTable] = mi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
816 } catch (Exception e) {
817 JOptionPane.showMessageDialog(frame, "Show All Modules:" + e.getMessage());
818 }
819 modelAllModules.addRow(s);
820 miList.add(mi);
821 }
822
823
824 TableSorter sorter = (TableSorter)jTableAllModules.getModel();
825 sorter.setSortState(modNameColForAllModTable, TableSorter.ASCENDING);
826 }
827
828 /**
829 * This method initializes this
830 *
831 * @return void
832 */
833 private void initialize() {
834 this.setSize(633, 533);
835 this.setTitle("Framework Modules");
836 this.setContentPane(getJSplitPane());
837 this.setVisible(true);
838
839 }
840
841 } // @jve:decl-index=0:visual-constraint="10,10"
842
843 class NonEditableTableModel extends DefaultTableModel {
844 /**
845 *
846 */
847 private static final long serialVersionUID = 1L;
848
849 public boolean isCellEditable(int row, int col) {
850 return false;
851 }
852 }
853
854 class FpdModulesTableModel extends DefaultTableModel {
855
856 /**
857 *
858 */
859 private static final long serialVersionUID = 1L;
860
861 public Class<?> getColumnClass (int c) {
862 if (getValueAt(0, c) != null){
863 return getValueAt(0, c).getClass();
864 }
865 return String.class;
866 }
867
868 public boolean isCellEditable (int row, int col) {
869 if (col == FpdFrameworkModules.forceDbgColForFpdModTable) {
870 return true;
871 }
872 return false;
873 }
874 }