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