]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java
add support arch check for pcd entries when adding a module to platform, sync. platfo...
[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 // 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(frame, 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 /**
842 * This is the default constructor
843 */
844 public FpdFrameworkModules() {
845 super();
846 initialize();
847 }
848
849 public FpdFrameworkModules(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
850 this();
851 init(fpd);
852
853 }
854
855 public FpdFrameworkModules(OpeningPlatformType opt) {
856 this(opt.getXmlFpd());
857 docConsole = opt;
858 Vector<String> vExceptions = new Vector<String>();
859 if (pcdSync(vExceptions)) {
860 JOptionPane.showMessageDialog(frame, "PCD in this platform are synchronized with those in MSA files.");
861 docConsole.setSaved(false);
862 }
863 if (vExceptions.size() > 0) {
864 String errorMsg = "";
865 for (int i = 0; i < vExceptions.size(); ++i) {
866 errorMsg += " " + vExceptions.get(i) + "\n";
867 }
868 JOptionPane.showMessageDialog(frame, "Error occurred during synchronization:\n" + errorMsg);
869 }
870 }
871
872 private void init(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
873
874 if (ffc == null) {
875 ffc = new FpdFileContents(fpd);
876 ffc.initDynPcdMap();
877 }
878
879 if (fpdMsa == null) {
880 fpdMsa = new HashMap<String, ArrayList<String>>();
881 }
882
883 if (ffc.getFrameworkModulesCount() > 0) {
884 String[][] saa = new String[ffc.getFrameworkModulesCount()][5];
885 ffc.getFrameworkModulesInfo(saa);
886 for (int i = 0; i < saa.length; ++i) {
887 ModuleIdentification mi = WorkspaceProfile.getModuleId(saa[i][ffcModGuid] + " " + saa[i][ffcModVer] + " "
888 + saa[i][ffcPkgGuid] + " " + saa[i][ffcPkgVer]);
889 Object[] row = { "", "", "", "", "", "", "", "" };
890 if (mi != null) {
891 row[modNameColForFpdModTable] = mi.getName();
892 row[modVerColForFpdModTable] = mi.getVersion();
893 row[typeColForFpdModTable] = SurfaceAreaQuery.getModuleType(mi);
894 row[pkgNameColForFpdModTable] = mi.getPackageId().getName();
895 row[pkgVerColForFpdModTable] = mi.getPackageId().getVersion();
896 row[archColForFpdModTable] = saa[i][ffcModArch];
897 try {
898 row[pathColForFpdModTable] = mi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1);
899 } catch (Exception e) {
900 JOptionPane.showMessageDialog(frame, "Show FPD Modules:" + e.getMessage());
901 }
902
903 String fpdMsaKey = saa[i][ffcModGuid] + row[modVerColForFpdModTable]
904 + saa[i][ffcPkgGuid] + row[pkgVerColForFpdModTable];
905 ArrayList<String> al = fpdMsa.get(fpdMsaKey);
906 if (al == null) {
907 al = new ArrayList<String>();
908 fpdMsa.put(fpdMsaKey, al);
909 }
910 al.add(saa[i][ffcModArch]);
911 }
912 else {
913 row[modNameColForFpdModTable] = saa[i][ffcModGuid];
914 row[modVerColForFpdModTable] = saa[i][ffcModVer];
915 row[pkgNameColForFpdModTable] = saa[i][ffcPkgGuid];
916 row[pkgVerColForFpdModTable] = saa[i][ffcPkgVer];
917 row[archColForFpdModTable] = saa[i][ffcModArch];
918 }
919 row[forceDbgColForFpdModTable] = ffc.getModuleSAForceDebug(i);
920 modelFpdModules.addRow(row);
921
922 }
923 TableSorter sorter = (TableSorter)jTableFpdModules.getModel();
924 sorter.setSortState(modNameColForFpdModTable, TableSorter.ASCENDING);
925 }
926
927 showAllModules();
928
929 }
930
931 private boolean pcdSync(Vector<String> v) {
932 boolean synced = false;
933 for (int i = 0; i < jTableFpdModules.getRowCount(); ++i) {
934 try {
935 if (ffc.adjustPcd(i, v)) {
936 synced = true;
937 }
938 }
939 catch (Exception exp) {
940 // JOptionPane.showMessageDialog(frame, exp.getMessage());
941 continue;
942 }
943 }
944 return synced;
945
946 }
947
948 private void showAllModules() {
949
950 if (miList == null) {
951 miList = new ArrayList<ModuleIdentification>();
952 }
953
954 String[] s = { "", "", "", "", "", "" };
955
956 Iterator ismi = GlobalData.vModuleList.iterator();
957 while (ismi.hasNext()) {
958 ModuleIdentification mi = (ModuleIdentification) ismi.next();
959 s[modNameColForAllModTable] = mi.getName();
960 s[modVerColForAllModTable] = mi.getVersion();
961 s[typeColForAllModTable] = SurfaceAreaQuery.getModuleType(mi);
962 s[pkgNameColForAllModTable] = mi.getPackageId().getName();
963 s[pkgVerColForAllModTable] = mi.getPackageId().getVersion();
964 try {
965 s[pathColForAllModTable] = mi.getPath().substring(Workspace.getCurrentWorkspace().length() + 1);
966 } catch (Exception e) {
967 JOptionPane.showMessageDialog(frame, "Show All Modules:" + e.getMessage());
968 }
969 modelAllModules.addRow(s);
970 miList.add(mi);
971 }
972
973
974 TableSorter sorter = (TableSorter)jTableAllModules.getModel();
975 sorter.setSortState(modNameColForAllModTable, TableSorter.ASCENDING);
976 }
977
978 /**
979 * This method initializes this
980 *
981 * @return void
982 */
983 private void initialize() {
984 this.setSize(633, 533);
985 this.setTitle("Framework Modules");
986 this.setContentPane(getJSplitPane());
987 this.setVisible(true);
988
989 }
990
991 } // @jve:decl-index=0:visual-constraint="10,10"
992
993 class NonEditableTableModel extends DefaultTableModel {
994 /**
995 *
996 */
997 private static final long serialVersionUID = 1L;
998
999 public boolean isCellEditable(int row, int col) {
1000 return false;
1001 }
1002 }
1003
1004 class FpdModulesTableModel extends DefaultTableModel {
1005
1006 /**
1007 *
1008 */
1009 private static final long serialVersionUID = 1L;
1010
1011 public Class<?> getColumnClass (int c) {
1012 if (getValueAt(0, c) != null){
1013 return getValueAt(0, c).getClass();
1014 }
1015 return String.class;
1016 }
1017
1018 public boolean isCellEditable (int row, int col) {
1019 if (col == FpdFrameworkModules.forceDbgColForFpdModTable) {
1020 return true;
1021 }
1022 return false;
1023 }
1024 }