]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/PpisDlg.java
1. Fix EDKT321 A module's all top level elements' arch should be in range of the...
[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.ModuleIdentification;
40 import org.tianocore.frameworkwizard.module.Identifications.Ppis.PpisIdentification;
41 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
42 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
43
44 /**
45 * The class is used to create, update Ppi section of the MSA file
46 *
47 * It extends IDialog
48 *
49 */
50 public class PpisDlg extends IDialog implements ItemListener {
51
52 // /
53 // / Define class Serial Version UID
54 // /
55 private static final long serialVersionUID = -4284901202357037724L;
56
57 //
58 // Define class members
59 //
60 private JPanel jContentPane = null;
61
62 private JLabel jLabelC_Name = null;
63
64 private JComboBox jComboBoxCName = null;
65
66 private JTextField jTextFieldFeatureFlag = null;
67
68 private JLabel jLabelFeatureFlag = null;
69
70 private JLabel jLabelUsage = null;
71
72 private JComboBox jComboBoxUsage = null;
73
74 private JLabel jLabelPpiType = null;
75
76 private StarLabel jStarLabel1 = null;
77
78 private StarLabel jStarLabel2 = null;
79
80 private StarLabel jStarLabel3 = null;
81
82 private JComboBox jComboBoxPpiType = null;
83
84 private JLabel jLabelArch = null;
85
86 private JScrollPane jScrollPane = null;
87
88 private JLabel jLabelHelpText = null;
89
90 private JTextArea jTextAreaHelpText = null;
91
92 private JScrollPane jScrollPaneHelpText = null;
93
94 private ArchCheckBox jArchCheckBox = null;
95
96 private JButton jButtonOk = null;
97
98 private JButton jButtonCancel = null;
99
100 //
101 // Not used by UI
102 //
103 private PpisIdentification id = null;
104
105 private WorkspaceTools wt = new WorkspaceTools();
106
107 private EnumerationData ed = new EnumerationData();
108
109 /**
110 * This method initializes jComboBoxPpiType
111 *
112 * @return javax.swing.JComboBox
113 */
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);
120 jComboBoxPpiType
121 .setToolTipText("<html>PPIs are named by GUID.<br>PPI Notify is consumed via a register PPI Notify mechanism</html>");
122 }
123 return jComboBoxPpiType;
124 }
125
126 /**
127 * This method initializes jTextFieldC_Name
128 *
129 * @return javax.swing.JTextField jTextFieldC_Name
130 *
131 */
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");
138 }
139 return jComboBoxCName;
140 }
141
142 /**
143 * This method initializes jComboBoxUsage
144 *
145 * @return javax.swing.JComboBox jComboBoxUsage
146 *
147 */
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));
153 jComboBoxUsage
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>");
155 }
156 return jComboBoxUsage;
157 }
158
159 /**
160 * This method initializes jTextFieldFeatureFlag
161 *
162 * @return javax.swing.JTextField jTextFieldFeatureFlag
163 *
164 */
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);
172 }
173 return jTextFieldFeatureFlag;
174 }
175
176 /**
177 * This method initializes jScrollPane
178 *
179 * @return javax.swing.JScrollPane
180 */
181 private JScrollPane getJScrollPane() {
182 if (jScrollPane == null) {
183 jScrollPane = new JScrollPane();
184 jScrollPane.setViewportView(getJContentPane());
185 }
186 return jScrollPane;
187 }
188
189 /**
190 * This method initializes jTextAreaHelpText
191 *
192 * @return javax.swing.JTextArea
193 *
194 */
195 private JTextArea getJTextAreaHelpText() {
196 if (jTextAreaHelpText == null) {
197 jTextAreaHelpText = new JTextArea();
198 jTextAreaHelpText.setLineWrap(true);
199 jTextAreaHelpText.setWrapStyleWord(true);
200 }
201 return jTextAreaHelpText;
202 }
203
204 /**
205 * This method initializes jScrollPaneHelpText
206 *
207 * @return javax.swing.JScrollPane
208 *
209 */
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());
218 }
219 return jScrollPaneHelpText;
220 }
221
222 /**
223 * This method initializes jButtonOk
224 *
225 * @return javax.swing.JButton
226 *
227 */
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);
234 }
235 return jButtonOk;
236 }
237
238 /**
239 * This method initializes jButtonCancel
240 *
241 * @return javax.swing.JButton
242 *
243 */
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);
250 }
251 return jButtonCancel;
252 }
253
254 /**
255 * This method initializes this
256 *
257 */
258 private void init() {
259 this.setSize(505, 260);
260 this.setContentPane(getJScrollPane());
261 this.setTitle("PPI Definitions");
262 initFrame();
263 this.centerWindow();
264 }
265
266 /**
267 This method initializes this Fill values to all fields if these values are
268 not empty
269
270 @param inPpisId
271 @param mid
272
273 **/
274 private void init(PpisIdentification inPpisId, ModuleIdentification mid) {
275 init();
276 this.id = inPpisId;
277
278 //
279 // Init arch with module's arch
280 //
281 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
282
283 //
284 // Get defined ppis from dependent packages
285 //
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");
289 }
290
291 Tools.generateComboBoxByVector(this.jComboBoxCName,
292 wt.getAllPpiDeclarationsFromPackages(wt.getPackageDependenciesOfModule(mid)));
293
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());
301 }
302 }
303
304 /**
305 * This is the override edit constructor
306 *
307 * @param inProtocolsIdentification
308 * @param iFrame
309 *
310 */
311 public PpisDlg(PpisIdentification inPpisIdentification, IFrame iFrame, ModuleIdentification mid) {
312 super(iFrame, true);
313 init(inPpisIdentification, mid);
314 }
315
316 /**
317 * This method initializes jContentPane
318 *
319 * @return javax.swing.JPanel jContentPane
320 *
321 */
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");
329
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));
335
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));
341
342 jLabelHelpText = new JLabel();
343 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 87, 168, 20));
344 jLabelHelpText.setText("Help Text");
345
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);
350
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));
357
358 jContentPane = new JPanel();
359 jContentPane.setLayout(null);
360 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
361
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);
379 }
380 return jContentPane;
381 }
382
383 /**
384 * This method initializes Usage type
385 *
386 */
387 private void initFrame() {
388 Tools.generateComboBoxByVector(jComboBoxPpiType, ed.getVPpiType());
389 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
390 }
391
392 /*
393 * (non-Javadoc)
394 *
395 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
396 *
397 * Override actionPerformed to listen all actions
398 *
399 */
400 public void actionPerformed(ActionEvent arg0) {
401 if (arg0.getSource() == jButtonOk) {
402 if (checkAdd()) {
403 getCurrentPpis();
404 this.returnType = DataType.RETURN_TYPE_OK;
405 this.setVisible(false);
406 }
407 }
408
409 if (arg0.getSource() == jButtonCancel) {
410 this.returnType = DataType.RETURN_TYPE_CANCEL;
411 this.setVisible(false);
412 }
413 }
414
415 /**
416 * Data validation for all fields
417 *
418 * @retval true - All datas are valid
419 * @retval false - At least one data is invalid
420 *
421 */
422 public boolean checkAdd() {
423 //
424 // Check if all fields have correct data types
425 //
426
427 //
428 // Check Name
429 //
430 if (this.jComboBoxCName.getSelectedItem() == null) {
431 Log.wrn("Update Ppis", "Please select one Ppi/PpiNotify Name");
432 return false;
433 }
434
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");
438 return false;
439 }
440 }
441
442 //
443 // Check FeatureFlag
444 //
445 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
446 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
447 Log.wrn("Update Ppis", "Incorrect data type for Feature Flag");
448 return false;
449 }
450 }
451
452 return true;
453 }
454
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();
459
460 String arg3 = this.jTextFieldFeatureFlag.getText();
461 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
462 String arg5 = this.jTextAreaHelpText.getText();
463
464 id = new PpisIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
465 return id;
466 } /*
467 * (non-Javadoc)
468 *
469 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
470 *
471 * Reflesh the frame when selected item changed
472 *
473 */
474
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());
479 } else {
480 Tools.generateComboBoxByVector(this.jComboBoxUsage, ed.getVPpiNotifyUsage());
481 }
482 }
483 }
484
485 public PpisIdentification getId() {
486 return id;
487 }
488
489 public void setId(PpisIdentification id) {
490 this.id = id;
491 }
492 }