3 The file is used to show a table with all defined PPIs
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
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.
15 package org
.tianocore
.frameworkwizard
.common
.find
;
17 import java
.awt
.Dimension
;
18 import java
.awt
.event
.ActionEvent
;
19 import java
.awt
.event
.ComponentEvent
;
20 import java
.awt
.event
.MouseEvent
;
21 import java
.awt
.event
.MouseListener
;
22 import java
.awt
.event
.WindowEvent
;
23 import java
.util
.Vector
;
25 import javax
.swing
.JButton
;
26 import javax
.swing
.JFrame
;
27 import javax
.swing
.JPanel
;
28 import javax
.swing
.JScrollPane
;
29 import javax
.swing
.JTable
;
30 import javax
.swing
.ListSelectionModel
;
31 import javax
.swing
.SwingConstants
;
32 import javax
.swing
.event
.ListSelectionEvent
;
33 import javax
.swing
.event
.ListSelectionListener
;
34 import javax
.swing
.event
.TableModelEvent
;
35 import javax
.swing
.event
.TableModelListener
;
36 import javax
.swing
.table
.DefaultTableCellRenderer
;
38 import org
.tianocore
.frameworkwizard
.common
.DataType
;
39 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
40 import org
.tianocore
.frameworkwizard
.common
.Log
;
41 import org
.tianocore
.frameworkwizard
.common
.Tools
;
42 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
44 import org
.tianocore
.frameworkwizard
.module
.Identifications
.LibraryClass
.LibraryClassVector
;
45 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdCodedVector
;
47 public class FindResult
extends IFrame
implements TableModelListener
, ListSelectionListener
, MouseListener
{
50 /// Define class Serial Version UID
52 private static final long serialVersionUID
= -2448484533878401714L;
55 // Define class members
57 private JTable jTable
= null;
59 private JPanel jContentPane
= null;
61 private JScrollPane jScrollPane
= null;
63 private JScrollPane jScrollPaneTable
= null;
65 private JButton jButtonClose
= null;
70 private IDefaultTableModel model
= null;
72 private String method
= "";
74 private static FindResult findPpisResult
= null;
76 private static FindResult findProtocolsResult
= null;
78 private static FindResult findGuidsResult
= null;
80 private static FindResult findPcdsResult
= null;
82 private static FindResult findLibraryClassResult
= null;
84 private int selectedRow
= -1;
86 private LibraryClassVector lcv
= null;
88 private Vector
<FindResultId
> vLibraryClassFindResult
= null;
90 private PcdCodedVector pv
= null;
92 private Vector
<PcdFindResultId
> vPcdFindResult
= null;
95 * This is the default constructor
97 public FindResult(String method
) {
103 * This method initializes this
107 private void init(String method
) {
108 this.setSize(600, 500);
109 this.setContentPane(getJScrollPane());
110 this.setTitle("Find Result");
111 this.setResizable(true);
112 this.setDefaultCloseOperation(JFrame
.HIDE_ON_CLOSE
);
118 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
119 this.method
= method
;
124 * This method initializes jContentPane
126 * @return javax.swing.JPanel
128 private JPanel
getJContentPane() {
129 if (jContentPane
== null) {
130 jContentPane
= new JPanel();
131 jContentPane
.setLayout(null);
132 jContentPane
.add(getJScrollPaneTable(), null);
133 jContentPane
.add(getJButtonClose(), null);
134 jContentPane
.setPreferredSize(new java
.awt
.Dimension(585, 445));
140 This method initializes jScrollPane
142 @return javax.swing.JScrollPane
144 private JScrollPane
getJScrollPane() {
145 if (jScrollPane
== null) {
146 jScrollPane
= new JScrollPane();
147 jScrollPane
.setViewportView(getJContentPane());
153 This method initializes jScrollPaneTable
155 @return javax.swing.JScrollPane
157 private JScrollPane
getJScrollPaneTable() {
158 if (jScrollPaneTable
== null) {
159 jScrollPaneTable
= new JScrollPane();
160 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(0, 0, 585, 395));
161 jScrollPaneTable
.setPreferredSize(new Dimension(585, 395));
162 jScrollPaneTable
.setViewportView(getJTable());
164 return jScrollPaneTable
;
168 This method initializes jTable
170 @return javax.swing.JTable
172 private JTable
getJTable() {
173 if (jTable
== null) {
174 model
= new IDefaultTableModel();
175 jTable
= new JTable(model
);
176 jTable
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_OFF
);
177 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
179 jTable
.getSelectionModel().addListSelectionListener(this);
180 jTable
.getModel().addTableModelListener(this);
181 jTable
.addMouseListener(this);
183 model
.addColumn("Name");
184 model
.addColumn("Type");
185 model
.addColumn("Produced by");
186 model
.addColumn("Consumed by");
187 model
.addColumn("Declared by");
189 jTable
.getColumn("Name").setCellRenderer(new MyTableCellRenderer());
190 jTable
.getColumn("Type").setCellRenderer(new MyTableCellRenderer());
191 jTable
.getColumn("Produced by").setCellRenderer(new MyTableCellRenderer());
192 jTable
.getColumn("Consumed by").setCellRenderer(new MyTableCellRenderer());
193 jTable
.getColumn("Declared by").setCellRenderer(new MyTableCellRenderer());
195 int columnWidth
= (this.getSize().width
- 28) / 5;
196 jTable
.getColumn("Name").setPreferredWidth(columnWidth
);
197 jTable
.getColumn("Type").setPreferredWidth(columnWidth
);
198 jTable
.getColumn("Produced by").setPreferredWidth(columnWidth
);
199 jTable
.getColumn("Consumed by").setPreferredWidth(columnWidth
);
200 jTable
.getColumn("Declared by").setPreferredWidth(columnWidth
);
206 This method initializes jButtonAdd
208 @return javax.swing.JButton jButtonAdd
211 private JButton
getJButtonClose() {
212 if (jButtonClose
== null) {
213 jButtonClose
= new JButton();
214 jButtonClose
.setText("Close");
215 jButtonClose
.addActionListener(this);
216 jButtonClose
.setBounds(new java
.awt
.Rectangle(255, 415, 80, 20));
217 jButtonClose
.setPreferredSize(new java
.awt
.Dimension(80, 20));
222 public static FindResult
getInstance(String method
) {
223 if (method
.equals("PPI")) {
224 if (findPpisResult
== null) {
225 findPpisResult
= new FindResult(method
);
227 findPpisResult
.init(method
);
228 return findPpisResult
;
231 if (method
.equals("PROTOCOL")) {
232 if (findProtocolsResult
== null) {
233 findProtocolsResult
= new FindResult(method
);
235 findProtocolsResult
.init(method
);
236 return findProtocolsResult
;
239 if (method
.equals("GUID")) {
240 if (findGuidsResult
== null) {
241 findGuidsResult
= new FindResult(method
);
243 findGuidsResult
.init(method
);
244 return findGuidsResult
;
247 if (method
.equals("PCD")) {
248 if (findPcdsResult
== null) {
249 findPcdsResult
= new FindResult(method
);
251 findPcdsResult
.init(method
);
252 return findPcdsResult
;
255 if (method
.equals("LIBRARY_CLASS")) {
256 if (findLibraryClassResult
== null) {
257 findLibraryClassResult
= new FindResult(method
);
259 findLibraryClassResult
.init(method
);
260 return findLibraryClassResult
;
270 private void clearAll() {
272 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
273 model
.removeRow(index
);
279 Read content of vector and put then into table
282 private void showTable() {
285 if (this.method
.equals("PPI")) {
286 Vector
<PpiId
> vPpi
= Find
.getAllPpisForFind();
288 if (vPpi
.size() > 0) {
290 for (int index
= 0; index
< vPpi
.size(); index
++) {
291 Vector
<String
> v
= new Vector
<String
>();
292 v
.addElement(vPpi
.elementAt(index
).getName());
293 v
.addElement(vPpi
.elementAt(index
).getType());
294 String strProducedModules
= vPpi
.elementAt(index
).getProducedModules();
295 if (strProducedModules
.indexOf("<br>") == 0) {
296 strProducedModules
= strProducedModules
.substring("<br>".length());
298 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
299 v
.addElement("<html>" + strProducedModules
+ "</html>");
301 String strConsumedModules
= vPpi
.elementAt(index
).getConsumedModules();
302 if (strConsumedModules
.indexOf("<br>") == 0) {
303 strConsumedModules
= strConsumedModules
.substring("<br>".length());
305 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
306 v
.addElement("<html>" + strConsumedModules
+ "</html>");
308 v
.addElement(vPpi
.elementAt(index
).getDeclaredBy());
311 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
314 Log
.wrn("Find PPIs", "No PPI found!!!");
318 if (this.method
.equals("PROTOCOL")) {
319 Vector
<ProtocolId
> vProtocol
= Find
.getAllProtocolsForFind();
321 if (vProtocol
.size() > 0) {
323 for (int index
= 0; index
< vProtocol
.size(); index
++) {
324 Vector
<String
> v
= new Vector
<String
>();
325 v
.addElement(vProtocol
.elementAt(index
).getName());
326 v
.addElement(vProtocol
.elementAt(index
).getType());
327 String strProducedModules
= vProtocol
.elementAt(index
).getProducedModules();
328 if (strProducedModules
.indexOf("<br>") == 0) {
329 strProducedModules
= strProducedModules
.substring("<br>".length());
331 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
332 v
.addElement("<html>" + strProducedModules
+ "</html>");
334 String strConsumedModules
= vProtocol
.elementAt(index
).getConsumedModules();
335 if (strConsumedModules
.indexOf("<br>") == 0) {
336 strConsumedModules
= strConsumedModules
.substring("<br>".length());
338 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
339 v
.addElement("<html>" + strConsumedModules
+ "</html>");
341 v
.addElement(vProtocol
.elementAt(index
).getDeclaredBy());
344 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
347 Log
.wrn("Find PROTOCOLs", "No PROTOCOL found!!!");
351 if (this.method
.equals("GUID")) {
352 Vector
<GuidId
> vGuid
= Find
.getAllGuidsForFind();
354 if (vGuid
.size() > 0) {
356 for (int index
= 0; index
< vGuid
.size(); index
++) {
357 Vector
<String
> v
= new Vector
<String
>();
358 v
.addElement(vGuid
.elementAt(index
).getName());
359 v
.addElement("GUID");
360 String strProducedModules
= vGuid
.elementAt(index
).getProducedModules();
361 if (strProducedModules
.indexOf("<br>") == 0) {
362 strProducedModules
= strProducedModules
.substring("<br>".length());
364 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
365 v
.addElement("<html>" + strProducedModules
+ "</html>");
367 String strConsumedModules
= vGuid
.elementAt(index
).getConsumedModules();
368 if (strConsumedModules
.indexOf("<br>") == 0) {
369 strConsumedModules
= strConsumedModules
.substring("<br>".length());
371 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
372 v
.addElement("<html>" + strConsumedModules
+ "</html>");
374 v
.addElement(vGuid
.elementAt(index
).getDeclaredBy());
377 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
380 Log
.wrn("Find GUIDs", "No GUID found!!!");
384 if (this.method
.equals("PCD")) {
385 pv
= Find
.getAllPcdCodedVector();
386 vPcdFindResult
= Find
.getAllPcdCodedForFind(pv
);
388 if (vPcdFindResult
.size() > 0) {
390 for (int index
= 0; index
< vPcdFindResult
.size(); index
++) {
391 Vector
<String
> v
= new Vector
<String
>();
392 v
.addElement(vPcdFindResult
.elementAt(index
).getName());
393 v
.addElement(vPcdFindResult
.elementAt(index
).getType());
396 // Generate Produced Modules List
398 String strProducedModules
= "";
399 Vector
<ModuleIdentification
> vModule
= vPcdFindResult
.elementAt(index
).getProducedModules();
400 for (int indexOfPM
= 0; indexOfPM
< vModule
.size(); indexOfPM
++) {
401 strProducedModules
= strProducedModules
+ "<br>"
402 + vModule
.get(indexOfPM
).getPackageId().getName() + "."
403 + vModule
.get(indexOfPM
).getName();
405 if (strProducedModules
.indexOf("<br>") == 0) {
406 strProducedModules
= strProducedModules
.substring("<br>".length());
408 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
409 v
.addElement("<html>" + strProducedModules
+ "</html>");
412 // Generate Consumed Modules List
414 String strConsumedModules
= "";
415 vModule
= vPcdFindResult
.elementAt(index
).getConsumedModules();
416 for (int indexOfCM
= 0; indexOfCM
< vModule
.size(); indexOfCM
++) {
417 strConsumedModules
= strConsumedModules
+ "<br>"
418 + vModule
.get(indexOfCM
).getPackageId().getName() + "."
419 + vModule
.get(indexOfCM
).getName();
421 if (strConsumedModules
.indexOf("<br>") == 0) {
422 strConsumedModules
= strConsumedModules
.substring("<br>".length());
424 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
425 v
.addElement("<html>" + strConsumedModules
+ "</html>");
428 // Add declare package name
430 v
.addElement(vPcdFindResult
.elementAt(index
).getDeclaredBy().getName());
433 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
436 Log
.wrn("Find PCDs", "No PCD found!!!");
440 if (this.method
.equals("LIBRARY_CLASS")) {
441 lcv
= Find
.getAllLibraryClassVector();
442 vLibraryClassFindResult
= Find
.getAllLibraryClassForFind(lcv
);
444 if (vLibraryClassFindResult
.size() > 0) {
445 for (int index
= 0; index
< vLibraryClassFindResult
.size(); index
++) {
446 Vector
<String
> v
= new Vector
<String
>();
447 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getName());
448 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getType());
451 // Generate Produced Modules List
453 String strProducedModules
= "";
454 Vector
<ModuleIdentification
> vModule
= vLibraryClassFindResult
.elementAt(index
)
455 .getProducedModules();
456 for (int indexOfPM
= 0; indexOfPM
< vModule
.size(); indexOfPM
++) {
457 strProducedModules
= strProducedModules
+ "<br>"
458 + vModule
.get(indexOfPM
).getPackageId().getName() + "."
459 + vModule
.get(indexOfPM
).getName();
461 if (strProducedModules
.indexOf("<br>") == 0) {
462 strProducedModules
= strProducedModules
.substring("<br>".length());
464 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
465 v
.addElement("<html>" + strProducedModules
+ "</html>");
468 // Generate Consumed Modules List
470 String strConsumedModules
= "";
471 vModule
= vLibraryClassFindResult
.elementAt(index
).getConsumedModules();
472 for (int indexOfCM
= 0; indexOfCM
< vModule
.size(); indexOfCM
++) {
473 strConsumedModules
= strConsumedModules
+ "<br>"
474 + vModule
.get(indexOfCM
).getPackageId().getName() + "."
475 + vModule
.get(indexOfCM
).getName();
477 if (strConsumedModules
.indexOf("<br>") == 0) {
478 strConsumedModules
= strConsumedModules
.substring("<br>".length());
480 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
481 v
.addElement("<html>" + strConsumedModules
+ "</html>");
483 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getDeclaredBy().getName());
486 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
489 Log
.wrn("Find Library Classes", "No Library Class found!!!");
493 this.jTable
.repaint();
494 this.jTable
.updateUI();
497 public void tableChanged(TableModelEvent arg0
) {
498 // TODO Auto-generated method stub
503 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
506 public void actionPerformed(ActionEvent arg0
) {
507 if (arg0
.getSource() == this.jButtonClose
) {
513 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
515 * Override componentResized to resize all components when frame's size is changed
517 public void componentResized(ComponentEvent arg0
) {
518 int intCurrentWidth
= this.getJContentPane().getWidth();
519 int intCurrentHeight
= this.getJContentPane().getHeight();
520 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
521 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
523 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
525 Tools
.centerComponent(this.jButtonClose
, intCurrentWidth
, intCurrentHeight
, intPreferredHeight
,
526 DataType
.SPACE_TO_BOTTOM_FOR_CLOSE_BUTTON
);
527 Tools
.resizeTableColumn(this.jTable
, this.getSize().width
- 28);
531 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
534 public void valueChanged(ListSelectionEvent arg0
) {
535 if (arg0
.getValueIsAdjusting()) {
538 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
539 if (lsm
.isSelectionEmpty()) {
542 selectedRow
= lsm
.getMinSelectionIndex();
547 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
550 public void mouseClicked(MouseEvent arg0
) {
551 if (arg0
.getClickCount() == 2) {
552 if (this.selectedRow
< 0) {
555 if (this.method
.equals("LIBRARY_CLASS")) {
556 FindResultDetailInfo frdi
= new FindResultDetailInfo(vLibraryClassFindResult
.elementAt(selectedRow
));
557 frdi
.setVisible(true);
559 if (this.method
.equals("PCD")) {
560 FindResultDetailInfo frdi
= new FindResultDetailInfo(vPcdFindResult
.elementAt(selectedRow
));
561 frdi
.setVisible(true);
568 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
570 * Override windowClosing to popup warning message to confirm quit
573 public void windowClosing(WindowEvent arg0
) {
577 class MyTableCellRenderer
extends DefaultTableCellRenderer
{
579 /// Define Class Serial Version UID
581 private static final long serialVersionUID
= -2082787479305255946L;
583 public void setValue(Object value
) {
584 this.setVerticalAlignment(SwingConstants
.TOP
);
585 super.setValue(value
);
589 public void mousePressed(MouseEvent e
) {
590 // TODO Auto-generated method stub
594 public void mouseReleased(MouseEvent e
) {
595 // TODO Auto-generated method stub
599 public void mouseEntered(MouseEvent e
) {
600 // TODO Auto-generated method stub
604 public void mouseExited(MouseEvent e
) {
605 // TODO Auto-generated method stub