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
.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
;
46 * The class is used to create, update Ppi section of the MSA file
51 public class PpisDlg
extends IDialog
implements ItemListener
{
54 // / Define class Serial Version UID
56 private static final long serialVersionUID
= -4284901202357037724L;
59 // Define class members
61 private JPanel jContentPane
= null;
63 private JLabel jLabelC_Name
= null;
65 private IComboBox iComboBoxCName
= null;
67 private JTextField jTextFieldFeatureFlag
= null;
69 private JLabel jLabelFeatureFlag
= null;
71 private JLabel jLabelUsage
= null;
73 private JComboBox jComboBoxUsage
= null;
75 private JLabel jLabelPpiType
= null;
77 private StarLabel jStarLabel1
= null;
79 private StarLabel jStarLabel2
= null;
81 private StarLabel jStarLabel3
= null;
83 private JComboBox jComboBoxPpiType
= null;
85 private JLabel jLabelArch
= null;
87 private JScrollPane jScrollPane
= null;
89 private JLabel jLabelHelpText
= null;
91 private JTextArea jTextAreaHelpText
= null;
93 private JScrollPane jScrollPaneHelpText
= null;
95 private ArchCheckBox jArchCheckBox
= null;
97 private JButton jButtonOk
= null;
99 private JButton jButtonCancel
= null;
104 private PpisIdentification id
= null;
106 private WorkspaceTools wt
= new WorkspaceTools();
108 private EnumerationData ed
= new EnumerationData();
111 * This method initializes jComboBoxPpiType
113 * @return javax.swing.JComboBox
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);
122 .setToolTipText("<html>PPIs are named by GUID.<br>PPI Notify is consumed via a register PPI Notify mechanism</html>");
124 return jComboBoxPpiType
;
128 * This method initializes jTextFieldC_Name
130 * @return javax.swing.JTextField jTextFieldC_Name
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");
140 return iComboBoxCName
;
144 * This method initializes jComboBoxUsage
146 * @return javax.swing.JComboBox jComboBoxUsage
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));
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>");
157 return jComboBoxUsage
;
161 * This method initializes jTextFieldFeatureFlag
163 * @return javax.swing.JTextField jTextFieldFeatureFlag
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);
174 return jTextFieldFeatureFlag
;
178 * This method initializes jScrollPane
180 * @return javax.swing.JScrollPane
182 private JScrollPane
getJScrollPane() {
183 if (jScrollPane
== null) {
184 jScrollPane
= new JScrollPane();
185 jScrollPane
.setViewportView(getJContentPane());
191 * This method initializes jTextAreaHelpText
193 * @return javax.swing.JTextArea
196 private JTextArea
getJTextAreaHelpText() {
197 if (jTextAreaHelpText
== null) {
198 jTextAreaHelpText
= new JTextArea();
199 jTextAreaHelpText
.setLineWrap(true);
200 jTextAreaHelpText
.setWrapStyleWord(true);
202 return jTextAreaHelpText
;
206 * This method initializes jScrollPaneHelpText
208 * @return javax.swing.JScrollPane
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());
220 return jScrollPaneHelpText
;
224 * This method initializes jButtonOk
226 * @return javax.swing.JButton
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);
240 * This method initializes jButtonCancel
242 * @return javax.swing.JButton
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);
252 return jButtonCancel
;
256 * This method initializes this
259 private void init() {
260 this.setSize(505, 260);
261 this.setContentPane(getJScrollPane());
262 this.setTitle("PPI Definitions");
268 This method initializes this Fill values to all fields if these values are
275 private void init(PpisIdentification inPpisId
, ModuleIdentification mid
) {
280 // Init arch with module's arch
282 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
285 // Get defined ppis from dependent packages
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");
292 Tools
.generateComboBoxByVector(this.iComboBoxCName
,
293 wt
.getAllPpiDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
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());
306 * This is the override edit constructor
308 * @param inProtocolsIdentification
312 public PpisDlg(PpisIdentification inPpisIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
314 init(inPpisIdentification
, mid
);
318 * This method initializes jContentPane
320 * @return javax.swing.JPanel jContentPane
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");
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));
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));
343 jLabelHelpText
= new JLabel();
344 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 87, 168, 20));
345 jLabelHelpText
.setText("Help Text");
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);
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));
359 jContentPane
= new JPanel();
360 jContentPane
.setLayout(null);
361 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
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);
385 * This method initializes Usage type
388 private void initFrame() {
389 Tools
.generateComboBoxByVector(jComboBoxPpiType
, ed
.getVPpiType());
390 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
396 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
398 * Override actionPerformed to listen all actions
401 public void actionPerformed(ActionEvent arg0
) {
402 if (arg0
.getSource() == jButtonOk
) {
405 this.returnType
= DataType
.RETURN_TYPE_OK
;
406 this.setVisible(false);
410 if (arg0
.getSource() == jButtonCancel
) {
411 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
412 this.setVisible(false);
417 * Data validation for all fields
419 * @retval true - All datas are valid
420 * @retval false - At least one data is invalid
423 public boolean checkAdd() {
425 // Check if all fields have correct data types
431 if (this.iComboBoxCName
.getSelectedItem() == null) {
432 Log
.wrn("Update Ppis", "Please select one Ppi/PpiNotify Name");
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");
446 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
447 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
448 Log
.wrn("Update Ppis", "Incorrect data type for Feature Flag");
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();
461 String arg3
= this.jTextFieldFeatureFlag
.getText();
462 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
463 String arg5
= this.jTextAreaHelpText
.getText();
465 id
= new PpisIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
470 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
472 * Reflesh the frame when selected item changed
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());
481 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVPpiNotifyUsage());
486 public PpisIdentification
getId() {
490 public void setId(PpisIdentification id
) {