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