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
.ComponentListener
;
21 import java
.awt
.event
.WindowEvent
;
22 import java
.util
.Vector
;
24 import javax
.swing
.JButton
;
25 import javax
.swing
.JFrame
;
26 import javax
.swing
.JPanel
;
27 import javax
.swing
.JScrollPane
;
28 import javax
.swing
.JTable
;
29 import javax
.swing
.ListSelectionModel
;
30 import javax
.swing
.SwingConstants
;
31 import javax
.swing
.event
.TableModelEvent
;
32 import javax
.swing
.event
.TableModelListener
;
33 import javax
.swing
.table
.DefaultTableCellRenderer
;
35 import org
.tianocore
.frameworkwizard
.common
.DataType
;
36 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
37 import org
.tianocore
.frameworkwizard
.common
.Log
;
38 import org
.tianocore
.frameworkwizard
.common
.Tools
;
39 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
41 public class FindResult
extends IFrame
implements TableModelListener
, ComponentListener
{
44 /// Define class Serial Version UID
46 private static final long serialVersionUID
= -2448484533878401714L;
49 // Define class members
51 private JTable jTable
= null;
53 private JPanel jContentPane
= null;
55 private JScrollPane jScrollPane
= null;
57 private JScrollPane jScrollPaneTable
= null;
59 private JButton jButtonClose
= null;
64 private IDefaultTableModel model
= null;
66 private String method
= "";
68 private static FindResult findPpisResult
= null;
70 private static FindResult findProtocolsResult
= null;
72 private static FindResult findGuidsResult
= null;
74 private static FindResult findPcdsResult
= null;
76 private static FindResult findLibraryClassResult
= null;
79 * This is the default constructor
81 public FindResult(String method
) {
87 * This method initializes this
91 private void init(String method
) {
92 this.setSize(600, 500);
93 this.setContentPane(getJScrollPane());
94 this.setTitle("Find Result");
95 this.setResizable(true);
96 this.setDefaultCloseOperation(JFrame
.HIDE_ON_CLOSE
);
102 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
103 this.method
= method
;
108 * This method initializes jContentPane
110 * @return javax.swing.JPanel
112 private JPanel
getJContentPane() {
113 if (jContentPane
== null) {
114 jContentPane
= new JPanel();
115 jContentPane
.setLayout(null);
116 jContentPane
.add(getJScrollPaneTable(), null);
117 jContentPane
.add(getJButtonClose(), null);
118 jContentPane
.setPreferredSize(new java
.awt
.Dimension(585, 445));
124 This method initializes jScrollPane
126 @return javax.swing.JScrollPane
128 private JScrollPane
getJScrollPane() {
129 if (jScrollPane
== null) {
130 jScrollPane
= new JScrollPane();
131 jScrollPane
.setViewportView(getJContentPane());
137 This method initializes jScrollPaneTable
139 @return javax.swing.JScrollPane
141 private JScrollPane
getJScrollPaneTable() {
142 if (jScrollPaneTable
== null) {
143 jScrollPaneTable
= new JScrollPane();
144 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(0, 0, 585, 395));
145 jScrollPaneTable
.setPreferredSize(new Dimension(585, 395));
146 jScrollPaneTable
.setViewportView(getJTable());
148 return jScrollPaneTable
;
152 This method initializes jTable
154 @return javax.swing.JTable
156 private JTable
getJTable() {
157 if (jTable
== null) {
158 model
= new IDefaultTableModel();
159 jTable
= new JTable(model
);
160 jTable
.setAutoResizeMode(javax
.swing
.JTable
.AUTO_RESIZE_OFF
);
161 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
163 jTable
.getModel().addTableModelListener(this);
165 model
.addColumn("Name");
166 model
.addColumn("Type");
167 model
.addColumn("Produced by");
168 model
.addColumn("Consumed by");
169 model
.addColumn("Declared by");
171 jTable
.getColumn("Name").setCellRenderer(new MyTableCellRenderer());
172 jTable
.getColumn("Type").setCellRenderer(new MyTableCellRenderer());
173 jTable
.getColumn("Produced by").setCellRenderer(new MyTableCellRenderer());
174 jTable
.getColumn("Consumed by").setCellRenderer(new MyTableCellRenderer());
175 jTable
.getColumn("Declared by").setCellRenderer(new MyTableCellRenderer());
177 // jTable.getColumn("Name").setPreferredWidth((this.getSize().width - 30) / 5);
178 // jTable.getColumn("Type").setPreferredWidth((this.getSize().width - 30) / 5);
179 // jTable.getColumn("Produced by").setPreferredWidth((this.getSize().width - 30) / 5);
180 // jTable.getColumn("Consumed by").setPreferredWidth((this.getSize().width - 30) / 5);
181 // jTable.getColumn("Declared by").setPreferredWidth((this.getSize().width - 30) / 5);
182 int columnWidth
= (this.getSize().width
- 28) / 5;
183 jTable
.getColumn("Name").setPreferredWidth(columnWidth
);
184 jTable
.getColumn("Type").setPreferredWidth(columnWidth
);
185 jTable
.getColumn("Produced by").setPreferredWidth(columnWidth
);
186 jTable
.getColumn("Consumed by").setPreferredWidth(columnWidth
);
187 jTable
.getColumn("Declared by").setPreferredWidth(columnWidth
);
193 This method initializes jButtonAdd
195 @return javax.swing.JButton jButtonAdd
198 private JButton
getJButtonClose() {
199 if (jButtonClose
== null) {
200 jButtonClose
= new JButton();
201 jButtonClose
.setText("Close");
202 jButtonClose
.addActionListener(this);
203 jButtonClose
.setBounds(new java
.awt
.Rectangle(255, 415, 80, 20));
204 jButtonClose
.setPreferredSize(new java
.awt
.Dimension(80, 20));
209 public static FindResult
getInstance(String method
) {
210 if (method
.equals("PPI")) {
211 if (findPpisResult
== null) {
212 findPpisResult
= new FindResult(method
);
214 findPpisResult
.init(method
);
215 return findPpisResult
;
218 if (method
.equals("PROTOCOL")) {
219 if (findProtocolsResult
== null) {
220 findProtocolsResult
= new FindResult(method
);
222 findProtocolsResult
.init(method
);
223 return findProtocolsResult
;
226 if (method
.equals("GUID")) {
227 if (findGuidsResult
== null) {
228 findGuidsResult
= new FindResult(method
);
230 findGuidsResult
.init(method
);
231 return findGuidsResult
;
234 if (method
.equals("PCD")) {
235 if (findPcdsResult
== null) {
236 findPcdsResult
= new FindResult(method
);
238 findPcdsResult
.init(method
);
239 return findPcdsResult
;
242 if (method
.equals("LIBRARY_CLASS")) {
243 if (findLibraryClassResult
== null) {
244 findLibraryClassResult
= new FindResult(method
);
246 findLibraryClassResult
.init(method
);
247 return findLibraryClassResult
;
257 private void clearAll() {
259 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
260 model
.removeRow(index
);
266 Read content of vector and put then into table
269 private void showTable() {
272 if (this.method
.equals("PPI")) {
273 Vector
<PpiId
> vPpi
= Find
.getAllPpisForFind();
275 if (vPpi
.size() > 0) {
277 for (int index
= 0; index
< vPpi
.size(); index
++) {
278 Vector
<String
> v
= new Vector
<String
>();
279 v
.addElement(vPpi
.elementAt(index
).getName());
280 v
.addElement(vPpi
.elementAt(index
).getType());
281 String strProducedModules
= vPpi
.elementAt(index
).getProducedModules();
282 if (strProducedModules
.indexOf("<br>") == 0) {
283 strProducedModules
= strProducedModules
.substring("<br>".length());
285 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
286 v
.addElement("<html>" + strProducedModules
+ "</html>");
288 String strConsumedModules
= vPpi
.elementAt(index
).getConsumedModules();
289 if (strConsumedModules
.indexOf("<br>") == 0) {
290 strConsumedModules
= strConsumedModules
.substring("<br>".length());
292 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
293 v
.addElement("<html>" + strConsumedModules
+ "</html>");
295 v
.addElement(vPpi
.elementAt(index
).getDeclaredBy());
298 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
301 Log
.wrn("Find PPIs", "No PPI found!!!");
305 if (this.method
.equals("PROTOCOL")) {
306 Vector
<ProtocolId
> vProtocol
= Find
.getAllProtocolsForFind();
308 if (vProtocol
.size() > 0) {
310 for (int index
= 0; index
< vProtocol
.size(); index
++) {
311 Vector
<String
> v
= new Vector
<String
>();
312 v
.addElement(vProtocol
.elementAt(index
).getName());
313 v
.addElement(vProtocol
.elementAt(index
).getType());
314 String strProducedModules
= vProtocol
.elementAt(index
).getProducedModules();
315 if (strProducedModules
.indexOf("<br>") == 0) {
316 strProducedModules
= strProducedModules
.substring("<br>".length());
318 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
319 v
.addElement("<html>" + strProducedModules
+ "</html>");
321 String strConsumedModules
= vProtocol
.elementAt(index
).getConsumedModules();
322 if (strConsumedModules
.indexOf("<br>") == 0) {
323 strConsumedModules
= strConsumedModules
.substring("<br>".length());
325 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
326 v
.addElement("<html>" + strConsumedModules
+ "</html>");
328 v
.addElement(vProtocol
.elementAt(index
).getDeclaredBy());
331 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
334 Log
.wrn("Find PROTOCOLs", "No PROTOCOL found!!!");
338 if (this.method
.equals("GUID")) {
339 Vector
<GuidId
> vGuid
= Find
.getAllGuidsForFind();
341 if (vGuid
.size() > 0) {
343 for (int index
= 0; index
< vGuid
.size(); index
++) {
344 Vector
<String
> v
= new Vector
<String
>();
345 v
.addElement(vGuid
.elementAt(index
).getName());
346 v
.addElement("GUID");
347 String strProducedModules
= vGuid
.elementAt(index
).getProducedModules();
348 if (strProducedModules
.indexOf("<br>") == 0) {
349 strProducedModules
= strProducedModules
.substring("<br>".length());
351 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
352 v
.addElement("<html>" + strProducedModules
+ "</html>");
354 String strConsumedModules
= vGuid
.elementAt(index
).getConsumedModules();
355 if (strConsumedModules
.indexOf("<br>") == 0) {
356 strConsumedModules
= strConsumedModules
.substring("<br>".length());
358 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
359 v
.addElement("<html>" + strConsumedModules
+ "</html>");
361 v
.addElement(vGuid
.elementAt(index
).getDeclaredBy());
364 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
367 Log
.wrn("Find GUIDs", "No GUID found!!!");
371 if (this.method
.equals("PCD")) {
372 Vector
<PcdId
> vPcd
= Find
.getAllPcdCodedForFind();
374 if (vPcd
.size() > 0) {
376 for (int index
= 0; index
< vPcd
.size(); index
++) {
377 Vector
<String
> v
= new Vector
<String
>();
378 v
.addElement(vPcd
.elementAt(index
).getName());
379 v
.addElement(vPcd
.elementAt(index
).getType());
380 String strProducedModules
= vPcd
.elementAt(index
).getProducedModules();
381 if (strProducedModules
.indexOf("<br>") == 0) {
382 strProducedModules
= strProducedModules
.substring("<br>".length());
384 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
385 v
.addElement("<html>" + strProducedModules
+ "</html>");
387 String strConsumedModules
= vPcd
.elementAt(index
).getConsumedModules();
388 if (strConsumedModules
.indexOf("<br>") == 0) {
389 strConsumedModules
= strConsumedModules
.substring("<br>".length());
391 int line2
= Tools
.getSpecificStringCount(strConsumedModules
, "<br>");
392 v
.addElement("<html>" + strConsumedModules
+ "</html>");
394 v
.addElement(vPcd
.elementAt(index
).getDeclaredBy());
397 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
400 Log
.wrn("Find PCDs", "No PCD found!!!");
404 if (this.method
.equals("LIBRARY_CLASS")) {
405 Vector
<LibraryClassId
> vLibraryClass
= Find
.getAllLibraryClassForFind();
407 if (vLibraryClass
.size() > 0) {
409 for (int index
= 0; index
< vLibraryClass
.size(); index
++) {
410 Vector
<String
> v
= new Vector
<String
>();
411 v
.addElement(vLibraryClass
.elementAt(index
).getName());
412 v
.addElement(vLibraryClass
.elementAt(index
).getType());
413 String strProducedModules
= vLibraryClass
.elementAt(index
).getProducedModules();
414 if (strProducedModules
.indexOf("<br>") == 0) {
415 strProducedModules
= strProducedModules
.substring("<br>".length());
417 int line1
= Tools
.getSpecificStringCount(strProducedModules
, "<br>");
418 v
.addElement("<html>" + strProducedModules
+ "</html>");
420 String strConsumedModules
= vLibraryClass
.elementAt(index
).getConsumedModules();
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>");
427 v
.addElement(vLibraryClass
.elementAt(index
).getDeclaredBy());
430 jTable
.setRowHeight(index
, (Math
.max(line1
, line2
) > 1 ? Math
.max(line1
, line2
) : 1) * 18);
433 Log
.wrn("Find Library Classes", "No Library Class found!!!");
437 this.jTable
.repaint();
438 this.jTable
.updateUI();
441 public void tableChanged(TableModelEvent arg0
) {
442 // TODO Auto-generated method stub
446 public void actionPerformed(ActionEvent arg0
) {
447 if (arg0
.getSource() == this.jButtonClose
) {
454 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
456 * Override componentResized to resize all components when frame's size is changed
458 public void componentResized(ComponentEvent arg0
) {
459 int intCurrentWidth
= this.getJContentPane().getWidth();
460 int intCurrentHeight
= this.getJContentPane().getHeight();
461 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
462 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
464 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
466 Tools
.centerComponent(this.jButtonClose
, intCurrentWidth
, intCurrentHeight
, intPreferredHeight
,
467 DataType
.SPACE_TO_BOTTOM_FOR_CLOSE_BUTTON
);
468 Tools
.resizeTableColumn(this.jTable
, this.getSize().width
- 28);
472 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
474 * Override windowClosing to popup warning message to confirm quit
477 public void windowClosing(WindowEvent arg0
) {
481 class MyTableCellRenderer
extends DefaultTableCellRenderer
{
485 private static final long serialVersionUID
= -2082787479305255946L;
487 public void setValue(Object value
) {
488 this.setVerticalAlignment(SwingConstants
.TOP
);
489 super.setValue(value
);