]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/GuidsDlg.java
Fixed spacing for Linux and iMac display
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / GuidsDlg.java
CommitLineData
06a19cee 1/** @file\r
5b38b75b 2 <<The file is used to create, update Guids of the MSA file>>\r
06a19cee 3 \r
4 Copyright (c) 2006, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9 \r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12 \r
13 **/\r
14package org.tianocore.frameworkwizard.module.ui.dialog;\r
15\r
16import java.awt.event.ActionEvent;\r
17import java.util.Vector;\r
18\r
19import javax.swing.JButton;\r
20import javax.swing.JComboBox;\r
21import javax.swing.JLabel;\r
22import javax.swing.JPanel;\r
23import javax.swing.JScrollPane;\r
24import javax.swing.JTextField;\r
5b38b75b 25import javax.swing.JTextArea;\r
06a19cee 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.Guids.GuidsIdentification;\r
37import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r
38\r
39/**\r
5b38b75b 40 * The class is used to create, update Guids of the MSA file\r
41 * \r
42 * It extends IDialog\r
43 * \r
44 */\r
45public class GuidsDlg extends IDialog {\r
06a19cee 46\r
a929458e 47 // /\r
48 // / Define class Serial Version UID\r
49 // /\r
50 private static final long serialVersionUID = 6710858997766979803L;\r
06a19cee 51\r
a929458e 52 //\r
53 // Define class members\r
54 //\r
55 private JPanel jContentPane = null;\r
06a19cee 56\r
a929458e 57 private JLabel jLabelC_Name = null;\r
06a19cee 58\r
a929458e 59 private JComboBox jComboBoxCName = null;\r
06a19cee 60\r
a929458e 61 private JLabel jLabelUsage = null;\r
06a19cee 62\r
a929458e 63 private JComboBox jComboBoxUsage = null;\r
06a19cee 64\r
a929458e 65 private StarLabel jStarLabel1 = null;\r
06a19cee 66\r
a929458e 67 private StarLabel jStarLabel2 = null;\r
06a19cee 68\r
a929458e 69 private JLabel jLabelFeatureFlag = null;\r
06a19cee 70\r
a929458e 71 private JTextField jTextFieldFeatureFlag = null;\r
06a19cee 72\r
a929458e 73 private JLabel jLabelArch = null;\r
06a19cee 74\r
a929458e 75 private JScrollPane jScrollPane = null;\r
06a19cee 76\r
a929458e 77 private JLabel jLabelHelpText = null;\r
06a19cee 78\r
a929458e 79 private JTextArea jTextAreaHelpText = null;\r
06a19cee 80\r
a929458e 81 private JScrollPane jScrollPaneHelpText = null;\r
06a19cee 82\r
a929458e 83 private ArchCheckBox jArchCheckBox = null;\r
06a19cee 84\r
a929458e 85 private JButton jButtonOk = null;\r
06a19cee 86\r
a929458e 87 private JButton jButtonCancel = null;\r
06a19cee 88\r
a929458e 89 //\r
90 // Not used by UI\r
91 //\r
92 private GuidsIdentification id = null;\r
93\r
94 private EnumerationData ed = new EnumerationData();\r
95\r
96 private WorkspaceTools wt = new WorkspaceTools();\r
97\r
98 /**\r
99 * This method initializes jTextFieldC_Name\r
100 * \r
101 * @return javax.swing.JTextField jTextFieldC_Name\r
102 * \r
103 */\r
104 private JComboBox getJComboBoxCName() {\r
105 if (jComboBoxCName == null) {\r
106 jComboBoxCName = new JComboBox();\r
107 jComboBoxCName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r
108 jComboBoxCName.setPreferredSize(new java.awt.Dimension(320, 20));\r
109 jComboBoxCName.setToolTipText("Select the C Name of the GUID");\r
110 }\r
111 return jComboBoxCName;\r
112 }\r
06a19cee 113\r
a929458e 114 /**\r
115 * This method initializes jComboBoxUsage\r
116 * \r
117 * @return javax.swing.JComboBox jComboBoxUsage\r
118 * \r
119 */\r
120 private JComboBox getJComboBoxUsage() {\r
121 if (jComboBoxUsage == null) {\r
122 jComboBoxUsage = new JComboBox();\r
123 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r
124 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));\r
125 jComboBoxUsage\r
126 .setToolTipText("<html><table>"\r
127 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the GUID</td></tr>"\r
128 + "<tr><td>SOMETIMES_CONSUMED</td><td>Module will use the GUID only if it is present</td></tr>"\r
129 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the GUID</td></tr>"\r
130 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module will sometimes produce the GUID</td></tr>"\r
131 + "<tr><td>DEFAULT</td><td>Default is the the GUID that specified the<br>instance of the package</td></tr>"\r
132 + "</table></html>");\r
133 }\r
134 return jComboBoxUsage;\r
06a19cee 135 }\r
a929458e 136\r
137 /**\r
138 * This method initializes jTextFieldFeatureFlag\r
139 * \r
140 * @return javax.swing.JTextField\r
141 * \r
142 */\r
143 private JTextField getJTextFieldFeatureFlag() {\r
144 if (jTextFieldFeatureFlag == null) {\r
145 jTextFieldFeatureFlag = new JTextField();\r
146 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 105, 320, 20));\r
147 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));\r
148 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");\r
149 }\r
150 return jTextFieldFeatureFlag;\r
06a19cee 151 }\r
a929458e 152\r
153 /**\r
154 * This method initializes jScrollPane\r
155 * \r
156 * @return javax.swing.JScrollPane\r
157 */\r
158 private JScrollPane getJScrollPane() {\r
159 if (jScrollPane == null) {\r
160 jScrollPane = new JScrollPane();\r
161 jScrollPane.setViewportView(getJContentPane());\r
162 }\r
163 return jScrollPane;\r
06a19cee 164 }\r
a929458e 165\r
166 /**\r
167 * This method initializes jTextAreaHelpText\r
168 * \r
169 * @return javax.swing.JTextArea\r
170 * \r
171 */\r
172 private JTextArea getJTextAreaHelpText() {\r
173 if (jTextAreaHelpText == null) {\r
174 jTextAreaHelpText = new JTextArea();\r
175 jTextAreaHelpText.setLineWrap(true);\r
176 jTextAreaHelpText.setWrapStyleWord(true);\r
177 }\r
178 return jTextAreaHelpText;\r
06a19cee 179 }\r
a929458e 180\r
181 /**\r
182 * \r
183 * This method initializes jScrollPaneHelpText\r
184 * \r
185 * @return javax.swing.JScrollPane jScrollPaneHelpText\r
186 * \r
187 **/\r
188 private JScrollPane getJScrollPaneHelpText() {\r
189 if (jScrollPaneHelpText == null) {\r
190 jScrollPaneHelpText = new JScrollPane();\r
191 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);\r
192 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));\r
193 jScrollPaneHelpText.setLocation(new java.awt.Point(160, 60));\r
194 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());\r
195 }\r
196 return jScrollPaneHelpText;\r
06a19cee 197 }\r
a929458e 198\r
199 /**\r
200 * This method initializes jButtonOk\r
201 * \r
202 * @return javax.swing.JButton\r
203 * \r
204 */\r
205 private JButton getJButtonOk() {\r
206 if (jButtonOk == null) {\r
207 jButtonOk = new JButton();\r
208 jButtonOk.setBounds(new java.awt.Rectangle(290, 157, 90, 20));\r
209 jButtonOk.setText("Ok");\r
210 jButtonOk.addActionListener(this);\r
211 }\r
212 return jButtonOk;\r
06a19cee 213 }\r
a929458e 214\r
215 /**\r
216 * This method initializes jButtonCancel\r
217 * \r
218 * @return javax.swing.JButton\r
219 * \r
220 */\r
221 private JButton getJButtonCancel() {\r
222 if (jButtonCancel == null) {\r
223 jButtonCancel = new JButton();\r
224 jButtonCancel.setBounds(new java.awt.Rectangle(390, 157, 90, 20));\r
225 jButtonCancel.setText("Cancel");\r
226 jButtonCancel.addActionListener(this);\r
227 }\r
228 return jButtonCancel;\r
06a19cee 229 }\r
a929458e 230\r
231 public static void main(String[] args) {\r
232\r
06a19cee 233 }\r
a929458e 234\r
235 /**\r
236 * \r
237 * This method initializes this\r
238 * \r
239 */\r
240 private void init() {\r
241 this.setSize(500, 230);\r
242 this.setContentPane(getJScrollPane());\r
243 this.setTitle("Guids");\r
244 initFrame();\r
245 this.setViewMode(false);\r
246 this.centerWindow();\r
06a19cee 247 }\r
a929458e 248\r
249 /**\r
250 * \r
251 * This method initializes this Fill values to all fields if these values are\r
252 * not empty\r
253 * \r
254 * @param inGuidsId\r
255 * \r
256 */\r
257 private void init(GuidsIdentification inGuidsId) {\r
258 init();\r
259 this.id = inGuidsId;\r
260\r
261 if (this.id != null) {\r
262 this.jComboBoxCName.setSelectedItem(id.getName());\r
263 this.jComboBoxUsage.setSelectedItem(id.getUsage());\r
264 this.jTextAreaHelpText.setText(id.getHelp());\r
265 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());\r
266 this.jArchCheckBox.setSelectedItems(id.getSupArchList());\r
267 }\r
06a19cee 268 }\r
a929458e 269\r
270 /**\r
271 * This is the override edit constructor\r
272 * \r
273 * @param inGuidsIdentification\r
274 * @param iFrame\r
275 * \r
276 */\r
277 public GuidsDlg(GuidsIdentification inGuidsIdentification, IFrame iFrame) {\r
278 super(iFrame, true);\r
279 init(inGuidsIdentification);\r
06a19cee 280 }\r
a929458e 281\r
282 /**\r
283 * Disable all components when the mode is view\r
284 * \r
285 * @param isView\r
286 * true - The view mode; false - The non-view mode\r
287 * \r
288 */\r
289 public void setViewMode(boolean isView) {\r
290 if (isView) {\r
291 this.jComboBoxUsage.setEnabled(!isView);\r
292 }\r
06a19cee 293 }\r
294\r
a929458e 295 /**\r
296 * This method initializes jContentPane\r
297 * \r
298 * @return javax.swing.JPanel jContentPane\r
299 * \r
300 */\r
301 private JPanel getJContentPane() {\r
302 if (jContentPane == null) {\r
303 jStarLabel1 = new StarLabel();\r
304 jStarLabel1.setLocation(new java.awt.Point(2, 10));\r
305 jLabelC_Name = new JLabel();\r
306 jLabelC_Name.setText("Select GUID's C Name");\r
307 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 10, 145, 20));\r
308\r
309 jStarLabel2 = new StarLabel();\r
310 jStarLabel2.setLocation(new java.awt.Point(2, 35));\r
311 jLabelUsage = new JLabel();\r
312 jLabelUsage.setText("Usage");\r
313 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 145, 20));\r
314\r
315 jLabelHelpText = new JLabel();\r
316 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 145, 20));\r
317 jLabelHelpText.setText("Help Text");\r
318\r
319 jLabelFeatureFlag = new JLabel();\r
320 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 105, 145, 20));\r
321 jLabelFeatureFlag.setText("Feature Flag Expression");\r
322\r
323 jLabelArch = new JLabel();\r
324 jLabelArch.setBounds(new java.awt.Rectangle(15, 130, 145, 20));\r
325 jLabelArch.setText("Supported Architectures");\r
326 jArchCheckBox = new ArchCheckBox();\r
327 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 130, 320, 20));\r
328 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));\r
329\r
330 jContentPane = new JPanel();\r
331 jContentPane.setLayout(null);\r
332 jContentPane.setPreferredSize(new java.awt.Dimension(490, 165));\r
333\r
334 jContentPane.add(jStarLabel1, null);\r
335 jContentPane.add(jLabelC_Name, null);\r
336 jContentPane.add(getJComboBoxCName(), null);\r
337 jContentPane.add(jStarLabel2, null);\r
338 jContentPane.add(jLabelUsage, null);\r
339 jContentPane.add(getJComboBoxUsage(), null);\r
340 jContentPane.add(jLabelHelpText, null);\r
341 jContentPane.add(getJScrollPaneHelpText(), null);\r
342 jContentPane.add(jLabelFeatureFlag, null);\r
343 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
344 jContentPane.add(jLabelArch, null);\r
345 jContentPane.add(jArchCheckBox, null);\r
346 jContentPane.add(getJButtonOk(), null);\r
347 jContentPane.add(getJButtonCancel(), null);\r
348 }\r
349 return jContentPane;\r
06a19cee 350 }\r
351\r
a929458e 352 /**\r
353 * This method initializes Usage type\r
354 * \r
355 */\r
356 private void initFrame() {\r
357 Tools.generateComboBoxByVector(jComboBoxCName, wt.getAllGuidDeclarationsFromWorkspace());\r
358 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVGuidUsage());\r
06a19cee 359 }\r
360\r
a929458e 361 /*\r
362 * (non-Javadoc)\r
363 * \r
364 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
365 * \r
366 * Override actionPerformed to listen all actions\r
367 * \r
368 */\r
369 public void actionPerformed(ActionEvent arg0) {\r
370 if (arg0.getSource() == jButtonOk) {\r
371 if (checkAdd()) {\r
372 getCurrentGuids();\r
373 this.returnType = DataType.RETURN_TYPE_OK;\r
374 this.setVisible(false);\r
375 }\r
376 }\r
377\r
378 if (arg0.getSource() == jButtonCancel) {\r
379 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
380 this.setVisible(false);\r
381 }\r
06a19cee 382 }\r
383\r
a929458e 384 /**\r
385 * Data validation for all fields\r
386 * \r
387 * @retval true - All datas are valid\r
388 * @retval false - At least one data is invalid\r
389 * \r
390 */\r
391 public boolean checkAdd() {\r
392 //\r
393 // Check if all fields have correct data types\r
394 //\r
395\r
396 //\r
397 // Check Name\r
398 //\r
399 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {\r
400 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {\r
401 Log.wrn("Update Guids", "Incorrect data type for Guid Name");\r
402 return false;\r
403 }\r
404 }\r
405\r
406 //\r
407 // Check FeatureFlag\r
408 //\r
409 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
410 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
411 Log.wrn("Update Guids", "Incorrect data type for Feature Flag");\r
412 return false;\r
413 }\r
414 }\r
415\r
416 return true;\r
417 }\r
5b38b75b 418\r
a929458e 419 private GuidsIdentification getCurrentGuids() {\r
06a19cee 420 String arg0 = this.jComboBoxCName.getSelectedItem().toString();\r
421 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();\r
422\r
423 String arg2 = this.jTextFieldFeatureFlag.getText();\r
424 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();\r
5b38b75b 425 String arg4 = this.jTextAreaHelpText.getText();\r
06a19cee 426\r
427 id = new GuidsIdentification(arg0, arg1, arg2, arg3, arg4);\r
428 return id;\r
a929458e 429 }\r
06a19cee 430\r
a929458e 431 public GuidsIdentification getId() {\r
432 return id;\r
433 }\r
434\r
435 public void setId(GuidsIdentification id) {\r
436 this.id = id;\r
437 }\r
06a19cee 438}\r