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
;
18 import java
.util
.Vector
;
20 import javax
.swing
.JButton
;
21 import javax
.swing
.JFileChooser
;
22 import javax
.swing
.JLabel
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JScrollPane
;
25 import javax
.swing
.JTextField
;
27 import org
.tianocore
.frameworkwizard
.common
.DataType
;
28 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
29 import org
.tianocore
.frameworkwizard
.common
.Log
;
30 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
31 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
32 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
34 import org
.tianocore
.frameworkwizard
.module
.Identifications
.SourceFiles
.SourceFilesIdentification
;
35 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
38 The class is used to create, update SourceFile of MSA/MBD file
39 It extends IInternalFrame
44 public class SourceFilesDlg
extends IDialog
{
47 /// Define class Serial Version UID
49 private static final long serialVersionUID
= -6765742852142775378L;
52 // Define class members
54 private JPanel jContentPane
= null;
56 private JLabel jLabelFileName
= null;
58 private JTextField jTextFieldFileName
= null;
60 private JButton jButtonOpenFile
= null;
62 private JLabel jLabelToolChainFamily
= null;
64 private StarLabel jStarLabel1
= null;
66 private JLabel jLabelArch
= null;
68 private JScrollPane jScrollPane
= null;
70 private JLabel jLabelTagName
= null;
72 private JTextField jTextFieldTagName
= null;
74 private JLabel jLabelToolCode
= null;
76 private JTextField jTextFieldToolCode
= null;
78 private JTextField jTextFieldToolChainFamily
= null;
80 private JLabel jLabelFeatureFlag
= null;
82 private JTextField jTextFieldFeatureFlag
= null;
84 private ArchCheckBox jArchCheckBox
= null;
89 private SourceFilesIdentification sfid
= null;
91 private JButton jButtonOk
= null;
93 private JButton jButtonCancel
= null;
96 This method initializes jTextFieldFileName
98 @return javax.swing.JTextField jTextFieldFileName
101 private JTextField
getJTextFieldSourceFilesDirectory() {
102 if (jTextFieldFileName
== null) {
103 jTextFieldFileName
= new JTextField();
104 jTextFieldFileName
.setBounds(new java
.awt
.Rectangle(140, 10, 250, 20));
105 jTextFieldFileName
.setPreferredSize(new java
.awt
.Dimension(250, 20));
106 jTextFieldFileName
.setToolTipText("Path is relative to the MSA file and must include the file name");
108 return jTextFieldFileName
;
112 This method initializes jButtonOpenFile
114 @return javax.swing.JButton jButtonOpenFile
117 private JButton
getJButtonOpenFile() {
118 if (jButtonOpenFile
== null) {
119 jButtonOpenFile
= new JButton();
120 jButtonOpenFile
.setText("Browse");
121 jButtonOpenFile
.setBounds(new java
.awt
.Rectangle(395, 10, 85, 20));
122 jButtonOpenFile
.setPreferredSize(new java
.awt
.Dimension(85, 20));
123 jButtonOpenFile
.addActionListener(this);
125 return jButtonOpenFile
;
129 This method initializes jScrollPane
131 @return javax.swing.JScrollPane
133 private JScrollPane
getJScrollPane() {
134 if (jScrollPane
== null) {
135 jScrollPane
= new JScrollPane();
136 jScrollPane
.setViewportView(getJContentPane());
142 * This method initializes jTextFieldTagName
144 * @return javax.swing.JTextField
146 private JTextField
getJTextFieldTagName() {
147 if (jTextFieldTagName
== null) {
148 jTextFieldTagName
= new JTextField();
149 jTextFieldTagName
.setBounds(new java
.awt
.Rectangle(140, 35, 340, 20));
150 jTextFieldTagName
.setPreferredSize(new java
.awt
.Dimension(340, 20));
151 jTextFieldTagName
.setToolTipText("You may specify a specific tool chain tag name, such as BILL1");
153 return jTextFieldTagName
;
157 * This method initializes jTextFieldToolCode
159 * @return javax.swing.JTextField
161 private JTextField
getJTextFieldToolCode() {
162 if (jTextFieldToolCode
== null) {
163 jTextFieldToolCode
= new JTextField();
164 jTextFieldToolCode
.setBounds(new java
.awt
.Rectangle(140, 60, 340, 20));
165 jTextFieldToolCode
.setPreferredSize(new java
.awt
.Dimension(340, 20));
166 jTextFieldToolCode
.setToolTipText("You may specify a specific tool command, such as ASM");
168 return jTextFieldToolCode
;
172 * This method initializes jTextFieldToolChainFamily
174 * @return javax.swing.JTextField
176 private JTextField
getJTextFieldToolChainFamily() {
177 if (jTextFieldToolChainFamily
== null) {
178 jTextFieldToolChainFamily
= new JTextField();
179 jTextFieldToolChainFamily
.setBounds(new java
.awt
.Rectangle(140, 85, 340, 20));
180 jTextFieldToolChainFamily
.setPreferredSize(new java
.awt
.Dimension(340, 20));
181 jTextFieldToolChainFamily
.setToolTipText("You may specify a specific tool chain family, such as GCC");
183 return jTextFieldToolChainFamily
;
187 * This method initializes jTextFieldFeatureFlag
189 * @return javax.swing.JTextField
191 private JTextField
getJTextFieldFeatureFlag() {
192 if (jTextFieldFeatureFlag
== null) {
193 jTextFieldFeatureFlag
= new JTextField();
194 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(140, 110, 340, 20));
195 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(340, 20));
196 jTextFieldFeatureFlag
.setToolTipText("RESERVED FOR FUTURE USE");
198 return jTextFieldFeatureFlag
;
202 This method initializes jButtonOk
204 @return javax.swing.JButton
207 private JButton
getJButtonOk() {
208 if (jButtonOk
== null) {
209 jButtonOk
= new JButton();
210 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 165, 90, 20));
211 jButtonOk
.setText("Ok");
212 jButtonOk
.addActionListener(this);
218 This method initializes jButtonCancel
220 @return javax.swing.JButton
223 private JButton
getJButtonCancel() {
224 if (jButtonCancel
== null) {
225 jButtonCancel
= new JButton();
226 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 165, 90, 20));
227 jButtonCancel
.setText("Cancel");
228 jButtonCancel
.addActionListener(this);
230 return jButtonCancel
;
233 public static void main(String
[] args
) {
238 This is the default constructor
241 public SourceFilesDlg(SourceFilesIdentification inSourceFilesIdentification
, IFrame iFrame
) {
243 init(inSourceFilesIdentification
);
247 This method initializes this
250 private void init() {
251 this.setSize(500, 235);
252 this.setContentPane(getJScrollPane());
253 this.setTitle("Source Files");
254 this.setViewMode(false);
259 This method initializes this
260 Fill values to all fields if these values are not empty
263 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
266 private void init(SourceFilesIdentification inSourceFilesIdentifications
) {
268 this.sfid
= inSourceFilesIdentifications
;
270 if (this.sfid
!= null) {
271 this.jTextFieldFileName
.setText(sfid
.getFilename());
272 this.jTextFieldTagName
.setText(sfid
.getTagName());
273 this.jTextFieldToolCode
.setText(sfid
.getToolCode());
274 this.jTextFieldToolChainFamily
.setText(sfid
.getToolChainFamily());
275 jTextFieldFeatureFlag
.setText(sfid
.getFeatureFlag());
276 this.jArchCheckBox
.setSelectedItems(sfid
.getSupArchList());
281 Disable all components when the mode is view
283 @param isView true - The view mode; false - The non-view mode
286 public void setViewMode(boolean isView
) {
288 this.jTextFieldFileName
.setEnabled(!isView
);
289 this.jButtonOpenFile
.setEnabled(!isView
);
294 This method initializes jContentPane
296 @return javax.swing.JPanel jContentPane
299 private JPanel
getJContentPane() {
300 if (jContentPane
== null) {
301 jArchCheckBox
= new ArchCheckBox();
302 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(140, 135, 340, 20));
303 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(340, 20));
304 jLabelFeatureFlag
= new JLabel();
305 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 110, 120, 20));
306 jLabelFeatureFlag
.setText("Feature Flag");
307 jLabelToolCode
= new JLabel();
308 jLabelToolCode
.setBounds(new java
.awt
.Rectangle(15, 60, 120, 20));
309 jLabelToolCode
.setText("Tool Code");
310 jLabelTagName
= new JLabel();
311 jLabelTagName
.setBounds(new java
.awt
.Rectangle(15, 35, 120, 20));
312 jLabelTagName
.setText("Tag Name");
313 jLabelArch
= new JLabel();
314 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 135, 120, 20));
315 jLabelArch
.setText("Sup Arch List");
316 jLabelToolChainFamily
= new JLabel();
317 jLabelToolChainFamily
.setBounds(new java
.awt
.Rectangle(15, 85, 120, 20));
318 jLabelToolChainFamily
.setText("Tool Chain Family");
319 jLabelFileName
= new JLabel();
320 jLabelFileName
.setText("File Name");
321 jLabelFileName
.setBounds(new java
.awt
.Rectangle(15, 10, 120, 20));
323 jContentPane
= new JPanel();
324 jContentPane
.setLayout(null);
325 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 185));
327 jContentPane
.add(jLabelFileName
, null);
328 jContentPane
.add(getJTextFieldSourceFilesDirectory(), null);
329 jContentPane
.add(getJButtonOpenFile(), null);
330 jContentPane
.add(jLabelToolChainFamily
, null);
331 jStarLabel1
= new StarLabel();
332 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
334 jContentPane
.add(jStarLabel1
, null);
335 jContentPane
.add(jLabelArch
, null);
336 jContentPane
.add(jLabelTagName
, null);
337 jContentPane
.add(getJTextFieldTagName(), null);
338 jContentPane
.add(jLabelToolCode
, null);
339 jContentPane
.add(getJTextFieldToolCode(), null);
340 jContentPane
.add(getJTextFieldToolChainFamily(), null);
341 jContentPane
.add(jLabelFeatureFlag
, null);
342 jContentPane
.add(getJTextFieldFeatureFlag(), null);
343 jContentPane
.add(jArchCheckBox
, null);
344 jContentPane
.add(getJButtonOk(), null);
345 jContentPane
.add(getJButtonCancel(), null);
351 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
353 * Override actionPerformed to listen all actions
356 public void actionPerformed(ActionEvent arg0
) {
357 if (arg0
.getSource() == jButtonOpenFile
) {
361 if (arg0
.getSource() == jButtonOk
) {
363 getCurrentSourceFiles();
364 this.returnType
= DataType
.RETURN_TYPE_OK
;
365 this.setVisible(false);
369 if (arg0
.getSource() == jButtonCancel
) {
370 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
371 this.setVisible(false);
375 private SourceFilesIdentification
getCurrentSourceFiles() {
376 String name
= this.jTextFieldFileName
.getText();
377 String tagName
= this.jTextFieldTagName
.getText();
378 String toolCode
= this.jTextFieldToolCode
.getText();
379 String tcf
= this.jTextFieldToolChainFamily
.getText();
380 String featureFlag
= this.jTextFieldFeatureFlag
.getText();
381 Vector
<String
> arch
= this.jArchCheckBox
.getSelectedItemsVector();
382 sfid
= new SourceFilesIdentification(name
, tagName
, toolCode
, tcf
, featureFlag
, arch
);
387 Data validation for all fields
389 @retval true - All datas are valid
390 @retval false - At least one data is invalid
393 public boolean checkAdd() {
397 if (isEmpty(this.jTextFieldFileName
.getText())) {
398 Log
.err("File Name couldn't be empty");
401 if (!DataValidation
.isFilename(this.jTextFieldFileName
.getText())) {
402 Log
.err("Incorrect data type for File Name");
409 if (!isEmpty(this.jTextFieldTagName
.getText())) {
410 if (!DataValidation
.isTagName(this.jTextFieldTagName
.getText())) {
411 Log
.err("Incorrect data type for Tag Name");
419 if (!isEmpty(this.jTextFieldToolCode
.getText())) {
420 if (!DataValidation
.isToolCode(this.jTextFieldToolCode
.getText())) {
421 Log
.err("Incorrect data type for Tool Code");
427 // Check ToolChainFamily
429 if (!isEmpty(this.jTextFieldToolChainFamily
.getText())) {
430 if (!DataValidation
.isToolChainFamily(this.jTextFieldToolChainFamily
.getText())) {
431 Log
.err("Incorrect data type for Tool Chain Family");
439 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
440 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
441 Log
.err("Incorrect data type for Feature Flag");
450 Display a file open browser to let user select file
453 private void selectFile() {
454 JFileChooser fc
= new JFileChooser(Workspace
.getCurrentWorkspace());
456 int result
= fc
.showOpenDialog(new JPanel());
457 if (result
== JFileChooser
.APPROVE_OPTION
) {
458 this.jTextFieldFileName
.setText(fc
.getSelectedFile().getName());
462 public SourceFilesIdentification
getSfid() {
466 public void setSfid(SourceFilesIdentification sfid
) {