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