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
;
46 public class FindResult
extends IFrame
implements TableModelListener
, ListSelectionListener
, MouseListener
{
49 /// Define class Serial Version UID
51 private static final long serialVersionUID
= -2448484533878401714L;
54 // Define class members
56 private JTable jTable
= null;
58 private JPanel jContentPane
= null;
60 private JScrollPane jScrollPane
= null;
62 private JScrollPane jScrollPaneTable
= null;
64 private JButton jButtonClose
= null;
69 private IDefaultTableModel model
= null;
71 private String method
= "";
73 private static FindResult findPpisResult
= null;
75 private static FindResult findProtocolsResult
= null;
77 private static FindResult findGuidsResult
= null;
79 private static FindResult findPcdsResult
= null;
81 private static FindResult findLibraryClassResult
= null;
83 private int selectedRow
= -1;
85 private LibraryClassVector lcv
= null;
87 private Vector
<FindResultId
> vLibraryClassFindResult
= null;
90 * This is the default constructor
92 public FindResult(String method
) {
98 * This method initializes this
102 private void init(String method
) {
103 this.setSize(600, 500);
104 this.setContentPane(getJScrollPane());
105 this.setTitle("Find Result");
106 this.setResizable(true);
107 this.setDefaultCloseOperation(JFrame
.HIDE_ON_CLOSE
);
113 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
114 this.method
= method
;
119 * This method initializes jContentPane
121 * @return javax.swing.JPanel
123 private JPanel
getJContentPane() {
124 if (jContentPane
== null) {
125 jContentPane
= new JPanel();
126 jContentPane
.setLayout(null);
127 jContentPane
.add(getJScrollPaneTable(), null);
128 jContentPane
.add(getJButtonClose(), null);
129 jContentPane
.setPreferredSize(new java
.awt
.Dimension(585, 445));
135 This method initializes jScrollPane
137 @return javax.swing.JScrollPane
139 private JScrollPane
getJScrollPane() {
140 if (jScrollPane
== null) {
141 jScrollPane
= new JScrollPane();
142 jScrollPane
.setViewportView(getJContentPane());
148 This method initializes jScrollPaneTable
150 @return javax.swing.JScrollPane
152 private JScrollPane
getJScrollPaneTable() {
153 if (jScrollPaneTable
== null) {
154 jScrollPaneTable
= new JScrollPane();
155 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(0, 0, 585, 395));
156 jScrollPaneTable
.setPreferredSize(new Dimension(585, 395));
157 jScrollPaneTable
.setViewportView(getJTable());
159 return jScrollPaneTable
;
163 This method initializes jTable
165 @return javax.swing.JTable
167 private JTable
getJTable() {
168 if (jTable
== null) {
169 model
= new IDefaultTableModel();
170 jTable
= new JTable(model
);
171 jTable
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_OFF
);
172 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
174 jTable
.getSelectionModel().addListSelectionListener(this);
175 jTable
.getModel().addTableModelListener(this);
176 jTable
.addMouseListener(this);
178 model
.addColumn("Name");
179 model
.addColumn("Type");
180 model
.addColumn("Produced by");
181 model
.addColumn("Consumed by");
182 model
.addColumn("Declared by");
184 jTable
.getColumn("Name").setCellRenderer(new MyTableCellRenderer());
185 jTable
.getColumn("Type").setCellRenderer(new MyTableCellRenderer());
186 jTable
.getColumn("Produced by").setCellRenderer(new MyTableCellRenderer());
187 jTable
.getColumn("Consumed by").setCellRenderer(new MyTableCellRenderer());
188 jTable
.getColumn("Declared by").setCellRenderer(new MyTableCellRenderer());
190 int columnWidth
= (this.getSize().width
- 28) / 5;
191 jTable
.getColumn("Name").setPreferredWidth(columnWidth
);
192 jTable
.getColumn("Type").setPreferredWidth(columnWidth
);
193 jTable
.getColumn("Produced by").setPreferredWidth(columnWidth
);
194 jTable
.getColumn("Consumed by").setPreferredWidth(columnWidth
);
195 jTable
.getColumn("Declared by").setPreferredWidth(columnWidth
);
201 This method initializes jButtonAdd
203 @return javax.swing.JButton jButtonAdd
206 private JButton
getJButtonClose() {
207 if (jButtonClose
== null) {
208 jButtonClose
= new JButton();
209 jButtonClose
.setText("Close");
210 jButtonClose
.addActionListener(this);
211 jButtonClose
.setBounds(new java
.awt
.Rectangle(255, 415, 80, 20));
212 jButtonClose
.setPreferredSize(new java
.awt
.Dimension(80, 20));
217 public static FindResult
getInstance(String method
) {
218 if (method
.equals("PPI")) {
219 if (findPpisResult
== null) {
220 findPpisResult
= new FindResult(method
);
222 findPpisResult
.init(method
);
223 return findPpisResult
;
226 if (method
.equals("PROTOCOL")) {
227 if (findProtocolsResult
== null) {
228 findProtocolsResult
= new FindResult(method
);
230 findProtocolsResult
.init(method
);
231 return findProtocolsResult
;
234 if (method
.equals("GUID")) {
235 if (findGuidsResult
== null) {
236 findGuidsResult
= new FindResult(method
);
238 findGuidsResult
.init(method
);
239 return findGuidsResult
;
242 if (method
.equals("PCD")) {
243 if (findPcdsResult
== null) {
244 findPcdsResult
= new FindResult(method
);
246 findPcdsResult
.init(method
);
247 return findPcdsResult
;
250 if (method
.equals("LIBRARY_CLASS")) {
251 if (findLibraryClassResult
== null) {
252 findLibraryClassResult
= new FindResult(method
);
254 findLibraryClassResult
.init(method
);
255 return findLibraryClassResult
;
265 private void clearAll() {
267 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
268 model
.removeRow(index
);
274 Read content of vector and put then into table
277 private void showTable() {
280 if (this.method
.equals("PPI")) {
281 Vector
<PpiId
> vPpi
= Find
.getAllPpisForFind();
283 if (vPpi
.size() > 0) {
285 for (int index
= 0; index
< vPpi
.size(); index
++) {
286 Vector
<String
> v
= new Vector
<String
>();
287 v
.addElement(vPpi
.elementAt(index
).getName());
288 v
.addElement(vPpi
.elementAt(index
).getType());
289 String strProducedModules
= vPpi
.elementAt(index
).getProducedModules();
290 if (strProducedModules
.indexOf("<br>") == 0) {
291 strProducedModules
= strProducedModules
.substring("<br>".length());
293 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
294 v
.addElement("<html>" + strProducedModules
+ "</html>");
296 String strConsumedModules
= vPpi
.elementAt(index
).getConsumedModules();
297 if (strConsumedModules
.indexOf("<br>") == 0) {
298 strConsumedModules
= strConsumedModules
.substring("<br>".length());
300 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
301 v
.addElement("<html>" + strConsumedModules
+ "</html>");
303 v
.addElement(vPpi
.elementAt(index
).getDeclaredBy());
306 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
309 Log
.wrn("Find PPIs", "No PPI found!!!");
313 if (this.method
.equals("PROTOCOL")) {
314 Vector
<ProtocolId
> vProtocol
= Find
.getAllProtocolsForFind();
316 if (vProtocol
.size() > 0) {
318 for (int index
= 0; index
< vProtocol
.size(); index
++) {
319 Vector
<String
> v
= new Vector
<String
>();
320 v
.addElement(vProtocol
.elementAt(index
).getName());
321 v
.addElement(vProtocol
.elementAt(index
).getType());
322 String strProducedModules
= vProtocol
.elementAt(index
).getProducedModules();
323 if (strProducedModules
.indexOf("<br>") == 0) {
324 strProducedModules
= strProducedModules
.substring("<br>".length());
326 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
327 v
.addElement("<html>" + strProducedModules
+ "</html>");
329 String strConsumedModules
= vProtocol
.elementAt(index
).getConsumedModules();
330 if (strConsumedModules
.indexOf("<br>") == 0) {
331 strConsumedModules
= strConsumedModules
.substring("<br>".length());
333 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
334 v
.addElement("<html>" + strConsumedModules
+ "</html>");
336 v
.addElement(vProtocol
.elementAt(index
).getDeclaredBy());
339 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
342 Log
.wrn("Find PROTOCOLs", "No PROTOCOL found!!!");
346 if (this.method
.equals("GUID")) {
347 Vector
<GuidId
> vGuid
= Find
.getAllGuidsForFind();
349 if (vGuid
.size() > 0) {
351 for (int index
= 0; index
< vGuid
.size(); index
++) {
352 Vector
<String
> v
= new Vector
<String
>();
353 v
.addElement(vGuid
.elementAt(index
).getName());
354 v
.addElement("GUID");
355 String strProducedModules
= vGuid
.elementAt(index
).getProducedModules();
356 if (strProducedModules
.indexOf("<br>") == 0) {
357 strProducedModules
= strProducedModules
.substring("<br>".length());
359 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
360 v
.addElement("<html>" + strProducedModules
+ "</html>");
362 String strConsumedModules
= vGuid
.elementAt(index
).getConsumedModules();
363 if (strConsumedModules
.indexOf("<br>") == 0) {
364 strConsumedModules
= strConsumedModules
.substring("<br>".length());
366 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
367 v
.addElement("<html>" + strConsumedModules
+ "</html>");
369 v
.addElement(vGuid
.elementAt(index
).getDeclaredBy());
372 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
375 Log
.wrn("Find GUIDs", "No GUID found!!!");
379 if (this.method
.equals("PCD")) {
380 Vector
<PcdId
> vPcd
= Find
.getAllPcdCodedForFind();
382 if (vPcd
.size() > 0) {
384 for (int index
= 0; index
< vPcd
.size(); index
++) {
385 Vector
<String
> v
= new Vector
<String
>();
386 v
.addElement(vPcd
.elementAt(index
).getName());
387 v
.addElement(vPcd
.elementAt(index
).getType());
388 String strProducedModules
= vPcd
.elementAt(index
).getProducedModules();
389 if (strProducedModules
.indexOf("<br>") == 0) {
390 strProducedModules
= strProducedModules
.substring("<br>".length());
392 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
393 v
.addElement("<html>" + strProducedModules
+ "</html>");
395 String strConsumedModules
= vPcd
.elementAt(index
).getConsumedModules();
396 if (strConsumedModules
.indexOf("<br>") == 0) {
397 strConsumedModules
= strConsumedModules
.substring("<br>".length());
399 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
400 v
.addElement("<html>" + strConsumedModules
+ "</html>");
402 v
.addElement(vPcd
.elementAt(index
).getDeclaredBy());
405 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
408 Log
.wrn("Find PCDs", "No PCD found!!!");
412 if (this.method
.equals("LIBRARY_CLASS")) {
413 lcv
= Find
.getAllLibraryClassVector();
414 vLibraryClassFindResult
= Find
.getAllLibraryClassForFind(lcv
);
416 if (vLibraryClassFindResult
.size() > 0) {
417 for (int index
= 0; index
< vLibraryClassFindResult
.size(); index
++) {
418 Vector
<String
> v
= new Vector
<String
>();
419 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getName());
420 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getType());
423 // Generate Produced Modules List
425 String strProducedModules
= "";
426 Vector
<ModuleIdentification
> vModule
= vLibraryClassFindResult
.elementAt(index
)
427 .getProducedModules();
428 for (int indexOfPM
= 0; indexOfPM
< vModule
.size(); indexOfPM
++) {
429 strProducedModules
= strProducedModules
+ "<br>"
430 + vModule
.get(indexOfPM
).getPackageId().getName() + "."
431 + vModule
.get(indexOfPM
).getName();
433 if (strProducedModules
.indexOf("<br>") == 0) {
434 strProducedModules
= strProducedModules
.substring("<br>".length());
436 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
437 v
.addElement("<html>" + strProducedModules
+ "</html>");
440 // Generate Consumed Modules List
442 String strConsumedModules
= "";
443 vModule
= vLibraryClassFindResult
.elementAt(index
).getConsumedModules();
444 for (int indexOfCM
= 0; indexOfCM
< vModule
.size(); indexOfCM
++) {
445 strConsumedModules
= strConsumedModules
+ "<br>"
446 + vModule
.get(indexOfCM
).getPackageId().getName() + "."
447 + vModule
.get(indexOfCM
).getName();
449 if (strConsumedModules
.indexOf("<br>") == 0) {
450 strConsumedModules
= strConsumedModules
.substring("<br>".length());
452 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
453 v
.addElement("<html>" + strConsumedModules
+ "</html>");
455 v
.addElement(vLibraryClassFindResult
.elementAt(index
).getDeclaredBy().getName());
458 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
461 Log
.wrn("Find Library Classes", "No Library Class found!!!");
465 this.jTable
.repaint();
466 this.jTable
.updateUI();
469 public void tableChanged(TableModelEvent arg0
) {
470 // TODO Auto-generated method stub
475 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
478 public void actionPerformed(ActionEvent arg0
) {
479 if (arg0
.getSource() == this.jButtonClose
) {
485 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
487 * Override componentResized to resize all components when frame's size is changed
489 public void componentResized(ComponentEvent arg0
) {
490 int intCurrentWidth
= this.getJContentPane().getWidth();
491 int intCurrentHeight
= this.getJContentPane().getHeight();
492 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
493 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
495 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
497 Tools
.centerComponent(this.jButtonClose
, intCurrentWidth
, intCurrentHeight
, intPreferredHeight
,
498 DataType
.SPACE_TO_BOTTOM_FOR_CLOSE_BUTTON
);
499 Tools
.resizeTableColumn(this.jTable
, this.getSize().width
- 28);
503 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
506 public void valueChanged(ListSelectionEvent arg0
) {
507 if (arg0
.getValueIsAdjusting()) {
510 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
511 if (lsm
.isSelectionEmpty()) {
514 selectedRow
= lsm
.getMinSelectionIndex();
519 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
522 public void mouseClicked(MouseEvent arg0
) {
523 if (arg0
.getClickCount() == 2) {
524 if (this.selectedRow
< 0) {
527 if (this.method
.equals("LIBRARY_CLASS")) {
528 FindResultDetailInfo frdi
= new FindResultDetailInfo(vLibraryClassFindResult
.elementAt(selectedRow
));
529 frdi
.setVisible(true);
536 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
538 * Override windowClosing to popup warning message to confirm quit
541 public void windowClosing(WindowEvent arg0
) {
545 class MyTableCellRenderer
extends DefaultTableCellRenderer
{
547 /// Define Class Serial Version UID
549 private static final long serialVersionUID
= -2082787479305255946L;
551 public void setValue(Object value
) {
552 this.setVerticalAlignment(SwingConstants
.TOP
);
553 super.setValue(value
);
557 public void mousePressed(MouseEvent e
) {
558 // TODO Auto-generated method stub
562 public void mouseReleased(MouseEvent e
) {
563 // TODO Auto-generated method stub
567 public void mouseEntered(MouseEvent e
) {
568 // TODO Auto-generated method stub
572 public void mouseExited(MouseEvent e
) {
573 // TODO Auto-generated method stub