Use table and popup window to add/edit all elements of module instead of original...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / LibraryClassDefsDlg.java
CommitLineData
06a19cee 1/** @file\r
2 \r
3 The file is used to create, update Library Class Definition 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.dialog;\r
16\r
17import java.awt.Dimension;\r
18import java.awt.event.ActionEvent;\r
19import java.util.Vector;\r
20\r
21import javax.swing.JButton;\r
22import javax.swing.JComboBox;\r
23import javax.swing.JLabel;\r
24import javax.swing.JPanel;\r
25import javax.swing.JScrollPane;\r
26import javax.swing.JTextField;\r
27\r
28import org.tianocore.frameworkwizard.common.DataType;\r
29import org.tianocore.frameworkwizard.common.DataValidation;\r
30import org.tianocore.frameworkwizard.common.EnumerationData;\r
31import org.tianocore.frameworkwizard.common.Log;\r
32import org.tianocore.frameworkwizard.common.Tools;\r
33import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r
34import org.tianocore.frameworkwizard.common.ui.IDialog;\r
35import org.tianocore.frameworkwizard.common.ui.IFrame;\r
36import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
37import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;\r
38import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassIdentification;\r
39import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
40\r
41/**\r
42 The class is used to create, update Library Class Definition of MSA/MBD file\r
43 It extends IInternalFrame\r
44 \r
45 **/\r
46public class LibraryClassDefsDlg extends IDialog {\r
47\r
48 ///\r
49 /// Define class Serial Version UID\r
50 ///\r
51 private static final long serialVersionUID = -1743248695411382857L;\r
52\r
53 //\r
54 //Define class members\r
55 //\r
56 private JPanel jContentPane = null;\r
57\r
58 private JComboBox jComboBoxLibraryClassName = null;\r
59\r
60 private JLabel jLabelUsage = null;\r
61\r
62 private JComboBox jComboBoxUsage = null;\r
63\r
64 private JLabel jLabelLibraryClassName = null;\r
65\r
66 private JScrollPane jScrollPane = null;\r
67\r
68 private StarLabel jStarLabel1 = null;\r
69\r
70 private StarLabel jStarLabel2 = null;\r
71\r
72 private JLabel jLabelRecommendedInstanceVersion = null;\r
73\r
74 private JTextField jTextFieldRecommendedInstanceVersion = null;\r
75\r
76 private JLabel jLabelRecommendedInstanceGuid = null;\r
77\r
78 private JTextField jTextFieldRecommendedInstanceGuid = null;\r
79\r
80 private JButton jButtonGenerateGuid = null;\r
81\r
82 private JLabel jLabelFeatureFlag = null;\r
83\r
84 private JTextField jTextFieldFeatureFlag = null;\r
85\r
86 private JLabel jLabelArch = null;\r
87\r
88 private JLabel jLabelModuleList = null;\r
89\r
90 private JScrollPane jScrollPaneModuleList = null;\r
91\r
92 private ICheckBoxList iCheckBoxListModule = null;\r
93\r
94 private JLabel jLabelHelpText = null;\r
95\r
96 private JTextField jTextFieldHelpText = null;\r
97\r
98 private ArchCheckBox jArchCheckBox = null;\r
99 \r
100 private JButton jButtonOk = null;\r
101\r
102 private JButton jButtonCancel = null;\r
103\r
104 //\r
105 // Not for UI\r
106 //\r
107 private EnumerationData ed = new EnumerationData();\r
108\r
109 private WorkspaceTools wt = new WorkspaceTools();\r
110\r
111 private LibraryClassIdentification lcid = null;\r
112\r
113 /**\r
114 This method initializes jComboBoxSelect \r
115 \r
116 @return javax.swing.JComboBox jComboBoxSelect\r
117 \r
118 **/\r
119 private JComboBox getJComboBoxLibraryClassName() {\r
120 if (jComboBoxLibraryClassName == null) {\r
121 jComboBoxLibraryClassName = new JComboBox();\r
122 jComboBoxLibraryClassName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r
123 jComboBoxLibraryClassName.setPreferredSize(new Dimension(320, 20));\r
124 jComboBoxLibraryClassName.setEnabled(true);\r
125 }\r
126 return jComboBoxLibraryClassName;\r
127 }\r
128\r
129 /**\r
130 This method initializes jComboBoxUsage \r
131 \r
132 @return javax.swing.JComboBox jComboBoxUsage\r
133 \r
134 **/\r
135 private JComboBox getJComboBoxUsage() {\r
136 if (jComboBoxUsage == null) {\r
137 jComboBoxUsage = new JComboBox();\r
138 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r
139 jComboBoxUsage.setPreferredSize(new Dimension(320, 20));\r
140 }\r
141 return jComboBoxUsage;\r
142 }\r
143\r
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
158 * This method initializes jTextFieldRecommendedInstanceVersion \r
159 * \r
160 * @return javax.swing.JTextField \r
161 */\r
162 private JTextField getJTextFieldRecommendedInstanceVersion() {\r
163 if (jTextFieldRecommendedInstanceVersion == null) {\r
164 jTextFieldRecommendedInstanceVersion = new JTextField();\r
165 jTextFieldRecommendedInstanceVersion.setPreferredSize(new java.awt.Dimension(260, 20));\r
166 jTextFieldRecommendedInstanceVersion.setSize(new java.awt.Dimension(260, 20));\r
167 jTextFieldRecommendedInstanceVersion.setLocation(new java.awt.Point(220, 85));\r
168 jTextFieldRecommendedInstanceVersion.setVisible(false);\r
169 }\r
170 return jTextFieldRecommendedInstanceVersion;\r
171 }\r
172\r
173 /**\r
174 * This method initializes jTextFieldRecommendedInstanceGuid \r
175 * \r
176 * @return javax.swing.JTextField \r
177 */\r
178 private JTextField getJTextFieldRecommendedInstanceGuid() {\r
179 if (jTextFieldRecommendedInstanceGuid == null) {\r
180 jTextFieldRecommendedInstanceGuid = new JTextField();\r
181 jTextFieldRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(220, 110, 190, 20));\r
182 jTextFieldRecommendedInstanceGuid.setPreferredSize(new java.awt.Dimension(190, 20));\r
183 jTextFieldRecommendedInstanceGuid.setVisible(false);\r
184 }\r
185 return jTextFieldRecommendedInstanceGuid;\r
186 }\r
187\r
188 /**\r
189 * This method initializes jButtonGenerateGuid \r
190 * \r
191 * @return javax.swing.JButton \r
192 */\r
193 private JButton getJButtonGenerateGuid() {\r
194 if (jButtonGenerateGuid == null) {\r
195 jButtonGenerateGuid = new JButton();\r
196 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 110, 65, 20));\r
197 jButtonGenerateGuid.setPreferredSize(new java.awt.Dimension(65, 20));\r
198 jButtonGenerateGuid.setText("GEN");\r
199 jButtonGenerateGuid.setVisible(false);\r
200 jButtonGenerateGuid.addActionListener(this);\r
201 }\r
202 return jButtonGenerateGuid;\r
203 }\r
204\r
205 /**\r
206 * This method initializes jTextFieldFeatureFlag \r
207 * \r
208 * @return javax.swing.JTextField \r
209 */\r
210 private JTextField getJTextFieldFeatureFlag() {\r
211 if (jTextFieldFeatureFlag == null) {\r
212 jTextFieldFeatureFlag = new JTextField();\r
213 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r
214 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r
215 }\r
216 return jTextFieldFeatureFlag;\r
217 }\r
218\r
219 /**\r
220 This method initializes iCheckBoxListArch \r
221 \r
222 @return ICheckBoxList \r
223 **/\r
224 private ICheckBoxList getICheckBoxListSupModuleList() {\r
225 if (iCheckBoxListModule == null) {\r
226 iCheckBoxListModule = new ICheckBoxList();\r
227 }\r
228 return iCheckBoxListModule;\r
229 }\r
230\r
231 /**\r
232 This method initializes jScrollPaneModuleList \r
233 \r
234 @return javax.swing.JScrollPane \r
235 \r
236 **/\r
237 private JScrollPane getJScrollPaneModuleList() {\r
238 if (jScrollPaneModuleList == null) {\r
239 jScrollPaneModuleList = new JScrollPane();\r
240 jScrollPaneModuleList.setBounds(new java.awt.Rectangle(160, 135, 320, 80));\r
241 jScrollPaneModuleList.setPreferredSize(new java.awt.Dimension(320, 80));\r
242 jScrollPaneModuleList.setViewportView(getICheckBoxListSupModuleList());\r
243 }\r
244 return jScrollPaneModuleList;\r
245 }\r
246\r
247 /**\r
248 This method initializes jTextFieldHelpText \r
249 \r
250 @return javax.swing.JTextField \r
251 \r
252 **/\r
253 private JTextField getJTextFieldHelpText() {\r
254 if (jTextFieldHelpText == null) {\r
255 jTextFieldHelpText = new JTextField();\r
256 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 60, 320, 20));\r
257 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));\r
258 }\r
259 return jTextFieldHelpText;\r
260 }\r
261\r
262 /**\r
263 This method initializes jButtonOk \r
264 \r
265 @return javax.swing.JButton \r
266 \r
267 **/\r
268 private JButton getJButtonOk() {\r
269 if (jButtonOk == null) {\r
270 jButtonOk = new JButton();\r
271 jButtonOk.setBounds(new java.awt.Rectangle(290, 225, 90, 20));\r
272 jButtonOk.setText("Ok");\r
273 jButtonOk.addActionListener(this);\r
274 }\r
275 return jButtonOk;\r
276 }\r
277\r
278 /**\r
279 This method initializes jButtonCancel \r
280 \r
281 @return javax.swing.JButton \r
282 \r
283 **/\r
284 private JButton getJButtonCancel() {\r
285 if (jButtonCancel == null) {\r
286 jButtonCancel = new JButton();\r
287 jButtonCancel.setBounds(new java.awt.Rectangle(390, 225, 90, 20));\r
288 jButtonCancel.setText("Cancel");\r
289 jButtonCancel.addActionListener(this);\r
290 }\r
291 return jButtonCancel;\r
292 }\r
293\r
294 public static void main(String[] args) {\r
295\r
296 }\r
297\r
298 /**\r
299 This is the default constructor\r
300 \r
301 **/\r
302 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification, IFrame iFrame) {\r
303 super(iFrame, true);\r
304 init(inLibraryClassIdentification);\r
305 }\r
306\r
307 /**\r
308 This method initializes this\r
309 \r
310 **/\r
311 private void init() {\r
312 this.setContentPane(getJScrollPane());\r
313 this.setTitle("Library Class Definitions");\r
314 this.setBounds(new java.awt.Rectangle(0, 0, 500, 295));\r
315 initFrame();\r
316 this.setViewMode(false);\r
317 this.centerWindow();\r
318 }\r
319\r
320 /**\r
321 This method initializes this\r
322 \r
323 **/\r
324 private void init(LibraryClassIdentification inLibraryClassIdentification) {\r
325 init();\r
326 this.lcid = inLibraryClassIdentification;\r
327 if (lcid != null) {\r
328 this.jComboBoxLibraryClassName.setSelectedItem(lcid.getLibraryClassName());\r
329 this.jComboBoxUsage.setSelectedItem(lcid.getUsage());\r
330 this.jTextFieldRecommendedInstanceVersion.setText(lcid.getRecommendedInstanceVersion());\r
331 this.jTextFieldRecommendedInstanceGuid.setText(lcid.getRecommendedInstanceGuid());\r
332 this.jTextFieldFeatureFlag.setText(lcid.getFeatureFlag());\r
333 this.jArchCheckBox.setSelectedItems(lcid.getSupArchList());\r
334 this.iCheckBoxListModule.setAllItemsUnchecked();\r
335 this.iCheckBoxListModule.initCheckedItem(true, lcid.getSupModuleList());\r
336 this.jTextFieldHelpText.setText(lcid.getHelp());\r
337 }\r
338 }\r
339\r
340 /**\r
341 Disable all components when the mode is view\r
342 \r
343 @param isView true - The view mode; false - The non-view mode\r
344 \r
345 **/\r
346 public void setViewMode(boolean isView) {\r
347 if (isView) {\r
348 this.jComboBoxLibraryClassName.setEnabled(!isView);\r
349 this.jComboBoxUsage.setEnabled(!isView);\r
350 }\r
351 }\r
352\r
353 /**\r
354 This method initializes jContentPane\r
355 \r
356 @return javax.swing.JPanel jContentPane\r
357 \r
358 **/\r
359 private JPanel getJContentPane() {\r
360 if (jContentPane == null) {\r
361 jArchCheckBox = new ArchCheckBox();\r
362 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 110, 320, 20));\r
363 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r
364 jLabelHelpText = new JLabel();\r
365 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 140, 20));\r
366 jLabelHelpText.setText("Help Text");\r
367 jLabelModuleList = new JLabel();\r
368 jLabelModuleList.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r
369 jLabelModuleList.setText("Sup Module List");\r
370 jLabelArch = new JLabel();\r
371 jLabelArch.setBounds(new java.awt.Rectangle(15, 110, 140, 20));\r
372 jLabelArch.setText("Sup Arch List");\r
373 jLabelFeatureFlag = new JLabel();\r
374 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 85, 140, 20));\r
375 jLabelFeatureFlag.setText("Feature Flag");\r
376 jLabelRecommendedInstanceGuid = new JLabel();\r
377 jLabelRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(15, 110, 200, 20));\r
378 jLabelRecommendedInstanceGuid.setText("Recommended Instance Guid");\r
379 jLabelRecommendedInstanceGuid.setVisible(false);\r
380 jLabelRecommendedInstanceVersion = new JLabel();\r
381 jLabelRecommendedInstanceVersion.setBounds(new java.awt.Rectangle(15, 85, 200, 20));\r
382 jLabelRecommendedInstanceVersion.setText("Recommended Instance Version");\r
383 jLabelRecommendedInstanceVersion.setVisible(false);\r
384 jLabelLibraryClassName = new JLabel();\r
385 jLabelLibraryClassName.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r
386 jLabelLibraryClassName.setText("Library Class Name");\r
387 jLabelUsage = new JLabel();\r
388 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r
389 jLabelUsage.setText("Usage");\r
390 jContentPane = new JPanel();\r
391 jContentPane.setLayout(null);\r
392 jContentPane.setPreferredSize(new java.awt.Dimension(490, 245));\r
393\r
394 jContentPane.add(getJComboBoxLibraryClassName(), null);\r
395 jContentPane.add(jLabelUsage, null);\r
396 jContentPane.add(getJComboBoxUsage(), null);\r
397 jContentPane.add(jLabelLibraryClassName, null);\r
398 jContentPane.add(jLabelRecommendedInstanceVersion, null);\r
399 jContentPane.add(getJTextFieldRecommendedInstanceVersion(), null);\r
400 jContentPane.add(jLabelRecommendedInstanceGuid, null);\r
401 jContentPane.add(getJTextFieldRecommendedInstanceGuid(), null);\r
402 jContentPane.add(getJButtonGenerateGuid(), null);\r
403 jContentPane.add(jLabelFeatureFlag, null);\r
404 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
405 jContentPane.add(jLabelArch, null);\r
406 jStarLabel1 = new StarLabel();\r
407 jStarLabel1.setLocation(new java.awt.Point(0, 10));\r
408 jStarLabel2 = new StarLabel();\r
409 jStarLabel2.setLocation(new java.awt.Point(0, 35));\r
410\r
411 jContentPane.add(jStarLabel1, null);\r
412 jContentPane.add(jStarLabel2, null);\r
413 jContentPane.add(jLabelModuleList, null);\r
414 jContentPane.add(getJScrollPaneModuleList(), null);\r
415 jContentPane.add(jLabelHelpText, null);\r
416 jContentPane.add(getJTextFieldHelpText(), null);\r
417 jContentPane.add(jArchCheckBox, null);\r
418 jContentPane.add(getJButtonOk(), null);\r
419 jContentPane.add(getJButtonCancel(), null);\r
420 }\r
421 return jContentPane;\r
422 }\r
423\r
424 /**\r
425 This method initializes all existing libraries and usage types\r
426 \r
427 **/\r
428 private void initFrame() {\r
429 Tools.generateComboBoxByVector(jComboBoxLibraryClassName, wt.getAllLibraryClassDefinitionsFromWorkspace());\r
430 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVLibraryUsage());\r
431 this.iCheckBoxListModule.setAllItems(ed.getVFrameworkModuleTypes());\r
432 }\r
433\r
434 /* (non-Javadoc)\r
435 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
436 *\r
437 * Override actionPerformed to listen all actions\r
438 * \r
439 */\r
440 public void actionPerformed(ActionEvent arg0) {\r
441 if (arg0.getSource() == jButtonGenerateGuid) {\r
442 this.jTextFieldRecommendedInstanceGuid.setText(Tools.generateUuidString());\r
443 }\r
444\r
445 if (arg0.getSource() == jButtonOk) {\r
446 if (checkAdd()) {\r
447 getCurrentLibraryClass();\r
448 this.returnType = DataType.RETURN_TYPE_OK;\r
449 this.setVisible(false);\r
450 }\r
451 }\r
452\r
453 if (arg0.getSource() == jButtonCancel) {\r
454 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
455 this.setVisible(false);\r
456 }\r
457 }\r
458\r
459 /**\r
460 Data validation for all fields\r
461 \r
462 @retval true - All datas are valid\r
463 @retval false - At least one data is invalid\r
464 \r
465 **/\r
466 public boolean checkAdd() {\r
467 //\r
468 // Check LibraryClass\r
469 //\r
470 if (this.jComboBoxLibraryClassName.getSelectedItem() == null) {\r
471 Log.err("No Library Class can be added");\r
472 return false;\r
473 }\r
474 if (!DataValidation.isLibraryClass(this.jComboBoxLibraryClassName.getSelectedItem().toString())) {\r
475 Log.err("Incorrect data type for Library Class");\r
476 return false;\r
477 }\r
478\r
479 //\r
480 // Check RecommendedInstanceVersion\r
481 //\r
482 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {\r
483 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {\r
484 // Log.err("Incorrect data type for Recommended Instance Version");\r
485 // return false;\r
486 // }\r
487 // }\r
488\r
489 //\r
490 // Check RecommendedInstanceGuid\r
491 //\r
492 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {\r
493 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {\r
494 // Log.err("Incorrect data type for Recommended Instance Guid");\r
495 // return false;\r
496 // }\r
497 // }\r
498\r
499 //\r
500 // Check FeatureFlag\r
501 //\r
502 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
503 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
504 Log.err("Incorrect data type for Feature Flag");\r
505 return false;\r
506 }\r
507 }\r
508\r
509 return true;\r
510 }\r
511\r
512 private LibraryClassIdentification getCurrentLibraryClass() {\r
513 String name = this.jComboBoxLibraryClassName.getSelectedItem().toString();\r
514 String usage = this.jComboBoxUsage.getSelectedItem().toString();\r
515 String version = this.jTextFieldRecommendedInstanceVersion.getText();\r
516 String guid = this.jTextFieldRecommendedInstanceGuid.getText();\r
517 String featureFlag = this.jTextFieldFeatureFlag.getText();\r
518 Vector<String> arch = this.jArchCheckBox.getSelectedItemsVector();\r
519 Vector<String> module = this.iCheckBoxListModule.getAllCheckedItemsString();\r
520 String help = this.jTextFieldHelpText.getText();\r
521 lcid = new LibraryClassIdentification(name, usage, version, guid, arch, featureFlag, module, help);\r
522 return lcid;\r
523 }\r
524\r
525 public LibraryClassIdentification getLcid() {\r
526 return lcid;\r
527 }\r
528\r
529 public void setLcid(LibraryClassIdentification lcid) {\r
530 this.lcid = lcid;\r
531 }\r
532}\r