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
) {
279 // Init arch with module's arch
281 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
284 // Get defined ppis from dependent packages
286 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
287 if (vpid
.size() <= 0) {
288 Log
.wrn("Init Ppi", "This module hasn't defined any package dependency, so there is no ppi can be added");
291 Tools
.generateComboBoxByVector(this.jComboBoxCName
,
292 wt
.getAllPpiDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
294 if (this.id
!= null) {
295 this.jComboBoxCName
.setSelectedItem(id
.getName());
296 this.jComboBoxPpiType
.setSelectedItem(id
.getType());
297 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
298 this.jTextAreaHelpText
.setText(id
.getHelp());
299 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
300 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
305 * This is the override edit constructor
307 * @param inProtocolsIdentification
311 public PpisDlg(PpisIdentification inPpisIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
313 init(inPpisIdentification
, mid
);
317 * This method initializes jContentPane
319 * @return javax.swing.JPanel jContentPane
322 private JPanel
getJContentPane() {
323 if (jContentPane
== null) {
324 jStarLabel1
= new StarLabel();
325 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
326 jLabelPpiType
= new JLabel();
327 jLabelPpiType
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
328 jLabelPpiType
.setText("Select Ppi Type");
330 jStarLabel2
= new StarLabel();
331 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
332 jLabelC_Name
= new JLabel();
333 jLabelC_Name
.setText("PPI GUID C Name");
334 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
336 jStarLabel3
= new StarLabel();
337 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
338 jLabelUsage
= new JLabel();
339 jLabelUsage
.setText("Usage");
340 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
342 jLabelHelpText
= new JLabel();
343 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 87, 168, 20));
344 jLabelHelpText
.setText("Help Text");
346 jLabelFeatureFlag
= new JLabel();
347 jLabelFeatureFlag
.setText("Feature Flag Expression");
348 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
349 jLabelFeatureFlag
.setEnabled(false);
351 jLabelArch
= new JLabel();
352 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 168, 20));
353 jLabelArch
.setText("Supported Architectures");
354 jArchCheckBox
= new ArchCheckBox();
355 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
356 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
358 jContentPane
= new JPanel();
359 jContentPane
.setLayout(null);
360 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
362 jContentPane
.add(jStarLabel1
, null);
363 jContentPane
.add(jLabelPpiType
, null);
364 jContentPane
.add(getJComboBoxPpiType(), null);
365 jContentPane
.add(jStarLabel2
, null);
366 jContentPane
.add(jLabelC_Name
, null);
367 jContentPane
.add(getJComboBoxCName(), null);
368 jContentPane
.add(jStarLabel3
, null);
369 jContentPane
.add(jLabelUsage
, null);
370 jContentPane
.add(getJComboBoxUsage(), null);
371 jContentPane
.add(jLabelHelpText
, null);
372 jContentPane
.add(getJScrollPaneHelpText(), null);
373 jContentPane
.add(jLabelFeatureFlag
, null);
374 jContentPane
.add(getJTextFieldFeatureFlag(), null);
375 jContentPane
.add(jLabelArch
, null);
376 jContentPane
.add(jArchCheckBox
, null);
377 jContentPane
.add(getJButtonOk(), null);
378 jContentPane
.add(getJButtonCancel(), null);
384 * This method initializes Usage type
387 private void initFrame() {
388 Tools
.generateComboBoxByVector(jComboBoxPpiType
, ed
.getVPpiType());
389 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
395 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
397 * Override actionPerformed to listen all actions
400 public void actionPerformed(ActionEvent arg0
) {
401 if (arg0
.getSource() == jButtonOk
) {
404 this.returnType
= DataType
.RETURN_TYPE_OK
;
405 this.setVisible(false);
409 if (arg0
.getSource() == jButtonCancel
) {
410 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
411 this.setVisible(false);
416 * Data validation for all fields
418 * @retval true - All datas are valid
419 * @retval false - At least one data is invalid
422 public boolean checkAdd() {
424 // Check if all fields have correct data types
430 if (this.jComboBoxCName
.getSelectedItem() == null) {
431 Log
.wrn("Update Ppis", "Please select one Ppi/PpiNotify Name");
435 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
436 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
437 Log
.wrn("Update Ppis", "Incorrect data type for Ppi/PpiNotify Name");
445 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
446 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
447 Log
.wrn("Update Ppis", "Incorrect data type for Feature Flag");
455 private PpisIdentification
getCurrentPpis() {
456 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
457 String arg1
= this.jComboBoxPpiType
.getSelectedItem().toString();
458 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
460 String arg3
= this.jTextFieldFeatureFlag
.getText();
461 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
462 String arg5
= this.jTextAreaHelpText
.getText();
464 id
= new PpisIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
469 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
471 * Reflesh the frame when selected item changed
475 public void itemStateChanged(ItemEvent arg0
) {
476 if (arg0
.getSource() == this.jComboBoxPpiType
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
477 if (this.jComboBoxPpiType
.getSelectedItem().toString().equals(ed
.getVPpiType().get(0))) {
478 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVPpiUsage());
480 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVPpiNotifyUsage());
485 public PpisIdentification
getId() {
489 public void setId(PpisIdentification id
) {