3 The file is used to create, update Ppi of MSA/MBD 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
.Ppis
.PpisIdentification
;
40 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
43 * The class is used to create, update Ppi of MSA/MBD file It extends
47 public class PpisDlg
extends IDialog
implements ItemListener
{
50 // / Define class Serial Version UID
52 private static final long serialVersionUID
= -4284901202357037724L;
55 // Define class members
57 private JPanel jContentPane
= null;
59 private JLabel jLabelC_Name
= null;
61 private JComboBox jComboBoxCName
= null;
63 private JTextField jTextFieldFeatureFlag
= null;
65 private JLabel jLabelFeatureFlag
= null;
67 private JLabel jLabelUsage
= null;
69 private JComboBox jComboBoxUsage
= null;
71 private JLabel jLabelPpiType
= null;
73 private StarLabel jStarLabel1
= null;
75 private StarLabel jStarLabel2
= null;
77 private StarLabel jStarLabel3
= null;
79 private JComboBox jComboBoxPpiType
= null;
81 private JLabel jLabelArch
= null;
83 private JScrollPane jScrollPane
= null;
85 private JLabel jLabelHelpText
= null;
87 private JTextArea jTextAreaHelpText
= null;
89 private JScrollPane jScrollPaneHelpText
= null;
91 private ArchCheckBox jArchCheckBox
= null;
93 private JButton jButtonOk
= null;
95 private JButton jButtonCancel
= null;
100 private PpisIdentification id
= null;
102 private WorkspaceTools wt
= new WorkspaceTools();
104 private EnumerationData ed
= new EnumerationData();
107 * This method initializes jComboBoxPpiType
109 * @return javax.swing.JComboBox
111 private JComboBox
getJComboBoxPpiType() {
112 if (jComboBoxPpiType
== null) {
113 jComboBoxPpiType
= new JComboBox();
114 jComboBoxPpiType
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
115 jComboBoxPpiType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
116 jComboBoxPpiType
.addItemListener(this);
117 jComboBoxPpiType
.setToolTipText("<html>PPIs are named by GUID.<br>PPI Notify is consumed via a register PPI Notify mechanism");
119 return jComboBoxPpiType
;
123 * This method initializes jTextFieldC_Name
125 * @return javax.swing.JTextField jTextFieldC_Name
128 private JComboBox
getJComboBoxCName() {
129 if (jComboBoxCName
== null) {
130 jComboBoxCName
= new JComboBox();
131 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
132 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
133 jComboBoxCName
.setToolTipText("Select Guid C Name of PPI");
135 return jComboBoxCName
;
139 * This method initializes jComboBoxUsage
141 * @return javax.swing.JComboBox jComboBoxUsage
144 private JComboBox
getJComboBoxUsage() {
145 if (jComboBoxUsage
== null) {
146 jComboBoxUsage
= new JComboBox();
147 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
148 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
149 jComboBoxUsage
.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>");
151 return jComboBoxUsage
;
155 * This method initializes jTextFieldFeatureFlag
157 * @return javax.swing.JTextField jTextFieldFeatureFlag
160 private JTextField
getJTextFieldFeatureFlag() {
161 if (jTextFieldFeatureFlag
== null) {
162 jTextFieldFeatureFlag
= new JTextField();
163 jTextFieldFeatureFlag
164 .setBounds(new java
.awt
.Rectangle(160, 130, 320, 20));
165 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
166 jTextFieldFeatureFlag
167 .setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
169 return jTextFieldFeatureFlag
;
173 * This method initializes jScrollPane
175 * @return javax.swing.JScrollPane
177 private JScrollPane
getJScrollPane() {
178 if (jScrollPane
== null) {
179 jScrollPane
= new JScrollPane();
180 jScrollPane
.setViewportView(getJContentPane());
186 * This method initializes jTextAreaHelpText
188 * @return javax.swing.JTextArea
191 private JTextArea
getJTextAreaHelpText() {
192 if (jTextAreaHelpText
== null) {
193 jTextAreaHelpText
= new JTextArea();
194 jTextAreaHelpText
.setLineWrap(true);
195 jTextAreaHelpText
.setWrapStyleWord(true);
197 return jTextAreaHelpText
;
201 * This method initializes jScrollPaneHelpText
203 * @return javax.swing.JScrollPane
206 private JScrollPane
getJScrollPaneHelpText() {
207 if (jScrollPaneHelpText
== null) {
208 jScrollPaneHelpText
= new JScrollPane();
210 .setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
211 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
212 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
213 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(160, 85));
214 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
216 return jScrollPaneHelpText
;
220 * This method initializes jButtonOk
222 * @return javax.swing.JButton
225 private JButton
getJButtonOk() {
226 if (jButtonOk
== null) {
227 jButtonOk
= new JButton();
228 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 182, 90, 20));
229 jButtonOk
.setText("Ok");
230 jButtonOk
.addActionListener(this);
236 * This method initializes jButtonCancel
238 * @return javax.swing.JButton
241 private JButton
getJButtonCancel() {
242 if (jButtonCancel
== null) {
243 jButtonCancel
= new JButton();
244 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 182, 90, 20));
245 jButtonCancel
.setText("Cancel");
246 jButtonCancel
.addActionListener(this);
248 return jButtonCancel
;
251 public static void main(String
[] args
) {
256 * This method initializes this
259 private void init() {
260 this.setSize(500, 255);
261 this.setContentPane(getJScrollPane());
262 this.setTitle("PPI Definitions");
268 * This method initializes this Fill values to all fields if these values are
271 * @param inProtocolsId
274 private void init(PpisIdentification inPpisId
) {
278 if (this.id
!= null) {
279 this.jComboBoxCName
.setSelectedItem(id
.getName());
280 this.jComboBoxPpiType
.setSelectedItem(id
.getType());
281 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
282 this.jTextAreaHelpText
.setText(id
.getHelp());
283 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
284 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
289 * This is the override edit constructor
291 * @param inProtocolsIdentification
295 public PpisDlg(PpisIdentification inPpisIdentification
, IFrame iFrame
) {
297 init(inPpisIdentification
);
301 * This method initializes jContentPane
303 * @return javax.swing.JPanel jContentPane
306 private JPanel
getJContentPane() {
307 if (jContentPane
== null) {
308 jStarLabel1
= new StarLabel();
309 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
310 jLabelPpiType
= new JLabel();
311 jLabelPpiType
.setBounds(new java
.awt
.Rectangle(15, 10, 145, 20));
312 jLabelPpiType
.setText("Ppi Type");
314 jStarLabel2
= new StarLabel();
315 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
316 jLabelC_Name
= new JLabel();
317 jLabelC_Name
.setText("PPI GUID C Name");
318 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 35, 145, 20));
320 jStarLabel3
= new StarLabel();
321 jStarLabel3
.setLocation(new java
.awt
.Point(2, 60));
322 jLabelUsage
= new JLabel();
323 jLabelUsage
.setText("Usage");
324 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 145, 20));
326 jLabelHelpText
= new JLabel();
327 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 85, 145, 20));
328 jLabelHelpText
.setText("Help Text");
330 jLabelFeatureFlag
= new JLabel();
331 jLabelFeatureFlag
.setText("Feature Flag");
332 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 130, 145, 20));
334 jLabelArch
= new JLabel();
335 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 155, 145, 20));
336 jLabelArch
.setText("Arch");
337 jArchCheckBox
= new ArchCheckBox();
338 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 155, 320, 20));
339 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
341 jContentPane
= new JPanel();
342 jContentPane
.setLayout(null);
343 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 210));
345 jContentPane
.add(jStarLabel1
, null);
346 jContentPane
.add(jLabelPpiType
, null);
347 jContentPane
.add(getJComboBoxPpiType(), null);
348 jContentPane
.add(jStarLabel2
, null);
349 jContentPane
.add(jLabelC_Name
, null);
350 jContentPane
.add(getJComboBoxCName(), null);
351 jContentPane
.add(jStarLabel3
, null);
352 jContentPane
.add(jLabelUsage
, null);
353 jContentPane
.add(getJComboBoxUsage(), null);
354 jContentPane
.add(jLabelHelpText
, null);
355 jContentPane
.add(getJScrollPaneHelpText(), null);
356 jContentPane
.add(jLabelFeatureFlag
, null);
357 jContentPane
.add(getJTextFieldFeatureFlag(), null);
358 jContentPane
.add(jLabelArch
, null);
359 jContentPane
.add(jArchCheckBox
, null);
360 jContentPane
.add(getJButtonOk(), null);
361 jContentPane
.add(getJButtonCancel(), null);
367 * This method initializes Usage type
370 private void initFrame() {
371 Tools
.generateComboBoxByVector(jComboBoxCName
, wt
372 .getAllPpiDeclarationsFromWorkspace());
373 Tools
.generateComboBoxByVector(jComboBoxPpiType
, ed
.getVPpiType());
374 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
380 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
382 * Override actionPerformed to listen all actions
385 public void actionPerformed(ActionEvent arg0
) {
386 if (arg0
.getSource() == jButtonOk
) {
389 this.returnType
= DataType
.RETURN_TYPE_OK
;
390 this.setVisible(false);
394 if (arg0
.getSource() == jButtonCancel
) {
395 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
396 this.setVisible(false);
401 * Data validation for all fields
403 * @retval true - All datas are valid
404 * @retval false - At least one data is invalid
407 public boolean checkAdd() {
409 // Check if all fields have correct data types
415 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
416 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem()
418 Log
.wrn("Update Ppis", "Incorrect data type for Ppi/PpiNotify Name");
426 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
427 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
428 Log
.wrn("Update Ppis", "Incorrect data type for Feature Flag");
436 private PpisIdentification
getCurrentPpis() {
437 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
438 String arg1
= this.jComboBoxPpiType
.getSelectedItem().toString();
439 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
441 String arg3
= this.jTextFieldFeatureFlag
.getText();
442 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
443 String arg5
= this.jTextAreaHelpText
.getText();
445 id
= new PpisIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
450 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
452 * Reflesh the frame when selected item changed
455 public void itemStateChanged(ItemEvent arg0
) {
456 if (arg0
.getSource() == this.jComboBoxPpiType
457 && arg0
.getStateChange() == ItemEvent
.SELECTED
) {
458 if (this.jComboBoxPpiType
.getSelectedItem().toString().equals(
459 ed
.getVPpiType().get(0))) {
460 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVPpiUsage());
462 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
463 .getVPpiNotifyUsage());
468 public PpisIdentification
getId() {
472 public void setId(PpisIdentification id
) {