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