]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/SourceFilesDlg.java
Adjusted sizes to accommodate Windows, iMac and Linux GUI
[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
a19466ad 216 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 112, 340, 20));\r
06a19cee 217 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(340, 20));\r
218 jTextFieldFeatureFlag.setToolTipText("RESERVED FOR FUTURE USE");\r
219 }\r
220 return jTextFieldFeatureFlag;\r
221 }\r
222\r
223 /**\r
224 This method initializes jButtonOk \r
225 \r
226 @return javax.swing.JButton \r
227 \r
228 **/\r
229 private JButton getJButtonOk() {\r
230 if (jButtonOk == null) {\r
231 jButtonOk = new JButton();\r
a19466ad 232 jButtonOk.setBounds(new java.awt.Rectangle(317, 172, 90, 20));\r
06a19cee 233 jButtonOk.setText("Ok");\r
234 jButtonOk.addActionListener(this);\r
235 }\r
236 return jButtonOk;\r
237 }\r
238\r
239 /**\r
240 This method initializes jButtonCancel \r
241 \r
242 @return javax.swing.JButton \r
243 \r
244 **/\r
245 private JButton getJButtonCancel() {\r
246 if (jButtonCancel == null) {\r
247 jButtonCancel = new JButton();\r
a19466ad 248 jButtonCancel.setBounds(new java.awt.Rectangle(412, 172, 90, 20));\r
06a19cee 249 jButtonCancel.setText("Cancel");\r
250 jButtonCancel.addActionListener(this);\r
251 }\r
252 return jButtonCancel;\r
253 }\r
254\r
255 public static void main(String[] args) {\r
256\r
257 }\r
258\r
259 /**\r
260 This is the default constructor\r
261 \r
262 **/\r
55a2762d 263 public SourceFilesDlg(SourceFilesIdentification inSourceFilesIdentification, IFrame iFrame, String fileName) {\r
06a19cee 264 super(iFrame, true);\r
55a2762d 265 init(inSourceFilesIdentification, fileName);\r
06a19cee 266 }\r
267\r
268 /**\r
269 This method initializes this\r
270 \r
271 **/\r
272 private void init() {\r
a19466ad 273 this.setSize(525, 240);\r
06a19cee 274 this.setContentPane(getJScrollPane());\r
275 this.setTitle("Source Files");\r
276 this.setViewMode(false);\r
277 this.centerWindow();\r
0c235b66 278 Tools.generateComboBoxByVector(iComboBoxToolCode, ed.getVToolCode());\r
06a19cee 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
a19466ad 351 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 137, 340, 20));\r
06a19cee 352 jArchCheckBox.setPreferredSize(new java.awt.Dimension(340, 20));\r
353 jLabelFeatureFlag = new JLabel();\r
a19466ad 354 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 112, 155, 20));\r
ccb063b1 355 jLabelFeatureFlag.setText("Feature Flag Expression");\r
06a19cee 356 jLabelToolCode = new JLabel();\r
a19466ad 357 jLabelToolCode.setBounds(new java.awt.Rectangle(12, 62, 155, 20));\r
06a19cee 358 jLabelToolCode.setText("Tool Code");\r
359 jLabelTagName = new JLabel();\r
a19466ad 360 jLabelTagName.setBounds(new java.awt.Rectangle(12, 37, 155, 20));\r
06a19cee 361 jLabelTagName.setText("Tag Name");\r
362 jLabelArch = new JLabel();\r
a19466ad 363 jLabelArch.setBounds(new java.awt.Rectangle(12, 137, 155, 20));\r
ccb063b1 364 jLabelArch.setText("Supported Architectures");\r
06a19cee 365 jLabelToolChainFamily = new JLabel();\r
a19466ad 366 jLabelToolChainFamily.setBounds(new java.awt.Rectangle(12, 87, 155, 20));\r
06a19cee 367 jLabelToolChainFamily.setText("Tool Chain Family");\r
368 jLabelFileName = new JLabel();\r
369 jLabelFileName.setText("File Name");\r
a19466ad 370 jLabelFileName.setBounds(new java.awt.Rectangle(12, 12, 155, 20));\r
06a19cee 371\r
372 jContentPane = new JPanel();\r
373 jContentPane.setLayout(null);\r
a19466ad 374 jContentPane.setPreferredSize(new java.awt.Dimension(505, 192));\r
06a19cee 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