]>
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 | |
102 | jButtonAdd.setBounds(new java.awt.Rectangle(230, 220, 80, 20));\r | |
103 | jButtonAdd.setText("Add");\r | |
104 | jButtonAdd.addActionListener(this);\r | |
105 | jButtonAdd.setPreferredSize(new java.awt.Dimension(80, 20));\r | |
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 | |
119 | jButtonRemove.setBounds(new java.awt.Rectangle(400, 220, 80, 20));\r | |
120 | jButtonRemove.setText("Remove");\r | |
121 | jButtonRemove.addActionListener(this);\r | |
122 | jButtonRemove.setPreferredSize(new java.awt.Dimension(80, 20));\r | |
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 | |
136 | jButtonUpdate.setBounds(new java.awt.Rectangle(315, 220, 80, 20));\r | |
137 | jButtonUpdate.setPreferredSize(new java.awt.Dimension(80, 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 | |
224 | String arg0 = variables.getVariableList().get(index).getVariableName();\r | |
225 | String arg1 = variables.getVariableList().get(index).getGuidCName();\r | |
226 | String arg2 = null;\r | |
227 | if (variables.getVariableList().get(index).getUsage() != null) {\r | |
228 | arg2 = variables.getVariableList().get(index).getUsage().toString();\r | |
229 | }\r | |
a13899c5 | 230 | \r |
06a19cee | 231 | String arg3 = variables.getVariableList().get(index).getFeatureFlag();\r |
232 | Vector<String> arg4 = Tools.convertListToVector(variables.getVariableList().get(index)\r | |
233 | .getSupArchList());\r | |
234 | String arg5 = variables.getVariableList().get(index).getHelpText();\r | |
235 | id = new VariablesIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r | |
236 | vid.addVariables(id);\r | |
237 | }\r | |
238 | }\r | |
239 | }\r | |
240 | showTable();\r | |
a13899c5 | 241 | }\r |
a13899c5 | 242 | \r |
243 | /**\r | |
244 | This is the default constructor\r | |
245 | \r | |
246 | **/\r | |
247 | public ModuleVariables() {\r | |
248 | super();\r | |
249 | init();\r | |
250 | this.setVisible(true);\r | |
251 | }\r | |
252 | \r | |
253 | /**\r | |
254 | This is the override edit constructor\r | |
255 | \r | |
256 | @param inVariables The input data of VariablesDocument.Variables\r | |
257 | \r | |
258 | **/\r | |
259 | public ModuleVariables(OpeningModuleType inOmt) {\r | |
260 | super();\r | |
261 | this.omt = inOmt;\r | |
262 | this.msa = omt.getXmlMsa();\r | |
263 | init(msa.getVariables());\r | |
264 | this.setVisible(true);\r | |
265 | }\r | |
266 | \r | |
a13899c5 | 267 | /**\r |
268 | This method initializes jContentPane\r | |
269 | \r | |
270 | @return javax.swing.JPanel jContentPane\r | |
271 | \r | |
272 | **/\r | |
273 | private JPanel getJContentPane() {\r | |
274 | if (jContentPane == null) {\r | |
a13899c5 | 275 | jContentPane = new JPanel();\r |
276 | jContentPane.setLayout(null);\r | |
06a19cee | 277 | jContentPane.setPreferredSize(new java.awt.Dimension(490, 490));\r |
278 | \r | |
a13899c5 | 279 | jContentPane.add(getJButtonAdd(), null);\r |
280 | jContentPane.add(getJButtonRemove(), null);\r | |
281 | jContentPane.add(getJButtonUpdate(), null);\r | |
06a19cee | 282 | jContentPane.add(getJScrollPaneTable(), null);\r |
a13899c5 | 283 | }\r |
284 | return jContentPane;\r | |
285 | }\r | |
286 | \r | |
06a19cee | 287 | private void showEdit(int index) {\r |
288 | VariablesDlg dlg = new VariablesDlg(vid.getVariables(index), new IFrame());\r | |
289 | int result = dlg.showDialog();\r | |
290 | if (result == DataType.RETURN_TYPE_OK) {\r | |
291 | if (index == -1) {\r | |
292 | this.vid.addVariables(dlg.getId());\r | |
293 | } else {\r | |
294 | this.vid.setVariables(dlg.getId(), index);\r | |
a13899c5 | 295 | }\r |
06a19cee | 296 | this.showTable();\r |
297 | this.save();\r | |
298 | dlg.dispose();\r | |
a13899c5 | 299 | }\r |
06a19cee | 300 | if (result == DataType.RETURN_TYPE_CANCEL) {\r |
301 | dlg.dispose();\r | |
a13899c5 | 302 | }\r |
303 | }\r | |
304 | \r | |
305 | /**\r | |
06a19cee | 306 | Clear all table rows\r |
a13899c5 | 307 | \r |
308 | **/\r | |
06a19cee | 309 | private void clearAll() {\r |
310 | if (model != null) {\r | |
311 | for (int index = model.getRowCount() - 1; index >= 0; index--) {\r | |
312 | model.removeRow(index);\r | |
313 | }\r | |
314 | }\r | |
a13899c5 | 315 | }\r |
316 | \r | |
317 | /**\r | |
06a19cee | 318 | Read content of vector and put then into table\r |
a13899c5 | 319 | \r |
320 | **/\r | |
06a19cee | 321 | private void showTable() {\r |
322 | clearAll();\r | |
323 | \r | |
324 | if (vid.size() > 0) {\r | |
325 | for (int index = 0; index < vid.size(); index++) {\r | |
326 | model.addRow(vid.toStringVector(index));\r | |
a13899c5 | 327 | }\r |
328 | }\r | |
06a19cee | 329 | this.jTable.repaint();\r |
330 | this.jTable.updateUI();\r | |
331 | }\r | |
332 | \r | |
333 | /* (non-Javadoc)\r | |
334 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
335 | *\r | |
336 | * Override actionPerformed to listen all actions\r | |
337 | * \r | |
338 | */\r | |
339 | public void actionPerformed(ActionEvent arg0) {\r | |
340 | if (arg0.getSource() == jButtonAdd) {\r | |
341 | showEdit(-1);\r | |
a13899c5 | 342 | }\r |
06a19cee | 343 | if (arg0.getSource() == jButtonUpdate) {\r |
344 | if (this.selectedRow < 0) {\r | |
ed1665f2 | 345 | Log.wrn("Update Variables", "Please select one record first.");\r |
06a19cee | 346 | return;\r |
a13899c5 | 347 | }\r |
06a19cee | 348 | showEdit(selectedRow);\r |
a13899c5 | 349 | }\r |
06a19cee | 350 | \r |
351 | if (arg0.getSource() == jButtonRemove) {\r | |
352 | if (jTable.isEditing()) {\r | |
353 | jTable.getCellEditor().stopCellEditing();\r | |
354 | }\r | |
355 | if (selectedRow > -1) {\r | |
356 | this.model.removeRow(selectedRow);\r | |
357 | this.vid.removeVariables(selectedRow);\r | |
358 | selectedRow = -1;\r | |
359 | this.save();\r | |
a13899c5 | 360 | }\r |
361 | }\r | |
a13899c5 | 362 | }\r |
363 | \r | |
364 | /**\r | |
365 | Save all components of Variables\r | |
366 | if exists variables, set the value directly\r | |
367 | if not exists variables, new an instance first\r | |
368 | \r | |
369 | **/\r | |
370 | public void save() {\r | |
371 | try {\r | |
372 | int count = this.vid.size();\r | |
373 | \r | |
374 | this.variables = Variables.Factory.newInstance();\r | |
375 | if (count > 0) {\r | |
376 | for (int index = 0; index < count; index++) {\r | |
377 | Variable p = Variable.Factory.newInstance();\r | |
378 | if (!isEmpty(vid.getVariables(index).getName())) {\r | |
379 | p.setVariableName(vid.getVariables(index).getName());\r | |
380 | }\r | |
381 | if (!isEmpty(vid.getVariables(index).getGuid())) {\r | |
382 | p.setGuidCName(vid.getVariables(index).getGuid());\r | |
383 | }\r | |
384 | if (!isEmpty(vid.getVariables(index).getUsage())) {\r | |
385 | p.setUsage(VariableUsage.Enum.forString(vid.getVariables(index).getUsage()));\r | |
386 | }\r | |
387 | if (!isEmpty(vid.getVariables(index).getFeatureFlag())) {\r | |
388 | p.setFeatureFlag(vid.getVariables(index).getFeatureFlag());\r | |
389 | }\r | |
06a19cee | 390 | if (vid.getVariables(index).getSupArchList() != null\r |
391 | && vid.getVariables(index).getSupArchList().size() > 0) {\r | |
a13899c5 | 392 | p.setSupArchList(vid.getVariables(index).getSupArchList());\r |
393 | }\r | |
394 | if (!isEmpty(vid.getVariables(index).getHelp())) {\r | |
395 | p.setHelpText(vid.getVariables(index).getHelp());\r | |
396 | }\r | |
397 | this.variables.addNewVariable();\r | |
398 | this.variables.setVariableArray(variables.getVariableList().size() - 1, p);\r | |
399 | }\r | |
400 | }\r | |
401 | \r | |
402 | this.msa.setVariables(variables);\r | |
403 | this.omt.setSaved(false);\r | |
404 | } catch (Exception e) {\r | |
ed1665f2 | 405 | Log.wrn("Update Variables", e.getMessage());\r |
a13899c5 | 406 | Log.err("Update Variables", e.getMessage());\r |
407 | }\r | |
408 | }\r | |
409 | \r | |
06a19cee | 410 | /* (non-Javadoc)\r |
411 | * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)\r | |
412 | *\r | |
413 | */\r | |
414 | public void valueChanged(ListSelectionEvent arg0) {\r | |
415 | if (arg0.getValueIsAdjusting()) {\r | |
416 | return;\r | |
417 | }\r | |
418 | ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();\r | |
419 | if (lsm.isSelectionEmpty()) {\r | |
420 | return;\r | |
421 | } else {\r | |
422 | selectedRow = lsm.getMinSelectionIndex();\r | |
423 | }\r | |
424 | }\r | |
425 | \r | |
426 | /* (non-Javadoc)\r | |
427 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)\r | |
428 | *\r | |
429 | */\r | |
430 | public void mouseClicked(MouseEvent arg0) {\r | |
431 | if (arg0.getClickCount() == 2) {\r | |
432 | if (this.selectedRow < 0) {\r | |
433 | return;\r | |
434 | } else {\r | |
435 | showEdit(selectedRow);\r | |
436 | }\r | |
437 | }\r | |
438 | }\r | |
439 | \r | |
a13899c5 | 440 | /* (non-Javadoc)\r |
441 | * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r | |
442 | * \r | |
443 | * Override componentResized to resize all components when frame's size is changed\r | |
444 | */\r | |
445 | public void componentResized(ComponentEvent arg0) {\r | |
446 | int intCurrentWidth = this.getJContentPane().getWidth();\r | |
447 | int intCurrentHeight = this.getJContentPane().getHeight();\r | |
448 | int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r | |
449 | int intPreferredHeight = this.getJContentPane().getPreferredSize().height;\r | |
450 | \r | |
06a19cee | 451 | resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight);\r |
452 | relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r | |
453 | DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);\r | |
454 | relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r | |
455 | DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);\r | |
456 | relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,\r | |
457 | DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);\r | |
a13899c5 | 458 | }\r |
a13899c5 | 459 | }\r |