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