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