3 The file is used to create, update SourceFiles section of the MSA file
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
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.
15 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
17 import java
.awt
.event
.ActionEvent
;
19 import java
.util
.Vector
;
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
;
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
;
41 * The class is used to create, update SourceFiles section of the MSA file
46 public class SourceFilesDlg
extends IDialog
{
49 /// Define class Serial Version UID
51 private static final long serialVersionUID
= -6765742852142775378L;
54 // Define class members
56 private JPanel jContentPane
= null;
58 private JLabel jLabelFileName
= null;
60 private JTextField jTextFieldFileName
= null;
62 private JButton jButtonOpenFile
= null;
64 private JLabel jLabelToolChainFamily
= null;
66 private StarLabel jStarLabel1
= null;
68 private JLabel jLabelArch
= null;
70 private JScrollPane jScrollPane
= null;
72 private JLabel jLabelTagName
= null;
74 private JTextField jTextFieldTagName
= null;
76 private JLabel jLabelToolCode
= null;
78 private JTextField jTextFieldToolCode
= null;
80 private IComboBox iComboBoxToolCode
= null;
82 private JTextField jTextFieldToolChainFamily
= null;
84 private JLabel jLabelFeatureFlag
= null;
86 private JTextField jTextFieldFeatureFlag
= null;
88 private ArchCheckBox jArchCheckBox
= null;
90 private JButton jButtonOk
= null;
92 private JButton jButtonCancel
= null;
97 private SourceFilesIdentification sfid
[] = null;
99 private String msaFileName
= "";
101 private EnumerationData ed
= new EnumerationData();
104 This method initializes jTextFieldFileName
106 @return javax.swing.JTextField jTextFieldFileName
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");
116 return jTextFieldFileName
;
120 This method initializes jButtonOpenFile
122 @return javax.swing.JButton jButtonOpenFile
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);
133 return jButtonOpenFile
;
137 This method initializes jScrollPane
139 @return javax.swing.JScrollPane
141 private JScrollPane
getJScrollPane() {
142 if (jScrollPane
== null) {
143 jScrollPane
= new JScrollPane();
144 jScrollPane
.setViewportView(getJContentPane());
150 * This method initializes jTextFieldTagName
152 * @return javax.swing.JTextField
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");
161 return jTextFieldTagName
;
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>");
174 return iComboBoxToolCode
;
178 * This method initializes jTextFieldToolCode
180 * @return javax.swing.JTextField
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);
190 return jTextFieldToolCode
;
194 * This method initializes jTextFieldToolChainFamily
196 * @return javax.swing.JTextField
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");
205 return jTextFieldToolChainFamily
;
209 * This method initializes jTextFieldFeatureFlag
211 * @return javax.swing.JTextField
213 private JTextField
getJTextFieldFeatureFlag() {
214 if (jTextFieldFeatureFlag
== null) {
215 jTextFieldFeatureFlag
= new JTextField();
216 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 112, 340, 20));
217 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(340, 20));
218 jTextFieldFeatureFlag
.setToolTipText("RESERVED FOR FUTURE USE");
220 return jTextFieldFeatureFlag
;
224 This method initializes jButtonOk
226 @return javax.swing.JButton
229 private JButton
getJButtonOk() {
230 if (jButtonOk
== null) {
231 jButtonOk
= new JButton();
232 jButtonOk
.setBounds(new java
.awt
.Rectangle(317, 172, 90, 20));
233 jButtonOk
.setText("Ok");
234 jButtonOk
.addActionListener(this);
240 This method initializes jButtonCancel
242 @return javax.swing.JButton
245 private JButton
getJButtonCancel() {
246 if (jButtonCancel
== null) {
247 jButtonCancel
= new JButton();
248 jButtonCancel
.setBounds(new java
.awt
.Rectangle(412, 172, 90, 20));
249 jButtonCancel
.setText("Cancel");
250 jButtonCancel
.addActionListener(this);
252 return jButtonCancel
;
255 public static void main(String
[] args
) {
260 This is the default constructor
263 public SourceFilesDlg(SourceFilesIdentification inSourceFilesIdentification
, IFrame iFrame
, String fileName
) {
265 init(inSourceFilesIdentification
, fileName
);
269 This method initializes this
272 private void init() {
273 this.setSize(525, 240);
274 this.setContentPane(getJScrollPane());
275 this.setTitle("Source Files");
276 this.setViewMode(false);
278 Tools
.generateComboBoxByVector(iComboBoxToolCode
, ed
.getVToolCode());
282 This method initializes this
283 Fill values to all fields if these values are not empty
286 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
289 private void init(SourceFilesIdentification inSourceFilesIdentifications
, String fileName
) {
291 //this.sfid = inSourceFilesIdentifications;
292 this.msaFileName
= fileName
;
294 if (inSourceFilesIdentifications
!= null) {
295 this.jTextFieldFileName
.setText(inSourceFilesIdentifications
.getFilename());
296 this.jTextFieldTagName
.setText(inSourceFilesIdentifications
.getTagName());
299 // Generate Tool Code selection list
301 Vector
<String
> v
= ed
.getVToolCode();
302 boolean isFind
= false;
303 String strToolCode
= inSourceFilesIdentifications
.getToolCode();
306 // If the input value is not in the default list, add it to the list
308 if (strToolCode
!= null) {
309 for (int index
= 0; index
< v
.size(); index
++) {
310 if (v
.elementAt(index
).equals(strToolCode
)) {
315 if (!isFind
&& !isEmpty(strToolCode
)) {
316 v
.addElement(strToolCode
);
320 Tools
.generateComboBoxByVector(iComboBoxToolCode
, v
);
321 this.iComboBoxToolCode
.setSelectedItem(strToolCode
);
323 this.jTextFieldToolChainFamily
.setText(inSourceFilesIdentifications
.getToolChainFamily());
324 jTextFieldFeatureFlag
.setText(inSourceFilesIdentifications
.getFeatureFlag());
325 this.jArchCheckBox
.setSelectedItems(inSourceFilesIdentifications
.getSupArchList());
330 Disable all components when the mode is view
332 @param isView true - The view mode; false - The non-view mode
335 public void setViewMode(boolean isView
) {
337 this.jTextFieldFileName
.setEnabled(!isView
);
338 this.jButtonOpenFile
.setEnabled(!isView
);
343 This method initializes jContentPane
345 @return javax.swing.JPanel jContentPane
348 private JPanel
getJContentPane() {
349 if (jContentPane
== null) {
350 jArchCheckBox
= new ArchCheckBox();
351 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 137, 340, 20));
352 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(340, 20));
353 jLabelFeatureFlag
= new JLabel();
354 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 112, 155, 20));
355 jLabelFeatureFlag
.setText("Feature Flag Expression");
356 jLabelToolCode
= new JLabel();
357 jLabelToolCode
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
358 jLabelToolCode
.setText("Tool Code");
359 jLabelTagName
= new JLabel();
360 jLabelTagName
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
361 jLabelTagName
.setText("Tag Name");
362 jLabelArch
= new JLabel();
363 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 137, 155, 20));
364 jLabelArch
.setText("Supported Architectures");
365 jLabelToolChainFamily
= new JLabel();
366 jLabelToolChainFamily
.setBounds(new java
.awt
.Rectangle(12, 87, 155, 20));
367 jLabelToolChainFamily
.setText("Tool Chain Family");
368 jLabelFileName
= new JLabel();
369 jLabelFileName
.setText("File Name");
370 jLabelFileName
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
372 jContentPane
= new JPanel();
373 jContentPane
.setLayout(null);
374 jContentPane
.setPreferredSize(new java
.awt
.Dimension(505, 192));
376 jContentPane
.add(jLabelFileName
, null);
377 jContentPane
.add(getJTextFieldSourceFilesDirectory(), null);
378 jContentPane
.add(getJButtonOpenFile(), null);
379 jContentPane
.add(jLabelToolChainFamily
, null);
380 jStarLabel1
= new StarLabel();
381 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
383 jContentPane
.add(jStarLabel1
, null);
384 jContentPane
.add(jLabelArch
, null);
385 jContentPane
.add(jLabelTagName
, null);
386 jContentPane
.add(getJTextFieldTagName(), null);
387 jContentPane
.add(jLabelToolCode
, null);
388 jContentPane
.add(getJTextFieldToolCode(), null);
389 jContentPane
.add(getIComboBoxToolCode(), null);
390 jContentPane
.add(getJTextFieldToolChainFamily(), null);
391 jContentPane
.add(jLabelFeatureFlag
, null);
392 jContentPane
.add(getJTextFieldFeatureFlag(), null);
393 jContentPane
.add(jArchCheckBox
, null);
394 jContentPane
.add(getJButtonOk(), null);
395 jContentPane
.add(getJButtonCancel(), null);
401 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
403 * Override actionPerformed to listen all actions
406 public void actionPerformed(ActionEvent arg0
) {
407 if (arg0
.getSource() == jButtonOpenFile
) {
411 if (arg0
.getSource() == jButtonOk
) {
413 getCurrentSourceFiles();
414 this.returnType
= DataType
.RETURN_TYPE_OK
;
415 this.setVisible(false);
419 if (arg0
.getSource() == jButtonCancel
) {
420 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
421 this.setVisible(false);
425 private SourceFilesIdentification
[] getCurrentSourceFiles() {
426 String name
= this.jTextFieldFileName
.getText();
427 String s
[] = name
.split(";");
428 String tagName
= this.jTextFieldTagName
.getText();
429 String toolCode
= this.iComboBoxToolCode
.getSelectedItem().toString();
430 if (toolCode
.equals(DataType
.EMPTY_SELECT_ITEM
)) {
433 String tcf
= this.jTextFieldToolChainFamily
.getText();
434 String featureFlag
= this.jTextFieldFeatureFlag
.getText();
435 Vector
<String
> arch
= this.jArchCheckBox
.getSelectedItemsVector();
436 sfid
= new SourceFilesIdentification
[s
.length
];
437 for (int index
= 0; index
< s
.length
; index
++) {
438 sfid
[index
] = new SourceFilesIdentification(s
[index
], tagName
, toolCode
, tcf
, featureFlag
, arch
);
444 Data validation for all fields
446 @retval true - All datas are valid
447 @retval false - At least one data is invalid
450 public boolean checkAdd() {
454 if (isEmpty(this.jTextFieldFileName
.getText())) {
455 Log
.wrn("Update Source Files", "File Name couldn't be empty");
458 if (!DataValidation
.isFilename(this.jTextFieldFileName
.getText())) {
459 Log
.wrn("Update Source Files", "Incorrect data type for File Name");
466 if (!isEmpty(this.jTextFieldTagName
.getText())) {
467 if (!DataValidation
.isTagName(this.jTextFieldTagName
.getText())) {
468 Log
.wrn("Update Source Files", "Incorrect data type for Tag Name");
476 if (!isEmpty(this.jTextFieldToolCode
.getText())) {
477 if (!DataValidation
.isToolCode(this.jTextFieldToolCode
.getText())) {
478 Log
.wrn("Update Source Files", "Incorrect data type for Tool Code");
484 // Check ToolChainFamily
486 if (!isEmpty(this.jTextFieldToolChainFamily
.getText())) {
487 if (!DataValidation
.isToolChainFamily(this.jTextFieldToolChainFamily
.getText())) {
488 Log
.wrn("Update Source Files", "Incorrect data type for Tool Chain Family");
496 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
497 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
498 Log
.wrn("Update Source Files", "Incorrect data type for Feature Flag");
507 Display a file open browser to let user select file
510 private void selectFile() {
511 JFileChooser fc
= new JFileChooser();
512 fc
.setCurrentDirectory(new File(Tools
.getFilePathOnly(msaFileName
)));
513 fc
.setMultiSelectionEnabled(true);
514 int result
= fc
.showOpenDialog(new JPanel());
515 if (result
== JFileChooser
.APPROVE_OPTION
) {
516 File f
[] = fc
.getSelectedFiles();
518 for (int index
= 0; index
< f
.length
; index
++) {
519 s
= s
+ f
[index
].getName() + ";";
521 this.jTextFieldFileName
.setText(s
);
525 public SourceFilesIdentification
[] getSfid() {
529 public void setSfid(SourceFilesIdentification
[] sfid
) {