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