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