]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/find/FindResult.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / 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.WindowEvent;
21 import java.util.Vector;
22
23 import javax.swing.JButton;
24 import javax.swing.JFrame;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTable;
28 import javax.swing.ListSelectionModel;
29 import javax.swing.SwingConstants;
30 import javax.swing.event.TableModelEvent;
31 import javax.swing.event.TableModelListener;
32 import javax.swing.table.DefaultTableCellRenderer;
33
34 import org.tianocore.frameworkwizard.common.DataType;
35 import org.tianocore.frameworkwizard.common.IDefaultTableModel;
36 import org.tianocore.frameworkwizard.common.Log;
37 import org.tianocore.frameworkwizard.common.Tools;
38 import org.tianocore.frameworkwizard.common.ui.IFrame;
39
40 public class FindResult extends IFrame implements TableModelListener {
41
42 ///
43 /// Define class Serial Version UID
44 ///
45 private static final long serialVersionUID = -2448484533878401714L;
46
47 //
48 // Define class members
49 //
50 private JTable jTable = null;
51
52 private JPanel jContentPane = null;
53
54 private JScrollPane jScrollPane = null;
55
56 private JScrollPane jScrollPaneTable = null;
57
58 private JButton jButtonClose = null;
59
60 //
61 // Not used by UI
62 //
63 private IDefaultTableModel model = null;
64
65 private String method = "";
66
67 private static FindResult findPpisResult = null;
68
69 private static FindResult findProtocolsResult = null;
70
71 private static FindResult findGuidsResult = null;
72
73 private static FindResult findPcdsResult = null;
74
75 private static FindResult findLibraryClassResult = null;
76
77 /**
78 * This is the default constructor
79 */
80 public FindResult(String method) {
81 super();
82 init(method);
83 }
84
85 /**
86 * This method initializes this
87 *
88 * @return void
89 */
90 private void init(String method) {
91 this.setSize(600, 500);
92 this.setContentPane(getJScrollPane());
93 this.setTitle("Find Result");
94 this.setResizable(true);
95 this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
96 this.centerWindow();
97
98 //
99 // max the window
100 //
101 //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
102 this.method = method;
103 this.showTable();
104 }
105
106 /**
107 * This method initializes jContentPane
108 *
109 * @return javax.swing.JPanel
110 */
111 private JPanel getJContentPane() {
112 if (jContentPane == null) {
113 jContentPane = new JPanel();
114 jContentPane.setLayout(null);
115 jContentPane.add(getJScrollPaneTable(), null);
116 jContentPane.add(getJButtonClose(), null);
117 jContentPane.setPreferredSize(new java.awt.Dimension(585, 445));
118 }
119 return jContentPane;
120 }
121
122 /**
123 This method initializes jScrollPane
124
125 @return javax.swing.JScrollPane
126 */
127 private JScrollPane getJScrollPane() {
128 if (jScrollPane == null) {
129 jScrollPane = new JScrollPane();
130 jScrollPane.setViewportView(getJContentPane());
131 }
132 return jScrollPane;
133 }
134
135 /**
136 This method initializes jScrollPaneTable
137
138 @return javax.swing.JScrollPane
139 **/
140 private JScrollPane getJScrollPaneTable() {
141 if (jScrollPaneTable == null) {
142 jScrollPaneTable = new JScrollPane();
143 jScrollPaneTable.setBounds(new java.awt.Rectangle(0, 0, 585, 395));
144 jScrollPaneTable.setPreferredSize(new Dimension(585, 395));
145 jScrollPaneTable.setViewportView(getJTable());
146 }
147 return jScrollPaneTable;
148 }
149
150 /**
151 This method initializes jTable
152
153 @return javax.swing.JTable
154 **/
155 private JTable getJTable() {
156 if (jTable == null) {
157 model = new IDefaultTableModel();
158 jTable = new JTable(model);
159
160 model.addColumn("Name");
161 model.addColumn("Type");
162 model.addColumn("Produced by");
163 model.addColumn("Consumed by");
164 model.addColumn("Declared by");
165
166 jTable.getColumn("Name").setCellRenderer(new MyTableCellRenderer());
167 jTable.getColumn("Type").setCellRenderer(new MyTableCellRenderer());
168 jTable.getColumn("Produced by").setCellRenderer(new MyTableCellRenderer());
169 jTable.getColumn("Consumed by").setCellRenderer(new MyTableCellRenderer());
170 jTable.getColumn("Declared by").setCellRenderer(new MyTableCellRenderer());
171
172 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
173 jTable.getModel().addTableModelListener(this);
174 }
175 return jTable;
176 }
177
178 /**
179 This method initializes jButtonAdd
180
181 @return javax.swing.JButton jButtonAdd
182
183 **/
184 private JButton getJButtonClose() {
185 if (jButtonClose == null) {
186 jButtonClose = new JButton();
187 jButtonClose.setText("Close");
188 jButtonClose.addActionListener(this);
189 jButtonClose.setBounds(new java.awt.Rectangle(255, 415, 80, 20));
190 jButtonClose.setPreferredSize(new java.awt.Dimension(80, 20));
191 }
192 return jButtonClose;
193 }
194
195 public static FindResult getInstance(String method) {
196 if (method.equals("PPI")) {
197 if (findPpisResult == null) {
198 findPpisResult = new FindResult(method);
199 }
200 findPpisResult.init(method);
201 return findPpisResult;
202 }
203
204 if (method.equals("PROTOCOL")) {
205 if (findProtocolsResult == null) {
206 findProtocolsResult = new FindResult(method);
207 }
208 findProtocolsResult.init(method);
209 return findProtocolsResult;
210 }
211
212 if (method.equals("GUID")) {
213 if (findGuidsResult == null) {
214 findGuidsResult = new FindResult(method);
215 }
216 findGuidsResult.init(method);
217 return findGuidsResult;
218 }
219
220 if (method.equals("PCD")) {
221 if (findPcdsResult == null) {
222 findPcdsResult = new FindResult(method);
223 }
224 findPcdsResult.init(method);
225 return findPcdsResult;
226 }
227
228 if (method.equals("LIBRARY_CLASS")) {
229 if (findLibraryClassResult == null) {
230 findLibraryClassResult = new FindResult(method);
231 }
232 findLibraryClassResult.init(method);
233 return findLibraryClassResult;
234 }
235
236 return null;
237 }
238
239 /**
240 Clear all table rows
241
242 **/
243 private void clearAll() {
244 if (model != null) {
245 for (int index = model.getRowCount() - 1; index >= 0; index--) {
246 model.removeRow(index);
247 }
248 }
249 }
250
251 /**
252 Read content of vector and put then into table
253
254 **/
255 private void showTable() {
256 clearAll();
257
258 if (this.method.equals("PPI")) {
259 Vector<PpiId> vPpi = Find.getAllPpisForFind();
260
261 if (vPpi.size() > 0) {
262
263 for (int index = 0; index < vPpi.size(); index++) {
264 Vector<String> v = new Vector<String>();
265 v.addElement(vPpi.elementAt(index).getName());
266 v.addElement(vPpi.elementAt(index).getType());
267 String strProducedModules = vPpi.elementAt(index).getProducedModules();
268 if (strProducedModules.indexOf("<br>") == 0) {
269 strProducedModules = strProducedModules.substring("<br>".length());
270 }
271 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
272 v.addElement("<html>" + strProducedModules + "</html>");
273
274 String strConsumedModules = vPpi.elementAt(index).getConsumedModules();
275 if (strConsumedModules.indexOf("<br>") == 0) {
276 strConsumedModules = strConsumedModules.substring("<br>".length());
277 }
278 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
279 v.addElement("<html>" + strConsumedModules + "</html>");
280
281 v.addElement(vPpi.elementAt(index).getDeclaredBy());
282
283 model.addRow(v);
284 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
285 }
286 } else {
287 Log.wrn("Find PPIs", "No PPI found!!!");
288 }
289 }
290
291 if (this.method.equals("PROTOCOL")) {
292 Vector<ProtocolId> vProtocol = Find.getAllProtocolsForFind();
293
294 if (vProtocol.size() > 0) {
295
296 for (int index = 0; index < vProtocol.size(); index++) {
297 Vector<String> v = new Vector<String>();
298 v.addElement(vProtocol.elementAt(index).getName());
299 v.addElement(vProtocol.elementAt(index).getType());
300 String strProducedModules = vProtocol.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 = vProtocol.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(vProtocol.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 PROTOCOLs", "No PROTOCOL found!!!");
321 }
322 }
323
324 if (this.method.equals("GUID")) {
325 Vector<GuidId> vGuid = Find.getAllGuidsForFind();
326
327 if (vGuid.size() > 0) {
328
329 for (int index = 0; index < vGuid.size(); index++) {
330 Vector<String> v = new Vector<String>();
331 v.addElement(vGuid.elementAt(index).getName());
332 v.addElement("GUID");
333 String strProducedModules = vGuid.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 = vGuid.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(vGuid.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 GUIDs", "No GUID found!!!");
354 }
355 }
356
357 if (this.method.equals("PCD")) {
358 Vector<PcdId> vPcd = Find.getAllPcdCodedForFind();
359
360 if (vPcd.size() > 0) {
361
362 for (int index = 0; index < vPcd.size(); index++) {
363 Vector<String> v = new Vector<String>();
364 v.addElement(vPcd.elementAt(index).getName());
365 v.addElement(vPcd.elementAt(index).getType());
366 String strProducedModules = vPcd.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 = vPcd.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(vPcd.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 PCDs", "No PCD found!!!");
387 }
388 }
389
390 if (this.method.equals("LIBRARY_CLASS")) {
391 Vector<LibraryClassId> vLibraryClass = Find.getAllLibraryClassForFind();
392
393 if (vLibraryClass.size() > 0) {
394
395 for (int index = 0; index < vLibraryClass.size(); index++) {
396 Vector<String> v = new Vector<String>();
397 v.addElement(vLibraryClass.elementAt(index).getName());
398 v.addElement(vLibraryClass.elementAt(index).getType());
399 String strProducedModules = vLibraryClass.elementAt(index).getProducedModules();
400 if (strProducedModules.indexOf("<br>") == 0) {
401 strProducedModules = strProducedModules.substring("<br>".length());
402 }
403 int line1 = Tools.getSpecificStringCount(strProducedModules, "<br>");
404 v.addElement("<html>" + strProducedModules + "</html>");
405
406 String strConsumedModules = vLibraryClass.elementAt(index).getConsumedModules();
407 if (strConsumedModules.indexOf("<br>") == 0) {
408 strConsumedModules = strConsumedModules.substring("<br>".length());
409 }
410 int line2 = Tools.getSpecificStringCount(strConsumedModules, "<br>");
411 v.addElement("<html>" + strConsumedModules + "</html>");
412
413 v.addElement(vLibraryClass.elementAt(index).getDeclaredBy());
414
415 model.addRow(v);
416 jTable.setRowHeight(index, (Math.max(line1, line2) > 1 ? Math.max(line1, line2) : 1) * 18);
417 }
418 } else {
419 Log.wrn("Find Library Classes", "No Library Class found!!!");
420 }
421 }
422
423 this.jTable.repaint();
424 this.jTable.updateUI();
425 }
426
427 public void tableChanged(TableModelEvent arg0) {
428 // TODO Auto-generated method stub
429
430 }
431
432 public void actionPerformed(ActionEvent arg0) {
433 if (arg0.getSource() == this.jButtonClose) {
434
435 this.dispose();
436 }
437 }
438
439 /* (non-Javadoc)
440 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
441 *
442 * Override componentResized to resize all components when frame's size is changed
443 */
444 public void componentResized(ComponentEvent arg0) {
445 int intCurrentWidth = this.getJContentPane().getWidth();
446 int intCurrentHeight = this.getJContentPane().getHeight();
447 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;
448 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;
449
450 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,
451 intPreferredHeight);
452 Tools.centerComponent(this.jButtonClose, intCurrentWidth, intCurrentHeight, intPreferredHeight,
453 DataType.SPACE_TO_BOTTOM_FOR_CLOSE_BUTTON);
454 }
455
456 /* (non-Javadoc)
457 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
458 *
459 * Override windowClosing to popup warning message to confirm quit
460 *
461 */
462 public void windowClosing(WindowEvent arg0) {
463 this.dispose();
464 }
465
466 class MyTableCellRenderer extends DefaultTableCellRenderer {
467 ///
468 ///
469 ///
470 private static final long serialVersionUID = -2082787479305255946L;
471
472 public void setValue(Object value) {
473 this.setVerticalAlignment(SwingConstants.TOP);
474 super.setValue(value);
475 }
476 }
477
478 }