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