3 The file is used to create, update Ppi section of the MSA file
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
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.
15 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.awt
.event
.ItemEvent
;
19 import java
.awt
.event
.ItemListener
;
20 import java
.util
.Vector
;
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
;
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
;
45 * The class is used to create, update Ppi section of the MSA file
50 public class PpisDlg
extends IDialog
implements ItemListener
{
53 // / Define class Serial Version UID
55 private static final long serialVersionUID
= -4284901202357037724L;
58 // Define class members
60 private JPanel jContentPane
= null;
62 private JLabel jLabelC_Name
= null;
64 private JComboBox jComboBoxCName
= null;
66 private JTextField jTextFieldFeatureFlag
= null;
68 private JLabel jLabelFeatureFlag
= null;
70 private JLabel jLabelUsage
= null;
72 private JComboBox jComboBoxUsage
= null;
74 private JLabel jLabelPpiType
= null;
76 private StarLabel jStarLabel1
= null;
78 private StarLabel jStarLabel2
= null;
80 private StarLabel jStarLabel3
= null;
82 private JComboBox jComboBoxPpiType
= null;
84 private JLabel jLabelArch
= null;
86 private JScrollPane jScrollPane
= null;
88 private JLabel jLabelHelpText
= null;
90 private JTextArea jTextAreaHelpText
= null;
92 private JScrollPane jScrollPaneHelpText
= null;
94 private ArchCheckBox jArchCheckBox
= null;
96 private JButton jButtonOk
= null;
98 private JButton jButtonCancel
= null;
103 private PpisIdentification id
= null;
105 private WorkspaceTools wt
= new WorkspaceTools();
107 private EnumerationData ed
= new EnumerationData();
110 * This method initializes jComboBoxPpiType
112 * @return javax.swing.JComboBox
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);
121 .setToolTipText("<html>PPIs are named by GUID.<br>PPI Notify is consumed via a register PPI Notify mechanism</html>");
123 return jComboBoxPpiType
;
127 * This method initializes jTextFieldC_Name
129 * @return javax.swing.JTextField jTextFieldC_Name
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");
139 return jComboBoxCName
;
143 * This method initializes jComboBoxUsage
145 * @return javax.swing.JComboBox jComboBoxUsage
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));
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>");
156 return jComboBoxUsage
;
160 * This method initializes jTextFieldFeatureFlag
162 * @return javax.swing.JTextField jTextFieldFeatureFlag
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);
173 return jTextFieldFeatureFlag
;
177 * This method initializes jScrollPane
179 * @return javax.swing.JScrollPane
181 private JScrollPane
getJScrollPane() {
182 if (jScrollPane
== null) {
183 jScrollPane
= new JScrollPane();
184 jScrollPane
.setViewportView(getJContentPane());
190 * This method initializes jTextAreaHelpText
192 * @return javax.swing.JTextArea
195 private JTextArea
getJTextAreaHelpText() {
196 if (jTextAreaHelpText
== null) {
197 jTextAreaHelpText
= new JTextArea();
198 jTextAreaHelpText
.setLineWrap(true);
199 jTextAreaHelpText
.setWrapStyleWord(true);
201 return jTextAreaHelpText
;
205 * This method initializes jScrollPaneHelpText
207 * @return javax.swing.JScrollPane
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());
219 return jScrollPaneHelpText
;
223 * This method initializes jButtonOk
225 * @return javax.swing.JButton
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);
239 * This method initializes jButtonCancel
241 * @return javax.swing.JButton
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);
251 return jButtonCancel
;
255 * This method initializes this
258 private void init() {
259 this.setSize(505, 260);
260 this.setContentPane(getJScrollPane());
261 this.setTitle("PPI Definitions");
267 This method initializes this Fill values to all fields if these values are
274 private void init(PpisIdentification inPpisId
, ModuleIdentification mid
) {
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");
283 Tools
.generateComboBoxByVector(this.jComboBoxCName
,
284 wt
.getAllPpiDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
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());
297 * This is the override edit constructor
299 * @param inProtocolsIdentification
303 public PpisDlg(PpisIdentification inPpisIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
305 init(inPpisIdentification
, mid
);
309 * This method initializes jContentPane
311 * @return javax.swing.JPanel jContentPane
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");
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));
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));
334 jLabelHelpText
= new JLabel();
335 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 87, 168, 20));
336 jLabelHelpText
.setText("Help Text");
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);
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));
350 jContentPane
= new JPanel();
351 jContentPane
.setLayout(null);
352 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
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);
376 * This method initializes Usage type
379 private void initFrame() {
380 Tools
.generateComboBoxByVector(jComboBoxPpiType
, ed
.getVPpiType());
381 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
387 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
389 * Override actionPerformed to listen all actions
392 public void actionPerformed(ActionEvent arg0
) {
393 if (arg0
.getSource() == jButtonOk
) {
396 this.returnType
= DataType
.RETURN_TYPE_OK
;
397 this.setVisible(false);
401 if (arg0
.getSource() == jButtonCancel
) {
402 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
403 this.setVisible(false);
408 * Data validation for all fields
410 * @retval true - All datas are valid
411 * @retval false - At least one data is invalid
414 public boolean checkAdd() {
416 // Check if all fields have correct data types
422 if (this.jComboBoxCName
.getSelectedItem() == null) {
423 Log
.wrn("Update Ppis", "Please select one Ppi/PpiNotify Name");
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");
437 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
438 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
439 Log
.wrn("Update Ppis", "Incorrect data type for Feature Flag");
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();
452 String arg3
= this.jTextFieldFeatureFlag
.getText();
453 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
454 String arg5
= this.jTextAreaHelpText
.getText();
456 id
= new PpisIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
461 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
463 * Reflesh the frame when selected item changed
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());
472 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVPpiNotifyUsage());
477 public PpisIdentification
getId() {
481 public void setId(PpisIdentification id
) {