]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/find/FindResult.java
1. Fix EDKT411: Need right and left scroll bar to display find results
[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.ComponentListener;
21 import java.awt.event.WindowEvent;
22 import java.util.Vector;
23
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;
34
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;
40
41 public class FindResult extends IFrame implements TableModelListener, ComponentListener {
42
43 ///
44 /// Define class Serial Version UID
45 ///
46 private static final long serialVersionUID = -2448484533878401714L;
47
48 //
49 // Define class members
50 //
51 private JTable jTable = null;
52
53 private JPanel jContentPane = null;
54
55 private JScrollPane jScrollPane = null;
56
57 private JScrollPane jScrollPaneTable = null;
58
59 private JButton jButtonClose = null;
60
61 //
62 // Not used by UI
63 //
64 private IDefaultTableModel model = null;
65
66 private String method = "";
67
68 private static FindResult findPpisResult = null;
69
70 private static FindResult findProtocolsResult = null;
71
72 private static FindResult findGuidsResult = null;
73
74 private static FindResult findPcdsResult = null;
75
76 private static FindResult findLibraryClassResult = null;
77
78 /**
79 * This is the default constructor
80 */
81 public FindResult(String method) {
82 super();
83 init(method);
84 }
85
86 /**
87 * This method initializes this
88 *
89 * @return void
90 */
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);
97 this.centerWindow();
98
99 //
100 // max the window
101 //
102 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
103 this.method = method;
104 this.showTable();
105 }
106
107 /**
108 * This method initializes jContentPane
109 *
110 * @return javax.swing.JPanel
111 */
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));
119 }
120 return jContentPane;
121 }
122
123 /**
124 This method initializes jScrollPane
125
126 @return javax.swing.JScrollPane
127 */
128 private JScrollPane getJScrollPane() {
129 if (jScrollPane == null) {
130 jScrollPane = new JScrollPane();
131 jScrollPane.setViewportView(getJContentPane());
132 }
133 return jScrollPane;
134 }
135
136 /**
137 This method initializes jScrollPaneTable
138
139 @return javax.swing.JScrollPane
140 **/
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());
147 }
148 return jScrollPaneTable;
149 }
150
151 /**
152 This method initializes jTable
153
154 @return javax.swing.JTable
155 **/
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);
162
163 jTable.getModel().addTableModelListener(this);
164
165 model.addColumn("Name");
166 model.addColumn("Type");
167 model.addColumn("Produced by");
168 model.addColumn("Consumed by");
169 model.addColumn("Declared by");
170
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());
176
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);
188 }
189 return jTable;
190 }
191
192 /**
193 This method initializes jButtonAdd
194
195 @return javax.swing.JButton jButtonAdd
196
197 **/
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));
205 }
206 return jButtonClose;
207 }
208
209 public static FindResult getInstance(String method) {
210 if (method.equals("PPI")) {
211 if (findPpisResult == null) {
212 findPpisResult = new FindResult(method);
213 }
214 findPpisResult.init(method);
215 return findPpisResult;
216 }
217
218 if (method.equals("PROTOCOL")) {
219 if (findProtocolsResult == null) {
220 findProtocolsResult = new FindResult(method);
221 }
222 findProtocolsResult.init(method);
223 return findProtocolsResult;
224 }
225
226 if (method.equals("GUID")) {
227 if (findGuidsResult == null) {
228 findGuidsResult = new FindResult(method);
229 }
230 findGuidsResult.init(method);
231 return findGuidsResult;
232 }
233
234 if (method.equals("PCD")) {
235 if (findPcdsResult == null) {
236 findPcdsResult = new FindResult(method);
237 }
238 findPcdsResult.init(method);
239 return findPcdsResult;
240 }
241
242 if (method.equals("LIBRARY_CLASS")) {
243 if (findLibraryClassResult == null) {
244 findLibraryClassResult = new FindResult(method);
245 }
246 findLibraryClassResult.init(method);
247 return findLibraryClassResult;
248 }
249
250 return null;
251 }
252
253 /**
254 Clear all table rows
255
256 **/
257 private void clearAll() {
258 if (model != null) {
259 for (int index = model.getRowCount() - 1; index >= 0; index--) {
260 model.removeRow(index);
261 }
262 }
263 }
264
265 /**
266 Read content of vector and put then into table
267
268 **/
269 private void showTable() {
270 clearAll();
271
272 if (this.method.equals("PPI")) {
273 Vector<PpiId> vPpi = Find.getAllPpisForFind();
274
275 if (vPpi.size() > 0) {
276
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());
284 }
285 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
286 v.addElement("<html>" + strProducedModules + "</html>");
287
288 String strConsumedModules = vPpi.elementAt(index).getConsumedModules();
289 if (strConsumedModules.indexOf("<br>") == 0) {
290 strConsumedModules = strConsumedModules.substring("<br>".length());
291 }
292 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
293 v.addElement("<html>" + strConsumedModules + "</html>");
294
295 v.addElement(vPpi.elementAt(index).getDeclaredBy());
296
297 model.addRow(v);
298 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
299 }
300 } else {
301 Log.wrn("Find PPIs", "No PPI found!!!");
302 }
303 }
304
305 if (this.method.equals("PROTOCOL")) {
306 Vector<ProtocolId> vProtocol = Find.getAllProtocolsForFind();
307
308 if (vProtocol.size() > 0) {
309
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());
317 }
318 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
319 v.addElement("<html>" + strProducedModules + "</html>");
320
321 String strConsumedModules = vProtocol.elementAt(index).getConsumedModules();
322 if (strConsumedModules.indexOf("<br>") == 0) {
323 strConsumedModules = strConsumedModules.substring("<br>".length());
324 }
325 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
326 v.addElement("<html>" + strConsumedModules + "</html>");
327
328 v.addElement(vProtocol.elementAt(index).getDeclaredBy());
329
330 model.addRow(v);
331 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
332 }
333 } else {
334 Log.wrn("Find PROTOCOLs", "No PROTOCOL found!!!");
335 }
336 }
337
338 if (this.method.equals("GUID")) {
339 Vector<GuidId> vGuid = Find.getAllGuidsForFind();
340
341 if (vGuid.size() > 0) {
342
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());
350 }
351 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
352 v.addElement("<html>" + strProducedModules + "</html>");
353
354 String strConsumedModules = vGuid.elementAt(index).getConsumedModules();
355 if (strConsumedModules.indexOf("<br>") == 0) {
356 strConsumedModules = strConsumedModules.substring("<br>".length());
357 }
358 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
359 v.addElement("<html>" + strConsumedModules + "</html>");
360
361 v.addElement(vGuid.elementAt(index).getDeclaredBy());
362
363 model.addRow(v);
364 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
365 }
366 } else {
367 Log.wrn("Find GUIDs", "No GUID found!!!");
368 }
369 }
370
371 if (this.method.equals("PCD")) {
372 Vector<PcdId> vPcd = Find.getAllPcdCodedForFind();
373
374 if (vPcd.size() > 0) {
375
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());
383 }
384 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
385 v.addElement("<html>" + strProducedModules + "</html>");
386
387 String strConsumedModules = vPcd.elementAt(index).getConsumedModules();
388 if (strConsumedModules.indexOf("<br>") == 0) {
389 strConsumedModules = strConsumedModules.substring("<br>".length());
390 }
391 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
392 v.addElement("<html>" + strConsumedModules + "</html>");
393
394 v.addElement(vPcd.elementAt(index).getDeclaredBy());
395
396 model.addRow(v);
397 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
398 }
399 } else {
400 Log.wrn("Find PCDs", "No PCD found!!!");
401 }
402 }
403
404 if (this.method.equals("LIBRARY_CLASS")) {
405 Vector<LibraryClassId> vLibraryClass = Find.getAllLibraryClassForFind();
406
407 if (vLibraryClass.size() > 0) {
408
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());
416 }
417 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
418 v.addElement("<html>" + strProducedModules + "</html>");
419
420 String strConsumedModules = vLibraryClass.elementAt(index).getConsumedModules();
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 v.addElement(vLibraryClass.elementAt(index).getDeclaredBy());
428
429 model.addRow(v);
430 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
431 }
432 } else {
433 Log.wrn("Find Library Classes", "No Library Class found!!!");
434 }
435 }
436
437 this.jTable.repaint();
438 this.jTable.updateUI();
439 }
440
441 public void tableChanged(TableModelEvent arg0) {
442 // TODO Auto-generated method stub
443
444 }
445
446 public void actionPerformed(ActionEvent arg0) {
447 if (arg0.getSource() == this.jButtonClose) {
448
449 this.dispose();
450 }
451 }
452
453 /* (non-Javadoc)
454 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
455 *
456 * Override componentResized to resize all components when frame's size is changed
457 */
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;
463
464 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,
465 intPreferredHeight);
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);
469 }
470
471 /* (non-Javadoc)
472 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
473 *
474 * Override windowClosing to popup warning message to confirm quit
475 *
476 */
477 public void windowClosing(WindowEvent arg0) {
478 this.dispose();
479 }
480
481 class MyTableCellRenderer extends DefaultTableCellRenderer {
482 ///
483 ///
484 ///
485 private static final long serialVersionUID = -2082787479305255946L;
486
487 public void setValue(Object value) {
488 this.setVerticalAlignment(SwingConstants.TOP);
489 super.setValue(value);
490 }
491 }
492
493 }