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