]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/find/FindResult.java
1. Fix EDKT339 Library Class Search need to get info for selected library class
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / find / FindResult.java
1 /** @file
2
3 The file is used to show a table with all defined PPIs
4
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
10
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.
13
14 **/
15 package org.tianocore.frameworkwizard.common.find;
16
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;
24
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;
37
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
46 public class FindResult extends IFrame implements TableModelListener, ListSelectionListener, MouseListener {
47
48 ///
49 /// Define class Serial Version UID
50 ///
51 private static final long serialVersionUID = -2448484533878401714L;
52
53 //
54 // Define class members
55 //
56 private JTable jTable = null;
57
58 private JPanel jContentPane = null;
59
60 private JScrollPane jScrollPane = null;
61
62 private JScrollPane jScrollPaneTable = null;
63
64 private JButton jButtonClose = null;
65
66 //
67 // Not used by UI
68 //
69 private IDefaultTableModel model = null;
70
71 private String method = "";
72
73 private static FindResult findPpisResult = null;
74
75 private static FindResult findProtocolsResult = null;
76
77 private static FindResult findGuidsResult = null;
78
79 private static FindResult findPcdsResult = null;
80
81 private static FindResult findLibraryClassResult = null;
82
83 private int selectedRow = -1;
84
85 private LibraryClassVector lcv = null;
86
87 private Vector<FindResultId> vLibraryClassFindResult = null;
88
89 /**
90 * This is the default constructor
91 */
92 public FindResult(String method) {
93 super();
94 init(method);
95 }
96
97 /**
98 * This method initializes this
99 *
100 * @return void
101 */
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);
108 this.centerWindow();
109
110 //
111 // max the window
112 //
113 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
114 this.method = method;
115 this.showTable();
116 }
117
118 /**
119 * This method initializes jContentPane
120 *
121 * @return javax.swing.JPanel
122 */
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));
130 }
131 return jContentPane;
132 }
133
134 /**
135 This method initializes jScrollPane
136
137 @return javax.swing.JScrollPane
138 */
139 private JScrollPane getJScrollPane() {
140 if (jScrollPane == null) {
141 jScrollPane = new JScrollPane();
142 jScrollPane.setViewportView(getJContentPane());
143 }
144 return jScrollPane;
145 }
146
147 /**
148 This method initializes jScrollPaneTable
149
150 @return javax.swing.JScrollPane
151 **/
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());
158 }
159 return jScrollPaneTable;
160 }
161
162 /**
163 This method initializes jTable
164
165 @return javax.swing.JTable
166 **/
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);
173
174 jTable.getSelectionModel().addListSelectionListener(this);
175 jTable.getModel().addTableModelListener(this);
176 jTable.addMouseListener(this);
177
178 model.addColumn("Name");
179 model.addColumn("Type");
180 model.addColumn("Produced by");
181 model.addColumn("Consumed by");
182 model.addColumn("Declared by");
183
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());
189
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);
196 }
197 return jTable;
198 }
199
200 /**
201 This method initializes jButtonAdd
202
203 @return javax.swing.JButton jButtonAdd
204
205 **/
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));
213 }
214 return jButtonClose;
215 }
216
217 public static FindResult getInstance(String method) {
218 if (method.equals("PPI")) {
219 if (findPpisResult == null) {
220 findPpisResult = new FindResult(method);
221 }
222 findPpisResult.init(method);
223 return findPpisResult;
224 }
225
226 if (method.equals("PROTOCOL")) {
227 if (findProtocolsResult == null) {
228 findProtocolsResult = new FindResult(method);
229 }
230 findProtocolsResult.init(method);
231 return findProtocolsResult;
232 }
233
234 if (method.equals("GUID")) {
235 if (findGuidsResult == null) {
236 findGuidsResult = new FindResult(method);
237 }
238 findGuidsResult.init(method);
239 return findGuidsResult;
240 }
241
242 if (method.equals("PCD")) {
243 if (findPcdsResult == null) {
244 findPcdsResult = new FindResult(method);
245 }
246 findPcdsResult.init(method);
247 return findPcdsResult;
248 }
249
250 if (method.equals("LIBRARY_CLASS")) {
251 if (findLibraryClassResult == null) {
252 findLibraryClassResult = new FindResult(method);
253 }
254 findLibraryClassResult.init(method);
255 return findLibraryClassResult;
256 }
257
258 return null;
259 }
260
261 /**
262 Clear all table rows
263
264 **/
265 private void clearAll() {
266 if (model != null) {
267 for (int index = model.getRowCount() - 1; index >= 0; index--) {
268 model.removeRow(index);
269 }
270 }
271 }
272
273 /**
274 Read content of vector and put then into table
275
276 **/
277 private void showTable() {
278 clearAll();
279
280 if (this.method.equals("PPI")) {
281 Vector<PpiId> vPpi = Find.getAllPpisForFind();
282
283 if (vPpi.size() > 0) {
284
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());
292 }
293 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
294 v.addElement("<html>" + strProducedModules + "</html>");
295
296 String strConsumedModules = vPpi.elementAt(index).getConsumedModules();
297 if (strConsumedModules.indexOf("<br>") == 0) {
298 strConsumedModules = strConsumedModules.substring("<br>".length());
299 }
300 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
301 v.addElement("<html>" + strConsumedModules + "</html>");
302
303 v.addElement(vPpi.elementAt(index).getDeclaredBy());
304
305 model.addRow(v);
306 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
307 }
308 } else {
309 Log.wrn("Find PPIs", "No PPI found!!!");
310 }
311 }
312
313 if (this.method.equals("PROTOCOL")) {
314 Vector<ProtocolId> vProtocol = Find.getAllProtocolsForFind();
315
316 if (vProtocol.size() > 0) {
317
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());
325 }
326 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
327 v.addElement("<html>" + strProducedModules + "</html>");
328
329 String strConsumedModules = vProtocol.elementAt(index).getConsumedModules();
330 if (strConsumedModules.indexOf("<br>") == 0) {
331 strConsumedModules = strConsumedModules.substring("<br>".length());
332 }
333 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
334 v.addElement("<html>" + strConsumedModules + "</html>");
335
336 v.addElement(vProtocol.elementAt(index).getDeclaredBy());
337
338 model.addRow(v);
339 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
340 }
341 } else {
342 Log.wrn("Find PROTOCOLs", "No PROTOCOL found!!!");
343 }
344 }
345
346 if (this.method.equals("GUID")) {
347 Vector<GuidId> vGuid = Find.getAllGuidsForFind();
348
349 if (vGuid.size() > 0) {
350
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());
358 }
359 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
360 v.addElement("<html>" + strProducedModules + "</html>");
361
362 String strConsumedModules = vGuid.elementAt(index).getConsumedModules();
363 if (strConsumedModules.indexOf("<br>") == 0) {
364 strConsumedModules = strConsumedModules.substring("<br>".length());
365 }
366 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
367 v.addElement("<html>" + strConsumedModules + "</html>");
368
369 v.addElement(vGuid.elementAt(index).getDeclaredBy());
370
371 model.addRow(v);
372 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
373 }
374 } else {
375 Log.wrn("Find GUIDs", "No GUID found!!!");
376 }
377 }
378
379 if (this.method.equals("PCD")) {
380 Vector<PcdId> vPcd = Find.getAllPcdCodedForFind();
381
382 if (vPcd.size() > 0) {
383
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());
391 }
392 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
393 v.addElement("<html>" + strProducedModules + "</html>");
394
395 String strConsumedModules = vPcd.elementAt(index).getConsumedModules();
396 if (strConsumedModules.indexOf("<br>") == 0) {
397 strConsumedModules = strConsumedModules.substring("<br>".length());
398 }
399 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
400 v.addElement("<html>" + strConsumedModules + "</html>");
401
402 v.addElement(vPcd.elementAt(index).getDeclaredBy());
403
404 model.addRow(v);
405 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
406 }
407 } else {
408 Log.wrn("Find PCDs", "No PCD found!!!");
409 }
410 }
411
412 if (this.method.equals("LIBRARY_CLASS")) {
413 lcv = Find.getAllLibraryClassVector();
414 vLibraryClassFindResult = Find.getAllLibraryClassForFind(lcv);
415
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());
421
422 //
423 // Generate Produced Modules List
424 //
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();
432 }
433 if (strProducedModules.indexOf("<br>") == 0) {
434 strProducedModules = strProducedModules.substring("<br>".length());
435 }
436 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
437 v.addElement("<html>" + strProducedModules + "</html>");
438
439 //
440 // Generate Consumed Modules List
441 //
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();
448 }
449 if (strConsumedModules.indexOf("<br>") == 0) {
450 strConsumedModules = strConsumedModules.substring("<br>".length());
451 }
452 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
453 v.addElement("<html>" + strConsumedModules + "</html>");
454
455 v.addElement(vLibraryClassFindResult.elementAt(index).getDeclaredBy().getName());
456
457 model.addRow(v);
458 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
459 }
460 } else {
461 Log.wrn("Find Library Classes", "No Library Class found!!!");
462 }
463 }
464
465 this.jTable.repaint();
466 this.jTable.updateUI();
467 }
468
469 public void tableChanged(TableModelEvent arg0) {
470 // TODO Auto-generated method stub
471
472 }
473
474 /* (non-Javadoc)
475 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
476 *
477 */
478 public void actionPerformed(ActionEvent arg0) {
479 if (arg0.getSource() == this.jButtonClose) {
480 this.dispose();
481 }
482 }
483
484 /* (non-Javadoc)
485 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
486 *
487 * Override componentResized to resize all components when frame's size is changed
488 */
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;
494
495 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,
496 intPreferredHeight);
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);
500 }
501
502 /* (non-Javadoc)
503 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
504 *
505 */
506 public void valueChanged(ListSelectionEvent arg0) {
507 if (arg0.getValueIsAdjusting()) {
508 return;
509 }
510 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();
511 if (lsm.isSelectionEmpty()) {
512 return;
513 } else {
514 selectedRow = lsm.getMinSelectionIndex();
515 }
516 }
517
518 /* (non-Javadoc)
519 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
520 *
521 */
522 public void mouseClicked(MouseEvent arg0) {
523 if (arg0.getClickCount() == 2) {
524 if (this.selectedRow < 0) {
525 return;
526 } else {
527 if (this.method.equals("LIBRARY_CLASS")) {
528 FindResultDetailInfo frdi = new FindResultDetailInfo(vLibraryClassFindResult.elementAt(selectedRow));
529 frdi.setVisible(true);
530 }
531 }
532 }
533 }
534
535 /* (non-Javadoc)
536 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
537 *
538 * Override windowClosing to popup warning message to confirm quit
539 *
540 */
541 public void windowClosing(WindowEvent arg0) {
542 this.dispose();
543 }
544
545 class MyTableCellRenderer extends DefaultTableCellRenderer {
546 ///
547 /// Define Class Serial Version UID
548 ///
549 private static final long serialVersionUID = -2082787479305255946L;
550
551 public void setValue(Object value) {
552 this.setVerticalAlignment(SwingConstants.TOP);
553 super.setValue(value);
554 }
555 }
556
557 public void mousePressed(MouseEvent e) {
558 // TODO Auto-generated method stub
559
560 }
561
562 public void mouseReleased(MouseEvent e) {
563 // TODO Auto-generated method stub
564
565 }
566
567 public void mouseEntered(MouseEvent e) {
568 // TODO Auto-generated method stub
569
570 }
571
572 public void mouseExited(MouseEvent e) {
573 // TODO Auto-generated method stub
574
575 }
576 }