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