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;
94 private JButton jButtonReload
= null;
96 private JPanel jPanelOperation
= null;
99 * This is the default constructor
101 public FindResult(String method
) {
107 * This method initializes this
111 private void init(String method
) {
112 this.setSize(600, 500);
113 this.setContentPane(getJScrollPane());
114 this.setTitle("Find Result");
115 this.setResizable(true);
116 this.setDefaultCloseOperation(JFrame
.HIDE_ON_CLOSE
);
122 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
123 this.method
= method
;
128 * This method initializes jContentPane
130 * @return javax.swing.JPanel
132 private JPanel
getJContentPane() {
133 if (jContentPane
== null) {
134 jContentPane
= new JPanel();
135 jContentPane
.setLayout(null);
136 jContentPane
.add(getJScrollPaneTable(), null);
137 jContentPane
.add(getJPanelOperation(), null);
138 jContentPane
.setPreferredSize(new java
.awt
.Dimension(585, 445));
144 This method initializes jScrollPane
146 @return javax.swing.JScrollPane
148 private JScrollPane
getJScrollPane() {
149 if (jScrollPane
== null) {
150 jScrollPane
= new JScrollPane();
151 jScrollPane
.setViewportView(getJContentPane());
157 This method initializes jScrollPaneTable
159 @return javax.swing.JScrollPane
161 private JScrollPane
getJScrollPaneTable() {
162 if (jScrollPaneTable
== null) {
163 jScrollPaneTable
= new JScrollPane();
164 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(0, 0, 585, 395));
165 jScrollPaneTable
.setPreferredSize(new Dimension(585, 395));
166 jScrollPaneTable
.setViewportView(getJTable());
168 return jScrollPaneTable
;
172 This method initializes jTable
174 @return javax.swing.JTable
176 private JTable
getJTable() {
177 if (jTable
== null) {
178 model
= new IDefaultTableModel();
179 jTable
= new JTable(model
);
180 jTable
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_OFF
);
181 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
183 jTable
.getSelectionModel().addListSelectionListener(this);
184 jTable
.getModel().addTableModelListener(this);
185 jTable
.addMouseListener(this);
187 model
.addColumn("Name");
188 model
.addColumn("Type");
189 model
.addColumn("Produced by");
190 model
.addColumn("Consumed by");
191 model
.addColumn("Declared by");
193 jTable
.getColumn("Name").setCellRenderer(new MyTableCellRenderer());
194 jTable
.getColumn("Type").setCellRenderer(new MyTableCellRenderer());
195 jTable
.getColumn("Produced by").setCellRenderer(new MyTableCellRenderer());
196 jTable
.getColumn("Consumed by").setCellRenderer(new MyTableCellRenderer());
197 jTable
.getColumn("Declared by").setCellRenderer(new MyTableCellRenderer());
199 int columnWidth
= (this.getSize().width
- 28) / 5;
200 jTable
.getColumn("Name").setPreferredWidth(columnWidth
);
201 jTable
.getColumn("Type").setPreferredWidth(columnWidth
);
202 jTable
.getColumn("Produced by").setPreferredWidth(columnWidth
);
203 jTable
.getColumn("Consumed by").setPreferredWidth(columnWidth
);
204 jTable
.getColumn("Declared by").setPreferredWidth(columnWidth
);
210 This method initializes jButtonAdd
212 @return javax.swing.JButton jButtonAdd
215 private JButton
getJButtonClose() {
216 if (jButtonClose
== null) {
217 jButtonClose
= new JButton();
218 jButtonClose
.setText("Close");
219 jButtonClose
.addActionListener(this);
220 jButtonClose
.setPreferredSize(new java
.awt
.Dimension(80, 20));
221 jButtonClose
.setBounds(new java
.awt
.Rectangle(90, 0, 80, 20));
226 public static FindResult
getInstance(String method
) {
227 if (method
.equals("PPI")) {
228 if (findPpisResult
== null) {
229 findPpisResult
= new FindResult(method
);
231 findPpisResult
.init(method
);
232 return findPpisResult
;
235 if (method
.equals("PROTOCOL")) {
236 if (findProtocolsResult
== null) {
237 findProtocolsResult
= new FindResult(method
);
239 findProtocolsResult
.init(method
);
240 return findProtocolsResult
;
243 if (method
.equals("GUID")) {
244 if (findGuidsResult
== null) {
245 findGuidsResult
= new FindResult(method
);
247 findGuidsResult
.init(method
);
248 return findGuidsResult
;
251 if (method
.equals("PCD")) {
252 if (findPcdsResult
== null) {
253 findPcdsResult
= new FindResult(method
);
255 findPcdsResult
.init(method
);
256 return findPcdsResult
;
259 if (method
.equals("LIBRARY_CLASS")) {
260 if (findLibraryClassResult
== null) {
261 findLibraryClassResult
= new FindResult(method
);
263 findLibraryClassResult
.init(method
);
264 return findLibraryClassResult
;
274 private void clearAll() {
276 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
277 model
.removeRow(index
);
283 Read content of vector and put then into table
286 private void showTable() {
288 this.jTable
.repaint();
289 this.jTable
.updateUI();
291 if (this.method
.equals("PPI")) {
292 Vector
<PpiId
> vPpi
= Find
.getAllPpisForFind();
294 if (vPpi
.size() > 0) {
296 for (int index
= 0; index
< vPpi
.size(); index
++) {
297 Vector
<String
> v
= new Vector
<String
>();
298 v
.addElement(vPpi
.elementAt(index
).getName());
299 v
.addElement(vPpi
.elementAt(index
).getType());
300 String strProducedModules
= vPpi
.elementAt(index
).getProducedModules();
301 if (strProducedModules
.indexOf("<br>") == 0) {
302 strProducedModules
= strProducedModules
.substring("<br>".length());
304 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
305 v
.addElement("<html>" + strProducedModules
+ "</html>");
307 String strConsumedModules
= vPpi
.elementAt(index
).getConsumedModules();
308 if (strConsumedModules
.indexOf("<br>") == 0) {
309 strConsumedModules
= strConsumedModules
.substring("<br>".length());
311 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
312 v
.addElement("<html>" + strConsumedModules
+ "</html>");
314 v
.addElement(vPpi
.elementAt(index
).getDeclaredBy());
317 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
320 Log
.wrn("Find PPIs", "No PPI found!!!");
324 if (this.method
.equals("PROTOCOL")) {
325 Vector
<ProtocolId
> vProtocol
= Find
.getAllProtocolsForFind();
327 if (vProtocol
.size() > 0) {
329 for (int index
= 0; index
< vProtocol
.size(); index
++) {
330 Vector
<String
> v
= new Vector
<String
>();
331 v
.addElement(vProtocol
.elementAt(index
).getName());
332 v
.addElement(vProtocol
.elementAt(index
).getType());
333 String strProducedModules
= vProtocol
.elementAt(index
).getProducedModules();
334 if (strProducedModules
.indexOf("<br>") == 0) {
335 strProducedModules
= strProducedModules
.substring("<br>".length());
337 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
338 v
.addElement("<html>" + strProducedModules
+ "</html>");
340 String strConsumedModules
= vProtocol
.elementAt(index
).getConsumedModules();
341 if (strConsumedModules
.indexOf("<br>") == 0) {
342 strConsumedModules
= strConsumedModules
.substring("<br>".length());
344 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
345 v
.addElement("<html>" + strConsumedModules
+ "</html>");
347 v
.addElement(vProtocol
.elementAt(index
).getDeclaredBy());
350 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
353 Log
.wrn("Find PROTOCOLs", "No PROTOCOL found!!!");
357 if (this.method
.equals("GUID")) {
358 Vector
<GuidId
> vGuid
= Find
.getAllGuidsForFind();
360 if (vGuid
.size() > 0) {
362 for (int index
= 0; index
< vGuid
.size(); index
++) {
363 Vector
<String
> v
= new Vector
<String
>();
364 v
.addElement(vGuid
.elementAt(index
).getName());
365 v
.addElement("GUID");
366 String strProducedModules
= vGuid
.elementAt(index
).getProducedModules();
367 if (strProducedModules
.indexOf("<br>") == 0) {
368 strProducedModules
= strProducedModules
.substring("<br>".length());
370 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
371 v
.addElement("<html>" + strProducedModules
+ "</html>");
373 String strConsumedModules
= vGuid
.elementAt(index
).getConsumedModules();
374 if (strConsumedModules
.indexOf("<br>") == 0) {
375 strConsumedModules
= strConsumedModules
.substring("<br>".length());
377 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
378 v
.addElement("<html>" + strConsumedModules
+ "</html>");
380 v
.addElement(vGuid
.elementAt(index
).getDeclaredBy());
383 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
386 Log
.wrn("Find GUIDs", "No GUID found!!!");
390 if (this.method
.equals("PCD")) {
391 pv
= Find
.getAllPcdCodedVector();
392 vPcdFindResult
= Find
.getAllPcdCodedForFind(pv
);
394 if (vPcdFindResult
.size() > 0) {
396 for (int index
= 0; index
< vPcdFindResult
.size(); index
++) {
397 Vector
<String
> v
= new Vector
<String
>();
398 v
.addElement(vPcdFindResult
.elementAt(index
).getName());
399 v
.addElement(vPcdFindResult
.elementAt(index
).getType());
402 // Generate Produced Modules List
404 String strProducedModules
= "";
405 Vector
<ModuleIdentification
> vModule
= vPcdFindResult
.elementAt(index
).getProducedModules();
406 for (int indexOfPM
= 0; indexOfPM
< vModule
.size(); indexOfPM
++) {
407 strProducedModules
= strProducedModules
+ "<br>"
408 + vModule
.get(indexOfPM
).getPackageId().getName() + "."
409 + vModule
.get(indexOfPM
).getName();
411 if (strProducedModules
.indexOf("<br>") == 0) {
412 strProducedModules
= strProducedModules
.substring("<br>".length());
414 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
415 v
.addElement("<html>" + strProducedModules
+ "</html>");
418 // Generate Consumed Modules List
420 String strConsumedModules
= "";
421 vModule
= vPcdFindResult
.elementAt(index
).getConsumedModules();
422 for (int indexOfCM
= 0; indexOfCM
< vModule
.size(); indexOfCM
++) {
423 strConsumedModules
= strConsumedModules
+ "<br>"
424 + vModule
.get(indexOfCM
).getPackageId().getName() + "."
425 + vModule
.get(indexOfCM
).getName();
427 if (strConsumedModules
.indexOf("<br>") == 0) {
428 strConsumedModules
= strConsumedModules
.substring("<br>".length());
430 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
431 v
.addElement("<html>" + strConsumedModules
+ "</html>");
434 // Add declare package name
436 v
.addElement(vPcdFindResult
.elementAt(index
).getDeclaredBy().getName());
439 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
442 Log
.wrn("Find PCDs", "No PCD found!!!");
446 if (this.method
.equals("LIBRARY_CLASS")) {
447 lcv
= Find
.getAllLibraryClassVector();
448 vLibraryClassFindResult
= Find
.getAllLibraryClassForFind(lcv
);
450 if (vLibraryClassFindResult
.size() > 0) {
451 for (int index
= 0; index
< vLibraryClassFindResult
.size(); index
++) {
452 Vector
<String
> v
= new Vector
<String
>();
453 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getName());
454 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getType());
457 // Generate Produced Modules List
459 String strProducedModules
= "";
460 Vector
<ModuleIdentification
> vModule
= vLibraryClassFindResult
.elementAt(index
)
461 .getProducedModules();
462 for (int indexOfPM
= 0; indexOfPM
< vModule
.size(); indexOfPM
++) {
463 strProducedModules
= strProducedModules
+ "<br>"
464 + vModule
.get(indexOfPM
).getPackageId().getName() + "."
465 + vModule
.get(indexOfPM
).getName();
467 if (strProducedModules
.indexOf("<br>") == 0) {
468 strProducedModules
= strProducedModules
.substring("<br>".length());
470 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
471 v
.addElement("<html>" + strProducedModules
+ "</html>");
474 // Generate Consumed Modules List
476 String strConsumedModules
= "";
477 vModule
= vLibraryClassFindResult
.elementAt(index
).getConsumedModules();
478 for (int indexOfCM
= 0; indexOfCM
< vModule
.size(); indexOfCM
++) {
479 strConsumedModules
= strConsumedModules
+ "<br>"
480 + vModule
.get(indexOfCM
).getPackageId().getName() + "."
481 + vModule
.get(indexOfCM
).getName();
483 if (strConsumedModules
.indexOf("<br>") == 0) {
484 strConsumedModules
= strConsumedModules
.substring("<br>".length());
486 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
487 v
.addElement("<html>" + strConsumedModules
+ "</html>");
489 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getDeclaredBy().getName());
492 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
495 Log
.wrn("Find Library Classes", "No Library Class found!!!");
499 this.jTable
.repaint();
500 this.jTable
.updateUI();
503 public void tableChanged(TableModelEvent arg0
) {
504 // TODO Auto-generated method stub
509 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
512 public void actionPerformed(ActionEvent arg0
) {
513 if (arg0
.getSource() == this.jButtonClose
) {
517 if (arg0
.getSource() == this.jButtonReload
) {
523 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
525 * Override componentResized to resize all components when frame's size is changed
527 public void componentResized(ComponentEvent arg0
) {
528 int intCurrentWidth
= this.getJContentPane().getWidth();
529 int intCurrentHeight
= this.getJContentPane().getHeight();
530 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
531 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
533 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
535 Tools
.centerComponent(this.jPanelOperation
, intCurrentWidth
, intCurrentHeight
, intPreferredHeight
,
536 DataType
.SPACE_TO_BOTTOM_FOR_CLOSE_BUTTON
);
537 Tools
.resizeTableColumn(this.jTable
, this.getSize().width
- 28);
541 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
544 public void valueChanged(ListSelectionEvent arg0
) {
545 if (arg0
.getValueIsAdjusting()) {
548 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
549 if (lsm
.isSelectionEmpty()) {
552 selectedRow
= lsm
.getMinSelectionIndex();
557 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
560 public void mouseClicked(MouseEvent arg0
) {
561 if (arg0
.getClickCount() == 2) {
562 if (this.selectedRow
< 0) {
565 if (this.method
.equals("LIBRARY_CLASS")) {
566 FindResultDetailInfo frdi
= new FindResultDetailInfo(vLibraryClassFindResult
.elementAt(selectedRow
));
567 frdi
.setVisible(true);
569 if (this.method
.equals("PCD")) {
570 FindResultDetailInfo frdi
= new FindResultDetailInfo(vPcdFindResult
.elementAt(selectedRow
));
571 frdi
.setVisible(true);
578 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
580 * Override windowClosing to popup warning message to confirm quit
583 public void windowClosing(WindowEvent arg0
) {
587 class MyTableCellRenderer
extends DefaultTableCellRenderer
{
589 /// Define Class Serial Version UID
591 private static final long serialVersionUID
= -2082787479305255946L;
593 public void setValue(Object value
) {
594 this.setVerticalAlignment(SwingConstants
.TOP
);
595 super.setValue(value
);
599 public void mousePressed(MouseEvent e
) {
600 // TODO Auto-generated method stub
604 public void mouseReleased(MouseEvent e
) {
605 // TODO Auto-generated method stub
609 public void mouseEntered(MouseEvent e
) {
610 // TODO Auto-generated method stub
614 public void mouseExited(MouseEvent e
) {
615 // TODO Auto-generated method stub
620 * This method initializes jButtonReload
622 * @return javax.swing.JButton
624 private JButton
getJButtonReload() {
625 if (jButtonReload
== null) {
626 jButtonReload
= new JButton();
627 jButtonReload
.setText("Reload");
628 jButtonReload
.addActionListener(this);
629 jButtonReload
.setBounds(new java
.awt
.Rectangle(0, 0, 80, 20));
630 jButtonReload
.setPreferredSize(new java
.awt
.Dimension(80, 20));
632 return jButtonReload
;
636 * This method initializes jPanelOperation
638 * @return javax.swing.JPanel
640 private JPanel
getJPanelOperation() {
641 if (jPanelOperation
== null) {
642 jPanelOperation
= new JPanel();
643 jPanelOperation
.setLayout(null);
644 jPanelOperation
.setBounds(new java
.awt
.Rectangle(300, 415, 170, 20));
645 jPanelOperation
.setPreferredSize(new java
.awt
.Dimension(170, 20));
646 jPanelOperation
.add(getJButtonClose(), null);
647 jPanelOperation
.add(getJButtonReload(), null);
649 return jPanelOperation
;