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
.WindowEvent
;
21 import java
.util
.Vector
;
23 import javax
.swing
.JButton
;
24 import javax
.swing
.JFrame
;
25 import javax
.swing
.JPanel
;
26 import javax
.swing
.JScrollPane
;
27 import javax
.swing
.JTable
;
28 import javax
.swing
.ListSelectionModel
;
29 import javax
.swing
.SwingConstants
;
30 import javax
.swing
.event
.TableModelEvent
;
31 import javax
.swing
.event
.TableModelListener
;
32 import javax
.swing
.table
.DefaultTableCellRenderer
;
34 import org
.tianocore
.frameworkwizard
.common
.DataType
;
35 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
36 import org
.tianocore
.frameworkwizard
.common
.Log
;
37 import org
.tianocore
.frameworkwizard
.common
.Tools
;
38 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
40 public class FindResult
extends IFrame
implements TableModelListener
{
43 /// Define class Serial Version UID
45 private static final long serialVersionUID
= -2448484533878401714L;
48 // Define class members
50 private JTable jTable
= null;
52 private JPanel jContentPane
= null;
54 private JScrollPane jScrollPane
= null;
56 private JScrollPane jScrollPaneTable
= null;
58 private JButton jButtonClose
= null;
63 private IDefaultTableModel model
= null;
65 private String method
= "";
67 private static FindResult findPpisResult
= null;
69 private static FindResult findProtocolsResult
= null;
71 private static FindResult findGuidsResult
= null;
73 private static FindResult findPcdsResult
= null;
75 private static FindResult findLibraryClassResult
= null;
78 * This is the default constructor
80 public FindResult(String method
) {
86 * This method initializes this
90 private void init(String method
) {
91 this.setSize(600, 500);
92 this.setContentPane(getJScrollPane());
93 this.setTitle("Find Result");
94 this.setResizable(true);
95 this.setDefaultCloseOperation(JFrame
.HIDE_ON_CLOSE
);
101 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
102 this.method
= method
;
107 * This method initializes jContentPane
109 * @return javax.swing.JPanel
111 private JPanel
getJContentPane() {
112 if (jContentPane
== null) {
113 jContentPane
= new JPanel();
114 jContentPane
.setLayout(null);
115 jContentPane
.add(getJScrollPaneTable(), null);
116 jContentPane
.add(getJButtonClose(), null);
117 jContentPane
.setPreferredSize(new java
.awt
.Dimension(585, 445));
123 This method initializes jScrollPane
125 @return javax.swing.JScrollPane
127 private JScrollPane
getJScrollPane() {
128 if (jScrollPane
== null) {
129 jScrollPane
= new JScrollPane();
130 jScrollPane
.setViewportView(getJContentPane());
136 This method initializes jScrollPaneTable
138 @return javax.swing.JScrollPane
140 private JScrollPane
getJScrollPaneTable() {
141 if (jScrollPaneTable
== null) {
142 jScrollPaneTable
= new JScrollPane();
143 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(0, 0, 585, 395));
144 jScrollPaneTable
.setPreferredSize(new Dimension(585, 395));
145 jScrollPaneTable
.setViewportView(getJTable());
147 return jScrollPaneTable
;
151 This method initializes jTable
153 @return javax.swing.JTable
155 private JTable
getJTable() {
156 if (jTable
== null) {
157 model
= new IDefaultTableModel();
158 jTable
= new JTable(model
);
160 model
.addColumn("Name");
161 model
.addColumn("Type");
162 model
.addColumn("Produced by");
163 model
.addColumn("Consumed by");
164 model
.addColumn("Declared by");
166 jTable
.getColumn("Name").setCellRenderer(new MyTableCellRenderer());
167 jTable
.getColumn("Type").setCellRenderer(new MyTableCellRenderer());
168 jTable
.getColumn("Produced by").setCellRenderer(new MyTableCellRenderer());
169 jTable
.getColumn("Consumed by").setCellRenderer(new MyTableCellRenderer());
170 jTable
.getColumn("Declared by").setCellRenderer(new MyTableCellRenderer());
172 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
173 jTable
.getModel().addTableModelListener(this);
179 This method initializes jButtonAdd
181 @return javax.swing.JButton jButtonAdd
184 private JButton
getJButtonClose() {
185 if (jButtonClose
== null) {
186 jButtonClose
= new JButton();
187 jButtonClose
.setText("Close");
188 jButtonClose
.addActionListener(this);
189 jButtonClose
.setBounds(new java
.awt
.Rectangle(255, 415, 80, 20));
190 jButtonClose
.setPreferredSize(new java
.awt
.Dimension(80, 20));
195 public static FindResult
getInstance(String method
) {
196 if (method
.equals("PPI")) {
197 if (findPpisResult
== null) {
198 findPpisResult
= new FindResult(method
);
200 findPpisResult
.init(method
);
201 return findPpisResult
;
204 if (method
.equals("PROTOCOL")) {
205 if (findProtocolsResult
== null) {
206 findProtocolsResult
= new FindResult(method
);
208 findProtocolsResult
.init(method
);
209 return findProtocolsResult
;
212 if (method
.equals("GUID")) {
213 if (findGuidsResult
== null) {
214 findGuidsResult
= new FindResult(method
);
216 findGuidsResult
.init(method
);
217 return findGuidsResult
;
220 if (method
.equals("PCD")) {
221 if (findPcdsResult
== null) {
222 findPcdsResult
= new FindResult(method
);
224 findPcdsResult
.init(method
);
225 return findPcdsResult
;
228 if (method
.equals("LIBRARY_CLASS")) {
229 if (findLibraryClassResult
== null) {
230 findLibraryClassResult
= new FindResult(method
);
232 findLibraryClassResult
.init(method
);
233 return findLibraryClassResult
;
243 private void clearAll() {
245 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
246 model
.removeRow(index
);
252 Read content of vector and put then into table
255 private void showTable() {
258 if (this.method
.equals("PPI")) {
259 Vector
<PpiId
> vPpi
= Find
.getAllPpisForFind();
261 if (vPpi
.size() > 0) {
263 for (int index
= 0; index
< vPpi
.size(); index
++) {
264 Vector
<String
> v
= new Vector
<String
>();
265 v
.addElement(vPpi
.elementAt(index
).getName());
266 v
.addElement(vPpi
.elementAt(index
).getType());
267 String strProducedModules
= vPpi
.elementAt(index
).getProducedModules();
268 if (strProducedModules
.indexOf("<br>") == 0) {
269 strProducedModules
= strProducedModules
.substring("<br>".length());
271 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
272 v
.addElement("<html>" + strProducedModules
+ "</html>");
274 String strConsumedModules
= vPpi
.elementAt(index
).getConsumedModules();
275 if (strConsumedModules
.indexOf("<br>") == 0) {
276 strConsumedModules
= strConsumedModules
.substring("<br>".length());
278 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
279 v
.addElement("<html>" + strConsumedModules
+ "</html>");
281 v
.addElement(vPpi
.elementAt(index
).getDeclaredBy());
284 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
287 Log
.wrn("Find PPIs", "No PPI found!!!");
291 if (this.method
.equals("PROTOCOL")) {
292 Vector
<ProtocolId
> vProtocol
= Find
.getAllProtocolsForFind();
294 if (vProtocol
.size() > 0) {
296 for (int index
= 0; index
< vProtocol
.size(); index
++) {
297 Vector
<String
> v
= new Vector
<String
>();
298 v
.addElement(vProtocol
.elementAt(index
).getName());
299 v
.addElement(vProtocol
.elementAt(index
).getType());
300 String strProducedModules
= vProtocol
.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
= vProtocol
.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(vProtocol
.elementAt(index
).getDeclaredBy());
317 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
320 Log
.wrn("Find PROTOCOLs", "No PROTOCOL found!!!");
324 if (this.method
.equals("GUID")) {
325 Vector
<GuidId
> vGuid
= Find
.getAllGuidsForFind();
327 if (vGuid
.size() > 0) {
329 for (int index
= 0; index
< vGuid
.size(); index
++) {
330 Vector
<String
> v
= new Vector
<String
>();
331 v
.addElement(vGuid
.elementAt(index
).getName());
332 v
.addElement("GUID");
333 String strProducedModules
= vGuid
.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
= vGuid
.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(vGuid
.elementAt(index
).getDeclaredBy());
350 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
353 Log
.wrn("Find GUIDs", "No GUID found!!!");
357 if (this.method
.equals("PCD")) {
358 Vector
<PcdId
> vPcd
= Find
.getAllPcdCodedForFind();
360 if (vPcd
.size() > 0) {
362 for (int index
= 0; index
< vPcd
.size(); index
++) {
363 Vector
<String
> v
= new Vector
<String
>();
364 v
.addElement(vPcd
.elementAt(index
).getName());
365 v
.addElement(vPcd
.elementAt(index
).getType());
366 String strProducedModules
= vPcd
.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
= vPcd
.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(vPcd
.elementAt(index
).getDeclaredBy());
383 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
386 Log
.wrn("Find PCDs", "No PCD found!!!");
390 if (this.method
.equals("LIBRARY_CLASS")) {
391 Vector
<LibraryClassId
> vLibraryClass
= Find
.getAllLibraryClassForFind();
393 if (vLibraryClass
.size() > 0) {
395 for (int index
= 0; index
< vLibraryClass
.size(); index
++) {
396 Vector
<String
> v
= new Vector
<String
>();
397 v
.addElement(vLibraryClass
.elementAt(index
).getName());
398 v
.addElement(vLibraryClass
.elementAt(index
).getType());
399 String strProducedModules
= vLibraryClass
.elementAt(index
).getProducedModules();
400 if (strProducedModules
.indexOf("<br>") == 0) {
401 strProducedModules
= strProducedModules
.substring("<br>".length());
403 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
404 v
.addElement("<html>" + strProducedModules
+ "</html>");
406 String strConsumedModules
= vLibraryClass
.elementAt(index
).getConsumedModules();
407 if (strConsumedModules
.indexOf("<br>") == 0) {
408 strConsumedModules
= strConsumedModules
.substring("<br>".length());
410 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
411 v
.addElement("<html>" + strConsumedModules
+ "</html>");
413 v
.addElement(vLibraryClass
.elementAt(index
).getDeclaredBy());
416 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
419 Log
.wrn("Find Library Classes", "No Library Class found!!!");
423 this.jTable
.repaint();
424 this.jTable
.updateUI();
427 public void tableChanged(TableModelEvent arg0
) {
428 // TODO Auto-generated method stub
432 public void actionPerformed(ActionEvent arg0
) {
433 if (arg0
.getSource() == this.jButtonClose
) {
440 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
442 * Override componentResized to resize all components when frame's size is changed
444 public void componentResized(ComponentEvent arg0
) {
445 int intCurrentWidth
= this.getJContentPane().getWidth();
446 int intCurrentHeight
= this.getJContentPane().getHeight();
447 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
448 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
450 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
452 Tools
.centerComponent(this.jButtonClose
, intCurrentWidth
, intCurrentHeight
, intPreferredHeight
,
453 DataType
.SPACE_TO_BOTTOM_FOR_CLOSE_BUTTON
);
457 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
459 * Override windowClosing to popup warning message to confirm quit
462 public void windowClosing(WindowEvent arg0
) {
466 class MyTableCellRenderer
extends DefaultTableCellRenderer
{
470 private static final long serialVersionUID
= -2082787479305255946L;
472 public void setValue(Object value
) {
473 this.setVerticalAlignment(SwingConstants
.TOP
);
474 super.setValue(value
);