]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/HobsDlg.java
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 / HobsDlg.java
CommitLineData
06a19cee 1/** @file\r
2 \r
3 The file is used to create, update Hob 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.event.ActionEvent;\r
18import java.util.Vector;\r
19\r
20import javax.swing.JButton;\r
21import javax.swing.JComboBox;\r
22import javax.swing.JLabel;\r
23import javax.swing.JPanel;\r
24import javax.swing.JScrollPane;\r
25import javax.swing.JTextField;\r
26\r
27import org.tianocore.frameworkwizard.common.DataType;\r
28import org.tianocore.frameworkwizard.common.DataValidation;\r
29import org.tianocore.frameworkwizard.common.EnumerationData;\r
30import org.tianocore.frameworkwizard.common.Log;\r
31import org.tianocore.frameworkwizard.common.Tools;\r
32import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r
33import org.tianocore.frameworkwizard.common.ui.IDialog;\r
34import org.tianocore.frameworkwizard.common.ui.IFrame;\r
35import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
36import org.tianocore.frameworkwizard.module.Identifications.Hobs.HobsIdentification;\r
37import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
38\r
39/**\r
40 The class is used to create, update Hob of MSA/MBD file\r
41 It extends IInternalFrame\r
42 \r
43 **/\r
44public class HobsDlg extends IDialog {\r
45\r
46 ///\r
47 /// Define class Serial Version UID\r
48 ///\r
49 private static final long serialVersionUID = -553473437579358325L;\r
50\r
51 //\r
52 //Define class members\r
53 //\r
54 private JPanel jContentPane = null;\r
55\r
56 private JLabel jLabel = null;\r
57\r
58 private JComboBox jComboBoxGuidC_Name = null;\r
59\r
60 private JLabel jLabelUsage = null;\r
61\r
62 private JLabel jLabelHobType = null;\r
63\r
64 private JComboBox jComboBoxUsage = null;\r
65\r
66 private JComboBox jComboBoxHobType = null;\r
67\r
68 private StarLabel jStarLabel1 = null;\r
69\r
70 private JLabel jLabelArch = null;\r
71\r
72 private JScrollPane jScrollPane = null;\r
73\r
74 private JLabel jLabelFeatureFlag = null;\r
75\r
76 private JTextField jTextFieldFeatureFlag = null;\r
77\r
78 private JLabel jLabelHelpText = null;\r
79\r
80 private JTextField jTextFieldHelpText = null;\r
81\r
82 private ArchCheckBox jArchCheckBox = null;\r
83\r
84 private JButton jButtonOk = null;\r
85\r
86 private JButton jButtonCancel = null;\r
87\r
88 //\r
89 // Not used by UI\r
90 //\r
91 private HobsIdentification id = null;\r
92\r
93 private EnumerationData ed = new EnumerationData();\r
94\r
95 private WorkspaceTools wt = new WorkspaceTools();\r
96\r
97 /**\r
98 This method initializes jTextField \r
99 \r
100 @return javax.swing.JTextField jTextFieldC_Name\r
101 \r
102 **/\r
103 private JComboBox getJComboBoxGuidC_Name() {\r
104 if (jComboBoxGuidC_Name == null) {\r
105 jComboBoxGuidC_Name = new JComboBox();\r
106 jComboBoxGuidC_Name.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r
107 jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));\r
108 jComboBoxGuidC_Name.setToolTipText("Select the GUID C Name of the Hob");\r
109 }\r
110 return jComboBoxGuidC_Name;\r
111 }\r
112\r
113 /**\r
114 This method initializes jComboBoxUsage \r
115 \r
116 @return javax.swing.JComboBox jComboBoxUsage\r
117 \r
118 **/\r
119 private JComboBox getJComboBoxUsage() {\r
120 if (jComboBoxUsage == null) {\r
121 jComboBoxUsage = new JComboBox();\r
122 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 60, 320, 20));\r
123 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));\r
124 }\r
125 return jComboBoxUsage;\r
126 }\r
127\r
128 /**\r
129 This method initializes jComboBoxHobType \r
130 \r
131 @return javax.swing.JComboBox jComboBoxHobType\r
132 \r
133 **/\r
134 private JComboBox getJComboBoxHobType() {\r
135 if (jComboBoxHobType == null) {\r
136 jComboBoxHobType = new JComboBox();\r
137 jComboBoxHobType.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r
138 jComboBoxHobType.setPreferredSize(new java.awt.Dimension(320, 20));\r
139 }\r
140 return jComboBoxHobType;\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 jTextFieldFeatureFlag \r
158 * \r
159 * @return javax.swing.JTextField \r
160 */\r
161 private JTextField getJTextFieldFeatureFlag() {\r
162 if (jTextFieldFeatureFlag == null) {\r
163 jTextFieldFeatureFlag = new JTextField();\r
164 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 110, 320, 20));\r
165 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r
166 }\r
167 return jTextFieldFeatureFlag;\r
168 }\r
169\r
170 /**\r
171 This method initializes jTextFieldHelpText \r
172 \r
173 @return javax.swing.JTextField \r
174 \r
175 **/\r
176 private JTextField getJTextFieldHelpText() {\r
177 if (jTextFieldHelpText == null) {\r
178 jTextFieldHelpText = new JTextField();\r
179 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 85, 320, 20));\r
180 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));\r
181 }\r
182 return jTextFieldHelpText;\r
183 }\r
184\r
185 /**\r
186 This method initializes jButtonOk \r
187 \r
188 @return javax.swing.JButton \r
189 \r
190 **/\r
191 private JButton getJButtonOk() {\r
192 if (jButtonOk == null) {\r
193 jButtonOk = new JButton();\r
194 jButtonOk.setBounds(new java.awt.Rectangle(290, 165, 90, 20));\r
195 jButtonOk.setText("Ok");\r
196 jButtonOk.addActionListener(this);\r
197 }\r
198 return jButtonOk;\r
199 }\r
200\r
201 /**\r
202 This method initializes jButtonCancel \r
203 \r
204 @return javax.swing.JButton \r
205 \r
206 **/\r
207 private JButton getJButtonCancel() {\r
208 if (jButtonCancel == null) {\r
209 jButtonCancel = new JButton();\r
210 jButtonCancel.setBounds(new java.awt.Rectangle(390, 165, 90, 20));\r
211 jButtonCancel.setText("Cancel");\r
212 jButtonCancel.addActionListener(this);\r
213 }\r
214 return jButtonCancel;\r
215 }\r
216\r
217 public static void main(String[] args) {\r
218\r
219 }\r
220\r
221 /**\r
222 This method initializes this\r
223 \r
224 **/\r
225 private void init() {\r
226 this.setSize(500, 225);\r
227 this.setContentPane(getJScrollPane());\r
228 this.setTitle("Hobs");\r
229 initFrame();\r
230 this.setViewMode(false);\r
231 this.centerWindow();\r
232 }\r
233\r
234 /**\r
235 This method initializes this\r
236 Fill values to all fields if these values are not empty\r
237 \r
238 @param inHobsId\r
239\r
240 **/\r
241 private void init(HobsIdentification inHobsId) {\r
242 init();\r
243 this.id = inHobsId;\r
244\r
245 if (this.id != null) {\r
246 this.jComboBoxGuidC_Name.setSelectedItem(id.getName());\r
247 this.jComboBoxHobType.setSelectedItem(id.getType());\r
248 this.jComboBoxUsage.setSelectedItem(id.getUsage());\r
249 this.jTextFieldHelpText.setText(id.getHelp());\r
250 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());\r
251 this.jArchCheckBox.setSelectedItems(id.getSupArchList());\r
252 }\r
253 }\r
254\r
255 /**\r
256 This is the override edit constructor\r
257 \r
258 @param inHobsIdentification\r
259 @param iFrame\r
260 \r
261 **/\r
262 public HobsDlg(HobsIdentification inHobsIdentification, IFrame iFrame) {\r
263 super(iFrame, true);\r
264 init(inHobsIdentification);\r
265 }\r
266\r
267 /**\r
268 Disable all components when the mode is view\r
269 \r
270 @param isView true - The view mode; false - The non-view mode\r
271 \r
272 **/\r
273 public void setViewMode(boolean isView) {\r
274 if (isView) {\r
275 this.jComboBoxGuidC_Name.setEnabled(!isView);\r
276 this.jComboBoxUsage.setEnabled(!isView);\r
277 this.jComboBoxHobType.setEnabled(!isView);\r
278 }\r
279 }\r
280\r
281 /**\r
282 This method initializes jContentPane\r
283 \r
284 @return javax.swing.JPanel jContentPane\r
285 \r
286 **/\r
287 public JPanel getJContentPane() {\r
288 if (jContentPane == null) {\r
289 jArchCheckBox = new ArchCheckBox();\r
290 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 135, 320, 20));\r
291 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r
292 jLabelFeatureFlag = new JLabel();\r
293 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 110, 140, 20));\r
294 jLabelFeatureFlag.setText("Feature Flag");\r
295 jLabelArch = new JLabel();\r
296 jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 140, 20));\r
297 jLabelArch.setText("Arch");\r
298 jLabelHobType = new JLabel();\r
299 jLabelHobType.setText("Hob Type");\r
300 jLabelHobType.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r
301 jLabelUsage = new JLabel();\r
302 jLabelUsage.setText("Usage");\r
303 jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r
304 jLabel = new JLabel();\r
305 jLabel.setText("Guid C_Name");\r
306 jLabel.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r
307 jLabelHelpText = new JLabel();\r
308 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 85, 140, 20));\r
309 jLabelHelpText.setText("Help Text");\r
310\r
311 jContentPane = new JPanel();\r
312 jContentPane.setLayout(null);\r
313 jContentPane.setPreferredSize(new java.awt.Dimension(490, 190));\r
314\r
315 jContentPane.add(jLabel, null);\r
316 jContentPane.add(getJComboBoxGuidC_Name(), null);\r
317 jContentPane.add(jLabelUsage, null);\r
318 jContentPane.add(jLabelHobType, null);\r
319 jContentPane.add(getJComboBoxUsage(), null);\r
320 jContentPane.add(getJComboBoxHobType(), null);\r
321 jStarLabel1 = new StarLabel();\r
322 jStarLabel1.setLocation(new java.awt.Point(0, 10));\r
323 jContentPane.add(jStarLabel1, null);\r
324\r
325 jContentPane.add(jLabelArch, null);\r
326\r
327 jContentPane.add(jLabelFeatureFlag, null);\r
328 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
329 jContentPane.add(jLabelHelpText, null);\r
330 jContentPane.add(getJTextFieldHelpText(), null);\r
331 jContentPane.add(jArchCheckBox, null);\r
332 jContentPane.add(getJButtonOk(), null);\r
333 jContentPane.add(getJButtonCancel(), null);\r
334 }\r
335 return jContentPane;\r
336 }\r
337\r
338 /**\r
339 This method initializes Usage type and Hob type\r
340 \r
341 **/\r
342 private void initFrame() {\r
343 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHobUsage());\r
344 Tools.generateComboBoxByVector(jComboBoxHobType, ed.getVHobType());\r
345 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());\r
346 }\r
347\r
348 /* (non-Javadoc)\r
349 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
350 *\r
351 * Override actionPerformed to listen all actions\r
352 * \r
353 */\r
354 public void actionPerformed(ActionEvent arg0) {\r
355 if (arg0.getSource() == jButtonOk) {\r
356 if (checkAdd()) {\r
357 getCurrentHobs();\r
358 this.returnType = DataType.RETURN_TYPE_OK;\r
359 this.setVisible(false);\r
360 }\r
361 }\r
362\r
363 if (arg0.getSource() == jButtonCancel) {\r
364 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
365 this.setVisible(false);\r
366 }\r
367 }\r
368\r
369 /**\r
370 Data validation for all fields\r
371 \r
372 @retval true - All datas are valid\r
373 @retval false - At least one data is invalid\r
374 \r
375 **/\r
376 public boolean checkAdd() {\r
377 //\r
378 // Check if all fields have correct data types \r
379 //\r
380\r
381 //\r
382 // Check Name \r
383 //\r
384 if (isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r
385 Log.err("Hob Name couldn't be empty");\r
386 return false;\r
387 }\r
388\r
389 if (!isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r
390 if (!DataValidation.isC_NameType(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {\r
391 Log.err("Incorrect data type for Hob Name");\r
392 return false;\r
393 }\r
394 }\r
395\r
396 //\r
397 // Check FeatureFlag\r
398 //\r
399 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
400 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
401 Log.err("Incorrect data type for Feature Flag");\r
402 return false;\r
403 }\r
404 }\r
405\r
406 return true;\r
407 }\r
408\r
409 private HobsIdentification getCurrentHobs() {\r
410 String arg0 = this.jComboBoxGuidC_Name.getSelectedItem().toString();\r
411 String arg1 = this.jComboBoxHobType.getSelectedItem().toString();\r
412 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();\r
413\r
414 String arg3 = this.jTextFieldFeatureFlag.getText();\r
415 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();\r
416 String arg5 = this.jTextFieldHelpText.getText();\r
417 id = new HobsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);\r
418 return id;\r
419 }\r
420\r
421 public HobsIdentification getId() {\r
422 return id;\r
423 }\r
424\r
425 public void setId(HobsIdentification id) {\r
426 this.id = id;\r
427 }\r
428}\r