]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/GuidsDlg.java
Fixed Absolute position of fields, Added ToolTipText and made HelpText a Scrolling...
[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(160, 10, 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(160, 35, 320, 20));
124 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
125 jComboBoxUsage.setToolTipText("<html><table><tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the GUID</td></tr><tr><td>SOMETIMES_CONSUMED</td><td>Module will use the GUID only if it is present</td></tr><tr><td>ALWAYS_PRODUCED</td><td>Module always produces the GUID</td></tr><tr><td>SOMETIMES_PRODUCED</td><td>Module will sometimes produce the GUID</td></tr><tr><td>DEFAULT</td><td>Default is the the GUID that specified the<br>instance of the package</td></tr></table></html>");
126 }
127 return jComboBoxUsage;
128 }
129
130 /**
131 * This method initializes jTextFieldFeatureFlag
132 *
133 * @return javax.swing.JTextField
134 *
135 */
136 private JTextField getJTextFieldFeatureFlag() {
137 if (jTextFieldFeatureFlag == null) {
138 jTextFieldFeatureFlag = new JTextField();
139 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 105, 320, 20));
140 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
141 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
142 }
143 return jTextFieldFeatureFlag;
144 }
145
146 /**
147 * This method initializes jScrollPane
148 *
149 * @return javax.swing.JScrollPane
150 */
151 private JScrollPane getJScrollPane() {
152 if (jScrollPane == null) {
153 jScrollPane = new JScrollPane();
154 jScrollPane.setViewportView(getJContentPane());
155 }
156 return jScrollPane;
157 }
158
159 /**
160 * This method initializes jTextAreaHelpText
161 *
162 * @return javax.swing.JTextArea
163 *
164 */
165 private JTextArea getJTextAreaHelpText() {
166 if (jTextAreaHelpText == null) {
167 jTextAreaHelpText = new JTextArea();
168 jTextAreaHelpText.setLineWrap(true);
169 jTextAreaHelpText.setWrapStyleWord(true);
170 }
171 return jTextAreaHelpText;
172 }
173
174 /**
175 *
176 * This method initializes jScrollPaneHelpText
177 *
178 * @return javax.swing.JScrollPane jScrollPaneHelpText
179 *
180 **/
181 private JScrollPane getJScrollPaneHelpText() {
182 if (jScrollPaneHelpText == null){
183 jScrollPaneHelpText = new JScrollPane();
184 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
185 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
186 jScrollPaneHelpText.setLocation(new java.awt.Point(160,60));
187 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
188 }
189 return jScrollPaneHelpText;
190 }
191 /**
192 * This method initializes jButtonOk
193 *
194 * @return javax.swing.JButton
195 *
196 */
197 private JButton getJButtonOk() {
198 if (jButtonOk == null) {
199 jButtonOk = new JButton();
200 jButtonOk.setBounds(new java.awt.Rectangle(290, 157, 90, 20));
201 jButtonOk.setText("Ok");
202 jButtonOk.addActionListener(this);
203 }
204 return jButtonOk;
205 }
206
207 /**
208 * This method initializes jButtonCancel
209 *
210 * @return javax.swing.JButton
211 *
212 */
213 private JButton getJButtonCancel() {
214 if (jButtonCancel == null) {
215 jButtonCancel = new JButton();
216 jButtonCancel.setBounds(new java.awt.Rectangle(390, 157, 90, 20));
217 jButtonCancel.setText("Cancel");
218 jButtonCancel.addActionListener(this);
219 }
220 return jButtonCancel;
221 }
222
223 public static void main(String[] args) {
224
225 }
226
227 /**
228 *
229 * This method initializes this
230 *
231 */
232 private void init() {
233 this.setSize(500, 230);
234 this.setContentPane(getJScrollPane());
235 this.setTitle("Guids");
236 initFrame();
237 this.setViewMode(false);
238 this.centerWindow();
239 }
240
241 /**
242 *
243 * This method initializes this Fill values to all fields if these values are
244 * not empty
245 *
246 * @param inGuidsId
247 *
248 */
249 private void init(GuidsIdentification inGuidsId) {
250 init();
251 this.id = inGuidsId;
252
253 if (this.id != null) {
254 this.jComboBoxCName.setSelectedItem(id.getName());
255 this.jComboBoxUsage.setSelectedItem(id.getUsage());
256 this.jTextAreaHelpText.setText(id.getHelp());
257 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
258 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
259 }
260 }
261
262 /**
263 * This is the override edit constructor
264 *
265 * @param inGuidsIdentification
266 * @param iFrame
267 *
268 */
269 public GuidsDlg(GuidsIdentification inGuidsIdentification, IFrame iFrame) {
270 super(iFrame, true);
271 init(inGuidsIdentification);
272 }
273
274 /**
275 * Disable all components when the mode is view
276 *
277 * @param isView
278 * true - The view mode; false - The non-view mode
279 *
280 */
281 public void setViewMode(boolean isView) {
282 if (isView) {
283 this.jComboBoxUsage.setEnabled(!isView);
284 }
285 }
286
287 /**
288 * This method initializes jContentPane
289 *
290 * @return javax.swing.JPanel jContentPane
291 *
292 */
293 private JPanel getJContentPane() {
294 if (jContentPane == null) {
295 jStarLabel1 = new StarLabel();
296 jStarLabel1.setLocation(new java.awt.Point(2, 10));
297 jLabelC_Name = new JLabel();
298 jLabelC_Name.setText("Select GUID's C Name");
299 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 10, 145, 20));
300
301 jStarLabel2 = new StarLabel();
302 jStarLabel2.setLocation(new java.awt.Point(2, 35));
303 jLabelUsage = new JLabel();
304 jLabelUsage.setText("Usage");
305 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 145, 20));
306
307 jLabelHelpText = new JLabel();
308 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 145, 20));
309 jLabelHelpText.setText("Help Text");
310
311 jLabelFeatureFlag = new JLabel();
312 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 105, 145, 20));
313 jLabelFeatureFlag.setText("Feature Flag Expression");
314
315 jLabelArch = new JLabel();
316 jLabelArch.setBounds(new java.awt.Rectangle(15, 130, 145, 20));
317 jLabelArch.setText("Supported Architectures");
318 jArchCheckBox = new ArchCheckBox();
319 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 130, 320, 20));
320 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
321
322 jContentPane = new JPanel();
323 jContentPane.setLayout(null);
324 jContentPane.setPreferredSize(new java.awt.Dimension(490, 165));
325
326 jContentPane.add(jStarLabel1, null);
327 jContentPane.add(jLabelC_Name, null);
328 jContentPane.add(getJComboBoxCName(), null);
329 jContentPane.add(jStarLabel2, null);
330 jContentPane.add(jLabelUsage, null);
331 jContentPane.add(getJComboBoxUsage(), null);
332 jContentPane.add(jLabelHelpText, null);
333 jContentPane.add(getJScrollPaneHelpText(), null);
334 jContentPane.add(jLabelFeatureFlag, null);
335 jContentPane.add(getJTextFieldFeatureFlag(), null);
336 jContentPane.add(jLabelArch, null);
337 jContentPane.add(jArchCheckBox, null);
338 jContentPane.add(getJButtonOk(), null);
339 jContentPane.add(getJButtonCancel(), null);
340 }
341 return jContentPane;
342 }
343
344 /**
345 * This method initializes Usage type
346 *
347 */
348 private void initFrame() {
349 Tools.generateComboBoxByVector(jComboBoxCName, wt
350 .getAllGuidDeclarationsFromWorkspace());
351 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVGuidUsage());
352 }
353
354 /*
355 * (non-Javadoc)
356 *
357 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
358 *
359 * Override actionPerformed to listen all actions
360 *
361 */
362 public void actionPerformed(ActionEvent arg0) {
363 if (arg0.getSource() == jButtonOk) {
364 if (checkAdd()) {
365 getCurrentGuids();
366 this.returnType = DataType.RETURN_TYPE_OK;
367 this.setVisible(false);
368 }
369 }
370
371 if (arg0.getSource() == jButtonCancel) {
372 this.returnType = DataType.RETURN_TYPE_CANCEL;
373 this.setVisible(false);
374 }
375 }
376
377 /**
378 * Data validation for all fields
379 *
380 * @retval true - All datas are valid
381 * @retval false - At least one data is invalid
382 *
383 */
384 public boolean checkAdd() {
385 //
386 // Check if all fields have correct data types
387 //
388
389 //
390 // Check Name
391 //
392 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {
393 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem()
394 .toString())) {
395 Log.wrn("Update Guids", "Incorrect data type for Guid Name");
396 return false;
397 }
398 }
399
400 //
401 // Check FeatureFlag
402 //
403 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
404 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
405 Log.wrn("Update Guids", "Incorrect data type for Feature Flag");
406 return false;
407 }
408 }
409
410 return true;
411 }
412
413 private GuidsIdentification getCurrentGuids() {
414 String arg0 = this.jComboBoxCName.getSelectedItem().toString();
415 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
416
417 String arg2 = this.jTextFieldFeatureFlag.getText();
418 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
419 String arg4 = this.jTextAreaHelpText.getText();
420
421 id = new GuidsIdentification(arg0, arg1, arg2, arg3, arg4);
422 return id;
423 } public GuidsIdentification getId() {
424 return id;
425 }
426
427 public void setId(GuidsIdentification id) {
428 this.id = id;
429 }
430 }