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