b8eb8c682b7b2df3a0cd0e01407e67ac34ecaf80
[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.JOptionPane;
22 import javax.swing.JPanel;
23 import javax.swing.JSplitPane;
24 import javax.swing.JLabel;
25 import javax.swing.JScrollPane;
26 import javax.swing.JTable;
27 import javax.swing.JButton;
28 import javax.swing.ListSelectionModel;
29 import javax.swing.event.TableModelEvent;
30 import javax.swing.table.DefaultTableModel;
31 import javax.swing.table.TableModel;
32
33 import org.tianocore.PlatformSurfaceAreaDocument;
34 import org.tianocore.frameworkwizard.FrameworkWizardUI;
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 static final int pcdSyncThreadNumber = 10;
63
64 private long savedMs = 0;
65
66 String searchField = "";
67
68 public static final int forceDbgColForFpdModTable = 7;
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(this, "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(this, "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(this, "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(this, "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(this, 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 // As PCD sync. check is full platform range now during opening FrameworkModules editor,
676 // the following check is no longer needed.
677 // try {
678 // Vector<String> vExceptions = new Vector<String>();
679 // if (ffc.adjustPcd(row, vExceptions)) {
680 // JOptionPane.showMessageDialog(frame, "Pcd entries sync. with those in MSA files.");
681 // docConsole.setSaved(false);
682 // }
683 // }
684 // catch (Exception exp) {
685 // JOptionPane.showMessageDialog(frame, exp.getMessage());
686 // }
687
688 if (settingDlg == null) {
689 settingDlg = new FpdModuleSA(ffc);
690 }
691
692 String[] sa = new String[5];
693 ffc.getFrameworkModuleInfo(row, sa);
694 String mg = sa[ffcModGuid];
695 String mv = sa[ffcModVer];
696 String pg = sa[ffcPkgGuid];
697 String pv = sa[ffcPkgVer];
698 String arch = sa[ffcModArch];
699 settingDlg.setKey(mg + " " + mv + " " + pg + " " + pv + " " + arch, row, docConsole);
700 settingDlg.setVisible(true);
701 }
702 /**
703 * This method initializes jButtonSettings
704 *
705 * @return javax.swing.JButton jButtonSettings
706 */
707 private JButton getJButtonSettings() {
708 if (jButtonSettings == null) {
709 jButtonSettings = new JButton();
710 jButtonSettings.setPreferredSize(new java.awt.Dimension(130,20));
711 jButtonSettings.setText("Settings");
712 jButtonSettings.addActionListener(new java.awt.event.ActionListener() {
713 public void actionPerformed(java.awt.event.ActionEvent e) {
714 int selectedRow = jTableFpdModules.getSelectedRow();
715 if (selectedRow < 0) {
716 return;
717 }
718
719 TableSorter sorter = (TableSorter) jTableFpdModules.getModel();
720 selectedRow = sorter.getModelRowIndex(selectedRow);
721 showSettingsDlg (selectedRow);
722 }
723 });
724 }
725 return jButtonSettings;
726 }
727
728 /**
729 * This method initializes jButtonRemoveModule
730 *
731 * @return javax.swing.JButton jButtonRemoveModule
732 */
733 private JButton getJButtonRemoveModule() {
734 if (jButtonRemoveModule == null) {
735 jButtonRemoveModule = new JButton();
736 jButtonRemoveModule.setText("Remove Module");
737 FontMetrics fm = jButtonRemoveModule.getFontMetrics(jButtonRemoveModule.getFont());
738 jButtonRemoveModule.setPreferredSize(new Dimension (fm.stringWidth(jButtonRemoveModule.getText()) + 40, 20));
739 jButtonRemoveModule.addActionListener(new java.awt.event.ActionListener() {
740 public void actionPerformed(java.awt.event.ActionEvent e) {
741 int selectedRow = jTableFpdModules.getSelectedRow();
742 if (selectedRow < 0) {
743 return;
744 }
745 int nextSelection = selectedRow;
746
747 TableSorter sorter = (TableSorter) jTableFpdModules.getModel();
748 selectedRow = sorter.getModelRowIndex(selectedRow);
749
750 String[] sa = new String[5];
751 ffc.getFrameworkModuleInfo(selectedRow, sa);
752 String mg = sa[ffcModGuid];
753 String mv = sa[ffcModVer];
754 String pg = sa[ffcPkgGuid];
755 String pv = sa[ffcPkgVer];
756 String arch = sa[ffcModArch];
757 //
758 // sync. module order list in BuildOptions-UserExtensions.
759 //
760 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
761 String fvBindings = ffc.getFvBinding(moduleKey);
762 if (fvBindings != null) {
763 String[] fvArray = fvBindings.split(" ");
764 for (int i = 0; i < fvArray.length; ++i) {
765 ffc.removeModuleInBuildOptionsUserExtensions(fvArray[i].trim(), "IMAGES", "1", mg, mv, pg, pv, arch);
766 }
767 }
768
769 ModuleIdentification mi = WorkspaceProfile.getModuleId(mg + " " + mv + " " + pg + " " + pv + " " + arch);
770 if (mi != null) {
771 mv = mi.getVersion();
772 pv = mi.getPackageId().getVersion();
773 }
774
775 try {
776 ffc.removeModuleSA(selectedRow);
777 }
778 catch (Exception exp) {
779 JOptionPane.showMessageDialog(FpdFrameworkModules.this, exp.getMessage());
780 return;
781 }
782
783 if (arch == null) {
784 // if no arch specified in ModuleSA
785 fpdMsa.remove(mg + mv + pg + pv);
786
787 } else {
788 ArrayList<String> al = fpdMsa.get(mg + mv + pg + pv);
789 if (al != null) {
790 al.remove(arch);
791 if (al.size() == 0) {
792 fpdMsa.remove(mg + mv + pg + pv);
793 }
794 }
795 }
796
797 modelFpdModules.removeRow(selectedRow);
798 if (nextSelection >= jTableFpdModules.getRowCount()) {
799 nextSelection = jTableFpdModules.getRowCount() - 1;
800 }
801 jTableFpdModules.changeSelection(nextSelection, 0, false, false);
802 docConsole.setSaved(false);
803 }
804 });
805 }
806 return jButtonRemoveModule;
807 }
808
809 /**
810 * This method initializes jButtonApriori
811 *
812 * @return javax.swing.JButton
813 */
814 private JButton getJButtonApriori() {
815 if (jButtonApriori == null) {
816 jButtonApriori = new JButton();
817 jButtonApriori.setText("Apriori Files");
818 FontMetrics fm = jButtonApriori.getFontMetrics(jButtonApriori.getFont());
819 int buttonWidth = fm.stringWidth(jButtonApriori.getText()) + 40;
820 if (jButtonRemoveModule.getWidth() > buttonWidth) {
821 buttonWidth = jButtonRemoveModule.getWidth();
822 }
823 jButtonApriori.setPreferredSize(new Dimension (buttonWidth, 20));
824 jButtonApriori.addActionListener(new java.awt.event.ActionListener() {
825 public void actionPerformed(ActionEvent arg0) {
826 new GenAprioriFileDialog(ffc, docConsole).setVisible(true);
827 }});
828 }
829 return jButtonApriori;
830 }
831
832 /**
833 *
834 * @param args
835 */
836 public static void main(String[] args) {
837 // Set the pane visable
838 new FpdFrameworkModules().setVisible(true);
839 }
840
841 private class PcdSyncTask extends Thread {
842
843 boolean pcdSynced = false;
844 public void run () {
845 Vector<String> vExceptions = new Vector<String>();
846 pcdSync(vExceptions);
847 if (pcdSynced) {
848 JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), "PCD in this platform are synchronized with those in MSA files.");
849 docConsole.setSaved(false);
850 }
851 if (vExceptions.size() > 0) {
852 String errorMsg = "";
853 for (int i = 0; i < vExceptions.size(); ++i) {
854 errorMsg += " " + vExceptions.get(i) + "\n";
855 }
856 JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), "Error occurred during synchronization:\n" + errorMsg);
857 }
858 }
859
860 private void pcdSync(Vector<String> v) {
861
862 Vector<PcdSyncSubTask> vThreads = new Vector<PcdSyncSubTask> ();
863 int moduleCount = jTableFpdModules.getRowCount();
864 int start = 0;
865 for (int i = 0; i < FpdFrameworkModules.pcdSyncThreadNumber; ++i) {
866 int end = start + moduleCount/FpdFrameworkModules.pcdSyncThreadNumber;
867 if (end > moduleCount) {
868 end = moduleCount;
869 }
870 vThreads.add(new PcdSyncSubTask (start, end, v));
871 start = end;
872 }
873
874 for (int i = 0; i < FpdFrameworkModules.pcdSyncThreadNumber; ++i) {
875 vThreads.get(i).start();
876 }
877
878 try {
879 for (int i = 0; i < FpdFrameworkModules.pcdSyncThreadNumber; ++i) {
880 vThreads.get(i).join();
881 }
882 }
883 catch (InterruptedException e) {
884
885 }
886
887 }
888
889 private class PcdSyncSubTask extends Thread {
890
891 private int startModule = 0;
892 private int endModulePlusOne = 1;
893 private Vector<String> v = null;
894
895 PcdSyncSubTask (int start, int endPlusOne, Vector<String> vErr) {
896 startModule = start;
897 endModulePlusOne = endPlusOne;
898 v = vErr;
899 }
900
901 public void run () {
902 String[] sa = new String[5];
903 for (int i = startModule; i < endModulePlusOne; ++i) {
904 try {
905 ffc.getFrameworkModuleInfo(i, sa);
906 String mg = sa[ffcModGuid];
907 String mv = sa[ffcModVer];
908 String pg = sa[ffcPkgGuid];
909 String pv = sa[ffcPkgVer];
910 String arch = sa[ffcModArch];
911 String key = mg + " " + mv + " " + pg + " " + pv + " " + arch;
912 if (ffc.adjustPcd(key, v)) {
913 pcdSynced = true;
914 }
915 }
916 catch (Exception exp) {
917 // JOptionPane.showMessageDialog(frame, exp.getMessage());
918 continue;
919 }
920 }
921 }
922 }
923 }
924
925 /**
926 * This is the default constructor
927 */
928 public FpdFrameworkModules() {
929 super();
930 initialize();
931 }
932
933 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
934 this();
935 init(fpd);
936
937 }
938
939 private PcdSyncTask pst = null;
940 public FpdFrameworkModules(OpeningPlatformType opt) {
941 this(opt.getXmlFpd());
942 docConsole = opt;
943 if (pst == null) {
944 pst = new PcdSyncTask();
945 }
946 pst.start();
947 }
948
949 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
950
951 if (ffc == null) {
952 ffc = new FpdFileContents(fpd);
953 ffc.initDynPcdMap();
954 }
955
956 if (fpdMsa == null) {
957 fpdMsa = new HashMap<String, ArrayList<String>>();
958 }
959
960 if (ffc.getFrameworkModulesCount() > 0) {
961 String[][] saa = new String[ffc.getFrameworkModulesCount()][5];
962 ffc.getFrameworkModulesInfo(saa);
963 for (int i = 0; i < saa.length; ++i) {
964 ModuleIdentification mi = WorkspaceProfile.getModuleId(saa[i][ffcModGuid] + " " + saa[i][ffcModVer] + " "
965 + saa[i][ffcPkgGuid] + " " + saa[i][ffcPkgVer]);
966 Object[] row = { "", "", "", "", "", "", "", "" };
967 if (mi != null) {
968 row[modNameColForFpdModTable] = mi.getName();
969 row[modVerColForFpdModTable] = mi.getVersion();
970 row[typeColForFpdModTable] = SurfaceAreaQuery.getModuleType(mi);
971 row[pkgNameColForFpdModTable] = mi.getPackageId().getName();
972 row[pkgVerColForFpdModTable] = mi.getPackageId().getVersion();
973 row[archColForFpdModTable] = saa[i][ffcModArch];
974 try {
975 row[pathColForFpdModTable] = mi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1);
976 } catch (Exception e) {
977 JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), "Show FPD Modules:" + e.getMessage());
978 }
979
980 String fpdMsaKey = saa[i][ffcModGuid] + row[modVerColForFpdModTable]
981 + saa[i][ffcPkgGuid] + row[pkgVerColForFpdModTable];
982 ArrayList<String> al = fpdMsa.get(fpdMsaKey);
983 if (al == null) {
984 al = new ArrayList<String>();
985 fpdMsa.put(fpdMsaKey, al);
986 }
987 al.add(saa[i][ffcModArch]);
988 }
989 else {
990 row[modNameColForFpdModTable] = saa[i][ffcModGuid];
991 row[modVerColForFpdModTable] = saa[i][ffcModVer];
992 row[pkgNameColForFpdModTable] = saa[i][ffcPkgGuid];
993 row[pkgVerColForFpdModTable] = saa[i][ffcPkgVer];
994 row[archColForFpdModTable] = saa[i][ffcModArch];
995 }
996 row[forceDbgColForFpdModTable] = ffc.getModuleSAForceDebug(i);
997 modelFpdModules.addRow(row);
998
999 }
1000 TableSorter sorter = (TableSorter)jTableFpdModules.getModel();
1001 sorter.setSortState(modNameColForFpdModTable, TableSorter.ASCENDING);
1002 }
1003
1004 showAllModules();
1005
1006 }
1007
1008 private void showAllModules() {
1009
1010 if (miList == null) {
1011 miList = new ArrayList<ModuleIdentification>();
1012 }
1013
1014 String[] s = { "", "", "", "", "", "" };
1015
1016 Iterator ismi = GlobalData.vModuleList.iterator();
1017 while (ismi.hasNext()) {
1018 ModuleIdentification mi = (ModuleIdentification) ismi.next();
1019 s[modNameColForAllModTable] = mi.getName();
1020 s[modVerColForAllModTable] = mi.getVersion();
1021 s[typeColForAllModTable] = SurfaceAreaQuery.getModuleType(mi);
1022 s[pkgNameColForAllModTable] = mi.getPackageId().getName();
1023 s[pkgVerColForAllModTable] = mi.getPackageId().getVersion();
1024 try {
1025 s[pathColForAllModTable] = mi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1);
1026 } catch (Exception e) {
1027 JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), "Show All Modules:" + e.getMessage());
1028 }
1029 modelAllModules.addRow(s);
1030 miList.add(mi);
1031 }
1032
1033
1034 TableSorter sorter = (TableSorter)jTableAllModules.getModel();
1035 sorter.setSortState(modNameColForAllModTable, TableSorter.ASCENDING);
1036 }
1037
1038 /**
1039 * This method initializes this
1040 *
1041 * @return void
1042 */
1043 private void initialize() {
1044 this.setSize(633, 533);
1045 this.setTitle("Framework Modules");
1046 this.setContentPane(getJSplitPane());
1047 this.setVisible(true);
1048
1049 }
1050
1051 } // @jve:decl-index=0:visual-constraint="10,10"
1052
1053 class NonEditableTableModel extends DefaultTableModel {
1054 /**
1055 *
1056 */
1057 private static final long serialVersionUID = 1L;
1058
1059 public boolean isCellEditable(int row, int col) {
1060 return false;
1061 }
1062 }
1063
1064 class FpdModulesTableModel extends DefaultTableModel {
1065
1066 /**
1067 *
1068 */
1069 private static final long serialVersionUID = 1L;
1070
1071 public Class<?> getColumnClass (int c) {
1072 if (getValueAt(0, c) != null){
1073 return getValueAt(0, c).getClass();
1074 }
1075 return String.class;
1076 }
1077
1078 public boolean isCellEditable (int row, int col) {
1079 if (col == FpdFrameworkModules.forceDbgColForFpdModTable) {
1080 return true;
1081 }
1082 return false;
1083 }
1084 }