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