]> 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
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
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
352 jArchCheckBox.setBounds(new java.awt.Rectangle(140, 135, 340, 20));\r
353 jArchCheckBox.setPreferredSize(new java.awt.Dimension(340, 20));\r
354 jLabelFeatureFlag = new JLabel();\r
355 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 110, 120, 20));\r
ccb063b1 356 jLabelFeatureFlag.setText("Feature Flag Expression");\r
06a19cee 357 jLabelToolCode = new JLabel();\r
358 jLabelToolCode.setBounds(new java.awt.Rectangle(15, 60, 120, 20));\r
359 jLabelToolCode.setText("Tool Code");\r
360 jLabelTagName = new JLabel();\r
361 jLabelTagName.setBounds(new java.awt.Rectangle(15, 35, 120, 20));\r
362 jLabelTagName.setText("Tag Name");\r
363 jLabelArch = new JLabel();\r
364 jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 120, 20));\r
ccb063b1 365 jLabelArch.setText("Supported Architectures");\r
06a19cee 366 jLabelToolChainFamily = new JLabel();\r
367 jLabelToolChainFamily.setBounds(new java.awt.Rectangle(15, 85, 120, 20));\r
368 jLabelToolChainFamily.setText("Tool Chain Family");\r
369 jLabelFileName = new JLabel();\r
370 jLabelFileName.setText("File Name");\r
371 jLabelFileName.setBounds(new java.awt.Rectangle(15, 10, 120, 20));\r
372\r
373 jContentPane = new JPanel();\r
374 jContentPane.setLayout(null);\r
375 jContentPane.setPreferredSize(new java.awt.Dimension(490, 185));\r
376\r
377 jContentPane.add(jLabelFileName, null);\r
378 jContentPane.add(getJTextFieldSourceFilesDirectory(), null);\r
379 jContentPane.add(getJButtonOpenFile(), null);\r
380 jContentPane.add(jLabelToolChainFamily, null);\r
381 jStarLabel1 = new StarLabel();\r
382 jStarLabel1.setLocation(new java.awt.Point(0, 10));\r
383\r
384 jContentPane.add(jStarLabel1, null);\r
385 jContentPane.add(jLabelArch, null);\r
386 jContentPane.add(jLabelTagName, null);\r
387 jContentPane.add(getJTextFieldTagName(), null);\r
388 jContentPane.add(jLabelToolCode, null);\r
389 jContentPane.add(getJTextFieldToolCode(), null);\r
a929458e 390 jContentPane.add(getIComboBoxToolCode(), null);\r
06a19cee 391 jContentPane.add(getJTextFieldToolChainFamily(), null);\r
392 jContentPane.add(jLabelFeatureFlag, null);\r
393 jContentPane.add(getJTextFieldFeatureFlag(), null);\r
394 jContentPane.add(jArchCheckBox, null);\r
395 jContentPane.add(getJButtonOk(), null);\r
396 jContentPane.add(getJButtonCancel(), null);\r
397 }\r
398 return jContentPane;\r
399 }\r
400\r
401 /* (non-Javadoc)\r
402 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r
403 *\r
404 * Override actionPerformed to listen all actions\r
405 * \r
406 */\r
407 public void actionPerformed(ActionEvent arg0) {\r
408 if (arg0.getSource() == jButtonOpenFile) {\r
409 selectFile();\r
410 }\r
411\r
412 if (arg0.getSource() == jButtonOk) {\r
413 if (checkAdd()) {\r
414 getCurrentSourceFiles();\r
415 this.returnType = DataType.RETURN_TYPE_OK;\r
416 this.setVisible(false);\r
417 }\r
418 }\r
419\r
420 if (arg0.getSource() == jButtonCancel) {\r
421 this.returnType = DataType.RETURN_TYPE_CANCEL;\r
422 this.setVisible(false);\r
423 }\r
424 }\r
425\r
2003a22e 426 private SourceFilesIdentification[] getCurrentSourceFiles() {\r
06a19cee 427 String name = this.jTextFieldFileName.getText();\r
2003a22e 428 String s[] = name.split(";");\r
06a19cee 429 String tagName = this.jTextFieldTagName.getText();\r
a929458e 430 String toolCode = this.iComboBoxToolCode.getSelectedItem().toString();\r
431 if (toolCode.equals(DataType.EMPTY_SELECT_ITEM)) {\r
432 toolCode = "";\r
433 }\r
06a19cee 434 String tcf = this.jTextFieldToolChainFamily.getText();\r
435 String featureFlag = this.jTextFieldFeatureFlag.getText();\r
436 Vector<String> arch = this.jArchCheckBox.getSelectedItemsVector();\r
2003a22e 437 sfid = new SourceFilesIdentification[s.length];\r
438 for (int index = 0; index < s.length; index++) {\r
a929458e 439 sfid[index] = new SourceFilesIdentification(s[index], tagName, toolCode, tcf, featureFlag, arch);\r
2003a22e 440 }\r
06a19cee 441 return sfid;\r
442 }\r
443\r
444 /**\r
445 Data validation for all fields\r
446 \r
447 @retval true - All datas are valid\r
448 @retval false - At least one data is invalid\r
449 \r
450 **/\r
451 public boolean checkAdd() {\r
452 //\r
453 // Check Filename\r
454 //\r
455 if (isEmpty(this.jTextFieldFileName.getText())) {\r
ed1665f2 456 Log.wrn("Update Source Files", "File Name couldn't be empty");\r
06a19cee 457 return false;\r
458 }\r
459 if (!DataValidation.isFilename(this.jTextFieldFileName.getText())) {\r
ed1665f2 460 Log.wrn("Update Source Files", "Incorrect data type for File Name");\r
06a19cee 461 return false;\r
462 }\r
463\r
464 //\r
465 // Check TagName \r
466 //\r
467 if (!isEmpty(this.jTextFieldTagName.getText())) {\r
468 if (!DataValidation.isTagName(this.jTextFieldTagName.getText())) {\r
ed1665f2 469 Log.wrn("Update Source Files", "Incorrect data type for Tag Name");\r
06a19cee 470 return false;\r
471 }\r
472 }\r
473\r
474 //\r
475 // Check ToolCode \r
476 //\r
477 if (!isEmpty(this.jTextFieldToolCode.getText())) {\r
478 if (!DataValidation.isToolCode(this.jTextFieldToolCode.getText())) {\r
ed1665f2 479 Log.wrn("Update Source Files", "Incorrect data type for Tool Code");\r
06a19cee 480 return false;\r
481 }\r
482 }\r
483\r
484 //\r
485 // Check ToolChainFamily \r
486 //\r
487 if (!isEmpty(this.jTextFieldToolChainFamily.getText())) {\r
488 if (!DataValidation.isToolChainFamily(this.jTextFieldToolChainFamily.getText())) {\r
ed1665f2 489 Log.wrn("Update Source Files", "Incorrect data type for Tool Chain Family");\r
06a19cee 490 return false;\r
491 }\r
492 }\r
493\r
494 //\r
495 // Check FeatureFlag\r
496 //\r
497 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r
498 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r
ed1665f2 499 Log.wrn("Update Source Files", "Incorrect data type for Feature Flag");\r
06a19cee 500 return false;\r
501 }\r
502 }\r
503\r
504 return true;\r
505 }\r
506\r
507 /**\r
508 Display a file open browser to let user select file\r
509 \r
510 **/\r
511 private void selectFile() {\r
55a2762d 512 JFileChooser fc = new JFileChooser();\r
513 fc.setCurrentDirectory(new File(Tools.getFilePathOnly(msaFileName)));\r
2003a22e 514 fc.setMultiSelectionEnabled(true);\r
06a19cee 515 int result = fc.showOpenDialog(new JPanel());\r
516 if (result == JFileChooser.APPROVE_OPTION) {\r
2003a22e 517 File f[] = fc.getSelectedFiles();\r
518 String s = "";\r
519 for (int index = 0; index < f.length; index++) {\r
520 s = s + f[index].getName() + ";";\r
521 }\r
522 this.jTextFieldFileName.setText(s);\r
06a19cee 523 }\r
524 }\r
525\r
2003a22e 526 public SourceFilesIdentification[] getSfid() {\r
06a19cee 527 return sfid;\r
528 }\r
529\r
2003a22e 530 public void setSfid(SourceFilesIdentification[] sfid) {\r
06a19cee 531 this.sfid = sfid;\r
532 }\r
533}\r