Bug fixing for FPD ModuleSA editor.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdModuleSA.java
1 package org.tianocore.frameworkwizard.platform.ui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.Toolkit;
6
7 import javax.swing.JFrame;
8 import javax.swing.JOptionPane;
9 import javax.swing.JPanel;
10 import javax.swing.JDialog;
11 import javax.swing.JTabbedPane;
12 import javax.swing.JLabel;
13 import javax.swing.JScrollPane;
14 import javax.swing.JTable;
15 import javax.swing.JTextArea;
16 import javax.swing.JSplitPane;
17 import javax.swing.JButton;
18 import javax.swing.ListSelectionModel;
19 import javax.swing.event.ListSelectionEvent;
20 import javax.swing.event.ListSelectionListener;
21 import javax.swing.event.TableModelEvent;
22 import javax.swing.event.TableModelListener;
23 import javax.swing.table.DefaultTableModel;
24 import javax.swing.table.TableModel;
25
26 import org.apache.xmlbeans.XmlObject;
27 import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;
28 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
29 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
30 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
31
32 import java.awt.FlowLayout;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.Iterator;
38 import java.util.ListIterator;
39 import java.util.Map;
40 import java.util.Set;
41 import java.util.Vector;
42
43 import javax.swing.JTextField;
44
45 public class FpdModuleSA extends JDialog implements ActionListener {
46
47 /**
48 *
49 */
50 private static final long serialVersionUID = 1L;
51 static JFrame frame;
52 private JPanel jContentPane = null;
53 private JTabbedPane jTabbedPane = null;
54 private JPanel jPanel = null;
55 private JPanel jPanel1 = null;
56 private JLabel jLabel = null;
57 private JScrollPane jScrollPane = null;
58 private JTable jTable = null;
59 private JPanel jPanel2 = null;
60 private JScrollPane jScrollPane1 = null;
61 private JTextArea jTextArea = null;
62 private JPanel jPanel3 = null;
63 private JSplitPane jSplitPane = null;
64 private JPanel jPanel4 = null;
65 private JPanel jPanel5 = null;
66 private JLabel jLabel1 = null;
67 private JLabel jLabel2 = null;
68 private JScrollPane jScrollPane2 = null;
69 private JTable jTable1 = null;
70 private JScrollPane jScrollPane3 = null;
71 private JTable jTable2 = null;
72 private JScrollPane jScrollPane4 = null;
73 private JTable jTable3 = null;
74 private JPanel jPanel6 = null;
75 private JPanel jPanel7 = null;
76 private JScrollPane jScrollPane5 = null;
77 private JTextArea jTextArea1 = null;
78 private JLabel jLabel3 = null;
79 private JLabel jLabel4 = null;
80 private JButton jButton = null;
81 private JButton jButton1 = null;
82 private JLabel jLabel5 = null;
83 private JButton jButton2 = null;
84 private JButton jButton3 = null;
85 private PartialEditableTableModel model = null;
86 private LibraryTableModel model1 = null;
87 private LibraryTableModel model2 = null;
88 private LibraryTableModel model3 = null;
89 private DefaultTableModel optionsTableModel = null;
90 private FpdFileContents ffc = null;
91 private String moduleKey = null;
92 private HashMap<String, ArrayList<String>> classInstanceMap = null;
93 private ArrayList<String> classProduced = null;
94 private HashMap<String, ArrayList<String>> classConsumed = null;
95 private JPanel jPanel8 = null;
96 private JLabel jLabel6 = null;
97 private JTextField jTextField = null;
98 private JLabel jLabel7 = null;
99 private JTextField jTextField1 = null;
100 private JLabel jLabel8 = null;
101 private JTextField jTextField2 = null;
102 private JScrollPane jScrollPane6 = null;
103 private JTable jTable4 = null;
104 private JButton jButton4 = null;
105 private JButton jButton5 = null;
106 /**
107 * This is the default constructor
108 */
109 public FpdModuleSA() {
110 super();
111 initialize();
112 }
113 public FpdModuleSA(FpdFileContents ffc) {
114 this();
115 this.ffc = ffc;
116 }
117
118 public void setKey(String k){
119 this.moduleKey = k;
120 }
121
122 /**
123 init will be called each time FpdModuleSA object is to be shown.
124 @param key Module information.
125 **/
126 public void init(String key) {
127 //
128 // display pcd for key.
129 //
130 model.setRowCount(0);
131 int pcdCount = ffc.getPcdDataCount(key);
132 if (pcdCount != 0) {
133 String[][] saa = new String[pcdCount][6];
134 ffc.getPcdData(key, saa);
135 for (int i = 0; i < saa.length; ++i) {
136 model.addRow(saa[i]);
137 }
138 }
139 //
140 // display library classes that need to be resolved. also potential instances for them.
141 //
142 resolveLibraryInstances(key);
143 //
144 // display lib instances already selected for key
145 //
146 model1.setRowCount(0);
147 int instanceCount = ffc.getLibraryInstancesCount(key);
148 if (instanceCount != 0) {
149 String[][] saa = new String[instanceCount][5];
150 ffc.getLibraryInstances(key, saa);
151 for (int i = 0; i < saa.length; ++i) {
152 ModuleIdentification mi = getModuleId(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4]);
153 if (mi != null) {
154 saa[i][0] = mi.getName();
155 saa[i][2] = mi.getVersion();
156 saa[i][4] = mi.getPackage().getVersion();
157 //
158 // re-evaluate lib instance usage when adding a already-selected lib instance.
159 //
160 resolveLibraryInstances(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4]);
161 model1.addRow(saa[i]);
162 }
163
164
165 }
166 }
167
168 //
169 // display module SA options
170 //
171 String fvBinding = ffc.getFvBinding(key);
172 if (fvBinding != null) {
173 jTextField.setText(fvBinding);
174 }
175 String fileGuid = ffc.getFfsFileNameGuid(key);
176 if (fileGuid != null) {
177 jTextField1.setText(fileGuid);
178 }
179 String ffsKey = ffc.getFfsFormatKey(key);
180 if (ffsKey != null) {
181 jTextField2.setText(ffsKey);
182 }
183 }
184
185 private void resolveLibraryInstances(String key) {
186 ModuleIdentification mi = getModuleId(key);
187 PackageIdentification[] depPkgList = null;
188 try{
189 Map<String, XmlObject> m = GlobalData.getNativeMsa(mi);
190 SurfaceAreaQuery.setDoc(m);
191 //
192 // Get dependency pkg list into which we will search lib instances.
193 //
194 depPkgList = SurfaceAreaQuery.getDependencePkg(null);
195 //
196 // Get the lib class consumed, produced by this module itself.
197 //
198 String[] classConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED");
199
200 if (this.classConsumed == null) {
201 this.classConsumed = new HashMap<String, ArrayList<String>>();
202 }
203
204 for(int i = 0; i < classConsumed.length; ++i){
205 ArrayList<String> consumedBy = this.classConsumed.get(classConsumed[i]);
206 if (consumedBy == null) {
207 consumedBy = new ArrayList<String>();
208 }
209 consumedBy.add(key);
210 this.classConsumed.put(classConsumed[i], consumedBy);
211 }
212
213 String[] classProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED");
214 if (this.classProduced == null) {
215 this.classProduced = new ArrayList<String>();
216 }
217 for(int i = 0; i < classProduced.length; ++i){
218 if (!this.classProduced.contains(classProduced[i])){
219 this.classProduced.add(classProduced[i]);
220 }
221 }
222 //
223 // Get classes unresolved
224 //
225 // Iterator<String> lip = this.classProduced.listIterator();
226 // while(lip.hasNext()){
227 // String clsProduced = lip.next();
228 // this.classConsumed.remove(clsProduced);
229 //
230 // }
231 //
232 // find potential instances in all dependency pkgs for classes still in classConsumed.
233 //
234 if (classInstanceMap == null){
235 classInstanceMap = new HashMap<String, ArrayList<String>>();
236 }
237 Iterator<String> lic = this.classConsumed.keySet().iterator();
238 while(lic.hasNext()){
239 String cls = lic.next();
240 if (this.classProduced.contains(cls) || classInstanceMap.containsKey(cls)) {
241 continue;
242 }
243 ArrayList<String> instances = getInstancesForClass(cls, depPkgList);
244 if (instances.size() == 0){
245 JOptionPane.showMessageDialog(frame, "No Applicable Instance for Library Class " +
246 cls + ", Platform Build will Fail.");
247 }
248 classInstanceMap.put(cls, instances);
249
250 }
251
252 showClassToResolved();
253 }
254 catch(Exception e) {
255 e.printStackTrace();
256 }
257 }
258
259 private ArrayList<String> getInstancesForClass(String cls, PackageIdentification[] depPkgList) throws Exception{
260 ArrayList<String> al = new ArrayList<String>();
261
262 for (int i = 0; i < depPkgList.length; ++i) {
263 Set<ModuleIdentification> smi = GlobalData.getModules(depPkgList[i]);
264 Iterator ismi = smi.iterator();
265 while(ismi.hasNext()) {
266 ModuleIdentification mi = (ModuleIdentification)ismi.next();
267
268 String[] clsProduced = getClassProduced(mi);
269
270 boolean isPotential = false;
271 for (int j = 0; j < clsProduced.length; ++j) {
272 if (clsProduced[j] == null) {
273 continue;
274 }
275 if (clsProduced[j].equals(cls)){
276 isPotential = true;
277 }
278 if (classProduced.contains(clsProduced[j])) {
279 isPotential = false;
280 break;
281 }
282 }
283 if (isPotential) {
284 al.add(mi.getGuid() + " " + mi.getVersion() + " " +
285 depPkgList[i].getGuid() + " " + depPkgList[i].getVersion());
286 }
287 }
288 }
289
290 return al;
291 }
292
293 private void removeInstance(String key) {
294 ModuleIdentification mi = getModuleId(key);
295 //
296 // remove pcd information of instance from current ModuleSA
297 //
298 ffc.removePcdDataFromLibraryInstance(moduleKey, key);
299 //
300 // remove class produced by this instance and add back these produced class to be bound.
301 //
302 String[] clsProduced = getClassProduced(mi);
303 for (int i = 0; i < clsProduced.length; ++i) {
304
305 classProduced.remove(clsProduced[i]);
306 }
307 //
308 // remove class consumed by this instance. we do not need to bound it now.
309 //
310 String[] clsConsumed = getClassConsumed(mi);
311 for (int i = 0; i < clsConsumed.length; ++i) {
312 ArrayList<String> al = classConsumed.get(clsConsumed[i]);
313
314 if (al == null ) {
315 classConsumed.remove(clsConsumed[i]);
316 continue;
317 }
318 al.remove(key);
319 if (al.size() == 0) {
320 classConsumed.remove(clsConsumed[i]);
321 }
322
323 }
324
325 showClassToResolved();
326
327 }
328
329 private ModuleIdentification getModuleId(String key){
330 //
331 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.
332 //
333 String[] keyPart = key.split(" ");
334 Set<PackageIdentification> spi = GlobalData.getPackageList();
335 Iterator ispi = spi.iterator();
336
337 while(ispi.hasNext()) {
338 PackageIdentification pi = (PackageIdentification)ispi.next();
339 if ( !pi.getGuid().equals(keyPart[2])){
340 // || !pi.getVersion().equals(keyPart[3])){
341 continue;
342 }
343 Set<ModuleIdentification> smi = GlobalData.getModules(pi);
344 Iterator ismi = smi.iterator();
345 while(ismi.hasNext()) {
346 ModuleIdentification mi = (ModuleIdentification)ismi.next();
347 if (mi.getGuid().equals(keyPart[0])){
348 // && mi.getVersion().equals(keyPart[1])){
349 return mi;
350 }
351 }
352 }
353 return null;
354 }
355
356 private String[] getClassProduced(ModuleIdentification mi){
357
358 try{
359 Map<String, XmlObject> m = GlobalData.getNativeMsa(mi);
360 SurfaceAreaQuery.setDoc(m);
361 String[] clsProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED");
362 return clsProduced;
363
364 }catch (Exception e) {
365 e.printStackTrace();
366 }
367 return new String[0];
368
369 }
370
371 private String[] getClassConsumed(ModuleIdentification mi){
372
373 String[] clsConsumed = null;
374 try{
375 Map<String, XmlObject> m = GlobalData.getNativeMsa(mi);
376 SurfaceAreaQuery.setDoc(m);
377 clsConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED");
378
379 }catch (Exception e) {
380 e.printStackTrace();
381 }
382 return clsConsumed;
383 }
384
385 private void showClassToResolved(){
386 model2.setRowCount(0);
387 if (classConsumed.size() == 0) {
388 return;
389 }
390 Iterator<String> li = classConsumed.keySet().iterator();
391 while(li.hasNext()){
392
393 String[] s = {li.next()};
394 if (classConsumed.get(s[0]) == null) {
395 continue;
396 }
397 if (classConsumed.get(s[0]).size() == 0) {
398 continue;
399 }
400 if (!classProduced.contains(s[0])){
401 model2.addRow(s);
402 }
403 }
404 model3.setRowCount(0);
405 }
406 /**
407 * This method initializes this
408 *
409 * @return void
410 */
411 private void initialize() {
412 this.setSize(664, 515);
413 this.centerWindow();
414 this.setModal(true);
415 this.setTitle("Module Settings");
416 this.setContentPane(getJContentPane());
417 }
418
419 /**
420 * This method initializes jContentPane
421 *
422 * @return javax.swing.JPanel
423 */
424 private JPanel getJContentPane() {
425 if (jContentPane == null) {
426 jContentPane = new JPanel();
427 jContentPane.setLayout(new BorderLayout());
428 jContentPane.add(getJTabbedPane(), java.awt.BorderLayout.CENTER);
429 jContentPane.add(getJPanel3(), java.awt.BorderLayout.SOUTH);
430 }
431 return jContentPane;
432 }
433
434 /**
435 * This method initializes jTabbedPane
436 *
437 * @return javax.swing.JTabbedPane
438 */
439 private JTabbedPane getJTabbedPane() {
440 if (jTabbedPane == null) {
441 jTabbedPane = new JTabbedPane();
442 jTabbedPane.addTab("PCD Build Definition", null, getJPanel(), null);
443 jTabbedPane.addTab("Module SA Options", null, getJPanel8(), null);
444 jTabbedPane.addTab("Libraries", null, getJPanel1(), null);
445 }
446 return jTabbedPane;
447 }
448
449 /**
450 * This method initializes jPanel
451 *
452 * @return javax.swing.JPanel
453 */
454 private JPanel getJPanel() {
455 if (jPanel == null) {
456 jLabel = new JLabel();
457 jLabel.setText("PcdData");
458 jPanel = new JPanel();
459 jPanel.setLayout(new BorderLayout());
460 jPanel.add(jLabel, java.awt.BorderLayout.NORTH);
461 jPanel.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
462 jPanel.add(getJPanel2(), java.awt.BorderLayout.SOUTH);
463 jPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
464 public void componentShown(java.awt.event.ComponentEvent e) {
465 init(moduleKey);
466 }
467 });
468
469 }
470 return jPanel;
471 }
472
473 /**
474 * This method initializes jPanel1
475 *
476 * @return javax.swing.JPanel
477 */
478 private JPanel getJPanel1() {
479 if (jPanel1 == null) {
480 jPanel1 = new JPanel();
481 jPanel1.setLayout(new BorderLayout());
482 jPanel1.add(getJSplitPane(), java.awt.BorderLayout.NORTH);
483 jPanel1.add(getJPanel6(), java.awt.BorderLayout.SOUTH);
484 jPanel1.add(getJPanel7(), java.awt.BorderLayout.CENTER);
485 jPanel1.addComponentListener(new java.awt.event.ComponentAdapter() {
486 public void componentShown(java.awt.event.ComponentEvent e) {
487 init(moduleKey);
488 }
489 });
490 }
491 return jPanel1;
492 }
493
494 /**
495 * This method initializes jScrollPane
496 *
497 * @return javax.swing.JScrollPane
498 */
499 private JScrollPane getJScrollPane() {
500 if (jScrollPane == null) {
501 jScrollPane = new JScrollPane();
502 jScrollPane.setViewportView(getJTable());
503 }
504 return jScrollPane;
505 }
506
507 /**
508 * This method initializes jTable
509 *
510 * @return javax.swing.JTable
511 */
512 private JTable getJTable() {
513 if (jTable == null) {
514 model = new PartialEditableTableModel();
515 jTable = new JTable(model);
516 jTable.setRowHeight(20);
517 jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
518 model.addColumn("CName");
519 model.addColumn("TokenSpaceGUID");
520 model.addColumn("ItemType");
521 model.addColumn("Token");
522 model.addColumn("DataType");
523 model.addColumn("DefaultValue");
524
525 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
526 jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
527 public void valueChanged(ListSelectionEvent e) {
528
529 if (e.getValueIsAdjusting()){
530 return;
531 }
532 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
533 if (lsm.isSelectionEmpty()) {
534 return;
535 }
536 else{
537 // int selectedRow = lsm.getMinSelectionIndex();
538
539
540 }
541 }
542 });
543
544 jTable.getModel().addTableModelListener(new TableModelListener() {
545 public void tableChanged(TableModelEvent arg0) {
546 // TODO Auto-generated method stub
547 int row = arg0.getFirstRow();
548 TableModel m = (TableModel)arg0.getSource();
549 if (arg0.getType() == TableModelEvent.INSERT) {
550 //
551 // Set combo box values for item type according to pcd values added.
552 //
553
554 }
555 if (arg0.getType() == TableModelEvent.UPDATE){
556 //ToDo Data Validition check.
557
558 }
559 }
560 });
561 }
562 return jTable;
563 }
564
565 /**
566 * This method initializes jPanel2
567 *
568 * @return javax.swing.JPanel
569 */
570 private JPanel getJPanel2() {
571 if (jPanel2 == null) {
572 jLabel5 = new JLabel();
573 jLabel5.setText("PCD Description");
574 jPanel2 = new JPanel();
575 jPanel2.add(jLabel5, null);
576 jPanel2.add(getJScrollPane1(), null);
577 }
578 return jPanel2;
579 }
580
581 /**
582 * This method initializes jScrollPane1
583 *
584 * @return javax.swing.JScrollPane
585 */
586 private JScrollPane getJScrollPane1() {
587 if (jScrollPane1 == null) {
588 jScrollPane1 = new JScrollPane();
589 jScrollPane1.setPreferredSize(new java.awt.Dimension(500,100));
590 jScrollPane1.setViewportView(getJTextArea());
591 }
592 return jScrollPane1;
593 }
594
595 /**
596 * This method initializes jTextArea
597 *
598 * @return javax.swing.JTextArea
599 */
600 private JTextArea getJTextArea() {
601 if (jTextArea == null) {
602 jTextArea = new JTextArea();
603 jTextArea.setEditable(false);
604 }
605 return jTextArea;
606 }
607
608 /**
609 * This method initializes jPanel3
610 *
611 * @return javax.swing.JPanel
612 */
613 private JPanel getJPanel3() {
614 if (jPanel3 == null) {
615 FlowLayout flowLayout = new FlowLayout();
616 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
617 jPanel3 = new JPanel();
618 jPanel3.setLayout(flowLayout);
619 jPanel3.add(getJButton2(), null);
620 jPanel3.add(getJButton3(), null);
621 }
622 return jPanel3;
623 }
624
625 /**
626 * This method initializes jSplitPane
627 *
628 * @return javax.swing.JSplitPane
629 */
630 private JSplitPane getJSplitPane() {
631 if (jSplitPane == null) {
632 jSplitPane = new JSplitPane();
633 jSplitPane.setDividerLocation(200);
634 jSplitPane.setLeftComponent(getJPanel4());
635 jSplitPane.setRightComponent(getJPanel5());
636 jSplitPane.setPreferredSize(new java.awt.Dimension(202,200));
637 }
638 return jSplitPane;
639 }
640
641 /**
642 * This method initializes jPanel4
643 *
644 * @return javax.swing.JPanel
645 */
646 private JPanel getJPanel4() {
647 if (jPanel4 == null) {
648 jLabel1 = new JLabel();
649 jLabel1.setText("Library Classes Consumed");
650 jPanel4 = new JPanel();
651 jPanel4.add(jLabel1, null);
652 jPanel4.add(getJScrollPane3(), null);
653 }
654 return jPanel4;
655 }
656
657 /**
658 * This method initializes jPanel5
659 *
660 * @return javax.swing.JPanel
661 */
662 private JPanel getJPanel5() {
663 if (jPanel5 == null) {
664 jLabel2 = new JLabel();
665 jLabel2.setText("Instances Available");
666 jPanel5 = new JPanel();
667 jPanel5.add(jLabel2, null);
668 jPanel5.add(getJScrollPane4(), null);
669 }
670 return jPanel5;
671 }
672
673 /**
674 * This method initializes jScrollPane2
675 *
676 * @return javax.swing.JScrollPane
677 */
678 private JScrollPane getJScrollPane2() {
679 if (jScrollPane2 == null) {
680 jScrollPane2 = new JScrollPane();
681 jScrollPane2.setPreferredSize(new java.awt.Dimension(453,150));
682 jScrollPane2.setViewportView(getJTable1());
683 }
684 return jScrollPane2;
685 }
686
687 /**
688 * This method initializes jTable1
689 *
690 * @return javax.swing.JTable
691 */
692 private JTable getJTable1() {
693 if (jTable1 == null) {
694 model1 = new LibraryTableModel();
695 model1.addColumn("Name");
696 model1.addColumn("ModuleGUID");
697 model1.addColumn("ModuleVersion");
698 model1.addColumn("PackageGUID");
699 model1.addColumn("PackageVersion");
700 jTable1 = new JTable(model1);
701 jTable1.setRowHeight(20);
702 jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
703 jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
704 jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
705 public void valueChanged(ListSelectionEvent e) {
706 int selectedRow1 = -1;
707 if (e.getValueIsAdjusting()){
708 return;
709 }
710 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
711 if (lsm.isSelectionEmpty()) {
712 return;
713 }
714 else{
715 selectedRow1 = lsm.getMinSelectionIndex();
716
717
718 }
719 }
720 });
721
722
723 }
724 return jTable1;
725 }
726
727 /**
728 * This method initializes jScrollPane3
729 *
730 * @return javax.swing.JScrollPane
731 */
732 private JScrollPane getJScrollPane3() {
733 if (jScrollPane3 == null) {
734 jScrollPane3 = new JScrollPane();
735 jScrollPane3.setPreferredSize(new java.awt.Dimension(200,170));
736 jScrollPane3.setViewportView(getJTable2());
737 }
738 return jScrollPane3;
739 }
740
741 /**
742 * This method initializes jTable2
743 *
744 * @return javax.swing.JTable
745 */
746 private JTable getJTable2() {
747 if (jTable2 == null) {
748 model2 = new LibraryTableModel();
749 model2.addColumn("LibraryClass");
750 jTable2 = new JTable(model2);
751 jTable2.setRowHeight(20);
752 jTable2.setShowGrid(false);
753 jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
754 jTable2.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
755 public void valueChanged(ListSelectionEvent e) {
756 if (e.getValueIsAdjusting()){
757 return;
758 }
759 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
760 if (lsm.isSelectionEmpty()) {
761 return;
762 }
763 else{
764 int selectedRow2 = lsm.getMinSelectionIndex();
765 if (selectedRow2 < 0) {
766 return;
767 }
768 //
769 // display potential lib instances according to class selection
770 //
771 model3.setRowCount(0);
772 String cls = model2.getValueAt(selectedRow2, 0).toString();
773 ArrayList<String> al = classInstanceMap.get(cls);
774 ListIterator<String> li = al.listIterator();
775 while(li.hasNext()) {
776 String instance = li.next();
777 String[] s = {"", "", "", "", ""};
778 if (getModuleId(instance) != null) {
779 s[0] = getModuleId(instance).getName();
780 }
781
782 String[] instancePart = instance.split(" ");
783 for (int i = 0; i < instancePart.length; ++i){
784 s[i+1] = instancePart[i];
785 }
786 model3.addRow(s);
787 }
788
789 }
790 }
791 });
792 }
793 return jTable2;
794 }
795
796 /**
797 * This method initializes jScrollPane4
798 *
799 * @return javax.swing.JScrollPane
800 */
801 private JScrollPane getJScrollPane4() {
802 if (jScrollPane4 == null) {
803 jScrollPane4 = new JScrollPane();
804 jScrollPane4.setPreferredSize(new java.awt.Dimension(450,170));
805 jScrollPane4.setViewportView(getJTable3());
806 }
807 return jScrollPane4;
808 }
809
810 /**
811 * This method initializes jTable3
812 *
813 * @return javax.swing.JTable
814 */
815 private JTable getJTable3() {
816 if (jTable3 == null) {
817 model3 = new LibraryTableModel();
818 model3.addColumn("Name");
819 model3.addColumn("ModuleGUID");
820 model3.addColumn("ModuleVersion");
821 model3.addColumn("PackageGUID");
822 model3.addColumn("PackageVersion");
823 jTable3 = new JTable(model3);
824 jTable3.setRowHeight(20);
825 jTable3.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
826 jTable3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
827 jTable3.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
828 public void valueChanged(ListSelectionEvent e) {
829 int selectedRow3 = -1;
830 if (e.getValueIsAdjusting()){
831 return;
832 }
833 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
834 if (lsm.isSelectionEmpty()) {
835 return;
836 }
837 else{
838 selectedRow3 = lsm.getMinSelectionIndex();
839
840
841 }
842 }
843 });
844 }
845 return jTable3;
846 }
847
848 /**
849 * This method initializes jPanel6
850 *
851 * @return javax.swing.JPanel
852 */
853 private JPanel getJPanel6() {
854 if (jPanel6 == null) {
855 jPanel6 = new JPanel();
856 }
857 return jPanel6;
858 }
859
860 /**
861 * This method initializes jPanel7
862 *
863 * @return javax.swing.JPanel
864 */
865 private JPanel getJPanel7() {
866 if (jPanel7 == null) {
867 jLabel4 = new JLabel();
868 jLabel4.setText("Instance Description");
869 jLabel3 = new JLabel();
870 jLabel3.setText("Selected Instances");
871 jPanel7 = new JPanel();
872 jPanel7.add(jLabel4, null);
873 jPanel7.add(getJScrollPane5(), null);
874 jPanel7.add(getJButton(), null);
875 jPanel7.add(getJButton1(), null);
876 jPanel7.add(jLabel3, null);
877 jPanel7.add(getJScrollPane2(), null);
878 }
879 return jPanel7;
880 }
881
882 /**
883 * This method initializes jScrollPane5
884 *
885 * @return javax.swing.JScrollPane
886 */
887 private JScrollPane getJScrollPane5() {
888 if (jScrollPane5 == null) {
889 jScrollPane5 = new JScrollPane();
890 jScrollPane5.setPreferredSize(new java.awt.Dimension(300,50));
891 jScrollPane5.setViewportView(getJTextArea1());
892 }
893 return jScrollPane5;
894 }
895
896 /**
897 * This method initializes jTextArea1
898 *
899 * @return javax.swing.JTextArea
900 */
901 private JTextArea getJTextArea1() {
902 if (jTextArea1 == null) {
903 jTextArea1 = new JTextArea();
904 jTextArea1.setEditable(false);
905 }
906 return jTextArea1;
907 }
908
909 /**
910 * This method initializes jButton
911 *
912 * @return javax.swing.JButton
913 */
914 private JButton getJButton() {
915 if (jButton == null) {
916 jButton = new JButton();
917 jButton.setPreferredSize(new java.awt.Dimension(80,20));
918 jButton.setText("Add");
919 jButton.addActionListener(new java.awt.event.ActionListener() {
920 public void actionPerformed(java.awt.event.ActionEvent e) {
921 int row = jTable3.getSelectedRow();
922 if (row < 0) {
923 return;
924 }
925 Object[] s = {model3.getValueAt(row, 0), model3.getValueAt(row, 1),
926 model3.getValueAt(row, 2), model3.getValueAt(row, 3),
927 model3.getValueAt(row, 4)};
928 model1.addRow(s);
929 String instanceValue = model3.getValueAt(row, 1) + " " +
930 model3.getValueAt(row, 2) + " " +
931 model3.getValueAt(row, 3) + " " +
932 model3.getValueAt(row, 4);
933 //
934 // Add pcd information of selected instance to current moduleSA
935 //
936 ffc.addFrameworkModulesPcdBuildDefs(getModuleId(instanceValue), ffc.getModuleSA(moduleKey));
937
938 resolveLibraryInstances(instanceValue);
939 }
940 });
941 }
942 return jButton;
943 }
944
945 /**
946 * This method initializes jButton1
947 *
948 * @return javax.swing.JButton
949 */
950 private JButton getJButton1() {
951 if (jButton1 == null) {
952 jButton1 = new JButton();
953 jButton1.setPreferredSize(new java.awt.Dimension(80,20));
954 jButton1.setText("Delete");
955 jButton1.addActionListener(new java.awt.event.ActionListener() {
956 public void actionPerformed(java.awt.event.ActionEvent e) {
957 int row = jTable1.getSelectedRow();
958 if (row < 0) {
959 return;
960 }
961 removeInstance(model1.getValueAt(row, 1) + " " +
962 model1.getValueAt(row, 2) + " " +
963 model1.getValueAt(row, 3) + " " +
964 model1.getValueAt(row, 4));
965 model1.removeRow(row);
966
967 }
968 });
969 }
970 return jButton1;
971 }
972
973 /**
974 * This method initializes jButton2
975 *
976 * @return javax.swing.JButton
977 */
978 private JButton getJButton2() {
979 if (jButton2 == null) {
980 jButton2 = new JButton();
981 jButton2.setPreferredSize(new java.awt.Dimension(80,20));
982 jButton2.setText("Ok");
983 jButton2.addActionListener(this);
984 }
985 return jButton2;
986 }
987
988 /**
989 * This method initializes jButton3
990 *
991 * @return javax.swing.JButton
992 */
993 private JButton getJButton3() {
994 if (jButton3 == null) {
995 jButton3 = new JButton();
996 jButton3.setPreferredSize(new java.awt.Dimension(80,20));
997 jButton3.setText("Cancel");
998 jButton3.setVisible(false);
999 }
1000 return jButton3;
1001 }
1002 public void actionPerformed(ActionEvent arg0) {
1003
1004 if (arg0.getSource() == jButton2) {
1005 ffc.removeLibraryInstances(moduleKey);
1006 for (int i = 0; i < model1.getRowCount(); ++i) {
1007 String mg = model1.getValueAt(i, 1)+"";
1008 String mv = model1.getValueAt(i, 2)+"";
1009 String pg = model1.getValueAt(i, 3)+"";
1010 String pv = model1.getValueAt(i, 4)+"";
1011 ffc.genLibraryInstance(mg, mv, pg, pv, moduleKey);
1012 }
1013 this.setVisible(false);
1014 }
1015 }
1016 /**
1017 * This method initializes jPanel8
1018 *
1019 * @return javax.swing.JPanel
1020 */
1021 private JPanel getJPanel8() {
1022 if (jPanel8 == null) {
1023 jLabel8 = new JLabel();
1024 jLabel8.setText("FFS Format Key");
1025 jLabel7 = new JLabel();
1026 jLabel7.setText("FFS File GUID");
1027 jLabel6 = new JLabel();
1028 jLabel6.setText("FV Binding");
1029 jPanel8 = new JPanel();
1030 jPanel8.add(jLabel6, null);
1031 jPanel8.add(getJTextField(), null);
1032 jPanel8.add(jLabel7, null);
1033 jPanel8.add(getJTextField1(), null);
1034 jPanel8.add(jLabel8, null);
1035 jPanel8.add(getJTextField2(), null);
1036 jPanel8.add(getJScrollPane6(), null);
1037 jPanel8.add(getJButton4(), null);
1038 jPanel8.add(getJButton5(), null);
1039 jPanel8.addComponentListener(new java.awt.event.ComponentAdapter() {
1040 public void componentShown(java.awt.event.ComponentEvent e) {
1041 init(moduleKey);
1042 }
1043 });
1044 }
1045 return jPanel8;
1046 }
1047 /**
1048 * This method initializes jTextField
1049 *
1050 * @return javax.swing.JTextField
1051 */
1052 private JTextField getJTextField() {
1053 if (jTextField == null) {
1054 jTextField = new JTextField();
1055 jTextField.setPreferredSize(new java.awt.Dimension(100,20));
1056 jTextField.addFocusListener(new java.awt.event.FocusAdapter() {
1057 public void focusLost(java.awt.event.FocusEvent e) {
1058 ffc.setFvBinding(moduleKey, jTextField.getText());
1059 }
1060 });
1061 }
1062 return jTextField;
1063 }
1064 /**
1065 * This method initializes jTextField1
1066 *
1067 * @return javax.swing.JTextField
1068 */
1069 private JTextField getJTextField1() {
1070 if (jTextField1 == null) {
1071 jTextField1 = new JTextField();
1072 jTextField1.setPreferredSize(new java.awt.Dimension(100,20));
1073 jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
1074 public void focusLost(java.awt.event.FocusEvent e) {
1075 ffc.setFfsFileNameGuid(moduleKey, jTextField1.getText());
1076 }
1077 });
1078 }
1079 return jTextField1;
1080 }
1081 /**
1082 * This method initializes jTextField2
1083 *
1084 * @return javax.swing.JTextField
1085 */
1086 private JTextField getJTextField2() {
1087 if (jTextField2 == null) {
1088 jTextField2 = new JTextField();
1089 jTextField2.setPreferredSize(new java.awt.Dimension(100,20));
1090 jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
1091 public void focusLost(java.awt.event.FocusEvent e) {
1092 ffc.setFfsFormatKey(moduleKey, jTextField2.getText());
1093 }
1094 });
1095 }
1096 return jTextField2;
1097 }
1098 /**
1099 * This method initializes jScrollPane6
1100 *
1101 * @return javax.swing.JScrollPane
1102 */
1103 private JScrollPane getJScrollPane6() {
1104 if (jScrollPane6 == null) {
1105 jScrollPane6 = new JScrollPane();
1106 jScrollPane6.setPreferredSize(new java.awt.Dimension(600,200));
1107 jScrollPane6.setViewportView(getJTable4());
1108 }
1109 return jScrollPane6;
1110 }
1111 /**
1112 * This method initializes jTable4
1113 *
1114 * @return javax.swing.JTable
1115 */
1116 private JTable getJTable4() {
1117 if (jTable4 == null) {
1118 optionsTableModel = new DefaultTableModel();
1119 optionsTableModel.addColumn("BuildTargets");
1120 optionsTableModel.addColumn("ToolChainFamily");
1121 optionsTableModel.addColumn("TagName");
1122 optionsTableModel.addColumn("ToolCode");
1123 optionsTableModel.addColumn("SupportedArchs");
1124 optionsTableModel.addColumn("Contents");
1125 jTable4 = new JTable(optionsTableModel);
1126 jTable4.setRowHeight(20);
1127 Vector<String> vArch = new Vector<String>();
1128 vArch.add("IA32");
1129 vArch.add("X64");
1130 vArch.add("IPF");
1131 vArch.add("EBC");
1132 vArch.add("ARM");
1133 vArch.add("PPC");
1134 jTable4.getColumnModel().getColumn(4).setCellEditor(new ListEditor(vArch));
1135 jTable4.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1136 jTable4.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
1137 jTable4.getModel().addTableModelListener(new TableModelListener() {
1138 public void tableChanged(TableModelEvent arg0) {
1139 // TODO Auto-generated method stub
1140 int row = arg0.getFirstRow();
1141 TableModel m = (TableModel)arg0.getSource();
1142
1143 if (arg0.getType() == TableModelEvent.UPDATE){
1144 //ToDo Data Validition check.
1145 String targets = m.getValueAt(row, 0) + "";
1146 Vector<Object> targetName = null;
1147 if (targets.length() > 0) {
1148 targetName = new Vector<Object>();
1149 String[] sArray = targets.split(" ");
1150 for (int i = 0; i < sArray.length; ++i) {
1151 targetName.add(sArray[i]);
1152 }
1153 }
1154
1155 String toolChain = m.getValueAt(row, 1) + "";
1156 String tagName = m.getValueAt(row, 2) + "";
1157 String toolCode = m.getValueAt(row, 3) + "";
1158 String archs = m.getValueAt(row, 4) + "";
1159 Vector<Object> supArch = null;
1160 if (archs.length() > 0) {
1161 supArch = new Vector<Object>();
1162 String[] sArray1 = archs.split(" ");
1163 for (int i = 0; i < sArray1.length; ++i) {
1164 supArch.add(sArray1[i]);
1165 }
1166 }
1167
1168 String contents = m.getValueAt(row, 5) + "";
1169
1170 ffc.updateModuleSAOptionsOpt(moduleKey, row, targetName, toolChain, tagName, toolCode, supArch, contents);
1171 }
1172 }
1173 });
1174 }
1175 return jTable4;
1176 }
1177 /**
1178 * This method initializes jButton4
1179 *
1180 * @return javax.swing.JButton
1181 */
1182 private JButton getJButton4() {
1183 if (jButton4 == null) {
1184 jButton4 = new JButton();
1185 jButton4.setPreferredSize(new java.awt.Dimension(80,20));
1186 jButton4.setText("New");
1187 jButton4.addActionListener(new java.awt.event.ActionListener() {
1188 public void actionPerformed(java.awt.event.ActionEvent e) {
1189 String[] row = {"", "", "", "", "IA32", ""};
1190 optionsTableModel.addRow(row);
1191 Vector<Object> v = new Vector<Object>();
1192 Vector<Object> v1 = new Vector<Object>();
1193 v1.add("IA32");
1194 ffc.genModuleSAOptionsOpt(moduleKey, v, "", "", "", v1, "");
1195 }
1196 });
1197 }
1198 return jButton4;
1199 }
1200 /**
1201 * This method initializes jButton5
1202 *
1203 * @return javax.swing.JButton
1204 */
1205 private JButton getJButton5() {
1206 if (jButton5 == null) {
1207 jButton5 = new JButton();
1208 jButton5.setPreferredSize(new java.awt.Dimension(80,20));
1209 jButton5.setText("Delete");
1210 jButton5.addActionListener(new java.awt.event.ActionListener() {
1211 public void actionPerformed(java.awt.event.ActionEvent e) {
1212 if (jTable4.getSelectedRow() < 0) {
1213 return;
1214 }
1215
1216 ffc.removeModuleSAOptionsOpt(moduleKey, jTable4.getSelectedRow());
1217 optionsTableModel.removeRow(jTable4.getSelectedRow());
1218 }
1219 });
1220 }
1221 return jButton5;
1222 }
1223
1224 /**
1225 Start the window at the center of screen
1226
1227 **/
1228 protected void centerWindow(int intWidth, int intHeight) {
1229 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
1230 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
1231 }
1232
1233 /**
1234 Start the window at the center of screen
1235
1236 **/
1237 protected void centerWindow() {
1238 centerWindow(this.getSize().width, this.getSize().height);
1239 }
1240
1241
1242 } // @jve:decl-index=0:visual-constraint="10,10"
1243
1244 class PartialEditableTableModel extends DefaultTableModel {
1245 /**
1246 *
1247 */
1248 private static final long serialVersionUID = 1L;
1249
1250 public boolean isCellEditable(int row, int col) {
1251 switch (col){
1252 case 2:
1253 return true;
1254 default:
1255 return false;
1256 }
1257
1258 }
1259 }
1260
1261 class LibraryTableModel extends DefaultTableModel {
1262 /**
1263 *
1264 */
1265 private static final long serialVersionUID = 1L;
1266
1267 public boolean isCellEditable(int row, int col) {
1268 return false;
1269 }
1270 }