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