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