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