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