]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/find/FindResult.java
c0991025aca904b4a823deaf33a9a58a5a92b422
[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 import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdCodedVector;
46
47 public class FindResult extends IFrame implements TableModelListener, ListSelectionListener, MouseListener {
48
49 ///
50 /// Define class Serial Version UID
51 ///
52 private static final long serialVersionUID = -2448484533878401714L;
53
54 //
55 // Define class members
56 //
57 private JTable jTable = null;
58
59 private JPanel jContentPane = null;
60
61 private JScrollPane jScrollPane = null;
62
63 private JScrollPane jScrollPaneTable = null;
64
65 private JButton jButtonClose = null;
66
67 //
68 // Not used by UI
69 //
70 private IDefaultTableModel model = null;
71
72 private String method = "";
73
74 private static FindResult findPpisResult = null;
75
76 private static FindResult findProtocolsResult = null;
77
78 private static FindResult findGuidsResult = null;
79
80 private static FindResult findPcdsResult = null;
81
82 private static FindResult findLibraryClassResult = null;
83
84 private int selectedRow = -1;
85
86 private LibraryClassVector lcv = null;
87
88 private Vector<FindResultId> vLibraryClassFindResult = null;
89
90 private PcdCodedVector pv = null;
91
92 private Vector<PcdFindResultId> vPcdFindResult = null;
93
94 /**
95 * This is the default constructor
96 */
97 public FindResult(String method) {
98 super();
99 init(method);
100 }
101
102 /**
103 * This method initializes this
104 *
105 * @return void
106 */
107 private void init(String method) {
108 this.setSize(600, 500);
109 this.setContentPane(getJScrollPane());
110 this.setTitle("Find Result");
111 this.setResizable(true);
112 this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
113 this.centerWindow();
114
115 //
116 // max the window
117 //
118 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
119 this.method = method;
120 this.showTable();
121 }
122
123 /**
124 * This method initializes jContentPane
125 *
126 * @return javax.swing.JPanel
127 */
128 private JPanel getJContentPane() {
129 if (jContentPane == null) {
130 jContentPane = new JPanel();
131 jContentPane.setLayout(null);
132 jContentPane.add(getJScrollPaneTable(), null);
133 jContentPane.add(getJButtonClose(), null);
134 jContentPane.setPreferredSize(new java.awt.Dimension(585, 445));
135 }
136 return jContentPane;
137 }
138
139 /**
140 This method initializes jScrollPane
141
142 @return javax.swing.JScrollPane
143 */
144 private JScrollPane getJScrollPane() {
145 if (jScrollPane == null) {
146 jScrollPane = new JScrollPane();
147 jScrollPane.setViewportView(getJContentPane());
148 }
149 return jScrollPane;
150 }
151
152 /**
153 This method initializes jScrollPaneTable
154
155 @return javax.swing.JScrollPane
156 **/
157 private JScrollPane getJScrollPaneTable() {
158 if (jScrollPaneTable == null) {
159 jScrollPaneTable = new JScrollPane();
160 jScrollPaneTable.setBounds(new java.awt.Rectangle(0, 0, 585, 395));
161 jScrollPaneTable.setPreferredSize(new Dimension(585, 395));
162 jScrollPaneTable.setViewportView(getJTable());
163 }
164 return jScrollPaneTable;
165 }
166
167 /**
168 This method initializes jTable
169
170 @return javax.swing.JTable
171 **/
172 private JTable getJTable() {
173 if (jTable == null) {
174 model = new IDefaultTableModel();
175 jTable = new JTable(model);
176 jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
177 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
178
179 jTable.getSelectionModel().addListSelectionListener(this);
180 jTable.getModel().addTableModelListener(this);
181 jTable.addMouseListener(this);
182
183 model.addColumn("Name");
184 model.addColumn("Type");
185 model.addColumn("Produced by");
186 model.addColumn("Consumed by");
187 model.addColumn("Declared by");
188
189 jTable.getColumn("Name").setCellRenderer(new MyTableCellRenderer());
190 jTable.getColumn("Type").setCellRenderer(new MyTableCellRenderer());
191 jTable.getColumn("Produced by").setCellRenderer(new MyTableCellRenderer());
192 jTable.getColumn("Consumed by").setCellRenderer(new MyTableCellRenderer());
193 jTable.getColumn("Declared by").setCellRenderer(new MyTableCellRenderer());
194
195 int columnWidth = (this.getSize().width - 28) / 5;
196 jTable.getColumn("Name").setPreferredWidth(columnWidth);
197 jTable.getColumn("Type").setPreferredWidth(columnWidth);
198 jTable.getColumn("Produced by").setPreferredWidth(columnWidth);
199 jTable.getColumn("Consumed by").setPreferredWidth(columnWidth);
200 jTable.getColumn("Declared by").setPreferredWidth(columnWidth);
201 }
202 return jTable;
203 }
204
205 /**
206 This method initializes jButtonAdd
207
208 @return javax.swing.JButton jButtonAdd
209
210 **/
211 private JButton getJButtonClose() {
212 if (jButtonClose == null) {
213 jButtonClose = new JButton();
214 jButtonClose.setText("Close");
215 jButtonClose.addActionListener(this);
216 jButtonClose.setBounds(new java.awt.Rectangle(255, 415, 80, 20));
217 jButtonClose.setPreferredSize(new java.awt.Dimension(80, 20));
218 }
219 return jButtonClose;
220 }
221
222 public static FindResult getInstance(String method) {
223 if (method.equals("PPI")) {
224 if (findPpisResult == null) {
225 findPpisResult = new FindResult(method);
226 }
227 findPpisResult.init(method);
228 return findPpisResult;
229 }
230
231 if (method.equals("PROTOCOL")) {
232 if (findProtocolsResult == null) {
233 findProtocolsResult = new FindResult(method);
234 }
235 findProtocolsResult.init(method);
236 return findProtocolsResult;
237 }
238
239 if (method.equals("GUID")) {
240 if (findGuidsResult == null) {
241 findGuidsResult = new FindResult(method);
242 }
243 findGuidsResult.init(method);
244 return findGuidsResult;
245 }
246
247 if (method.equals("PCD")) {
248 if (findPcdsResult == null) {
249 findPcdsResult = new FindResult(method);
250 }
251 findPcdsResult.init(method);
252 return findPcdsResult;
253 }
254
255 if (method.equals("LIBRARY_CLASS")) {
256 if (findLibraryClassResult == null) {
257 findLibraryClassResult = new FindResult(method);
258 }
259 findLibraryClassResult.init(method);
260 return findLibraryClassResult;
261 }
262
263 return null;
264 }
265
266 /**
267 Clear all table rows
268
269 **/
270 private void clearAll() {
271 if (model != null) {
272 for (int index = model.getRowCount() - 1; index >= 0; index--) {
273 model.removeRow(index);
274 }
275 }
276 }
277
278 /**
279 Read content of vector and put then into table
280
281 **/
282 private void showTable() {
283 clearAll();
284
285 if (this.method.equals("PPI")) {
286 Vector<PpiId> vPpi = Find.getAllPpisForFind();
287
288 if (vPpi.size() > 0) {
289
290 for (int index = 0; index < vPpi.size(); index++) {
291 Vector<String> v = new Vector<String>();
292 v.addElement(vPpi.elementAt(index).getName());
293 v.addElement(vPpi.elementAt(index).getType());
294 String strProducedModules = vPpi.elementAt(index).getProducedModules();
295 if (strProducedModules.indexOf("<br>") == 0) {
296 strProducedModules = strProducedModules.substring("<br>".length());
297 }
298 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
299 v.addElement("<html>" + strProducedModules + "</html>");
300
301 String strConsumedModules = vPpi.elementAt(index).getConsumedModules();
302 if (strConsumedModules.indexOf("<br>") == 0) {
303 strConsumedModules = strConsumedModules.substring("<br>".length());
304 }
305 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
306 v.addElement("<html>" + strConsumedModules + "</html>");
307
308 v.addElement(vPpi.elementAt(index).getDeclaredBy());
309
310 model.addRow(v);
311 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
312 }
313 } else {
314 Log.wrn("Find PPIs", "No PPI found!!!");
315 }
316 }
317
318 if (this.method.equals("PROTOCOL")) {
319 Vector<ProtocolId> vProtocol = Find.getAllProtocolsForFind();
320
321 if (vProtocol.size() > 0) {
322
323 for (int index = 0; index < vProtocol.size(); index++) {
324 Vector<String> v = new Vector<String>();
325 v.addElement(vProtocol.elementAt(index).getName());
326 v.addElement(vProtocol.elementAt(index).getType());
327 String strProducedModules = vProtocol.elementAt(index).getProducedModules();
328 if (strProducedModules.indexOf("<br>") == 0) {
329 strProducedModules = strProducedModules.substring("<br>".length());
330 }
331 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
332 v.addElement("<html>" + strProducedModules + "</html>");
333
334 String strConsumedModules = vProtocol.elementAt(index).getConsumedModules();
335 if (strConsumedModules.indexOf("<br>") == 0) {
336 strConsumedModules = strConsumedModules.substring("<br>".length());
337 }
338 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
339 v.addElement("<html>" + strConsumedModules + "</html>");
340
341 v.addElement(vProtocol.elementAt(index).getDeclaredBy());
342
343 model.addRow(v);
344 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
345 }
346 } else {
347 Log.wrn("Find PROTOCOLs", "No PROTOCOL found!!!");
348 }
349 }
350
351 if (this.method.equals("GUID")) {
352 Vector<GuidId> vGuid = Find.getAllGuidsForFind();
353
354 if (vGuid.size() > 0) {
355
356 for (int index = 0; index < vGuid.size(); index++) {
357 Vector<String> v = new Vector<String>();
358 v.addElement(vGuid.elementAt(index).getName());
359 v.addElement("GUID");
360 String strProducedModules = vGuid.elementAt(index).getProducedModules();
361 if (strProducedModules.indexOf("<br>") == 0) {
362 strProducedModules = strProducedModules.substring("<br>".length());
363 }
364 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
365 v.addElement("<html>" + strProducedModules + "</html>");
366
367 String strConsumedModules = vGuid.elementAt(index).getConsumedModules();
368 if (strConsumedModules.indexOf("<br>") == 0) {
369 strConsumedModules = strConsumedModules.substring("<br>".length());
370 }
371 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
372 v.addElement("<html>" + strConsumedModules + "</html>");
373
374 v.addElement(vGuid.elementAt(index).getDeclaredBy());
375
376 model.addRow(v);
377 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
378 }
379 } else {
380 Log.wrn("Find GUIDs", "No GUID found!!!");
381 }
382 }
383
384 if (this.method.equals("PCD")) {
385 pv = Find.getAllPcdCodedVector();
386 vPcdFindResult = Find.getAllPcdCodedForFind(pv);
387
388 if (vPcdFindResult.size() > 0) {
389
390 for (int index = 0; index < vPcdFindResult.size(); index++) {
391 Vector<String> v = new Vector<String>();
392 v.addElement(vPcdFindResult.elementAt(index).getName());
393 v.addElement(vPcdFindResult.elementAt(index).getType());
394
395 //
396 // Generate Produced Modules List
397 //
398 String strProducedModules = "";
399 Vector<ModuleIdentification> vModule = vPcdFindResult.elementAt(index).getProducedModules();
400 for (int indexOfPM = 0; indexOfPM < vModule.size(); indexOfPM++) {
401 strProducedModules = strProducedModules + "<br>"
402 + vModule.get(indexOfPM).getPackageId().getName() + "."
403 + vModule.get(indexOfPM).getName();
404 }
405 if (strProducedModules.indexOf("<br>") == 0) {
406 strProducedModules = strProducedModules.substring("<br>".length());
407 }
408 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
409 v.addElement("<html>" + strProducedModules + "</html>");
410
411 //
412 // Generate Consumed Modules List
413 //
414 String strConsumedModules = "";
415 vModule = vPcdFindResult.elementAt(index).getConsumedModules();
416 for (int indexOfCM = 0; indexOfCM < vModule.size(); indexOfCM++) {
417 strConsumedModules = strConsumedModules + "<br>"
418 + vModule.get(indexOfCM).getPackageId().getName() + "."
419 + vModule.get(indexOfCM).getName();
420 }
421 if (strConsumedModules.indexOf("<br>") == 0) {
422 strConsumedModules = strConsumedModules.substring("<br>".length());
423 }
424 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
425 v.addElement("<html>" + strConsumedModules + "</html>");
426
427 //
428 // Add declare package name
429 //
430 v.addElement(vPcdFindResult.elementAt(index).getDeclaredBy().getName());
431
432 model.addRow(v);
433 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
434 }
435 } else {
436 Log.wrn("Find PCDs", "No PCD found!!!");
437 }
438 }
439
440 if (this.method.equals("LIBRARY_CLASS")) {
441 lcv = Find.getAllLibraryClassVector();
442 vLibraryClassFindResult = Find.getAllLibraryClassForFind(lcv);
443
444 if (vLibraryClassFindResult.size() > 0) {
445 for (int index = 0; index < vLibraryClassFindResult.size(); index++) {
446 Vector<String> v = new Vector<String>();
447 v.addElement(vLibraryClassFindResult.elementAt(index).getName());
448 v.addElement(vLibraryClassFindResult.elementAt(index).getType());
449
450 //
451 // Generate Produced Modules List
452 //
453 String strProducedModules = "";
454 Vector<ModuleIdentification> vModule = vLibraryClassFindResult.elementAt(index)
455 .getProducedModules();
456 for (int indexOfPM = 0; indexOfPM < vModule.size(); indexOfPM++) {
457 strProducedModules = strProducedModules + "<br>"
458 + vModule.get(indexOfPM).getPackageId().getName() + "."
459 + vModule.get(indexOfPM).getName();
460 }
461 if (strProducedModules.indexOf("<br>") == 0) {
462 strProducedModules = strProducedModules.substring("<br>".length());
463 }
464 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
465 v.addElement("<html>" + strProducedModules + "</html>");
466
467 //
468 // Generate Consumed Modules List
469 //
470 String strConsumedModules = "";
471 vModule = vLibraryClassFindResult.elementAt(index).getConsumedModules();
472 for (int indexOfCM = 0; indexOfCM < vModule.size(); indexOfCM++) {
473 strConsumedModules = strConsumedModules + "<br>"
474 + vModule.get(indexOfCM).getPackageId().getName() + "."
475 + vModule.get(indexOfCM).getName();
476 }
477 if (strConsumedModules.indexOf("<br>") == 0) {
478 strConsumedModules = strConsumedModules.substring("<br>".length());
479 }
480 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
481 v.addElement("<html>" + strConsumedModules + "</html>");
482
483 v.addElement(vLibraryClassFindResult.elementAt(index).getDeclaredBy().getName());
484
485 model.addRow(v);
486 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
487 }
488 } else {
489 Log.wrn("Find Library Classes", "No Library Class found!!!");
490 }
491 }
492
493 this.jTable.repaint();
494 this.jTable.updateUI();
495 }
496
497 public void tableChanged(TableModelEvent arg0) {
498 // TODO Auto-generated method stub
499
500 }
501
502 /* (non-Javadoc)
503 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
504 *
505 */
506 public void actionPerformed(ActionEvent arg0) {
507 if (arg0.getSource() == this.jButtonClose) {
508 this.dispose();
509 }
510 }
511
512 /* (non-Javadoc)
513 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
514 *
515 * Override componentResized to resize all components when frame's size is changed
516 */
517 public void componentResized(ComponentEvent arg0) {
518 int intCurrentWidth = this.getJContentPane().getWidth();
519 int intCurrentHeight = this.getJContentPane().getHeight();
520 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;
521 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;
522
523 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,
524 intPreferredHeight);
525 Tools.centerComponent(this.jButtonClose, intCurrentWidth, intCurrentHeight, intPreferredHeight,
526 DataType.SPACE_TO_BOTTOM_FOR_CLOSE_BUTTON);
527 Tools.resizeTableColumn(this.jTable, this.getSize().width - 28);
528 }
529
530 /* (non-Javadoc)
531 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
532 *
533 */
534 public void valueChanged(ListSelectionEvent arg0) {
535 if (arg0.getValueIsAdjusting()) {
536 return;
537 }
538 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();
539 if (lsm.isSelectionEmpty()) {
540 return;
541 } else {
542 selectedRow = lsm.getMinSelectionIndex();
543 }
544 }
545
546 /* (non-Javadoc)
547 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
548 *
549 */
550 public void mouseClicked(MouseEvent arg0) {
551 if (arg0.getClickCount() == 2) {
552 if (this.selectedRow < 0) {
553 return;
554 } else {
555 if (this.method.equals("LIBRARY_CLASS")) {
556 FindResultDetailInfo frdi = new FindResultDetailInfo(vLibraryClassFindResult.elementAt(selectedRow));
557 frdi.setVisible(true);
558 }
559 if (this.method.equals("PCD")) {
560 FindResultDetailInfo frdi = new FindResultDetailInfo(vPcdFindResult.elementAt(selectedRow));
561 frdi.setVisible(true);
562 }
563 }
564 }
565 }
566
567 /* (non-Javadoc)
568 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
569 *
570 * Override windowClosing to popup warning message to confirm quit
571 *
572 */
573 public void windowClosing(WindowEvent arg0) {
574 this.dispose();
575 }
576
577 class MyTableCellRenderer extends DefaultTableCellRenderer {
578 ///
579 /// Define Class Serial Version UID
580 ///
581 private static final long serialVersionUID = -2082787479305255946L;
582
583 public void setValue(Object value) {
584 this.setVerticalAlignment(SwingConstants.TOP);
585 super.setValue(value);
586 }
587 }
588
589 public void mousePressed(MouseEvent e) {
590 // TODO Auto-generated method stub
591
592 }
593
594 public void mouseReleased(MouseEvent e) {
595 // TODO Auto-generated method stub
596
597 }
598
599 public void mouseEntered(MouseEvent e) {
600 // TODO Auto-generated method stub
601
602 }
603
604 public void mouseExited(MouseEvent e) {
605 // TODO Auto-generated method stub
606
607 }
608 }