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