]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/BuildOptionsDlg.java
1. Fix EDKT461 [Framework Wizard] Can't change ModuleBuildOptions for MSA file
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / BuildOptionsDlg.java
1 /** @file
2
3 The file is used to create, update SourceFiles 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.util.Vector;
19
20 import javax.swing.JButton;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTextField;
25
26 import org.tianocore.frameworkwizard.common.DataType;
27 import org.tianocore.frameworkwizard.common.DataValidation;
28 import org.tianocore.frameworkwizard.common.EnumerationData;
29 import org.tianocore.frameworkwizard.common.Log;
30 import org.tianocore.frameworkwizard.common.Tools;
31 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
32 import org.tianocore.frameworkwizard.common.ui.IComboBox;
33 import org.tianocore.frameworkwizard.common.ui.IDialog;
34 import org.tianocore.frameworkwizard.common.ui.IFrame;
35 import org.tianocore.frameworkwizard.common.ui.StarLabel;
36 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;
37 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
38 import org.tianocore.frameworkwizard.module.Identifications.BuildOptions.BuildOptionsIdentification;
39 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
40
41 /**
42 * The class is used to create, update SourceFiles section of the MSA file
43 *
44 * It extends IDialog
45 *
46 **/
47 public class BuildOptionsDlg extends IDialog {
48
49 ///
50 /// Define class Serial Version UID
51 ///
52 private static final long serialVersionUID = -6765742852142775378L;
53
54 //
55 // Define class members
56 //
57 private JPanel jContentPane = null;
58
59 private JLabel jLabelFileName = null;
60
61 private JTextField jTextFieldFileOption = null;
62
63 private JLabel jLabelToolChainFamily = null;
64
65 private StarLabel jStarLabel1 = null;
66
67 private JLabel jLabelArch = null;
68
69 private JScrollPane jScrollPane = null;
70
71 private JLabel jLabelTagName = null;
72
73 private JTextField jTextFieldTagName = null;
74
75 private JLabel jLabelToolCode = null;
76
77 private JTextField jTextFieldToolCode = null;
78
79 private IComboBox iComboBoxToolCode = null;
80
81 private JTextField jTextFieldToolChainFamily = null;
82
83 private ArchCheckBox jArchCheckBox = null;
84
85 private JButton jButtonOk = null;
86
87 private JButton jButtonCancel = null;
88
89 private JScrollPane jScrollPaneBuildTargets = null;
90
91 private ICheckBoxList iCheckBoxListBuildTargets = null;
92
93 //
94 // Not used by UI
95 //
96 private BuildOptionsIdentification id = null;
97
98 private EnumerationData ed = new EnumerationData();
99
100 private WorkspaceTools wt = new WorkspaceTools();
101
102 private JLabel jLabelBuildTargets = null;
103
104 /**
105 This method initializes jTextFieldFileOption
106
107 @return javax.swing.JTextField jTextFieldFileOption
108
109 **/
110 private JTextField getJTextFieldSourceFilesDirectory() {
111 if (jTextFieldFileOption == null) {
112 jTextFieldFileOption = new JTextField();
113 jTextFieldFileOption.setBounds(new java.awt.Rectangle(168, 12, 340, 20));
114 jTextFieldFileOption.setPreferredSize(new java.awt.Dimension(340, 20));
115 jTextFieldFileOption.setToolTipText("Path is relative to the MSA file and must include the file name");
116 }
117 return jTextFieldFileOption;
118 }
119
120 /**
121 This method initializes jScrollPane
122
123 @return javax.swing.JScrollPane
124 */
125 private JScrollPane getJScrollPane() {
126 if (jScrollPane == null) {
127 jScrollPane = new JScrollPane();
128 jScrollPane.setViewportView(getJContentPane());
129 }
130 return jScrollPane;
131 }
132
133 /**
134 * This method initializes jTextFieldTagName
135 *
136 * @return javax.swing.JTextField
137 */
138 private JTextField getJTextFieldTagName() {
139 if (jTextFieldTagName == null) {
140 jTextFieldTagName = new JTextField();
141 jTextFieldTagName.setBounds(new java.awt.Rectangle(168, 37, 340, 20));
142 jTextFieldTagName.setPreferredSize(new java.awt.Dimension(340, 20));
143 jTextFieldTagName.setToolTipText("You may specify a specific tool chain tag name, such as BILL1");
144 }
145 return jTextFieldTagName;
146 }
147
148 private IComboBox getIComboBoxToolCode() {
149 if (iComboBoxToolCode == null) {
150 iComboBoxToolCode = new IComboBox();
151 iComboBoxToolCode.setBounds(new java.awt.Rectangle(168, 62, 340, 20));
152 iComboBoxToolCode.setPreferredSize(new java.awt.Dimension(340, 20));
153 iComboBoxToolCode.setToolTipText("<html>You may select a specific tool command from drop down list,<br>"
154 + "or you can DOUBLE-CLICK this field to enter your customized<br>"
155 + "tool command.<br>"
156 + "Press ENTER to save your input or press ESCAPE to quit</html>");
157 }
158 return iComboBoxToolCode;
159 }
160
161 /**
162 * This method initializes jTextFieldToolCode
163 *
164 * @return javax.swing.JTextField
165 */
166 private JTextField getJTextFieldToolCode() {
167 if (jTextFieldToolCode == null) {
168 jTextFieldToolCode = new JTextField();
169 jTextFieldToolCode.setBounds(new java.awt.Rectangle(168, 62, 340, 20));
170 jTextFieldToolCode.setPreferredSize(new java.awt.Dimension(340, 20));
171 jTextFieldToolCode.setToolTipText("You may specify a specific tool command, such as ASM");
172 jTextFieldToolCode.setVisible(false);
173 }
174 return jTextFieldToolCode;
175 }
176
177 /**
178 * This method initializes jTextFieldToolChainFamily
179 *
180 * @return javax.swing.JTextField
181 */
182 private JTextField getJTextFieldToolChainFamily() {
183 if (jTextFieldToolChainFamily == null) {
184 jTextFieldToolChainFamily = new JTextField();
185 jTextFieldToolChainFamily.setBounds(new java.awt.Rectangle(168, 87, 340, 20));
186 jTextFieldToolChainFamily.setPreferredSize(new java.awt.Dimension(340, 20));
187 jTextFieldToolChainFamily.setToolTipText("You may specify a specific tool chain family, such as GCC");
188 }
189 return jTextFieldToolChainFamily;
190 }
191
192 /**
193 This method initializes jButtonOk
194
195 @return javax.swing.JButton
196
197 **/
198 private JButton getJButtonOk() {
199 if (jButtonOk == null) {
200 jButtonOk = new JButton();
201 jButtonOk.setBounds(new java.awt.Rectangle(317, 202, 90, 20));
202 jButtonOk.setText("Ok");
203 jButtonOk.addActionListener(this);
204 }
205 return jButtonOk;
206 }
207
208 /**
209 This method initializes jButtonCancel
210
211 @return javax.swing.JButton
212
213 **/
214 private JButton getJButtonCancel() {
215 if (jButtonCancel == null) {
216 jButtonCancel = new JButton();
217 jButtonCancel.setBounds(new java.awt.Rectangle(412, 202, 90, 20));
218 jButtonCancel.setText("Cancel");
219 jButtonCancel.addActionListener(this);
220 }
221 return jButtonCancel;
222 }
223
224 /**
225 This method initializes iCheckBoxListArch
226
227 @return ICheckBoxList
228 **/
229 private ICheckBoxList getICheckBoxListSupModuleList() {
230 if (iCheckBoxListBuildTargets == null) {
231 iCheckBoxListBuildTargets = new ICheckBoxList();
232 }
233 return iCheckBoxListBuildTargets;
234 }
235
236 /**
237 This method initializes jScrollPaneBuildTargets
238
239 @return javax.swing.JScrollPane
240
241 **/
242 private JScrollPane getJScrollPaneBuildTargets() {
243 if (jScrollPaneBuildTargets == null) {
244 jScrollPaneBuildTargets = new JScrollPane();
245 jScrollPaneBuildTargets.setBounds(new java.awt.Rectangle(168, 137, 340, 40));
246 jScrollPaneBuildTargets.setPreferredSize(new java.awt.Dimension(340, 40));
247 jScrollPaneBuildTargets.setViewportView(getICheckBoxListSupModuleList());
248 }
249 return jScrollPaneBuildTargets;
250 }
251
252 public static void main(String[] args) {
253
254 }
255
256 /**
257 This is the default constructor
258
259 **/
260 public BuildOptionsDlg(BuildOptionsIdentification inBuildOptionsIdentification, IFrame iFrame,
261 ModuleIdentification mid) {
262 super(iFrame, true);
263 init(inBuildOptionsIdentification, mid);
264 }
265
266 /**
267 This method initializes this
268
269 **/
270 private void init() {
271 this.setSize(525, 270);
272 this.setContentPane(getJScrollPane());
273 this.setTitle("Source Files");
274 this.setViewMode(false);
275 this.centerWindow();
276 Tools.generateComboBoxByVector(iComboBoxToolCode, ed.getVToolCode());
277 this.iCheckBoxListBuildTargets.setAllItems(ed.getVBuildTargets());
278 }
279
280 /**
281 This method initializes this
282 Fill values to all fields if these values are not empty
283
284
285 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
286
287 **/
288 private void init(BuildOptionsIdentification inBuildOptionsIdentification, ModuleIdentification mid) {
289 init();
290
291 //
292 // Init arch with module's arch
293 //
294 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
295
296 if (inBuildOptionsIdentification != null) {
297 this.jTextFieldFileOption.setText(inBuildOptionsIdentification.getOption());
298 this.jTextFieldTagName.setText(inBuildOptionsIdentification.getTagName());
299
300 //
301 // Generate Tool Code selection list
302 //
303 Vector<String> v = ed.getVToolCode();
304 boolean isFind = false;
305 String strToolCode = inBuildOptionsIdentification.getToolCode();
306
307 //
308 // If the input value is not in the default list, add it to the list
309 //
310 if (strToolCode != null) {
311 for (int index = 0; index < v.size(); index++) {
312 if (v.elementAt(index).equals(strToolCode)) {
313 isFind = true;
314 break;
315 }
316 }
317 if (!isFind && !isEmpty(strToolCode)) {
318 v.addElement(strToolCode);
319 }
320 }
321
322 Tools.generateComboBoxByVector(iComboBoxToolCode, v);
323 this.iComboBoxToolCode.setSelectedItem(strToolCode);
324
325 this.jTextFieldToolChainFamily.setText(inBuildOptionsIdentification.getToolChainFamily());
326
327 this.jArchCheckBox.setSelectedItems(inBuildOptionsIdentification.getSupArchList());
328
329 this.iCheckBoxListBuildTargets.setAllItemsUnchecked();
330 this.iCheckBoxListBuildTargets.initCheckedItem(true, inBuildOptionsIdentification.getBuildTargets());
331 }
332 }
333
334 /**
335 Disable all components when the mode is view
336
337 @param isView true - The view mode; false - The non-view mode
338
339 **/
340 public void setViewMode(boolean isView) {
341 if (isView) {
342 this.jTextFieldFileOption.setEnabled(!isView);
343 }
344 }
345
346 /**
347 This method initializes jContentPane
348
349 @return javax.swing.JPanel jContentPane
350
351 **/
352 private JPanel getJContentPane() {
353 if (jContentPane == null) {
354 jLabelBuildTargets = new JLabel();
355 jLabelBuildTargets.setBounds(new java.awt.Rectangle(12, 137, 155, 20));
356 jLabelBuildTargets.setText("Build Targets");
357 jArchCheckBox = new ArchCheckBox();
358 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 112, 340, 20));
359 jArchCheckBox.setPreferredSize(new java.awt.Dimension(340, 20));
360 jLabelToolCode = new JLabel();
361 jLabelToolCode.setBounds(new java.awt.Rectangle(12, 62, 155, 20));
362 jLabelToolCode.setText("Tool Code");
363 jLabelTagName = new JLabel();
364 jLabelTagName.setBounds(new java.awt.Rectangle(12, 37, 155, 20));
365 jLabelTagName.setText("Tag Name");
366 jLabelArch = new JLabel();
367 jLabelArch.setBounds(new java.awt.Rectangle(12, 112, 155, 20));
368 jLabelArch.setText("Supported Architectures");
369 jLabelToolChainFamily = new JLabel();
370 jLabelToolChainFamily.setBounds(new java.awt.Rectangle(12, 87, 155, 20));
371 jLabelToolChainFamily.setText("Tool Chain Family");
372 jLabelFileName = new JLabel();
373 jLabelFileName.setText("Option String");
374 jLabelFileName.setBounds(new java.awt.Rectangle(12, 12, 155, 20));
375
376 jContentPane = new JPanel();
377 jContentPane.setLayout(null);
378 jContentPane.setPreferredSize(new java.awt.Dimension(505, 222));
379
380 jContentPane.add(jLabelFileName, null);
381 jContentPane.add(getJTextFieldSourceFilesDirectory(), null);
382 jContentPane.add(jLabelToolChainFamily, null);
383 jStarLabel1 = new StarLabel();
384 jStarLabel1.setLocation(new java.awt.Point(0, 10));
385
386 jContentPane.add(jStarLabel1, null);
387 jContentPane.add(jLabelArch, null);
388 jContentPane.add(jLabelTagName, null);
389 jContentPane.add(getJTextFieldTagName(), null);
390 jContentPane.add(jLabelToolCode, null);
391 jContentPane.add(getJTextFieldToolCode(), null);
392 jContentPane.add(getIComboBoxToolCode(), null);
393 jContentPane.add(getJTextFieldToolChainFamily(), null);
394 jContentPane.add(jArchCheckBox, null);
395 jContentPane.add(getJButtonOk(), null);
396 jContentPane.add(getJButtonCancel(), null);
397 jContentPane.add(jLabelBuildTargets, null);
398 jContentPane.add(getJScrollPaneBuildTargets(), null);
399 }
400 return jContentPane;
401 }
402
403 /* (non-Javadoc)
404 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
405 *
406 * Override actionPerformed to listen all actions
407 *
408 */
409 public void actionPerformed(ActionEvent arg0) {
410 if (arg0.getSource() == jButtonOk) {
411 if (checkAdd()) {
412 getCurrentId();
413 this.returnType = DataType.RETURN_TYPE_OK;
414 this.setVisible(false);
415 }
416 }
417
418 if (arg0.getSource() == jButtonCancel) {
419 this.returnType = DataType.RETURN_TYPE_CANCEL;
420 this.setVisible(false);
421 }
422 }
423
424 private BuildOptionsIdentification getCurrentId() {
425 String arg0 = this.jTextFieldFileOption.getText();
426 Vector<String> arg1 = this.iCheckBoxListBuildTargets.getAllCheckedItemsString();
427 String arg2 = this.jTextFieldToolChainFamily.getText();
428 String arg3 = this.jTextFieldTagName.getText();
429 String arg4 = this.iComboBoxToolCode.getSelectedItem().toString();
430 if (arg4.equals(DataType.EMPTY_SELECT_ITEM)) {
431 arg4 = "";
432 }
433 Vector<String> arg5 = this.jArchCheckBox.getSelectedItemsVector();
434
435 id = new BuildOptionsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
436 return id;
437 }
438
439 /**
440 Data validation for all fields
441
442 @retval true - All datas are valid
443 @retval false - At least one data is invalid
444
445 **/
446 public boolean checkAdd() {
447 //
448 // Check Option
449 //
450 if (isEmpty(this.jTextFieldFileOption.getText())) {
451 Log.wrn("Update Build Options", "Option String must be entered!");
452 return false;
453 }
454
455 //
456 // Check TagName
457 //
458 if (!isEmpty(this.jTextFieldTagName.getText())) {
459 if (!DataValidation.isTagName(this.jTextFieldTagName.getText())) {
460 Log.wrn("Update Build Options", "Incorrect data type for Tag Name");
461 return false;
462 }
463 }
464
465 //
466 // Check ToolCode
467 //
468 if (!isEmpty(this.jTextFieldToolCode.getText())) {
469 if (!DataValidation.isToolCode(this.jTextFieldToolCode.getText())) {
470 Log.wrn("Update Build Options", "Incorrect data type for Tool Code");
471 return false;
472 }
473 }
474
475 //
476 // Check ToolChainFamily
477 //
478 if (!isEmpty(this.jTextFieldToolChainFamily.getText())) {
479 if (!DataValidation.isToolChainFamily(this.jTextFieldToolChainFamily.getText())) {
480 Log.wrn("Update Build Options", "Incorrect data type for Tool Chain Family");
481 return false;
482 }
483 }
484
485 return true;
486 }
487
488 public BuildOptionsIdentification getId() {
489 return id;
490 }
491
492 public void setId(BuildOptionsIdentification id) {
493 this.id = id;
494 }
495 }