]>
Commit | Line | Data |
---|---|---|
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 | |
15 | package org.tianocore.frameworkwizard.module.ui;\r | |
16 | \r | |
17 | import java.awt.Dimension;\r | |
18 | import java.awt.event.ActionEvent;\r | |
19 | import java.awt.event.ComponentEvent;\r | |
06a19cee | 20 | import java.awt.event.MouseEvent;\r |
a13899c5 | 21 | import java.util.Vector;\r |
22 | \r | |
23 | import javax.swing.JButton;\r | |
a13899c5 | 24 | import javax.swing.JPanel;\r |
25 | import javax.swing.JScrollPane;\r | |
06a19cee | 26 | import javax.swing.JTable;\r |
27 | import javax.swing.ListSelectionModel;\r | |
28 | import javax.swing.event.ListSelectionEvent;\r | |
a13899c5 | 29 | \r |
30 | import org.tianocore.LibraryClassDefinitionsDocument;\r | |
31 | import org.tianocore.LibraryUsage;\r | |
32 | import org.tianocore.ModuleSurfaceAreaDocument;\r | |
33 | import org.tianocore.LibraryClassDefinitionsDocument.LibraryClassDefinitions;\r | |
34 | import org.tianocore.LibraryClassDocument.LibraryClass;\r | |
35 | import org.tianocore.frameworkwizard.common.DataType;\r | |
06a19cee | 36 | import org.tianocore.frameworkwizard.common.IDefaultTableModel;\r |
a13899c5 | 37 | import org.tianocore.frameworkwizard.common.Log;\r |
a13899c5 | 38 | import org.tianocore.frameworkwizard.common.Tools;\r |
79cb6fdb | 39 | import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r |
06a19cee | 40 | import org.tianocore.frameworkwizard.common.ui.IFrame;\r |
a13899c5 | 41 | import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r |
79cb6fdb | 42 | import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassIdentification;\r |
43 | import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassVector;\r | |
06a19cee | 44 | import 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 | |
51 | public 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 | |
ed1665f2 | 337 | Log.wrn("Update Library Class Definitions", e.getMessage());\r |
a13899c5 | 338 | Log.err("Update Library Class Definitions", e.getMessage());\r |
339 | }\r | |
340 | }\r | |
341 | \r | |
06a19cee | 342 | private void showEdit(int index) {\r |
343 | LibraryClassDefsDlg mcdd = new LibraryClassDefsDlg(vLibraryClass.getLibraryClass(index), new IFrame());\r | |
344 | int result = mcdd.showDialog();\r | |
345 | if (result == DataType.RETURN_TYPE_OK) {\r | |
346 | if (index == -1) {\r | |
347 | this.vLibraryClass.addLibraryClass(mcdd.getLcid());\r | |
348 | } else {\r | |
349 | this.vLibraryClass.setLibraryClass(mcdd.getLcid(), index);\r | |
350 | }\r | |
351 | this.showTable();\r | |
352 | this.save();\r | |
353 | mcdd.dispose();\r | |
354 | }\r | |
355 | if (result == DataType.RETURN_TYPE_CANCEL) {\r | |
356 | mcdd.dispose();\r | |
357 | }\r | |
a13899c5 | 358 | }\r |
359 | \r | |
06a19cee | 360 | /* (non-Javadoc)\r |
361 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
362 | *\r | |
363 | * Override actionPerformed to listen all actions\r | |
364 | * \r | |
365 | */\r | |
366 | public void actionPerformed(ActionEvent arg0) {\r | |
367 | if (arg0.getSource() == jButtonAdd) {\r | |
368 | showEdit(-1);\r | |
369 | }\r | |
370 | if (arg0.getSource() == jButtonUpdate) {\r | |
371 | if (this.selectedRow < 0) {\r | |
ed1665f2 | 372 | Log.wrn("Update Library Class Definitions", "Please select one record first.");\r |
06a19cee | 373 | return;\r |
374 | }\r | |
375 | showEdit(selectedRow);\r | |
a13899c5 | 376 | }\r |
377 | \r | |
06a19cee | 378 | if (arg0.getSource() == jButtonRemove) {\r |
379 | if (jTable.isEditing()) {\r | |
380 | jTable.getCellEditor().stopCellEditing();\r | |
381 | }\r | |
382 | if (selectedRow > -1) {\r | |
383 | this.model.removeRow(selectedRow);\r | |
384 | this.vLibraryClass.removeLibraryClass(selectedRow);\r | |
385 | selectedRow = -1;\r | |
386 | this.save();\r | |
387 | }\r | |
388 | }\r | |
a13899c5 | 389 | }\r |
390 | \r | |
391 | /**\r | |
06a19cee | 392 | Clear all table rows\r |
a13899c5 | 393 | \r |
394 | **/\r | |
06a19cee | 395 | private void clearAll() {\r |
396 | if (model != null) {\r | |
397 | for (int index = model.getRowCount() - 1; index >= 0; index--) {\r | |
398 | model.removeRow(index);\r | |
399 | }\r | |
a13899c5 | 400 | }\r |
a13899c5 | 401 | }\r |
402 | \r | |
403 | /**\r | |
06a19cee | 404 | Read content of vector and put then into table\r |
a13899c5 | 405 | \r |
406 | **/\r | |
06a19cee | 407 | private void showTable() {\r |
408 | clearAll();\r | |
409 | \r | |
a13899c5 | 410 | if (vLibraryClass.size() > 0) {\r |
06a19cee | 411 | for (int index = 0; index < vLibraryClass.size(); index++) {\r |
412 | model.addRow(vLibraryClass.toStringVector(index));\r | |
413 | }\r | |
a13899c5 | 414 | }\r |
06a19cee | 415 | this.jTable.repaint();\r |
416 | this.jTable.updateUI();\r | |
417 | //this.jScrollPane.setViewportView(this.jTable);\r | |
a13899c5 | 418 | }\r |
419 | \r | |
06a19cee | 420 | /* (non-Javadoc)\r |
421 | * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r | |
422 | *\r | |
423 | */\r | |
424 | public void valueChanged(ListSelectionEvent arg0) {\r | |
425 | if (arg0.getValueIsAdjusting()) {\r | |
426 | return;\r | |
427 | }\r | |
428 | ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r | |
429 | if (lsm.isSelectionEmpty()) {\r | |
430 | return;\r | |
431 | } else {\r | |
432 | selectedRow = lsm.getMinSelectionIndex();\r | |
a13899c5 | 433 | }\r |
a13899c5 | 434 | }\r |
435 | \r | |
436 | /* (non-Javadoc)\r | |
06a19cee | 437 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r |
a13899c5 | 438 | *\r |
a13899c5 | 439 | */\r |
06a19cee | 440 | public void mouseClicked(MouseEvent arg0) {\r |
441 | if (arg0.getClickCount() == 2) {\r | |
442 | if (this.selectedRow < 0) {\r | |
443 | return;\r | |
444 | } else {\r | |
445 | showEdit(selectedRow);\r | |
446 | }\r | |
a13899c5 | 447 | }\r |
448 | }\r | |
449 | \r | |
450 | /* (non-Javadoc)\r | |
451 | * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r | |
452 | * \r | |
453 | * Override componentResized to resize all components when frame's size is changed\r | |
454 | */\r | |
455 | public void componentResized(ComponentEvent arg0) {\r | |
456 | int intCurrentWidth = this.getJContentPane().getWidth();\r | |
457 | int intCurrentHeight = this.getJContentPane().getHeight();\r | |
458 | int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r | |
459 | int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r | |
460 | \r | |
06a19cee | 461 | resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight);\r |
462 | relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r | |
463 | DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r | |
464 | relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r | |
465 | DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r | |
466 | relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r | |
467 | DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r | |
a13899c5 | 468 | }\r |
469 | }\r |