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