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