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