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
.Log
;
31 import org
.tianocore
.frameworkwizard
.common
.Tools
;
32 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
36 import org
.tianocore
.frameworkwizard
.module
.Identifications
.SourceFiles
.SourceFilesIdentification
;
39 The class is used to create, update SourceFile of MSA/MBD file
40 It extends IInternalFrame
45 public class SourceFilesDlg
extends IDialog
{
48 /// Define class Serial Version UID
50 private static final long serialVersionUID
= -6765742852142775378L;
53 // Define class members
55 private JPanel jContentPane
= null;
57 private JLabel jLabelFileName
= null;
59 private JTextField jTextFieldFileName
= null;
61 private JButton jButtonOpenFile
= null;
63 private JLabel jLabelToolChainFamily
= null;
65 private StarLabel jStarLabel1
= null;
67 private JLabel jLabelArch
= null;
69 private JScrollPane jScrollPane
= null;
71 private JLabel jLabelTagName
= null;
73 private JTextField jTextFieldTagName
= null;
75 private JLabel jLabelToolCode
= null;
77 private JTextField jTextFieldToolCode
= null;
79 private JTextField jTextFieldToolChainFamily
= null;
81 private JLabel jLabelFeatureFlag
= null;
83 private JTextField jTextFieldFeatureFlag
= null;
85 private ArchCheckBox jArchCheckBox
= null;
87 private JButton jButtonOk
= null;
89 private JButton jButtonCancel
= null;
94 private SourceFilesIdentification sfid
[] = null;
96 private String msaFileName
= "";
99 This method initializes jTextFieldFileName
101 @return javax.swing.JTextField jTextFieldFileName
104 private JTextField
getJTextFieldSourceFilesDirectory() {
105 if (jTextFieldFileName
== null) {
106 jTextFieldFileName
= new JTextField();
107 jTextFieldFileName
.setBounds(new java
.awt
.Rectangle(140, 10, 250, 20));
108 jTextFieldFileName
.setPreferredSize(new java
.awt
.Dimension(250, 20));
109 jTextFieldFileName
.setToolTipText("Path is relative to the MSA file and must include the file name");
111 return jTextFieldFileName
;
115 This method initializes jButtonOpenFile
117 @return javax.swing.JButton jButtonOpenFile
120 private JButton
getJButtonOpenFile() {
121 if (jButtonOpenFile
== null) {
122 jButtonOpenFile
= new JButton();
123 jButtonOpenFile
.setText("Browse");
124 jButtonOpenFile
.setBounds(new java
.awt
.Rectangle(395, 10, 85, 20));
125 jButtonOpenFile
.setPreferredSize(new java
.awt
.Dimension(85, 20));
126 jButtonOpenFile
.addActionListener(this);
128 return jButtonOpenFile
;
132 This method initializes jScrollPane
134 @return javax.swing.JScrollPane
136 private JScrollPane
getJScrollPane() {
137 if (jScrollPane
== null) {
138 jScrollPane
= new JScrollPane();
139 jScrollPane
.setViewportView(getJContentPane());
145 * This method initializes jTextFieldTagName
147 * @return javax.swing.JTextField
149 private JTextField
getJTextFieldTagName() {
150 if (jTextFieldTagName
== null) {
151 jTextFieldTagName
= new JTextField();
152 jTextFieldTagName
.setBounds(new java
.awt
.Rectangle(140, 35, 340, 20));
153 jTextFieldTagName
.setPreferredSize(new java
.awt
.Dimension(340, 20));
154 jTextFieldTagName
.setToolTipText("You may specify a specific tool chain tag name, such as BILL1");
156 return jTextFieldTagName
;
160 * This method initializes jTextFieldToolCode
162 * @return javax.swing.JTextField
164 private JTextField
getJTextFieldToolCode() {
165 if (jTextFieldToolCode
== null) {
166 jTextFieldToolCode
= new JTextField();
167 jTextFieldToolCode
.setBounds(new java
.awt
.Rectangle(140, 60, 340, 20));
168 jTextFieldToolCode
.setPreferredSize(new java
.awt
.Dimension(340, 20));
169 jTextFieldToolCode
.setToolTipText("You may specify a specific tool command, such as ASM");
171 return jTextFieldToolCode
;
175 * This method initializes jTextFieldToolChainFamily
177 * @return javax.swing.JTextField
179 private JTextField
getJTextFieldToolChainFamily() {
180 if (jTextFieldToolChainFamily
== null) {
181 jTextFieldToolChainFamily
= new JTextField();
182 jTextFieldToolChainFamily
.setBounds(new java
.awt
.Rectangle(140, 85, 340, 20));
183 jTextFieldToolChainFamily
.setPreferredSize(new java
.awt
.Dimension(340, 20));
184 jTextFieldToolChainFamily
.setToolTipText("You may specify a specific tool chain family, such as GCC");
186 return jTextFieldToolChainFamily
;
190 * This method initializes jTextFieldFeatureFlag
192 * @return javax.swing.JTextField
194 private JTextField
getJTextFieldFeatureFlag() {
195 if (jTextFieldFeatureFlag
== null) {
196 jTextFieldFeatureFlag
= new JTextField();
197 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(140, 110, 340, 20));
198 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(340, 20));
199 jTextFieldFeatureFlag
.setToolTipText("RESERVED FOR FUTURE USE");
201 return jTextFieldFeatureFlag
;
205 This method initializes jButtonOk
207 @return javax.swing.JButton
210 private JButton
getJButtonOk() {
211 if (jButtonOk
== null) {
212 jButtonOk
= new JButton();
213 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 165, 90, 20));
214 jButtonOk
.setText("Ok");
215 jButtonOk
.addActionListener(this);
221 This method initializes jButtonCancel
223 @return javax.swing.JButton
226 private JButton
getJButtonCancel() {
227 if (jButtonCancel
== null) {
228 jButtonCancel
= new JButton();
229 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 165, 90, 20));
230 jButtonCancel
.setText("Cancel");
231 jButtonCancel
.addActionListener(this);
233 return jButtonCancel
;
236 public static void main(String
[] args
) {
241 This is the default constructor
244 public SourceFilesDlg(SourceFilesIdentification inSourceFilesIdentification
, IFrame iFrame
, String fileName
) {
246 init(inSourceFilesIdentification
, fileName
);
250 This method initializes this
253 private void init() {
254 this.setSize(510, 240);
255 this.setContentPane(getJScrollPane());
256 this.setTitle("Source Files");
257 this.setViewMode(false);
262 This method initializes this
263 Fill values to all fields if these values are not empty
266 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
269 private void init(SourceFilesIdentification inSourceFilesIdentifications
, String fileName
) {
271 //this.sfid = inSourceFilesIdentifications;
272 this.msaFileName
= fileName
;
274 if (inSourceFilesIdentifications
!= null) {
275 this.jTextFieldFileName
.setText(inSourceFilesIdentifications
.getFilename());
276 this.jTextFieldTagName
.setText(inSourceFilesIdentifications
.getTagName());
277 this.jTextFieldToolCode
.setText(inSourceFilesIdentifications
.getToolCode());
278 this.jTextFieldToolChainFamily
.setText(inSourceFilesIdentifications
.getToolChainFamily());
279 jTextFieldFeatureFlag
.setText(inSourceFilesIdentifications
.getFeatureFlag());
280 this.jArchCheckBox
.setSelectedItems(inSourceFilesIdentifications
.getSupArchList());
285 Disable all components when the mode is view
287 @param isView true - The view mode; false - The non-view mode
290 public void setViewMode(boolean isView
) {
292 this.jTextFieldFileName
.setEnabled(!isView
);
293 this.jButtonOpenFile
.setEnabled(!isView
);
298 This method initializes jContentPane
300 @return javax.swing.JPanel jContentPane
303 private JPanel
getJContentPane() {
304 if (jContentPane
== null) {
305 jArchCheckBox
= new ArchCheckBox();
306 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(140, 135, 340, 20));
307 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(340, 20));
308 jLabelFeatureFlag
= new JLabel();
309 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 110, 120, 20));
310 jLabelFeatureFlag
.setText("Feature Flag Expression");
311 jLabelToolCode
= new JLabel();
312 jLabelToolCode
.setBounds(new java
.awt
.Rectangle(15, 60, 120, 20));
313 jLabelToolCode
.setText("Tool Code");
314 jLabelTagName
= new JLabel();
315 jLabelTagName
.setBounds(new java
.awt
.Rectangle(15, 35, 120, 20));
316 jLabelTagName
.setText("Tag Name");
317 jLabelArch
= new JLabel();
318 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 135, 120, 20));
319 jLabelArch
.setText("Supported Architectures");
320 jLabelToolChainFamily
= new JLabel();
321 jLabelToolChainFamily
.setBounds(new java
.awt
.Rectangle(15, 85, 120, 20));
322 jLabelToolChainFamily
.setText("Tool Chain Family");
323 jLabelFileName
= new JLabel();
324 jLabelFileName
.setText("File Name");
325 jLabelFileName
.setBounds(new java
.awt
.Rectangle(15, 10, 120, 20));
327 jContentPane
= new JPanel();
328 jContentPane
.setLayout(null);
329 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 185));
331 jContentPane
.add(jLabelFileName
, null);
332 jContentPane
.add(getJTextFieldSourceFilesDirectory(), null);
333 jContentPane
.add(getJButtonOpenFile(), null);
334 jContentPane
.add(jLabelToolChainFamily
, null);
335 jStarLabel1
= new StarLabel();
336 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
338 jContentPane
.add(jStarLabel1
, null);
339 jContentPane
.add(jLabelArch
, null);
340 jContentPane
.add(jLabelTagName
, null);
341 jContentPane
.add(getJTextFieldTagName(), null);
342 jContentPane
.add(jLabelToolCode
, null);
343 jContentPane
.add(getJTextFieldToolCode(), null);
344 jContentPane
.add(getJTextFieldToolChainFamily(), null);
345 jContentPane
.add(jLabelFeatureFlag
, null);
346 jContentPane
.add(getJTextFieldFeatureFlag(), null);
347 jContentPane
.add(jArchCheckBox
, null);
348 jContentPane
.add(getJButtonOk(), null);
349 jContentPane
.add(getJButtonCancel(), null);
355 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
357 * Override actionPerformed to listen all actions
360 public void actionPerformed(ActionEvent arg0
) {
361 if (arg0
.getSource() == jButtonOpenFile
) {
365 if (arg0
.getSource() == jButtonOk
) {
367 getCurrentSourceFiles();
368 this.returnType
= DataType
.RETURN_TYPE_OK
;
369 this.setVisible(false);
373 if (arg0
.getSource() == jButtonCancel
) {
374 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
375 this.setVisible(false);
379 private SourceFilesIdentification
[] getCurrentSourceFiles() {
380 String name
= this.jTextFieldFileName
.getText();
381 String s
[] = name
.split(";");
382 String tagName
= this.jTextFieldTagName
.getText();
383 String toolCode
= this.jTextFieldToolCode
.getText();
384 String tcf
= this.jTextFieldToolChainFamily
.getText();
385 String featureFlag
= this.jTextFieldFeatureFlag
.getText();
386 Vector
<String
> arch
= this.jArchCheckBox
.getSelectedItemsVector();
387 sfid
= new SourceFilesIdentification
[s
.length
];
388 for (int index
= 0; index
< s
.length
; index
++) {
389 sfid
[index
] = new SourceFilesIdentification(s
[index
], tagName
, toolCode
, tcf
, featureFlag
, arch
);
395 Data validation for all fields
397 @retval true - All datas are valid
398 @retval false - At least one data is invalid
401 public boolean checkAdd() {
405 if (isEmpty(this.jTextFieldFileName
.getText())) {
406 Log
.wrn("Update Source Files", "File Name couldn't be empty");
409 if (!DataValidation
.isFilename(this.jTextFieldFileName
.getText())) {
410 Log
.wrn("Update Source Files", "Incorrect data type for File Name");
417 if (!isEmpty(this.jTextFieldTagName
.getText())) {
418 if (!DataValidation
.isTagName(this.jTextFieldTagName
.getText())) {
419 Log
.wrn("Update Source Files", "Incorrect data type for Tag Name");
427 if (!isEmpty(this.jTextFieldToolCode
.getText())) {
428 if (!DataValidation
.isToolCode(this.jTextFieldToolCode
.getText())) {
429 Log
.wrn("Update Source Files", "Incorrect data type for Tool Code");
435 // Check ToolChainFamily
437 if (!isEmpty(this.jTextFieldToolChainFamily
.getText())) {
438 if (!DataValidation
.isToolChainFamily(this.jTextFieldToolChainFamily
.getText())) {
439 Log
.wrn("Update Source Files", "Incorrect data type for Tool Chain Family");
447 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
448 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
449 Log
.wrn("Update Source Files", "Incorrect data type for Feature Flag");
458 Display a file open browser to let user select file
461 private void selectFile() {
462 JFileChooser fc
= new JFileChooser();
463 fc
.setCurrentDirectory(new File(Tools
.getFilePathOnly(msaFileName
)));
464 fc
.setMultiSelectionEnabled(true);
465 int result
= fc
.showOpenDialog(new JPanel());
466 if (result
== JFileChooser
.APPROVE_OPTION
) {
467 File f
[] = fc
.getSelectedFiles();
469 for (int index
= 0; index
< f
.length
; index
++) {
470 s
= s
+ f
[index
].getName() + ";";
472 this.jTextFieldFileName
.setText(s
);
476 public SourceFilesIdentification
[] getSfid() {
480 public void setSfid(SourceFilesIdentification
[] sfid
) {