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