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
.ModuleIdentification
;
39 import org
.tianocore
.frameworkwizard
.module
.Identifications
.SourceFiles
.SourceFilesIdentification
;
40 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
43 * The class is used to create, update SourceFiles section of the MSA file
48 public class SourceFilesDlg
extends IDialog
{
51 /// Define class Serial Version UID
53 private static final long serialVersionUID
= -6765742852142775378L;
56 // Define class members
58 private JPanel jContentPane
= null;
60 private JLabel jLabelFileName
= null;
62 private JTextField jTextFieldFileName
= null;
64 private JButton jButtonOpenFile
= null;
66 private JLabel jLabelToolChainFamily
= null;
68 private StarLabel jStarLabel1
= null;
70 private JLabel jLabelArch
= null;
72 private JScrollPane jScrollPane
= null;
74 private JLabel jLabelTagName
= null;
76 private JTextField jTextFieldTagName
= null;
78 private JLabel jLabelToolCode
= null;
80 private JTextField jTextFieldToolCode
= null;
82 private IComboBox iComboBoxToolCode
= null;
84 private JTextField jTextFieldToolChainFamily
= null;
86 private JLabel jLabelFeatureFlag
= null;
88 private JTextField jTextFieldFeatureFlag
= null;
90 private ArchCheckBox jArchCheckBox
= null;
92 private JButton jButtonOk
= null;
94 private JButton jButtonCancel
= null;
99 private SourceFilesIdentification sfid
[] = null;
101 private String msaFileName
= "";
103 private EnumerationData ed
= new EnumerationData();
105 private WorkspaceTools wt
= new WorkspaceTools();
108 This method initializes jTextFieldFileName
110 @return javax.swing.JTextField jTextFieldFileName
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");
120 return jTextFieldFileName
;
124 This method initializes jButtonOpenFile
126 @return javax.swing.JButton jButtonOpenFile
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);
137 return jButtonOpenFile
;
141 This method initializes jScrollPane
143 @return javax.swing.JScrollPane
145 private JScrollPane
getJScrollPane() {
146 if (jScrollPane
== null) {
147 jScrollPane
= new JScrollPane();
148 jScrollPane
.setViewportView(getJContentPane());
154 * This method initializes jTextFieldTagName
156 * @return javax.swing.JTextField
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");
165 return jTextFieldTagName
;
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>");
178 return iComboBoxToolCode
;
182 * This method initializes jTextFieldToolCode
184 * @return javax.swing.JTextField
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);
194 return jTextFieldToolCode
;
198 * This method initializes jTextFieldToolChainFamily
200 * @return javax.swing.JTextField
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");
209 return jTextFieldToolChainFamily
;
213 * This method initializes jTextFieldFeatureFlag
215 * @return javax.swing.JTextField
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);
225 return jTextFieldFeatureFlag
;
229 This method initializes jButtonOk
231 @return javax.swing.JButton
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);
245 This method initializes jButtonCancel
247 @return javax.swing.JButton
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);
257 return jButtonCancel
;
260 public static void main(String
[] args
) {
265 This is the default constructor
268 public SourceFilesDlg(SourceFilesIdentification inSourceFilesIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
270 init(inSourceFilesIdentification
, mid
);
274 This method initializes this
277 private void init() {
278 this.setSize(525, 240);
279 this.setContentPane(getJScrollPane());
280 this.setTitle("Source Files");
281 this.setViewMode(false);
283 Tools
.generateComboBoxByVector(iComboBoxToolCode
, ed
.getVToolCode());
287 This method initializes this
288 Fill values to all fields if these values are not empty
291 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
294 private void init(SourceFilesIdentification inSourceFilesIdentifications
, ModuleIdentification mid
) {
296 this.msaFileName
= mid
.getPath();
299 // Init arch with module's arch
301 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
303 if (inSourceFilesIdentifications
!= null) {
304 this.jTextFieldFileName
.setText(inSourceFilesIdentifications
.getFilename());
305 this.jTextFieldTagName
.setText(inSourceFilesIdentifications
.getTagName());
308 // // Generate Tool Code selection list
310 // Vector<String> v = ed.getVToolCode();
311 // boolean isFind = false;
312 // String strToolCode = inSourceFilesIdentifications.getToolCode();
315 // // If the input value is not in the default list, add it to the list
317 // if (strToolCode != null) {
318 // for (int index = 0; index < v.size(); index++) {
319 // if (v.elementAt(index).equals(strToolCode)) {
324 // if (!isFind && !isEmpty(strToolCode)) {
325 // v.addElement(strToolCode);
329 Tools
.generateComboBoxByVector(iComboBoxToolCode
, ed
.getVToolCode());
330 this.iComboBoxToolCode
.setSelectedItem(inSourceFilesIdentifications
.getToolCode());
332 this.jTextFieldToolChainFamily
.setText(inSourceFilesIdentifications
.getToolChainFamily());
333 jTextFieldFeatureFlag
.setText(inSourceFilesIdentifications
.getFeatureFlag());
334 this.jArchCheckBox
.setSelectedItems(inSourceFilesIdentifications
.getSupArchList());
339 Disable all components when the mode is view
341 @param isView true - The view mode; false - The non-view mode
344 public void setViewMode(boolean isView
) {
346 this.jTextFieldFileName
.setEnabled(!isView
);
347 this.jButtonOpenFile
.setEnabled(!isView
);
352 This method initializes jContentPane
354 @return javax.swing.JPanel jContentPane
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));
382 jContentPane
= new JPanel();
383 jContentPane
.setLayout(null);
384 jContentPane
.setPreferredSize(new java
.awt
.Dimension(505, 192));
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));
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);
411 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
413 * Override actionPerformed to listen all actions
416 public void actionPerformed(ActionEvent arg0
) {
417 if (arg0
.getSource() == jButtonOpenFile
) {
421 if (arg0
.getSource() == jButtonOk
) {
423 getCurrentSourceFiles();
424 this.returnType
= DataType
.RETURN_TYPE_OK
;
425 this.setVisible(false);
429 if (arg0
.getSource() == jButtonCancel
) {
430 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
431 this.setVisible(false);
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
)) {
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
);
454 Data validation for all fields
456 @retval true - All datas are valid
457 @retval false - At least one data is invalid
460 public boolean checkAdd() {
464 if (isEmpty(this.jTextFieldFileName
.getText())) {
465 Log
.wrn("Update Source Files", "File Name must be entered!");
468 if (!DataValidation
.isFilename(this.jTextFieldFileName
.getText())) {
469 Log
.wrn("Update Source Files", "Incorrect data type for File Name");
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");
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");
494 // Check ToolChainFamily
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");
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");
517 Display a file open browser to let user select file
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();
528 for (int index
= 0; index
< f
.length
; index
++) {
529 String relativePath
= "";
530 relativePath
= Tools
.getRelativePath(Tools
.getFilePathOnly(f
[index
].getPath()), Tools
.getFilePathOnly(msaFileName
));
531 if (!Tools
.isEmpty(relativePath
)) {
532 relativePath
= relativePath
+ DataType
.UNIX_FILE_SEPARATOR
;
534 s
= s
+ relativePath
+ f
[index
].getName() + ";";
536 this.jTextFieldFileName
.setText(s
);
540 public SourceFilesIdentification
[] getSfid() {
544 public void setSfid(SourceFilesIdentification
[] sfid
) {