3 The file is used to create, update SourceFile of MSA/MBD 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 SourceFile of MSA/MBD file
42 It extends IInternalFrame
47 public class SourceFilesDlg
extends IDialog
{
50 /// Define class Serial Version UID
52 private static final long serialVersionUID
= -6765742852142775378L;
55 // Define class members
57 private JPanel jContentPane
= null;
59 private JLabel jLabelFileName
= null;
61 private JTextField jTextFieldFileName
= null;
63 private JButton jButtonOpenFile
= null;
65 private JLabel jLabelToolChainFamily
= null;
67 private StarLabel jStarLabel1
= null;
69 private JLabel jLabelArch
= null;
71 private JScrollPane jScrollPane
= null;
73 private JLabel jLabelTagName
= null;
75 private JTextField jTextFieldTagName
= null;
77 private JLabel jLabelToolCode
= null;
79 private JTextField jTextFieldToolCode
= null;
81 private IComboBox iComboBoxToolCode
= null;
83 private JTextField jTextFieldToolChainFamily
= null;
85 private JLabel jLabelFeatureFlag
= null;
87 private JTextField jTextFieldFeatureFlag
= null;
89 private ArchCheckBox jArchCheckBox
= null;
91 private JButton jButtonOk
= null;
93 private JButton jButtonCancel
= null;
98 private SourceFilesIdentification sfid
[] = null;
100 private String msaFileName
= "";
102 private EnumerationData ed
= new EnumerationData();
105 This method initializes jTextFieldFileName
107 @return javax.swing.JTextField jTextFieldFileName
110 private JTextField
getJTextFieldSourceFilesDirectory() {
111 if (jTextFieldFileName
== null) {
112 jTextFieldFileName
= new JTextField();
113 jTextFieldFileName
.setBounds(new java
.awt
.Rectangle(140, 10, 250, 20));
114 jTextFieldFileName
.setPreferredSize(new java
.awt
.Dimension(250, 20));
115 jTextFieldFileName
.setToolTipText("Path is relative to the MSA file and must include the file name");
117 return jTextFieldFileName
;
121 This method initializes jButtonOpenFile
123 @return javax.swing.JButton jButtonOpenFile
126 private JButton
getJButtonOpenFile() {
127 if (jButtonOpenFile
== null) {
128 jButtonOpenFile
= new JButton();
129 jButtonOpenFile
.setText("Browse");
130 jButtonOpenFile
.setBounds(new java
.awt
.Rectangle(395, 10, 85, 20));
131 jButtonOpenFile
.setPreferredSize(new java
.awt
.Dimension(85, 20));
132 jButtonOpenFile
.addActionListener(this);
134 return jButtonOpenFile
;
138 This method initializes jScrollPane
140 @return javax.swing.JScrollPane
142 private JScrollPane
getJScrollPane() {
143 if (jScrollPane
== null) {
144 jScrollPane
= new JScrollPane();
145 jScrollPane
.setViewportView(getJContentPane());
151 * This method initializes jTextFieldTagName
153 * @return javax.swing.JTextField
155 private JTextField
getJTextFieldTagName() {
156 if (jTextFieldTagName
== null) {
157 jTextFieldTagName
= new JTextField();
158 jTextFieldTagName
.setBounds(new java
.awt
.Rectangle(140, 35, 340, 20));
159 jTextFieldTagName
.setPreferredSize(new java
.awt
.Dimension(340, 20));
160 jTextFieldTagName
.setToolTipText("You may specify a specific tool chain tag name, such as BILL1");
162 return jTextFieldTagName
;
165 private IComboBox
getIComboBoxToolCode() {
166 if (iComboBoxToolCode
== null) {
167 iComboBoxToolCode
= new IComboBox();
168 iComboBoxToolCode
.setBounds(new java
.awt
.Rectangle(140, 60, 340, 20));
169 iComboBoxToolCode
.setPreferredSize(new java
.awt
.Dimension(340, 20));
170 iComboBoxToolCode
.setToolTipText("<html>You may select a specific tool command from drop down list, <br>"
171 + "or you can DOUBLE-CLICK this fild to enter your customizing <br>"
172 + "tool command.<br>"
173 + "Press ENTER to save your input or press ESCAPE to quit</html>");
175 return iComboBoxToolCode
;
179 * This method initializes jTextFieldToolCode
181 * @return javax.swing.JTextField
183 private JTextField
getJTextFieldToolCode() {
184 if (jTextFieldToolCode
== null) {
185 jTextFieldToolCode
= new JTextField();
186 jTextFieldToolCode
.setBounds(new java
.awt
.Rectangle(140, 60, 340, 20));
187 jTextFieldToolCode
.setPreferredSize(new java
.awt
.Dimension(340, 20));
188 jTextFieldToolCode
.setToolTipText("You may specify a specific tool command, such as ASM");
189 jTextFieldToolCode
.setVisible(false);
191 return jTextFieldToolCode
;
195 * This method initializes jTextFieldToolChainFamily
197 * @return javax.swing.JTextField
199 private JTextField
getJTextFieldToolChainFamily() {
200 if (jTextFieldToolChainFamily
== null) {
201 jTextFieldToolChainFamily
= new JTextField();
202 jTextFieldToolChainFamily
.setBounds(new java
.awt
.Rectangle(140, 85, 340, 20));
203 jTextFieldToolChainFamily
.setPreferredSize(new java
.awt
.Dimension(340, 20));
204 jTextFieldToolChainFamily
.setToolTipText("You may specify a specific tool chain family, such as GCC");
206 return jTextFieldToolChainFamily
;
210 * This method initializes jTextFieldFeatureFlag
212 * @return javax.swing.JTextField
214 private JTextField
getJTextFieldFeatureFlag() {
215 if (jTextFieldFeatureFlag
== null) {
216 jTextFieldFeatureFlag
= new JTextField();
217 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(140, 110, 340, 20));
218 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(340, 20));
219 jTextFieldFeatureFlag
.setToolTipText("RESERVED FOR FUTURE USE");
221 return jTextFieldFeatureFlag
;
225 This method initializes jButtonOk
227 @return javax.swing.JButton
230 private JButton
getJButtonOk() {
231 if (jButtonOk
== null) {
232 jButtonOk
= new JButton();
233 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 165, 90, 20));
234 jButtonOk
.setText("Ok");
235 jButtonOk
.addActionListener(this);
241 This method initializes jButtonCancel
243 @return javax.swing.JButton
246 private JButton
getJButtonCancel() {
247 if (jButtonCancel
== null) {
248 jButtonCancel
= new JButton();
249 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 165, 90, 20));
250 jButtonCancel
.setText("Cancel");
251 jButtonCancel
.addActionListener(this);
253 return jButtonCancel
;
256 public static void main(String
[] args
) {
261 This is the default constructor
264 public SourceFilesDlg(SourceFilesIdentification inSourceFilesIdentification
, IFrame iFrame
, String fileName
) {
266 init(inSourceFilesIdentification
, fileName
);
270 This method initializes this
273 private void init() {
274 this.setSize(510, 240);
275 this.setContentPane(getJScrollPane());
276 this.setTitle("Source Files");
277 this.setViewMode(false);
279 Tools
.generateComboBoxByVector(iComboBoxToolCode
, ed
.getVToolCode());
283 This method initializes this
284 Fill values to all fields if these values are not empty
287 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
290 private void init(SourceFilesIdentification inSourceFilesIdentifications
, String fileName
) {
292 //this.sfid = inSourceFilesIdentifications;
293 this.msaFileName
= fileName
;
295 if (inSourceFilesIdentifications
!= null) {
296 this.jTextFieldFileName
.setText(inSourceFilesIdentifications
.getFilename());
297 this.jTextFieldTagName
.setText(inSourceFilesIdentifications
.getTagName());
300 // Generate Tool Code selection list
302 Vector
<String
> v
= ed
.getVToolCode();
303 boolean isFind
= false;
304 String strToolCode
= inSourceFilesIdentifications
.getToolCode();
307 // If the input value is not in the default list, add it to the list
309 if (strToolCode
!= null) {
310 for (int index
= 0; index
< v
.size(); index
++) {
311 if (v
.elementAt(index
).equals(strToolCode
)) {
316 if (!isFind
&& !isEmpty(strToolCode
)) {
317 v
.addElement(strToolCode
);
321 Tools
.generateComboBoxByVector(iComboBoxToolCode
, v
);
322 this.iComboBoxToolCode
.setSelectedItem(strToolCode
);
324 this.jTextFieldToolChainFamily
.setText(inSourceFilesIdentifications
.getToolChainFamily());
325 jTextFieldFeatureFlag
.setText(inSourceFilesIdentifications
.getFeatureFlag());
326 this.jArchCheckBox
.setSelectedItems(inSourceFilesIdentifications
.getSupArchList());
331 Disable all components when the mode is view
333 @param isView true - The view mode; false - The non-view mode
336 public void setViewMode(boolean isView
) {
338 this.jTextFieldFileName
.setEnabled(!isView
);
339 this.jButtonOpenFile
.setEnabled(!isView
);
344 This method initializes jContentPane
346 @return javax.swing.JPanel jContentPane
349 private JPanel
getJContentPane() {
350 if (jContentPane
== null) {
351 jArchCheckBox
= new ArchCheckBox();
352 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(140, 135, 340, 20));
353 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(340, 20));
354 jLabelFeatureFlag
= new JLabel();
355 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 110, 120, 20));
356 jLabelFeatureFlag
.setText("Feature Flag Expression");
357 jLabelToolCode
= new JLabel();
358 jLabelToolCode
.setBounds(new java
.awt
.Rectangle(15, 60, 120, 20));
359 jLabelToolCode
.setText("Tool Code");
360 jLabelTagName
= new JLabel();
361 jLabelTagName
.setBounds(new java
.awt
.Rectangle(15, 35, 120, 20));
362 jLabelTagName
.setText("Tag Name");
363 jLabelArch
= new JLabel();
364 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 135, 120, 20));
365 jLabelArch
.setText("Supported Architectures");
366 jLabelToolChainFamily
= new JLabel();
367 jLabelToolChainFamily
.setBounds(new java
.awt
.Rectangle(15, 85, 120, 20));
368 jLabelToolChainFamily
.setText("Tool Chain Family");
369 jLabelFileName
= new JLabel();
370 jLabelFileName
.setText("File Name");
371 jLabelFileName
.setBounds(new java
.awt
.Rectangle(15, 10, 120, 20));
373 jContentPane
= new JPanel();
374 jContentPane
.setLayout(null);
375 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 185));
377 jContentPane
.add(jLabelFileName
, null);
378 jContentPane
.add(getJTextFieldSourceFilesDirectory(), null);
379 jContentPane
.add(getJButtonOpenFile(), null);
380 jContentPane
.add(jLabelToolChainFamily
, null);
381 jStarLabel1
= new StarLabel();
382 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
384 jContentPane
.add(jStarLabel1
, null);
385 jContentPane
.add(jLabelArch
, null);
386 jContentPane
.add(jLabelTagName
, null);
387 jContentPane
.add(getJTextFieldTagName(), null);
388 jContentPane
.add(jLabelToolCode
, null);
389 jContentPane
.add(getJTextFieldToolCode(), null);
390 jContentPane
.add(getIComboBoxToolCode(), null);
391 jContentPane
.add(getJTextFieldToolChainFamily(), null);
392 jContentPane
.add(jLabelFeatureFlag
, null);
393 jContentPane
.add(getJTextFieldFeatureFlag(), null);
394 jContentPane
.add(jArchCheckBox
, null);
395 jContentPane
.add(getJButtonOk(), null);
396 jContentPane
.add(getJButtonCancel(), null);
402 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
404 * Override actionPerformed to listen all actions
407 public void actionPerformed(ActionEvent arg0
) {
408 if (arg0
.getSource() == jButtonOpenFile
) {
412 if (arg0
.getSource() == jButtonOk
) {
414 getCurrentSourceFiles();
415 this.returnType
= DataType
.RETURN_TYPE_OK
;
416 this.setVisible(false);
420 if (arg0
.getSource() == jButtonCancel
) {
421 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
422 this.setVisible(false);
426 private SourceFilesIdentification
[] getCurrentSourceFiles() {
427 String name
= this.jTextFieldFileName
.getText();
428 String s
[] = name
.split(";");
429 String tagName
= this.jTextFieldTagName
.getText();
430 String toolCode
= this.iComboBoxToolCode
.getSelectedItem().toString();
431 if (toolCode
.equals(DataType
.EMPTY_SELECT_ITEM
)) {
434 String tcf
= this.jTextFieldToolChainFamily
.getText();
435 String featureFlag
= this.jTextFieldFeatureFlag
.getText();
436 Vector
<String
> arch
= this.jArchCheckBox
.getSelectedItemsVector();
437 sfid
= new SourceFilesIdentification
[s
.length
];
438 for (int index
= 0; index
< s
.length
; index
++) {
439 sfid
[index
] = new SourceFilesIdentification(s
[index
], tagName
, toolCode
, tcf
, featureFlag
, arch
);
445 Data validation for all fields
447 @retval true - All datas are valid
448 @retval false - At least one data is invalid
451 public boolean checkAdd() {
455 if (isEmpty(this.jTextFieldFileName
.getText())) {
456 Log
.wrn("Update Source Files", "File Name couldn't be empty");
459 if (!DataValidation
.isFilename(this.jTextFieldFileName
.getText())) {
460 Log
.wrn("Update Source Files", "Incorrect data type for File Name");
467 if (!isEmpty(this.jTextFieldTagName
.getText())) {
468 if (!DataValidation
.isTagName(this.jTextFieldTagName
.getText())) {
469 Log
.wrn("Update Source Files", "Incorrect data type for Tag Name");
477 if (!isEmpty(this.jTextFieldToolCode
.getText())) {
478 if (!DataValidation
.isToolCode(this.jTextFieldToolCode
.getText())) {
479 Log
.wrn("Update Source Files", "Incorrect data type for Tool Code");
485 // Check ToolChainFamily
487 if (!isEmpty(this.jTextFieldToolChainFamily
.getText())) {
488 if (!DataValidation
.isToolChainFamily(this.jTextFieldToolChainFamily
.getText())) {
489 Log
.wrn("Update Source Files", "Incorrect data type for Tool Chain Family");
497 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
498 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
499 Log
.wrn("Update Source Files", "Incorrect data type for Feature Flag");
508 Display a file open browser to let user select file
511 private void selectFile() {
512 JFileChooser fc
= new JFileChooser();
513 fc
.setCurrentDirectory(new File(Tools
.getFilePathOnly(msaFileName
)));
514 fc
.setMultiSelectionEnabled(true);
515 int result
= fc
.showOpenDialog(new JPanel());
516 if (result
== JFileChooser
.APPROVE_OPTION
) {
517 File f
[] = fc
.getSelectedFiles();
519 for (int index
= 0; index
< f
.length
; index
++) {
520 s
= s
+ f
[index
].getName() + ";";
522 this.jTextFieldFileName
.setText(s
);
526 public SourceFilesIdentification
[] getSfid() {
530 public void setSfid(SourceFilesIdentification
[] sfid
) {