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