Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / SourceFilesDlg.java
CommitLineData
06a19cee 1/** @file\r
2 \r
a19466ad 3 The file is used to create, update SourceFiles section of the MSA file\r
06a19cee 4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15package org.tianocore.frameworkwizard.module.ui.dialog;\r
16\r
17import java.awt.event.ActionEvent;\r
55a2762d 18import java.io.File;\r
06a19cee 19import java.util.Vector;\r
20\r
21import javax.swing.JButton;\r
22import javax.swing.JFileChooser;\r
23import javax.swing.JLabel;\r
24import javax.swing.JPanel;\r
25import javax.swing.JScrollPane;\r
26import javax.swing.JTextField;\r
27\r
28import org.tianocore.frameworkwizard.common.DataType;\r
29import org.tianocore.frameworkwizard.common.DataValidation;\r
a929458e 30import org.tianocore.frameworkwizard.common.EnumerationData;\r
06a19cee 31import org.tianocore.frameworkwizard.common.Log;\r
55a2762d 32import org.tianocore.frameworkwizard.common.Tools;\r
06a19cee 33import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r
a929458e 34import org.tianocore.frameworkwizard.common.ui.IComboBox;\r
06a19cee 35import org.tianocore.frameworkwizard.common.ui.IDialog;\r
36import org.tianocore.frameworkwizard.common.ui.IFrame;\r
37import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
38import org.tianocore.frameworkwizard.module.Identifications.SourceFiles.SourceFilesIdentification;\r
06a19cee 39\r
40/**\r
a19466ad 41 * The class is used to create, update SourceFiles section of the MSA file\r
42 *\r
43 * It extends IDialog\r
44 * \r
06a19cee 45 **/\r
46public class SourceFilesDlg extends IDialog {\r
47\r
48 ///\r
49 /// Define class Serial Version UID\r
50 ///\r
51 private static final long serialVersionUID = -6765742852142775378L;\r
52\r
53 //\r
54 // Define class members\r
55 //\r
56 private JPanel jContentPane = null;\r
57\r
58 private JLabel jLabelFileName = null;\r
59\r
60 private JTextField jTextFieldFileName = null;\r
61\r
62 private JButton jButtonOpenFile = null;\r
63\r
64 private JLabel jLabelToolChainFamily = null;\r
65\r
66 private StarLabel jStarLabel1 = null;\r
67\r
68 private JLabel jLabelArch = null;\r
69\r
70 private JScrollPane jScrollPane = null;\r
71\r
72 private JLabel jLabelTagName = null;\r
73\r
74 private JTextField jTextFieldTagName = null;\r
75\r
76 private JLabel jLabelToolCode = null;\r
77\r
78 private JTextField jTextFieldToolCode = null;\r
79\r
a929458e 80 private IComboBox iComboBoxToolCode = null;\r
81\r
06a19cee 82 private JTextField jTextFieldToolChainFamily = null;\r
83\r
84 private JLabel jLabelFeatureFlag = null;\r
85\r
86 private JTextField jTextFieldFeatureFlag = null;\r
87\r
88 private ArchCheckBox jArchCheckBox = null;\r
a929458e 89\r
55a2762d 90 private JButton jButtonOk = null;\r
91\r
92 private JButton jButtonCancel = null;\r
06a19cee 93\r
94 //\r
95 // Not used by UI\r
96 //\r
2003a22e 97 private SourceFilesIdentification sfid[] = null;\r
06a19cee 98\r
55a2762d 99 private String msaFileName = "";\r
06a19cee 100\r
a929458e 101 private EnumerationData ed = new EnumerationData();\r
102\r
06a19cee 103 /**\r
104 This method initializes jTextFieldFileName \r
105 \r
106 @return javax.swing.JTextField jTextFieldFileName\r
107 \r
108 **/\r
109 private JTextField getJTextFieldSourceFilesDirectory() {\r
110 if (jTextFieldFileName == null) {\r
111 jTextFieldFileName = new JTextField();\r
a19466ad 112 jTextFieldFileName.setBounds(new java.awt.Rectangle(168, 12, 250, 20));\r
06a19cee 113 jTextFieldFileName.setPreferredSize(new java.awt.Dimension(250, 20));\r
114 jTextFieldFileName.setToolTipText("Path is relative to the MSA file and must include the file name");\r
115 }\r
116 return jTextFieldFileName;\r
117 }\r
118\r
119 /**\r
120 This method initializes jButtonOpenFile \r
121 \r
122 @return javax.swing.JButton jButtonOpenFile\r
123 \r
124 **/\r
125 private JButton getJButtonOpenFile() {\r
126 if (jButtonOpenFile == null) {\r
127 jButtonOpenFile = new JButton();\r
128 jButtonOpenFile.setText("Browse");\r
a19466ad 129 jButtonOpenFile.setBounds(new java.awt.Rectangle(422, 12, 85, 20));\r
06a19cee 130 jButtonOpenFile.setPreferredSize(new java.awt.Dimension(85, 20));\r
131 jButtonOpenFile.addActionListener(this);\r
132 }\r
133 return jButtonOpenFile;\r
134 }\r
135\r
136 /**\r
137 This method initializes jScrollPane \r
138 \r
139 @return javax.swing.JScrollPane \r
140 */\r
141 private JScrollPane getJScrollPane() {\r
142 if (jScrollPane == null) {\r
143 jScrollPane = new JScrollPane();\r
144 jScrollPane.setViewportView(getJContentPane());\r
145 }\r
146 return jScrollPane;\r
147 }\r
148\r
149 /**\r
150 * This method initializes jTextFieldTagName \r
151 * \r
152 * @return javax.swing.JTextField \r
153 */\r
154 private JTextField getJTextFieldTagName() {\r
155 if (jTextFieldTagName == null) {\r
156 jTextFieldTagName = new JTextField();\r
a19466ad 157 jTextFieldTagName.setBounds(new java.awt.Rectangle(168, 37, 340, 20));\r
06a19cee 158 jTextFieldTagName.setPreferredSize(new java.awt.Dimension(340, 20));\r
159 jTextFieldTagName.setToolTipText("You may specify a specific tool chain tag name, such as BILL1");\r
160 }\r
161 return jTextFieldTagName;\r
162 }\r
163\r
a929458e 164 private IComboBox getIComboBoxToolCode() {\r
165 if (iComboBoxToolCode == null) {\r
166 iComboBoxToolCode = new IComboBox();\r
a19466ad 167 iComboBoxToolCode.setBounds(new java.awt.Rectangle(168, 62, 340, 20));\r
a929458e 168 iComboBoxToolCode.setPreferredSize(new java.awt.Dimension(340, 20));\r
169 iComboBoxToolCode.setToolTipText("<html>You may select a specific tool command from drop down list, <br>"\r
170 + "or you can DOUBLE-CLICK this fild to enter your customizing <br>"\r
171 + "tool command.<br>"\r
172 + "Press ENTER to save your input or press ESCAPE to quit</html>");\r
173 }\r
174 return iComboBoxToolCode;\r
175 }\r
176\r
06a19cee 177 /**\r
178 * This method initializes jTextFieldToolCode \r
179 * \r
180 * @return javax.swing.JTextField \r
181 */\r
182 private JTextField getJTextFieldToolCode() {\r
183 if (jTextFieldToolCode == null) {\r
184 jTextFieldToolCode = new JTextField();\r
a19466ad 185 jTextFieldToolCode.setBounds(new java.awt.Rectangle(168, 62, 340, 20));\r
06a19cee 186 jTextFieldToolCode.setPreferredSize(new java.awt.Dimension(340, 20));\r
187 jTextFieldToolCode.setToolTipText("You may specify a specific tool command, such as ASM");\r
a929458e 188 jTextFieldToolCode.setVisible(false);\r
06a19cee 189 }\r
190 return jTextFieldToolCode;\r
191 }\r
192\r
193 /**\r
194 * This method initializes jTextFieldToolChainFamily \r
195 * \r
196 * @return javax.swing.JTextField \r
197 */\r
198 private JTextField getJTextFieldToolChainFamily() {\r
199 if (jTextFieldToolChainFamily == null) {\r
200 jTextFieldToolChainFamily = new JTextField();\r
a19466ad 201 jTextFieldToolChainFamily.setBounds(new java.awt.Rectangle(168, 87, 340, 20));\r
06a19cee 202 jTextFieldToolChainFamily.setPreferredSize(new java.awt.Dimension(340, 20));\r
203 jTextFieldToolChainFamily.setToolTipText("You may specify a specific tool chain family, such as GCC");\r
204 }\r
205 return jTextFieldToolChainFamily;\r
206 }\r
207\r
208 /**\r
209 * This method initializes jTextFieldFeatureFlag \r
210 * \r
211 * @return javax.swing.JTextField \r
212 */\r
213 private JTextField getJTextFieldFeatureFlag() {\r
214 if (jTextFieldFeatureFlag == null) {\r
215 jTextFieldFeatureFlag = new JTextField();\r
21b42c66 216 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 137, 340, 20));\r
06a19cee 217 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(340, 20));\r
218 jTextFieldFeatureFlag.setToolTipText("RESERVED FOR FUTURE USE");\r
21b42c66 219 jTextFieldFeatureFlag.setEnabled(false);\r
06a19cee 220 }\r
221 return jTextFieldFeatureFlag;\r
222 }\r
223\r
224 /**\r
225 This method initializes jButtonOk \r
226 \r
227 @return javax.swing.JButton \r
228 \r
229 **/\r
230 private JButton getJButtonOk() {\r
231 if (jButtonOk == null) {\r
232 jButtonOk = new JButton();\r
a19466ad 233 jButtonOk.setBounds(new java.awt.Rectangle(317, 172, 90, 20));\r
06a19cee 234 jButtonOk.setText("Ok");\r
235 jButtonOk.addActionListener(this);\r
236 }\r
237 return jButtonOk;\r
238 }\r
239\r
240 /**\r
241 This method initializes jButtonCancel \r
242 \r
243 @return javax.swing.JButton \r
244 \r
245 **/\r
246 private JButton getJButtonCancel() {\r
247 if (jButtonCancel == null) {\r
248 jButtonCancel = new JButton();\r
a19466ad 249 jButtonCancel.setBounds(new java.awt.Rectangle(412, 172, 90, 20));\r
06a19cee 250 jButtonCancel.setText("Cancel");\r
251 jButtonCancel.addActionListener(this);\r
252 }\r
253 return jButtonCancel;\r
254 }\r
255\r
256 public static void main(String[] args) {\r
257\r
258 }\r
259\r
260 /**\r
261 This is the default constructor\r
262 \r
263 **/\r
55a2762d 264 public SourceFilesDlg(SourceFilesIdentification inSourceFilesIdentification, IFrame iFrame, String fileName) {\r
06a19cee 265 super(iFrame, true);\r
55a2762d 266 init(inSourceFilesIdentification, fileName);\r
06a19cee 267 }\r
268\r
269 /**\r
270 This method initializes this\r
271 \r
272 **/\r
273 private void init() {\r
a19466ad 274 this.setSize(525, 240);\r
06a19cee 275 this.setContentPane(getJScrollPane());\r
276 this.setTitle("Source Files");\r
277 this.setViewMode(false);\r
278 this.centerWindow();\r
0c235b66 279 Tools.generateComboBoxByVector(iComboBoxToolCode, ed.getVToolCode());\r
06a19cee 280 }\r
281\r
282 /** \r
283 This method initializes this\r
284 Fill values to all fields if these values are not empty\r
285 \r
286 \r
287 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles\r
288 \r
289 **/\r
55a2762d 290 private void init(SourceFilesIdentification inSourceFilesIdentifications, String fileName) {\r
06a19cee 291 init();\r
2003a22e 292 //this.sfid = inSourceFilesIdentifications;\r
55a2762d 293 this.msaFileName = fileName;\r
06a19cee 294\r
2003a22e 295 if (inSourceFilesIdentifications != null) {\r
296 this.jTextFieldFileName.setText(inSourceFilesIdentifications.getFilename());\r
297 this.jTextFieldTagName.setText(inSourceFilesIdentifications.getTagName());\r
a929458e 298\r
299 //\r
300 // Generate Tool Code selection list\r
301 //\r
302 Vector<String> v = ed.getVToolCode();\r
303 boolean isFind = false;\r
304 String strToolCode = inSourceFilesIdentifications.getToolCode();\r
305\r
306 //\r
307 // If the input value is not in the default list, add it to the list\r
308 //\r
309 if (strToolCode != null) {\r
310 for (int index = 0; index < v.size(); index++) {\r
311 if (v.elementAt(index).equals(strToolCode)) {\r
312 isFind = true;\r
313 break;\r
314 }\r
315 }\r
316 if (!isFind && !isEmpty(strToolCode)) {\r
317 v.addElement(strToolCode);\r
318 }\r
319 }\r
320\r
321 Tools.generateComboBoxByVector(iComboBoxToolCode, v);\r
322 this.iComboBoxToolCode.setSelectedItem(strToolCode);\r
323\r
2003a22e 324 this.jTextFieldToolChainFamily.setText(inSourceFilesIdentifications.getToolChainFamily());\r
325 jTextFieldFeatureFlag.setText(inSourceFilesIdentifications.getFeatureFlag());\r
326 this.jArchCheckBox.setSelectedItems(inSourceFilesIdentifications.getSupArchList());\r
06a19cee 327 }\r
328 }\r
329\r
330 /**\r
331 Disable all components when the mode is view\r
332 \r
333 @param isView true - The view mode; false - The non-view mode\r
334 \r
335 **/\r
336 public void setViewMode(boolean isView) {\r
337 if (isView) {\r
338 this.jTextFieldFileName.setEnabled(!isView);\r
339 this.jButtonOpenFile.setEnabled(!isView);\r
340 }\r
341 }\r
342\r
343 /**\r
344 This method initializes jContentPane\r
345 \r
346 @return javax.swing.JPanel jContentPane\r
347 \r
348 **/\r
349 private JPanel getJContentPane() {\r
350 if (jContentPane == null) {\r
351 jArchCheckBox = new ArchCheckBox();\r
21b42c66 352 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 112, 340, 20));\r
06a19cee 353 jArchCheckBox.setPreferredSize(new java.awt.Dimension(340, 20));\r
354 jLabelFeatureFlag = new JLabel();\r
21b42c66 355 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 137, 155, 20));\r
ccb063b1 356 jLabelFeatureFlag.setText("Feature Flag Expression");\r
21b42c66 357 jLabelFeatureFlag.setEnabled(false);\r
06a19cee 358 jLabelToolCode = new JLabel();\r
a19466ad 359 jLabelToolCode.setBounds(new java.awt.Rectangle(12, 62, 155, 20));\r
06a19cee 360 jLabelToolCode.setText("Tool Code");\r
361 jLabelTagName = new JLabel();\r
a19466ad 362 jLabelTagName.setBounds(new java.awt.Rectangle(12, 37, 155, 20));\r
06a19cee 363 jLabelTagName.setText("Tag Name");\r
364 jLabelArch = new JLabel();\r
21b42c66 365 jLabelArch.setBounds(new java.awt.Rectangle(12, 112, 155, 20));\r
ccb063b1 366 jLabelArch.setText("Supported Architectures");\r
06a19cee 367 jLabelToolChainFamily = new JLabel();\r
a19466ad 368 jLabelToolChainFamily.setBounds(new java.awt.Rectangle(12, 87, 155, 20));\r
06a19cee 369 jLabelToolChainFamily.setText("Tool Chain Family");\r
370 jLabelFileName = new JLabel();\r
371 jLabelFileName.setText("File Name");\r
a19466ad 372 jLabelFileName.setBounds(new java.awt.Rectangle(12, 12, 155, 20));\r
06a19cee 373\r
374 jContentPane = new JPanel();\r
375 jContentPane.setLayout(null);\r
a19466ad 376 jContentPane.setPreferredSize(new java.awt.Dimension(505, 192));\r
06a19cee 377\r
378 jContentPane.add(jLabelFileName, null);\r
379 jContentPane.add(getJTextFieldSourceFilesDirectory(), null);\r
380 jContentPane.add(getJButtonOpenFile(), null);\r
381 jContentPane.add(jLabelToolChainFamily, null);\r
382 jStarLabel1 = new StarLabel();\r
383 jStarLabel1.setLocation(new java.awt.Point(0, 10));\r
384\r
385 jContentPane.add(jStarLabel1, null);\r
386 jContentPane.add(jLabelArch, null);\r
387 jContentPane.add(jLabelTagName, null);\r
388 jContentPane.add(getJTextFieldTagName(), null);\r
389 jContentPane.add(jLabelToolCode, null);\r
390 jContentPane.add(getJTextFieldToolCode(), null);\r
a929458e 391 jContentPane.add(getIComboBoxToolCode(), null);\r
06a19cee 392 jContentPane.add(getJTextFieldToolChainFamily(), null);\r
393 jContentPane.add(jLabelFeatureFlag, null);\r
394 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
395 jContentPane.add(jArchCheckBox, null);\r
396 jContentPane.add(getJButtonOk(), null);\r
397 jContentPane.add(getJButtonCancel(), null);\r
398 }\r
399 return jContentPane;\r
400 }\r
401\r
402 /* (non-Javadoc)\r
403 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
404 *\r
405 * Override actionPerformed to listen all actions\r
406 * \r
407 */\r
408 public void actionPerformed(ActionEvent arg0) {\r
409 if (arg0.getSource() == jButtonOpenFile) {\r
410 selectFile();\r
411 }\r
412\r
413 if (arg0.getSource() == jButtonOk) {\r
414 if (checkAdd()) {\r
415 getCurrentSourceFiles();\r
416 this.returnType = DataType.RETURN_TYPE_OK;\r
417 this.setVisible(false);\r
418 }\r
419 }\r
420\r
421 if (arg0.getSource() == jButtonCancel) {\r
422 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
423 this.setVisible(false);\r
424 }\r
425 }\r
426\r
2003a22e 427 private SourceFilesIdentification[] getCurrentSourceFiles() {\r
06a19cee 428 String name = this.jTextFieldFileName.getText();\r
2003a22e 429 String s[] = name.split(";");\r
06a19cee 430 String tagName = this.jTextFieldTagName.getText();\r
a929458e 431 String toolCode = this.iComboBoxToolCode.getSelectedItem().toString();\r
432 if (toolCode.equals(DataType.EMPTY_SELECT_ITEM)) {\r
433 toolCode = "";\r
434 }\r
06a19cee 435 String tcf = this.jTextFieldToolChainFamily.getText();\r
436 String featureFlag = this.jTextFieldFeatureFlag.getText();\r
437 Vector<String> arch = this.jArchCheckBox.getSelectedItemsVector();\r
2003a22e 438 sfid = new SourceFilesIdentification[s.length];\r
439 for (int index = 0; index < s.length; index++) {\r
a929458e 440 sfid[index] = new SourceFilesIdentification(s[index], tagName, toolCode, tcf, featureFlag, arch);\r
2003a22e 441 }\r
06a19cee 442 return sfid;\r
443 }\r
444\r
445 /**\r
446 Data validation for all fields\r
447 \r
448 @retval true - All datas are valid\r
449 @retval false - At least one data is invalid\r
450 \r
451 **/\r
452 public boolean checkAdd() {\r
453 //\r
454 // Check Filename\r
455 //\r
456 if (isEmpty(this.jTextFieldFileName.getText())) {\r
623db5ca 457 Log.wrn("Update Source Files", "File Name must be entered!");\r
06a19cee 458 return false;\r
459 }\r
460 if (!DataValidation.isFilename(this.jTextFieldFileName.getText())) {\r
ed1665f2 461 Log.wrn("Update Source Files", "Incorrect data type for File Name");\r
06a19cee 462 return false;\r
463 }\r
464\r
465 //\r
466 // Check TagName \r
467 //\r
468 if (!isEmpty(this.jTextFieldTagName.getText())) {\r
469 if (!DataValidation.isTagName(this.jTextFieldTagName.getText())) {\r
ed1665f2 470 Log.wrn("Update Source Files", "Incorrect data type for Tag Name");\r
06a19cee 471 return false;\r
472 }\r
473 }\r
474\r
475 //\r
476 // Check ToolCode \r
477 //\r
478 if (!isEmpty(this.jTextFieldToolCode.getText())) {\r
479 if (!DataValidation.isToolCode(this.jTextFieldToolCode.getText())) {\r
ed1665f2 480 Log.wrn("Update Source Files", "Incorrect data type for Tool Code");\r
06a19cee 481 return false;\r
482 }\r
483 }\r
484\r
485 //\r
486 // Check ToolChainFamily \r
487 //\r
488 if (!isEmpty(this.jTextFieldToolChainFamily.getText())) {\r
489 if (!DataValidation.isToolChainFamily(this.jTextFieldToolChainFamily.getText())) {\r
ed1665f2 490 Log.wrn("Update Source Files", "Incorrect data type for Tool Chain Family");\r
06a19cee 491 return false;\r
492 }\r
493 }\r
494\r
495 //\r
496 // Check FeatureFlag\r
497 //\r
498 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
499 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
ed1665f2 500 Log.wrn("Update Source Files", "Incorrect data type for Feature Flag");\r
06a19cee 501 return false;\r
502 }\r
503 }\r
504\r
505 return true;\r
506 }\r
507\r
508 /**\r
509 Display a file open browser to let user select file\r
510 \r
511 **/\r
512 private void selectFile() {\r
55a2762d 513 JFileChooser fc = new JFileChooser();\r
514 fc.setCurrentDirectory(new File(Tools.getFilePathOnly(msaFileName)));\r
2003a22e 515 fc.setMultiSelectionEnabled(true);\r
06a19cee 516 int result = fc.showOpenDialog(new JPanel());\r
517 if (result == JFileChooser.APPROVE_OPTION) {\r
2003a22e 518 File f[] = fc.getSelectedFiles();\r
519 String s = "";\r
520 for (int index = 0; index < f.length; index++) {\r
521 s = s + f[index].getName() + ";";\r
522 }\r
523 this.jTextFieldFileName.setText(s);\r
06a19cee 524 }\r
525 }\r
526\r
2003a22e 527 public SourceFilesIdentification[] getSfid() {\r
06a19cee 528 return sfid;\r
529 }\r
530\r
2003a22e 531 public void setSfid(SourceFilesIdentification[] sfid) {\r
06a19cee 532 this.sfid = sfid;\r
533 }\r
534}\r