]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/LibraryClassDefsDlg.java
1. Wrap text by word when showing a message box
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / LibraryClassDefsDlg.java
1 /** @file
2
3 The file is used to create, update Library Class Definition 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.Dimension;
18 import java.awt.event.ActionEvent;
19 import java.util.Vector;
20
21 import javax.swing.JButton;
22 import javax.swing.JComboBox;
23 import javax.swing.JLabel;
24 import javax.swing.JPanel;
25 import javax.swing.JScrollPane;
26 import javax.swing.JTextField;
27
28 import org.tianocore.frameworkwizard.common.DataType;
29 import org.tianocore.frameworkwizard.common.DataValidation;
30 import org.tianocore.frameworkwizard.common.EnumerationData;
31 import org.tianocore.frameworkwizard.common.Log;
32 import org.tianocore.frameworkwizard.common.Tools;
33 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
34 import org.tianocore.frameworkwizard.common.ui.IDialog;
35 import org.tianocore.frameworkwizard.common.ui.IFrame;
36 import org.tianocore.frameworkwizard.common.ui.StarLabel;
37 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;
38 import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassIdentification;
39 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
40
41 /**
42 The class is used to create, update Library Class Definition of MSA/MBD file
43 It extends IInternalFrame
44
45 **/
46 public class LibraryClassDefsDlg extends IDialog {
47
48 ///
49 /// Define class Serial Version UID
50 ///
51 private static final long serialVersionUID = -1743248695411382857L;
52
53 //
54 //Define class members
55 //
56 private JPanel jContentPane = null;
57
58 private JComboBox jComboBoxLibraryClassName = null;
59
60 private JLabel jLabelUsage = null;
61
62 private JComboBox jComboBoxUsage = null;
63
64 private JLabel jLabelLibraryClassName = null;
65
66 private JScrollPane jScrollPane = null;
67
68 private StarLabel jStarLabel1 = null;
69
70 private StarLabel jStarLabel2 = null;
71
72 private JLabel jLabelRecommendedInstanceVersion = null;
73
74 private JTextField jTextFieldRecommendedInstanceVersion = null;
75
76 private JLabel jLabelRecommendedInstanceGuid = null;
77
78 private JTextField jTextFieldRecommendedInstanceGuid = null;
79
80 private JButton jButtonGenerateGuid = null;
81
82 private JLabel jLabelFeatureFlag = null;
83
84 private JTextField jTextFieldFeatureFlag = null;
85
86 private JLabel jLabelArch = null;
87
88 private JLabel jLabelModuleList = null;
89
90 private JScrollPane jScrollPaneModuleList = null;
91
92 private ICheckBoxList iCheckBoxListModule = null;
93
94 private JLabel jLabelHelpText = null;
95
96 private JTextField jTextFieldHelpText = null;
97
98 private ArchCheckBox jArchCheckBox = null;
99
100 private JButton jButtonOk = null;
101
102 private JButton jButtonCancel = null;
103
104 //
105 // Not for UI
106 //
107 private EnumerationData ed = new EnumerationData();
108
109 private WorkspaceTools wt = new WorkspaceTools();
110
111 private LibraryClassIdentification lcid = null;
112
113 /**
114 This method initializes jComboBoxSelect
115
116 @return javax.swing.JComboBox jComboBoxSelect
117
118 **/
119 private JComboBox getJComboBoxLibraryClassName() {
120 if (jComboBoxLibraryClassName == null) {
121 jComboBoxLibraryClassName = new JComboBox();
122 jComboBoxLibraryClassName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
123 jComboBoxLibraryClassName.setPreferredSize(new Dimension(320, 20));
124 jComboBoxLibraryClassName.setEnabled(true);
125 }
126 return jComboBoxLibraryClassName;
127 }
128
129 /**
130 This method initializes jComboBoxUsage
131
132 @return javax.swing.JComboBox jComboBoxUsage
133
134 **/
135 private JComboBox getJComboBoxUsage() {
136 if (jComboBoxUsage == null) {
137 jComboBoxUsage = new JComboBox();
138 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
139 jComboBoxUsage.setPreferredSize(new Dimension(320, 20));
140 }
141 return jComboBoxUsage;
142 }
143
144 /**
145 This method initializes jScrollPane
146
147 @return javax.swing.JScrollPane
148 */
149 private JScrollPane getJScrollPane() {
150 if (jScrollPane == null) {
151 jScrollPane = new JScrollPane();
152 jScrollPane.setViewportView(getJContentPane());
153 }
154 return jScrollPane;
155 }
156
157 /**
158 * This method initializes jTextFieldRecommendedInstanceVersion
159 *
160 * @return javax.swing.JTextField
161 */
162 private JTextField getJTextFieldRecommendedInstanceVersion() {
163 if (jTextFieldRecommendedInstanceVersion == null) {
164 jTextFieldRecommendedInstanceVersion = new JTextField();
165 jTextFieldRecommendedInstanceVersion.setPreferredSize(new java.awt.Dimension(260, 20));
166 jTextFieldRecommendedInstanceVersion.setSize(new java.awt.Dimension(260, 20));
167 jTextFieldRecommendedInstanceVersion.setLocation(new java.awt.Point(220, 85));
168 jTextFieldRecommendedInstanceVersion.setVisible(false);
169 }
170 return jTextFieldRecommendedInstanceVersion;
171 }
172
173 /**
174 * This method initializes jTextFieldRecommendedInstanceGuid
175 *
176 * @return javax.swing.JTextField
177 */
178 private JTextField getJTextFieldRecommendedInstanceGuid() {
179 if (jTextFieldRecommendedInstanceGuid == null) {
180 jTextFieldRecommendedInstanceGuid = new JTextField();
181 jTextFieldRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(220, 110, 190, 20));
182 jTextFieldRecommendedInstanceGuid.setPreferredSize(new java.awt.Dimension(190, 20));
183 jTextFieldRecommendedInstanceGuid.setVisible(false);
184 }
185 return jTextFieldRecommendedInstanceGuid;
186 }
187
188 /**
189 * This method initializes jButtonGenerateGuid
190 *
191 * @return javax.swing.JButton
192 */
193 private JButton getJButtonGenerateGuid() {
194 if (jButtonGenerateGuid == null) {
195 jButtonGenerateGuid = new JButton();
196 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 110, 65, 20));
197 jButtonGenerateGuid.setPreferredSize(new java.awt.Dimension(65, 20));
198 jButtonGenerateGuid.setText("GEN");
199 jButtonGenerateGuid.setVisible(false);
200 jButtonGenerateGuid.addActionListener(this);
201 }
202 return jButtonGenerateGuid;
203 }
204
205 /**
206 * This method initializes jTextFieldFeatureFlag
207 *
208 * @return javax.swing.JTextField
209 */
210 private JTextField getJTextFieldFeatureFlag() {
211 if (jTextFieldFeatureFlag == null) {
212 jTextFieldFeatureFlag = new JTextField();
213 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
214 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
215 }
216 return jTextFieldFeatureFlag;
217 }
218
219 /**
220 This method initializes iCheckBoxListArch
221
222 @return ICheckBoxList
223 **/
224 private ICheckBoxList getICheckBoxListSupModuleList() {
225 if (iCheckBoxListModule == null) {
226 iCheckBoxListModule = new ICheckBoxList();
227 }
228 return iCheckBoxListModule;
229 }
230
231 /**
232 This method initializes jScrollPaneModuleList
233
234 @return javax.swing.JScrollPane
235
236 **/
237 private JScrollPane getJScrollPaneModuleList() {
238 if (jScrollPaneModuleList == null) {
239 jScrollPaneModuleList = new JScrollPane();
240 jScrollPaneModuleList.setBounds(new java.awt.Rectangle(160, 135, 320, 80));
241 jScrollPaneModuleList.setPreferredSize(new java.awt.Dimension(320, 80));
242 jScrollPaneModuleList.setViewportView(getICheckBoxListSupModuleList());
243 }
244 return jScrollPaneModuleList;
245 }
246
247 /**
248 This method initializes jTextFieldHelpText
249
250 @return javax.swing.JTextField
251
252 **/
253 private JTextField getJTextFieldHelpText() {
254 if (jTextFieldHelpText == null) {
255 jTextFieldHelpText = new JTextField();
256 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
257 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
258 }
259 return jTextFieldHelpText;
260 }
261
262 /**
263 This method initializes jButtonOk
264
265 @return javax.swing.JButton
266
267 **/
268 private JButton getJButtonOk() {
269 if (jButtonOk == null) {
270 jButtonOk = new JButton();
271 jButtonOk.setBounds(new java.awt.Rectangle(290, 225, 90, 20));
272 jButtonOk.setText("Ok");
273 jButtonOk.addActionListener(this);
274 }
275 return jButtonOk;
276 }
277
278 /**
279 This method initializes jButtonCancel
280
281 @return javax.swing.JButton
282
283 **/
284 private JButton getJButtonCancel() {
285 if (jButtonCancel == null) {
286 jButtonCancel = new JButton();
287 jButtonCancel.setBounds(new java.awt.Rectangle(390, 225, 90, 20));
288 jButtonCancel.setText("Cancel");
289 jButtonCancel.addActionListener(this);
290 }
291 return jButtonCancel;
292 }
293
294 public static void main(String[] args) {
295
296 }
297
298 /**
299 This is the default constructor
300
301 **/
302 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification, IFrame iFrame) {
303 super(iFrame, true);
304 init(inLibraryClassIdentification);
305 }
306
307 /**
308 This method initializes this
309
310 **/
311 private void init() {
312 this.setContentPane(getJScrollPane());
313 this.setTitle("Library Class Definitions");
314 this.setBounds(new java.awt.Rectangle(0, 0, 500, 295));
315 initFrame();
316 this.setViewMode(false);
317 this.centerWindow();
318 }
319
320 /**
321 This method initializes this
322
323 **/
324 private void init(LibraryClassIdentification inLibraryClassIdentification) {
325 init();
326 this.lcid = inLibraryClassIdentification;
327 if (lcid != null) {
328 this.jComboBoxLibraryClassName.setSelectedItem(lcid.getLibraryClassName());
329 this.jComboBoxUsage.setSelectedItem(lcid.getUsage());
330 this.jTextFieldRecommendedInstanceVersion.setText(lcid.getRecommendedInstanceVersion());
331 this.jTextFieldRecommendedInstanceGuid.setText(lcid.getRecommendedInstanceGuid());
332 this.jTextFieldFeatureFlag.setText(lcid.getFeatureFlag());
333 this.jArchCheckBox.setSelectedItems(lcid.getSupArchList());
334 this.iCheckBoxListModule.setAllItemsUnchecked();
335 this.iCheckBoxListModule.initCheckedItem(true, lcid.getSupModuleList());
336 this.jTextFieldHelpText.setText(lcid.getHelp());
337 }
338 }
339
340 /**
341 Disable all components when the mode is view
342
343 @param isView true - The view mode; false - The non-view mode
344
345 **/
346 public void setViewMode(boolean isView) {
347 if (isView) {
348 this.jComboBoxLibraryClassName.setEnabled(!isView);
349 this.jComboBoxUsage.setEnabled(!isView);
350 }
351 }
352
353 /**
354 This method initializes jContentPane
355
356 @return javax.swing.JPanel jContentPane
357
358 **/
359 private JPanel getJContentPane() {
360 if (jContentPane == null) {
361 jArchCheckBox = new ArchCheckBox();
362 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
363 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
364 jLabelHelpText = new JLabel();
365 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 140, 20));
366 jLabelHelpText.setText("Help Text");
367 jLabelModuleList = new JLabel();
368 jLabelModuleList.setBounds(new java.awt.Rectangle(15, 135, 140, 20));
369 jLabelModuleList.setText("Sup Module List");
370 jLabelArch = new JLabel();
371 jLabelArch.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
372 jLabelArch.setText("Sup Arch List");
373 jLabelFeatureFlag = new JLabel();
374 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
375 jLabelFeatureFlag.setText("Feature Flag");
376 jLabelRecommendedInstanceGuid = new JLabel();
377 jLabelRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(15, 110, 200, 20));
378 jLabelRecommendedInstanceGuid.setText("Recommended Instance Guid");
379 jLabelRecommendedInstanceGuid.setVisible(false);
380 jLabelRecommendedInstanceVersion = new JLabel();
381 jLabelRecommendedInstanceVersion.setBounds(new java.awt.Rectangle(15, 85, 200, 20));
382 jLabelRecommendedInstanceVersion.setText("Recommended Instance Version");
383 jLabelRecommendedInstanceVersion.setVisible(false);
384 jLabelLibraryClassName = new JLabel();
385 jLabelLibraryClassName.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
386 jLabelLibraryClassName.setText("Library Class Name");
387 jLabelUsage = new JLabel();
388 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
389 jLabelUsage.setText("Usage");
390 jContentPane = new JPanel();
391 jContentPane.setLayout(null);
392 jContentPane.setPreferredSize(new java.awt.Dimension(490, 245));
393
394 jContentPane.add(getJComboBoxLibraryClassName(), null);
395 jContentPane.add(jLabelUsage, null);
396 jContentPane.add(getJComboBoxUsage(), null);
397 jContentPane.add(jLabelLibraryClassName, null);
398 jContentPane.add(jLabelRecommendedInstanceVersion, null);
399 jContentPane.add(getJTextFieldRecommendedInstanceVersion(), null);
400 jContentPane.add(jLabelRecommendedInstanceGuid, null);
401 jContentPane.add(getJTextFieldRecommendedInstanceGuid(), null);
402 jContentPane.add(getJButtonGenerateGuid(), null);
403 jContentPane.add(jLabelFeatureFlag, null);
404 jContentPane.add(getJTextFieldFeatureFlag(), null);
405 jContentPane.add(jLabelArch, null);
406 jStarLabel1 = new StarLabel();
407 jStarLabel1.setLocation(new java.awt.Point(0, 10));
408 jStarLabel2 = new StarLabel();
409 jStarLabel2.setLocation(new java.awt.Point(0, 35));
410
411 jContentPane.add(jStarLabel1, null);
412 jContentPane.add(jStarLabel2, null);
413 jContentPane.add(jLabelModuleList, null);
414 jContentPane.add(getJScrollPaneModuleList(), null);
415 jContentPane.add(jLabelHelpText, null);
416 jContentPane.add(getJTextFieldHelpText(), null);
417 jContentPane.add(jArchCheckBox, null);
418 jContentPane.add(getJButtonOk(), null);
419 jContentPane.add(getJButtonCancel(), null);
420 }
421 return jContentPane;
422 }
423
424 /**
425 This method initializes all existing libraries and usage types
426
427 **/
428 private void initFrame() {
429 Tools.generateComboBoxByVector(jComboBoxLibraryClassName, wt.getAllLibraryClassDefinitionsFromWorkspace());
430 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVLibraryUsage());
431 this.iCheckBoxListModule.setAllItems(ed.getVFrameworkModuleTypes());
432 }
433
434 /* (non-Javadoc)
435 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
436 *
437 * Override actionPerformed to listen all actions
438 *
439 */
440 public void actionPerformed(ActionEvent arg0) {
441 if (arg0.getSource() == jButtonGenerateGuid) {
442 this.jTextFieldRecommendedInstanceGuid.setText(Tools.generateUuidString());
443 }
444
445 if (arg0.getSource() == jButtonOk) {
446 if (checkAdd()) {
447 getCurrentLibraryClass();
448 this.returnType = DataType.RETURN_TYPE_OK;
449 this.setVisible(false);
450 }
451 }
452
453 if (arg0.getSource() == jButtonCancel) {
454 this.returnType = DataType.RETURN_TYPE_CANCEL;
455 this.setVisible(false);
456 }
457 }
458
459 /**
460 Data validation for all fields
461
462 @retval true - All datas are valid
463 @retval false - At least one data is invalid
464
465 **/
466 public boolean checkAdd() {
467 //
468 // Check LibraryClass
469 //
470 if (this.jComboBoxLibraryClassName.getSelectedItem() == null) {
471 Log.wrn("Update Library Class Definitions", "No Library Class can be added");
472 return false;
473 }
474 if (!DataValidation.isLibraryClass(this.jComboBoxLibraryClassName.getSelectedItem().toString())) {
475 Log.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
476 return false;
477 }
478
479 //
480 // Check RecommendedInstanceVersion
481 //
482 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
483 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
484 // Log.err("Incorrect data type for Recommended Instance Version");
485 // return false;
486 // }
487 // }
488
489 //
490 // Check RecommendedInstanceGuid
491 //
492 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
493 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
494 // Log.err("Incorrect data type for Recommended Instance Guid");
495 // return false;
496 // }
497 // }
498
499 //
500 // Check FeatureFlag
501 //
502 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
503 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
504 Log.wrn("Update Library Class Definitions", "Incorrect data type for Feature Flag");
505 return false;
506 }
507 }
508
509 return true;
510 }
511
512 private LibraryClassIdentification getCurrentLibraryClass() {
513 String name = this.jComboBoxLibraryClassName.getSelectedItem().toString();
514 String usage = this.jComboBoxUsage.getSelectedItem().toString();
515 String version = this.jTextFieldRecommendedInstanceVersion.getText();
516 String guid = this.jTextFieldRecommendedInstanceGuid.getText();
517 String featureFlag = this.jTextFieldFeatureFlag.getText();
518 Vector<String> arch = this.jArchCheckBox.getSelectedItemsVector();
519 Vector<String> module = this.iCheckBoxListModule.getAllCheckedItemsString();
520 String help = this.jTextFieldHelpText.getText();
521 lcid = new LibraryClassIdentification(name, usage, version, guid, arch, featureFlag, module, help);
522 return lcid;
523 }
524
525 public LibraryClassIdentification getLcid() {
526 return lcid;
527 }
528
529 public void setLcid(LibraryClassIdentification lcid) {
530 this.lcid = lcid;
531 }
532 }