]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleProtocols.java
1. Wrap text by word when showing a message box
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / ModuleProtocols.java
... / ...
CommitLineData
1/** @file\r
2 \r
3 The file is used to create, update Protocol of MSA/MBD file\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\r
16package org.tianocore.frameworkwizard.module.ui;\r
17\r
18import java.awt.Dimension;\r
19import java.awt.event.ActionEvent;\r
20import java.awt.event.ComponentEvent;\r
21import java.awt.event.MouseEvent;\r
22import java.util.Vector;\r
23\r
24import javax.swing.JButton;\r
25import javax.swing.JPanel;\r
26import javax.swing.JScrollPane;\r
27import javax.swing.JTable;\r
28import javax.swing.ListSelectionModel;\r
29import javax.swing.event.ListSelectionEvent;\r
30\r
31import org.tianocore.ProtocolNotifyUsage;\r
32import org.tianocore.ProtocolUsage;\r
33import org.tianocore.ProtocolsDocument;\r
34import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
35import org.tianocore.ProtocolsDocument.Protocols;\r
36import org.tianocore.ProtocolsDocument.Protocols.Protocol;\r
37import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify;\r
38import org.tianocore.frameworkwizard.common.DataType;\r
39import org.tianocore.frameworkwizard.common.EnumerationData;\r
40import org.tianocore.frameworkwizard.common.IDefaultTableModel;\r
41import org.tianocore.frameworkwizard.common.Log;\r
42import org.tianocore.frameworkwizard.common.Tools;\r
43import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r
44import org.tianocore.frameworkwizard.common.ui.IFrame;\r
45import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r
46import org.tianocore.frameworkwizard.module.Identifications.Protocols.ProtocolsIdentification;\r
47import org.tianocore.frameworkwizard.module.Identifications.Protocols.ProtocolsVector;\r
48import org.tianocore.frameworkwizard.module.ui.dialog.ProtocolsDlg;\r
49\r
50/**\r
51 The class is used to create, update Protocol of MSA/MBD file\r
52 It extends IInternalFrame\r
53 \r
54\r
55\r
56 **/\r
57public class ModuleProtocols extends IInternalFrame {\r
58\r
59 ///\r
60 /// Define class Serial Version UID\r
61 ///\r
62 private static final long serialVersionUID = -9084913640747858848L;\r
63\r
64 //\r
65 //Define class members\r
66 //\r
67 private JPanel jContentPane = null;\r
68\r
69 private JButton jButtonAdd = null;\r
70\r
71 private JButton jButtonRemove = null;\r
72\r
73 private JButton jButtonUpdate = null;\r
74\r
75 private JScrollPane jScrollPane = null;\r
76\r
77 private JScrollPane jScrollPaneTable = null;\r
78\r
79 private JTable jTable = null;\r
80\r
81 //\r
82 // Not used by UI\r
83 //\r
84 private OpeningModuleType omt = null;\r
85\r
86 private ModuleSurfaceArea msa = null;\r
87\r
88 private ProtocolsDocument.Protocols protocols = null;\r
89\r
90 private ProtocolsIdentification id = null;\r
91\r
92 private ProtocolsVector vid = new ProtocolsVector();\r
93\r
94 private EnumerationData ed = new EnumerationData();\r
95\r
96 private IDefaultTableModel model = null;\r
97\r
98 private int selectedRow = -1;\r
99\r
100 /**\r
101 This method initializes jButtonAdd \r
102 \r
103 @return javax.swing.JButton jButtonAdd\r
104 \r
105 **/\r
106 private JButton getJButtonAdd() {\r
107 if (jButtonAdd == null) {\r
108 jButtonAdd = new JButton();\r
109 jButtonAdd.setBounds(new java.awt.Rectangle(230, 220, 80, 20));\r
110 jButtonAdd.setText("Add");\r
111 jButtonAdd.addActionListener(this);\r
112 jButtonAdd.setPreferredSize(new java.awt.Dimension(80, 20));\r
113 }\r
114 return jButtonAdd;\r
115 }\r
116\r
117 /**\r
118 This method initializes jButtonRemove \r
119 \r
120 @return javax.swing.JButton jButtonRemove\r
121 \r
122 **/\r
123 private JButton getJButtonRemove() {\r
124 if (jButtonRemove == null) {\r
125 jButtonRemove = new JButton();\r
126 jButtonRemove.setBounds(new java.awt.Rectangle(400, 220, 80, 20));\r
127 jButtonRemove.setText("Remove");\r
128 jButtonRemove.addActionListener(this);\r
129 jButtonRemove.setPreferredSize(new java.awt.Dimension(80, 20));\r
130 }\r
131 return jButtonRemove;\r
132 }\r
133\r
134 /**\r
135 This method initializes jButtonUpdate \r
136 \r
137 @return javax.swing.JButton jButtonUpdate\r
138 \r
139 **/\r
140 private JButton getJButtonUpdate() {\r
141 if (jButtonUpdate == null) {\r
142 jButtonUpdate = new JButton();\r
143 jButtonUpdate.setBounds(new java.awt.Rectangle(315, 220, 80, 20));\r
144 jButtonUpdate.setPreferredSize(new java.awt.Dimension(80, 20));\r
145 jButtonUpdate.setText("Edit");\r
146 jButtonUpdate.addActionListener(this);\r
147 }\r
148 return jButtonUpdate;\r
149 }\r
150\r
151 /**\r
152 This method initializes jScrollPane \r
153 \r
154 @return javax.swing.JScrollPane \r
155 */\r
156 private JScrollPane getJScrollPane() {\r
157 if (jScrollPane == null) {\r
158 jScrollPane = new JScrollPane();\r
159 jScrollPane.setViewportView(getJContentPane());\r
160 }\r
161 return jScrollPane;\r
162 }\r
163\r
164 /**\r
165 This method initializes jScrollPaneTable \r
166 \r
167 @return javax.swing.JScrollPane \r
168 **/\r
169 private JScrollPane getJScrollPaneTable() {\r
170 if (jScrollPaneTable == null) {\r
171 jScrollPaneTable = new JScrollPane();\r
172 jScrollPaneTable.setBounds(new java.awt.Rectangle(15, 10, 470, 420));\r
173 jScrollPaneTable.setPreferredSize(new Dimension(470, 420));\r
174 jScrollPaneTable.setViewportView(getJTable());\r
175 }\r
176 return jScrollPaneTable;\r
177 }\r
178\r
179 /**\r
180 This method initializes jTable \r
181 \r
182 @return javax.swing.JTable \r
183 **/\r
184 private JTable getJTable() {\r
185 if (jTable == null) {\r
186 jTable = new JTable();\r
187 model = new IDefaultTableModel();\r
188 jTable = new JTable(model);\r
189 jTable.setRowHeight(20);\r
190\r
191 model.addColumn("Guid C_Name");\r
192 model.addColumn("Type");\r
193 model.addColumn("Usage");\r
194\r
195 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
196 jTable.getSelectionModel().addListSelectionListener(this);\r
197 jTable.getModel().addTableModelListener(this);\r
198 jTable.addMouseListener(this);\r
199 }\r
200 return jTable;\r
201 }\r
202\r
203 public static void main(String[] args) {\r
204\r
205 }\r
206\r
207 /**\r
208 This method initializes this\r
209 \r
210 **/\r
211 private void init() {\r
212 this.setSize(500, 515);\r
213 this.setContentPane(getJScrollPane());\r
214 this.setTitle("Protocols");\r
215 }\r
216\r
217 /**\r
218 This method initializes this\r
219 Fill values to all fields if these values are not empty\r
220 \r
221 @param inPackageDependencies\r
222\r
223 **/\r
224 private void init(Protocols inProtocols) {\r
225 init();\r
226 this.protocols = inProtocols;\r
227\r
228 if (this.protocols != null) {\r
229 if (this.protocols.getProtocolList().size() > 0) {\r
230 for (int index = 0; index < this.protocols.getProtocolList().size(); index++) {\r
231 String arg0 = protocols.getProtocolList().get(index).getProtocolCName();\r
232 String arg1 = ed.getVProtocolType().get(0);\r
233 String arg2 = null;\r
234 if (protocols.getProtocolList().get(index).getUsage() != null) {\r
235 arg2 = protocols.getProtocolList().get(index).getUsage().toString();\r
236 }\r
237\r
238 String arg3 = protocols.getProtocolList().get(index).getFeatureFlag();\r
239 Vector<String> arg4 = Tools.convertListToVector(protocols.getProtocolList().get(index)\r
240 .getSupArchList());\r
241 String arg5 = protocols.getProtocolList().get(index).getHelpText();\r
242 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
243 vid.addProtocols(id);\r
244 }\r
245 }\r
246 if (this.protocols.getProtocolNotifyList().size() > 0) {\r
247 for (int index = 0; index < this.protocols.getProtocolNotifyList().size(); index++) {\r
248 String arg0 = protocols.getProtocolNotifyList().get(index).getProtocolNotifyCName();\r
249 String arg1 = ed.getVProtocolType().get(1);\r
250 String arg2 = null;\r
251 if (protocols.getProtocolNotifyList().get(index).getUsage() != null) {\r
252 arg2 = protocols.getProtocolNotifyList().get(index).getUsage().toString();\r
253 }\r
254\r
255 String arg3 = protocols.getProtocolNotifyList().get(index).getFeatureFlag();\r
256 Vector<String> arg4 = Tools.convertListToVector(protocols.getProtocolNotifyList().get(index)\r
257 .getSupArchList());\r
258 String arg5 = protocols.getProtocolNotifyList().get(index).getHelpText();\r
259 id = new ProtocolsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
260 vid.addProtocols(id);\r
261 }\r
262 }\r
263 }\r
264 showTable();\r
265 }\r
266\r
267 /**\r
268 This is the default constructor\r
269 \r
270 **/\r
271 public ModuleProtocols() {\r
272 super();\r
273 init();\r
274 this.setVisible(true);\r
275 }\r
276\r
277 /**\r
278 This is the override edit constructor\r
279 \r
280 @param inProtocol The input data of ProtocolsDocument.Protocols\r
281 \r
282 **/\r
283 public ModuleProtocols(OpeningModuleType inOmt) {\r
284 super();\r
285 this.omt = inOmt;\r
286 this.msa = omt.getXmlMsa();\r
287 init(msa.getProtocols());\r
288 this.setVisible(true);\r
289 }\r
290\r
291 /**\r
292 This method initializes jContentPane\r
293 \r
294 @return javax.swing.JPanel jContentPane\r
295 \r
296 **/\r
297 private JPanel getJContentPane() {\r
298 if (jContentPane == null) {\r
299 jContentPane = new JPanel();\r
300 jContentPane.setLayout(null);\r
301 jContentPane.setPreferredSize(new java.awt.Dimension(490, 490));\r
302\r
303 jContentPane.add(getJButtonAdd(), null);\r
304 jContentPane.add(getJButtonRemove(), null);\r
305 jContentPane.add(getJButtonUpdate(), null);\r
306 jContentPane.add(getJScrollPaneTable(), null);\r
307 }\r
308 return jContentPane;\r
309 }\r
310 \r
311 private void showEdit(int index) {\r
312 ProtocolsDlg dlg = new ProtocolsDlg(vid.getProtocols(index), new IFrame());\r
313 int result = dlg.showDialog();\r
314 if (result == DataType.RETURN_TYPE_OK) {\r
315 if (index == -1) {\r
316 this.vid.addProtocols(dlg.getId());\r
317 } else {\r
318 this.vid.setProtocols(dlg.getId(), index);\r
319 }\r
320 this.showTable();\r
321 this.save();\r
322 dlg.dispose();\r
323 }\r
324 if (result == DataType.RETURN_TYPE_CANCEL) {\r
325 dlg.dispose();\r
326 }\r
327 }\r
328\r
329 /**\r
330 Clear all table rows\r
331 \r
332 **/\r
333 private void clearAll() {\r
334 if (model != null) {\r
335 for (int index = model.getRowCount() - 1; index >= 0; index--) {\r
336 model.removeRow(index);\r
337 }\r
338 }\r
339 }\r
340\r
341 /**\r
342 Read content of vector and put then into table\r
343 \r
344 **/\r
345 private void showTable() {\r
346 clearAll();\r
347\r
348 if (vid.size() > 0) {\r
349 for (int index = 0; index < vid.size(); index++) {\r
350 model.addRow(vid.toStringVector(index));\r
351 }\r
352 }\r
353 this.jTable.repaint();\r
354 this.jTable.updateUI();\r
355 }\r
356\r
357 /* (non-Javadoc)\r
358 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
359 *\r
360 * Override actionPerformed to listen all actions\r
361 * \r
362 */\r
363 public void actionPerformed(ActionEvent arg0) {\r
364 if (arg0.getSource() == jButtonAdd) {\r
365 showEdit(-1);\r
366 }\r
367 if (arg0.getSource() == jButtonUpdate) {\r
368 if (this.selectedRow < 0) {\r
369 Log.wrn("Update Protocols", "Please select one record first.");\r
370 return;\r
371 }\r
372 showEdit(selectedRow);\r
373 }\r
374\r
375 if (arg0.getSource() == jButtonRemove) {\r
376 if (jTable.isEditing()) {\r
377 jTable.getCellEditor().stopCellEditing();\r
378 }\r
379 if (selectedRow > -1) {\r
380 this.model.removeRow(selectedRow);\r
381 this.vid.removeProtocols(selectedRow);\r
382 selectedRow = -1;\r
383 this.save();\r
384 }\r
385 }\r
386 }\r
387\r
388 /**\r
389 Save all components of Protocols\r
390 if exists protocols, set the value directly\r
391 if not exists protocols, new an instance first\r
392 \r
393 **/\r
394 public void save() {\r
395 try {\r
396 int count = this.vid.size();\r
397\r
398 this.protocols = Protocols.Factory.newInstance();\r
399 if (count > 0) {\r
400 for (int index = 0; index < count; index++) {\r
401 if (vid.getProtocols(index).getType().equals(ed.getVProtocolType().get(0))) {\r
402 Protocol p = Protocol.Factory.newInstance();\r
403 if (!isEmpty(vid.getProtocols(index).getName())) {\r
404 p.setProtocolCName(vid.getProtocols(index).getName());\r
405 }\r
406 if (!isEmpty(vid.getProtocols(index).getUsage())) {\r
407 p.setUsage(ProtocolUsage.Enum.forString(vid.getProtocols(index).getUsage()));\r
408 }\r
409 if (!isEmpty(vid.getProtocols(index).getFeatureFlag())) {\r
410 p.setFeatureFlag(vid.getProtocols(index).getFeatureFlag());\r
411 }\r
412 if (vid.getProtocols(index).getSupArchList() != null\r
413 && vid.getProtocols(index).getSupArchList().size() > 0) {\r
414 p.setSupArchList(vid.getProtocols(index).getSupArchList());\r
415 }\r
416 if (!isEmpty(vid.getProtocols(index).getHelp())) {\r
417 p.setHelpText(vid.getProtocols(index).getHelp());\r
418 }\r
419 this.protocols.addNewProtocol();\r
420 this.protocols.setProtocolArray(protocols.getProtocolList().size() - 1, p);\r
421 }\r
422 if (vid.getProtocols(index).getType().equals(ed.getVProtocolType().get(1))) {\r
423 ProtocolNotify p = ProtocolNotify.Factory.newInstance();\r
424 if (!isEmpty(vid.getProtocols(index).getName())) {\r
425 p.setProtocolNotifyCName(vid.getProtocols(index).getName());\r
426 }\r
427 if (!isEmpty(vid.getProtocols(index).getUsage())) {\r
428 p.setUsage(ProtocolNotifyUsage.Enum.forString(vid.getProtocols(index).getUsage()));\r
429 }\r
430 if (!isEmpty(vid.getProtocols(index).getFeatureFlag())) {\r
431 p.setFeatureFlag(vid.getProtocols(index).getFeatureFlag());\r
432 }\r
433 if (vid.getProtocols(index).getSupArchList() != null\r
434 && vid.getProtocols(index).getSupArchList().size() > 0) {\r
435 p.setSupArchList(vid.getProtocols(index).getSupArchList());\r
436 }\r
437 if (!isEmpty(vid.getProtocols(index).getHelp())) {\r
438 p.setHelpText(vid.getProtocols(index).getHelp());\r
439 }\r
440 this.protocols.addNewProtocolNotify();\r
441 this.protocols.setProtocolNotifyArray(protocols.getProtocolNotifyList().size() - 1, p);\r
442 }\r
443 }\r
444 }\r
445\r
446 this.msa.setProtocols(protocols);\r
447 this.omt.setSaved(false);\r
448 } catch (Exception e) {\r
449 Log.wrn("Update Protocols", e.getMessage());\r
450 Log.err("Update Protocols", e.getMessage());\r
451 }\r
452 }\r
453 \r
454 /* (non-Javadoc)\r
455 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r
456 *\r
457 */\r
458 public void valueChanged(ListSelectionEvent arg0) {\r
459 if (arg0.getValueIsAdjusting()) {\r
460 return;\r
461 }\r
462 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r
463 if (lsm.isSelectionEmpty()) {\r
464 return;\r
465 } else {\r
466 selectedRow = lsm.getMinSelectionIndex();\r
467 }\r
468 }\r
469\r
470 /* (non-Javadoc)\r
471 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r
472 *\r
473 */\r
474 public void mouseClicked(MouseEvent arg0) {\r
475 if (arg0.getClickCount() == 2) {\r
476 if (this.selectedRow < 0) {\r
477 return;\r
478 } else {\r
479 showEdit(selectedRow);\r
480 }\r
481 }\r
482 }\r
483\r
484 /* (non-Javadoc)\r
485 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r
486 * \r
487 * Override componentResized to resize all components when frame's size is changed\r
488 */\r
489 public void componentResized(ComponentEvent arg0) {\r
490 int intCurrentWidth = this.getJContentPane().getWidth();\r
491 int intCurrentHeight = this.getJContentPane().getHeight();\r
492 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r
493 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r
494\r
495 resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight);\r
496 relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r
497 DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r
498 relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r
499 DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r
500 relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r
501 DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r
502 }\r
503}\r