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