]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/PpisDlg.java
f7f50017ff630571f5684c8fc21759543c7b724e
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / PpisDlg.java
1 /** @file
2
3 The file is used to create, update Ppi 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.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.util.Vector;
21
22 import javax.swing.JButton;
23 import javax.swing.JComboBox;
24 import javax.swing.JLabel;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTextField;
28
29 import org.tianocore.frameworkwizard.common.DataType;
30 import org.tianocore.frameworkwizard.common.DataValidation;
31 import org.tianocore.frameworkwizard.common.EnumerationData;
32 import org.tianocore.frameworkwizard.common.Log;
33 import org.tianocore.frameworkwizard.common.Tools;
34 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
35 import org.tianocore.frameworkwizard.common.ui.IDialog;
36 import org.tianocore.frameworkwizard.common.ui.IFrame;
37 import org.tianocore.frameworkwizard.common.ui.StarLabel;
38 import org.tianocore.frameworkwizard.module.Identifications.Ppis.PpisIdentification;
39 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
40
41 /**
42 The class is used to create, update Ppi of MSA/MBD file
43 It extends IInternalFrame
44
45 **/
46 public class PpisDlg extends IDialog implements ItemListener {
47
48 ///
49 /// Define class Serial Version UID
50 ///
51 private static final long serialVersionUID = -4284901202357037724L;
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 JTextField jTextFieldFeatureFlag = null;
63
64 private JLabel jLabelFeatureFlag = null;
65
66 private JLabel jLabelUsage = null;
67
68 private JComboBox jComboBoxUsage = null;
69
70 private JLabel jLabelPpiType = null;
71
72 private StarLabel jStarLabel1 = null;
73
74 private StarLabel jStarLabel2 = null;
75
76 private JComboBox jComboBoxPpiType = null;
77
78 private JLabel jLabelArch = null;
79
80 private JScrollPane jScrollPane = null;
81
82 private JLabel jLabelHelpText = null;
83
84 private JTextField jTextFieldHelpText = null;
85
86 private ArchCheckBox jArchCheckBox = null;
87
88 private JButton jButtonOk = null;
89
90 private JButton jButtonCancel = null;
91
92 //
93 // Not used by UI
94 //
95 private PpisIdentification id = null;
96
97 private WorkspaceTools wt = new WorkspaceTools();
98
99 private EnumerationData ed = new EnumerationData();
100
101 /**
102 This method initializes jTextFieldC_Name
103
104 @return javax.swing.JTextField jTextFieldC_Name
105
106 **/
107 private JComboBox getJComboBoxCName() {
108 if (jComboBoxCName == null) {
109 jComboBoxCName = new JComboBox();
110 jComboBoxCName.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
111 jComboBoxCName.setPreferredSize(new java.awt.Dimension(320, 20));
112 }
113 return jComboBoxCName;
114 }
115
116 /**
117 This method initializes jTextFieldFeatureFlag
118
119 @return javax.swing.JTextField jTextFieldFeatureFlag
120
121 **/
122 private JTextField getJTextFieldFeatureFlag() {
123 if (jTextFieldFeatureFlag == null) {
124 jTextFieldFeatureFlag = new JTextField();
125 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
126 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
127 }
128 return jTextFieldFeatureFlag;
129 }
130
131 /**
132 This method initializes jComboBox
133
134 @return javax.swing.JComboBox jComboBoxUsage
135
136 **/
137 private JComboBox getJComboBox() {
138 if (jComboBoxUsage == null) {
139 jComboBoxUsage = new JComboBox();
140 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
141 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
142 }
143 return jComboBoxUsage;
144 }
145
146 /**
147 * This method initializes jComboBoxPpiType
148 *
149 * @return javax.swing.JComboBox
150 */
151 private JComboBox getJComboBoxPpiType() {
152 if (jComboBoxPpiType == null) {
153 jComboBoxPpiType = new JComboBox();
154 jComboBoxPpiType.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
155 jComboBoxPpiType.setPreferredSize(new java.awt.Dimension(320, 20));
156 jComboBoxPpiType.addItemListener(this);
157 }
158 return jComboBoxPpiType;
159 }
160
161 /**
162 This method initializes jScrollPane
163
164 @return javax.swing.JScrollPane
165 */
166 private JScrollPane getJScrollPane() {
167 if (jScrollPane == null) {
168 jScrollPane = new JScrollPane();
169 jScrollPane.setViewportView(getJContentPane());
170 }
171 return jScrollPane;
172 }
173
174 /**
175 This method initializes jTextFieldHelpText
176
177 @return javax.swing.JTextField
178
179 **/
180 private JTextField getJTextFieldHelpText() {
181 if (jTextFieldHelpText == null) {
182 jTextFieldHelpText = new JTextField();
183 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
184 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
185 }
186 return jTextFieldHelpText;
187 }
188
189 /**
190 This method initializes jButtonOk
191
192 @return javax.swing.JButton
193
194 **/
195 private JButton getJButtonOk() {
196 if (jButtonOk == null) {
197 jButtonOk = new JButton();
198 jButtonOk.setBounds(new java.awt.Rectangle(290, 165, 90, 20));
199 jButtonOk.setText("Ok");
200 jButtonOk.addActionListener(this);
201 }
202 return jButtonOk;
203 }
204
205 /**
206 This method initializes jButtonCancel
207
208 @return javax.swing.JButton
209
210 **/
211 private JButton getJButtonCancel() {
212 if (jButtonCancel == null) {
213 jButtonCancel = new JButton();
214 jButtonCancel.setBounds(new java.awt.Rectangle(390, 165, 90, 20));
215 jButtonCancel.setText("Cancel");
216 jButtonCancel.addActionListener(this);
217 }
218 return jButtonCancel;
219 }
220
221 public static void main(String[] args) {
222
223 }
224
225 /**
226 This method initializes this
227
228 **/
229 private void init() {
230 this.setSize(500, 225);
231 this.setContentPane(getJScrollPane());
232 this.setTitle("Ppis");
233 initFrame();
234 this.centerWindow();
235 }
236
237 /**
238 This method initializes this
239 Fill values to all fields if these values are not empty
240
241 @param inProtocolsId
242
243 **/
244 private void init(PpisIdentification inPpisId) {
245 init();
246 this.id = inPpisId;
247
248 if (this.id != null) {
249 this.jComboBoxCName.setSelectedItem(id.getName());
250 this.jComboBoxPpiType.setSelectedItem(id.getType());
251 this.jComboBoxUsage.setSelectedItem(id.getUsage());
252 this.jTextFieldHelpText.setText(id.getHelp());
253 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
254 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
255 }
256 }
257
258 /**
259 This is the override edit constructor
260
261 @param inProtocolsIdentification
262 @param iFrame
263
264 **/
265 public PpisDlg(PpisIdentification inPpisIdentification, IFrame iFrame) {
266 super(iFrame, true);
267 init(inPpisIdentification);
268 }
269
270 /**
271 This method initializes jContentPane
272
273 @return javax.swing.JPanel jContentPane
274
275 **/
276 private JPanel getJContentPane() {
277 if (jContentPane == null) {
278 jArchCheckBox = new ArchCheckBox();
279 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 135, 320, 20));
280 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
281 jLabelArch = new JLabel();
282 jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 140, 20));
283 jLabelArch.setText("Arch");
284 jLabelPpiType = new JLabel();
285 jLabelPpiType.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
286 jLabelPpiType.setText("Ppi Type");
287 jLabelUsage = new JLabel();
288 jLabelUsage.setText("Usage");
289 jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
290 jLabelFeatureFlag = new JLabel();
291 jLabelFeatureFlag.setText("Feature Flag");
292 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
293 jLabelC_Name = new JLabel();
294 jLabelC_Name.setText("C_Name Type");
295 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
296 jLabelHelpText = new JLabel();
297 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 85, 140, 20));
298 jLabelHelpText.setText("Help Text");
299
300 jContentPane = new JPanel();
301 jContentPane.setLayout(null);
302 jContentPane.setPreferredSize(new java.awt.Dimension(490, 190));
303
304 jContentPane.add(jLabelC_Name, null);
305 jContentPane.add(getJComboBoxCName(), null);
306 jContentPane.add(getJTextFieldFeatureFlag(), null);
307 jContentPane.add(jLabelFeatureFlag, null);
308 jContentPane.add(jLabelUsage, null);
309 jContentPane.add(getJComboBox(), null);
310 jContentPane.add(getJComboBoxPpiType(), null);
311 jContentPane.add(jLabelArch, null);
312 jContentPane.add(jLabelPpiType, null);
313 jStarLabel1 = new StarLabel();
314 jStarLabel1.setBounds(new java.awt.Rectangle(0, 10, 10, 20));
315 jStarLabel2 = new StarLabel();
316 jStarLabel2.setBounds(new java.awt.Rectangle(0, 35, 10, 20));
317
318 jContentPane.add(jStarLabel1, null);
319 jContentPane.add(jStarLabel2, null);
320
321 jContentPane.add(jLabelHelpText, null);
322 jContentPane.add(getJTextFieldHelpText(), null);
323 jContentPane.add(jArchCheckBox, null);
324 jContentPane.add(getJButtonOk(), null);
325 jContentPane.add(getJButtonCancel(), null);
326 }
327 return jContentPane;
328 }
329
330 /**
331 This method initializes Usage type
332
333 **/
334 private void initFrame() {
335 Tools.generateComboBoxByVector(jComboBoxCName, wt.getAllPpiDeclarationsFromWorkspace());
336 Tools.generateComboBoxByVector(jComboBoxPpiType, ed.getVPpiType());
337 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
338 }
339
340 /* (non-Javadoc)
341 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
342 *
343 * Override actionPerformed to listen all actions
344 *
345 */
346 public void actionPerformed(ActionEvent arg0) {
347 if (arg0.getSource() == jButtonOk) {
348 if (checkAdd()) {
349 getCurrentPpis();
350 this.returnType = DataType.RETURN_TYPE_OK;
351 this.setVisible(false);
352 }
353 }
354
355 if (arg0.getSource() == jButtonCancel) {
356 this.returnType = DataType.RETURN_TYPE_CANCEL;
357 this.setVisible(false);
358 }
359 }
360
361 /**
362 Data validation for all fields
363
364 @retval true - All datas are valid
365 @retval false - At least one data is invalid
366
367 **/
368 public boolean checkAdd() {
369 //
370 // Check if all fields have correct data types
371 //
372
373 //
374 // Check Name
375 //
376 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {
377 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {
378 Log.err("Incorrect data type for Ppi/PpiNotify Name");
379 return false;
380 }
381 }
382
383 //
384 // Check FeatureFlag
385 //
386 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
387 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
388 Log.err("Incorrect data type for Feature Flag");
389 return false;
390 }
391 }
392
393 return true;
394 }
395
396 private PpisIdentification getCurrentPpis() {
397 String arg0 = this.jComboBoxCName.getSelectedItem().toString();
398 String arg1 = this.jComboBoxPpiType.getSelectedItem().toString();
399 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
400
401 String arg3 = this.jTextFieldFeatureFlag.getText();
402 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
403 String arg5 = this.jTextFieldHelpText.getText();
404
405 id = new PpisIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
406 return id;
407 }
408
409 /* (non-Javadoc)
410 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
411 *
412 * Reflesh the frame when selected item changed
413 *
414 */
415 public void itemStateChanged(ItemEvent arg0) {
416 if (arg0.getSource() == this.jComboBoxPpiType && arg0.getStateChange() == ItemEvent.SELECTED) {
417 if (this.jComboBoxPpiType.getSelectedItem().toString().equals(ed.getVPpiType().get(0))) {
418 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVPpiUsage());
419 } else {
420 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVPpiNotifyUsage());
421 }
422 }
423 }
424
425 public PpisIdentification getId() {
426 return id;
427 }
428
429 public void setId(PpisIdentification id) {
430 this.id = id;
431 }
432 }