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