]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleLibraryClassDefinitions.java
Use table and popup window to add/edit all elements of module instead of original...
[mirror_edk2.git] / Tools / 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
321 if (!isEmpty(vLibraryClass.getLibraryClass(index).getHelp())) {\r
322 mLibraryClass.setHelpText(vLibraryClass.getLibraryClass(index).getHelp());\r
323 }\r
324\r
325 this.lcd.addNewLibraryClass();\r
326 this.lcd.setLibraryClassArray(index, mLibraryClass);\r
327 }\r
328 }\r
329\r
330 if (msa.getLibraryClassDefinitions() == null) {\r
331 this.msa.addNewLibraryClassDefinitions();\r
332 }\r
333 this.msa.setLibraryClassDefinitions(this.lcd);\r
334\r
335 this.omt.setSaved(false);\r
336 } catch (Exception e) {\r
337 Log.err("Update Library Class Definitions", e.getMessage());\r
338 }\r
339 }\r
340\r
06a19cee 341 private void showEdit(int index) {\r
342 LibraryClassDefsDlg mcdd = new LibraryClassDefsDlg(vLibraryClass.getLibraryClass(index), new IFrame());\r
343 int result = mcdd.showDialog();\r
344 if (result == DataType.RETURN_TYPE_OK) {\r
345 if (index == -1) {\r
346 this.vLibraryClass.addLibraryClass(mcdd.getLcid());\r
347 } else {\r
348 this.vLibraryClass.setLibraryClass(mcdd.getLcid(), index);\r
349 }\r
350 this.showTable();\r
351 this.save();\r
352 mcdd.dispose();\r
353 }\r
354 if (result == DataType.RETURN_TYPE_CANCEL) {\r
355 mcdd.dispose();\r
356 }\r
a13899c5 357 }\r
358\r
06a19cee 359 /* (non-Javadoc)\r
360 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
361 *\r
362 * Override actionPerformed to listen all actions\r
363 * \r
364 */\r
365 public void actionPerformed(ActionEvent arg0) {\r
366 if (arg0.getSource() == jButtonAdd) {\r
367 showEdit(-1);\r
368 }\r
369 if (arg0.getSource() == jButtonUpdate) {\r
370 if (this.selectedRow < 0) {\r
371 Log.err("Please select one record first.");\r
372 return;\r
373 }\r
374 showEdit(selectedRow);\r
a13899c5 375 }\r
376\r
06a19cee 377 if (arg0.getSource() == jButtonRemove) {\r
378 if (jTable.isEditing()) {\r
379 jTable.getCellEditor().stopCellEditing();\r
380 }\r
381 if (selectedRow > -1) {\r
382 this.model.removeRow(selectedRow);\r
383 this.vLibraryClass.removeLibraryClass(selectedRow);\r
384 selectedRow = -1;\r
385 this.save();\r
386 }\r
387 }\r
a13899c5 388 }\r
389\r
390 /**\r
06a19cee 391 Clear all table rows\r
a13899c5 392 \r
393 **/\r
06a19cee 394 private void clearAll() {\r
395 if (model != null) {\r
396 for (int index = model.getRowCount() - 1; index >= 0; index--) {\r
397 model.removeRow(index);\r
398 }\r
a13899c5 399 }\r
a13899c5 400 }\r
401\r
402 /**\r
06a19cee 403 Read content of vector and put then into table\r
a13899c5 404 \r
405 **/\r
06a19cee 406 private void showTable() {\r
407 clearAll();\r
408\r
a13899c5 409 if (vLibraryClass.size() > 0) {\r
06a19cee 410 for (int index = 0; index < vLibraryClass.size(); index++) {\r
411 model.addRow(vLibraryClass.toStringVector(index));\r
412 }\r
a13899c5 413 }\r
06a19cee 414 this.jTable.repaint();\r
415 this.jTable.updateUI();\r
416 //this.jScrollPane.setViewportView(this.jTable);\r
a13899c5 417 }\r
418\r
06a19cee 419 /* (non-Javadoc)\r
420 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r
421 *\r
422 */\r
423 public void valueChanged(ListSelectionEvent arg0) {\r
424 if (arg0.getValueIsAdjusting()) {\r
425 return;\r
426 }\r
427 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r
428 if (lsm.isSelectionEmpty()) {\r
429 return;\r
430 } else {\r
431 selectedRow = lsm.getMinSelectionIndex();\r
a13899c5 432 }\r
a13899c5 433 }\r
434\r
435 /* (non-Javadoc)\r
06a19cee 436 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r
a13899c5 437 *\r
a13899c5 438 */\r
06a19cee 439 public void mouseClicked(MouseEvent arg0) {\r
440 if (arg0.getClickCount() == 2) {\r
441 if (this.selectedRow < 0) {\r
442 return;\r
443 } else {\r
444 showEdit(selectedRow);\r
445 }\r
a13899c5 446 }\r
447 }\r
448\r
449 /* (non-Javadoc)\r
450 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r
451 * \r
452 * Override componentResized to resize all components when frame's size is changed\r
453 */\r
454 public void componentResized(ComponentEvent arg0) {\r
455 int intCurrentWidth = this.getJContentPane().getWidth();\r
456 int intCurrentHeight = this.getJContentPane().getHeight();\r
457 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r
458 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r
459\r
06a19cee 460 resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight);\r
461 relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r
462 DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r
463 relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r
464 DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r
465 relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r
466 DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r
a13899c5 467 }\r
468}\r