]>
Commit | Line | Data |
---|---|---|
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 | |
15 | package org.tianocore.frameworkwizard.module.ui.dialog;\r | |
16 | \r | |
17 | import java.awt.event.ActionEvent;\r | |
18 | import java.util.Vector;\r | |
19 | \r | |
20 | import javax.swing.JButton;\r | |
21 | import javax.swing.JFileChooser;\r | |
22 | import javax.swing.JLabel;\r | |
23 | import javax.swing.JPanel;\r | |
24 | import javax.swing.JScrollPane;\r | |
25 | import javax.swing.JTextField;\r | |
26 | \r | |
27 | import org.tianocore.frameworkwizard.common.DataType;\r | |
28 | import org.tianocore.frameworkwizard.common.DataValidation;\r | |
29 | import org.tianocore.frameworkwizard.common.Log;\r | |
30 | import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;\r | |
31 | import org.tianocore.frameworkwizard.common.ui.IDialog;\r | |
32 | import org.tianocore.frameworkwizard.common.ui.IFrame;\r | |
33 | import org.tianocore.frameworkwizard.common.ui.StarLabel;\r | |
34 | import org.tianocore.frameworkwizard.module.Identifications.SourceFiles.SourceFilesIdentification;\r | |
35 | import org.tianocore.frameworkwizard.workspace.Workspace;\r | |
36 | \r | |
37 | /**\r | |
38 | The class is used to create, update SourceFile of MSA/MBD file\r | |
39 | It extends IInternalFrame\r | |
40 | \r | |
41 | \r | |
42 | \r | |
43 | **/\r | |
44 | public class SourceFilesDlg extends IDialog {\r | |
45 | \r | |
46 | ///\r | |
47 | /// Define class Serial Version UID\r | |
48 | ///\r | |
49 | private static final long serialVersionUID = -6765742852142775378L;\r | |
50 | \r | |
51 | //\r | |
52 | // Define class members\r | |
53 | //\r | |
54 | private JPanel jContentPane = null;\r | |
55 | \r | |
56 | private JLabel jLabelFileName = null;\r | |
57 | \r | |
58 | private JTextField jTextFieldFileName = null;\r | |
59 | \r | |
60 | private JButton jButtonOpenFile = null;\r | |
61 | \r | |
62 | private JLabel jLabelToolChainFamily = null;\r | |
63 | \r | |
64 | private StarLabel jStarLabel1 = null;\r | |
65 | \r | |
66 | private JLabel jLabelArch = null;\r | |
67 | \r | |
68 | private JScrollPane jScrollPane = null;\r | |
69 | \r | |
70 | private JLabel jLabelTagName = null;\r | |
71 | \r | |
72 | private JTextField jTextFieldTagName = null;\r | |
73 | \r | |
74 | private JLabel jLabelToolCode = null;\r | |
75 | \r | |
76 | private JTextField jTextFieldToolCode = null;\r | |
77 | \r | |
78 | private JTextField jTextFieldToolChainFamily = null;\r | |
79 | \r | |
80 | private JLabel jLabelFeatureFlag = null;\r | |
81 | \r | |
82 | private JTextField jTextFieldFeatureFlag = null;\r | |
83 | \r | |
84 | private ArchCheckBox jArchCheckBox = null;\r | |
85 | \r | |
86 | //\r | |
87 | // Not used by UI\r | |
88 | //\r | |
89 | private SourceFilesIdentification sfid = null;\r | |
90 | \r | |
91 | private JButton jButtonOk = null;\r | |
92 | \r | |
93 | private JButton jButtonCancel = null;\r | |
94 | \r | |
95 | /**\r | |
96 | This method initializes jTextFieldFileName \r | |
97 | \r | |
98 | @return javax.swing.JTextField jTextFieldFileName\r | |
99 | \r | |
100 | **/\r | |
101 | private JTextField getJTextFieldSourceFilesDirectory() {\r | |
102 | if (jTextFieldFileName == null) {\r | |
103 | jTextFieldFileName = new JTextField();\r | |
104 | jTextFieldFileName.setBounds(new java.awt.Rectangle(140, 10, 250, 20));\r | |
105 | jTextFieldFileName.setPreferredSize(new java.awt.Dimension(250, 20));\r | |
106 | jTextFieldFileName.setToolTipText("Path is relative to the MSA file and must include the file name");\r | |
107 | }\r | |
108 | return jTextFieldFileName;\r | |
109 | }\r | |
110 | \r | |
111 | /**\r | |
112 | This method initializes jButtonOpenFile \r | |
113 | \r | |
114 | @return javax.swing.JButton jButtonOpenFile\r | |
115 | \r | |
116 | **/\r | |
117 | private JButton getJButtonOpenFile() {\r | |
118 | if (jButtonOpenFile == null) {\r | |
119 | jButtonOpenFile = new JButton();\r | |
120 | jButtonOpenFile.setText("Browse");\r | |
121 | jButtonOpenFile.setBounds(new java.awt.Rectangle(395, 10, 85, 20));\r | |
122 | jButtonOpenFile.setPreferredSize(new java.awt.Dimension(85, 20));\r | |
123 | jButtonOpenFile.addActionListener(this);\r | |
124 | }\r | |
125 | return jButtonOpenFile;\r | |
126 | }\r | |
127 | \r | |
128 | /**\r | |
129 | This method initializes jScrollPane \r | |
130 | \r | |
131 | @return javax.swing.JScrollPane \r | |
132 | */\r | |
133 | private JScrollPane getJScrollPane() {\r | |
134 | if (jScrollPane == null) {\r | |
135 | jScrollPane = new JScrollPane();\r | |
136 | jScrollPane.setViewportView(getJContentPane());\r | |
137 | }\r | |
138 | return jScrollPane;\r | |
139 | }\r | |
140 | \r | |
141 | /**\r | |
142 | * This method initializes jTextFieldTagName \r | |
143 | * \r | |
144 | * @return javax.swing.JTextField \r | |
145 | */\r | |
146 | private JTextField getJTextFieldTagName() {\r | |
147 | if (jTextFieldTagName == null) {\r | |
148 | jTextFieldTagName = new JTextField();\r | |
149 | jTextFieldTagName.setBounds(new java.awt.Rectangle(140, 35, 340, 20));\r | |
150 | jTextFieldTagName.setPreferredSize(new java.awt.Dimension(340, 20));\r | |
151 | jTextFieldTagName.setToolTipText("You may specify a specific tool chain tag name, such as BILL1");\r | |
152 | }\r | |
153 | return jTextFieldTagName;\r | |
154 | }\r | |
155 | \r | |
156 | /**\r | |
157 | * This method initializes jTextFieldToolCode \r | |
158 | * \r | |
159 | * @return javax.swing.JTextField \r | |
160 | */\r | |
161 | private JTextField getJTextFieldToolCode() {\r | |
162 | if (jTextFieldToolCode == null) {\r | |
163 | jTextFieldToolCode = new JTextField();\r | |
164 | jTextFieldToolCode.setBounds(new java.awt.Rectangle(140, 60, 340, 20));\r | |
165 | jTextFieldToolCode.setPreferredSize(new java.awt.Dimension(340, 20));\r | |
166 | jTextFieldToolCode.setToolTipText("You may specify a specific tool command, such as ASM");\r | |
167 | }\r | |
168 | return jTextFieldToolCode;\r | |
169 | }\r | |
170 | \r | |
171 | /**\r | |
172 | * This method initializes jTextFieldToolChainFamily \r | |
173 | * \r | |
174 | * @return javax.swing.JTextField \r | |
175 | */\r | |
176 | private JTextField getJTextFieldToolChainFamily() {\r | |
177 | if (jTextFieldToolChainFamily == null) {\r | |
178 | jTextFieldToolChainFamily = new JTextField();\r | |
179 | jTextFieldToolChainFamily.setBounds(new java.awt.Rectangle(140, 85, 340, 20));\r | |
180 | jTextFieldToolChainFamily.setPreferredSize(new java.awt.Dimension(340, 20));\r | |
181 | jTextFieldToolChainFamily.setToolTipText("You may specify a specific tool chain family, such as GCC");\r | |
182 | }\r | |
183 | return jTextFieldToolChainFamily;\r | |
184 | }\r | |
185 | \r | |
186 | /**\r | |
187 | * This method initializes jTextFieldFeatureFlag \r | |
188 | * \r | |
189 | * @return javax.swing.JTextField \r | |
190 | */\r | |
191 | private JTextField getJTextFieldFeatureFlag() {\r | |
192 | if (jTextFieldFeatureFlag == null) {\r | |
193 | jTextFieldFeatureFlag = new JTextField();\r | |
194 | jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(140, 110, 340, 20));\r | |
195 | jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(340, 20));\r | |
196 | jTextFieldFeatureFlag.setToolTipText("RESERVED FOR FUTURE USE");\r | |
197 | }\r | |
198 | return jTextFieldFeatureFlag;\r | |
199 | }\r | |
200 | \r | |
201 | /**\r | |
202 | This method initializes jButtonOk \r | |
203 | \r | |
204 | @return javax.swing.JButton \r | |
205 | \r | |
206 | **/\r | |
207 | private JButton getJButtonOk() {\r | |
208 | if (jButtonOk == null) {\r | |
209 | jButtonOk = new JButton();\r | |
210 | jButtonOk.setBounds(new java.awt.Rectangle(290, 165, 90, 20));\r | |
211 | jButtonOk.setText("Ok");\r | |
212 | jButtonOk.addActionListener(this);\r | |
213 | }\r | |
214 | return jButtonOk;\r | |
215 | }\r | |
216 | \r | |
217 | /**\r | |
218 | This method initializes jButtonCancel \r | |
219 | \r | |
220 | @return javax.swing.JButton \r | |
221 | \r | |
222 | **/\r | |
223 | private JButton getJButtonCancel() {\r | |
224 | if (jButtonCancel == null) {\r | |
225 | jButtonCancel = new JButton();\r | |
226 | jButtonCancel.setBounds(new java.awt.Rectangle(390, 165, 90, 20));\r | |
227 | jButtonCancel.setText("Cancel");\r | |
228 | jButtonCancel.addActionListener(this);\r | |
229 | }\r | |
230 | return jButtonCancel;\r | |
231 | }\r | |
232 | \r | |
233 | public static void main(String[] args) {\r | |
234 | \r | |
235 | }\r | |
236 | \r | |
237 | /**\r | |
238 | This is the default constructor\r | |
239 | \r | |
240 | **/\r | |
241 | public SourceFilesDlg(SourceFilesIdentification inSourceFilesIdentification, IFrame iFrame) {\r | |
242 | super(iFrame, true);\r | |
243 | init(inSourceFilesIdentification);\r | |
244 | }\r | |
245 | \r | |
246 | /**\r | |
247 | This method initializes this\r | |
248 | \r | |
249 | **/\r | |
250 | private void init() {\r | |
251 | this.setSize(500, 235);\r | |
252 | this.setContentPane(getJScrollPane());\r | |
253 | this.setTitle("Source Files");\r | |
254 | this.setViewMode(false);\r | |
255 | this.centerWindow();\r | |
256 | }\r | |
257 | \r | |
258 | /** \r | |
259 | This method initializes this\r | |
260 | Fill values to all fields if these values are not empty\r | |
261 | \r | |
262 | \r | |
263 | @param inSourceFiles The input data of SourceFilesDocument.SourceFiles\r | |
264 | \r | |
265 | **/\r | |
266 | private void init(SourceFilesIdentification inSourceFilesIdentifications) {\r | |
267 | init();\r | |
268 | this.sfid = inSourceFilesIdentifications;\r | |
269 | \r | |
270 | if (this.sfid != null) {\r | |
271 | this.jTextFieldFileName.setText(sfid.getFilename());\r | |
272 | this.jTextFieldTagName.setText(sfid.getTagName());\r | |
273 | this.jTextFieldToolCode.setText(sfid.getToolCode());\r | |
274 | this.jTextFieldToolChainFamily.setText(sfid.getToolChainFamily());\r | |
275 | jTextFieldFeatureFlag.setText(sfid.getFeatureFlag());\r | |
276 | this.jArchCheckBox.setSelectedItems(sfid.getSupArchList());\r | |
277 | }\r | |
278 | }\r | |
279 | \r | |
280 | /**\r | |
281 | Disable all components when the mode is view\r | |
282 | \r | |
283 | @param isView true - The view mode; false - The non-view mode\r | |
284 | \r | |
285 | **/\r | |
286 | public void setViewMode(boolean isView) {\r | |
287 | if (isView) {\r | |
288 | this.jTextFieldFileName.setEnabled(!isView);\r | |
289 | this.jButtonOpenFile.setEnabled(!isView);\r | |
290 | }\r | |
291 | }\r | |
292 | \r | |
293 | /**\r | |
294 | This method initializes jContentPane\r | |
295 | \r | |
296 | @return javax.swing.JPanel jContentPane\r | |
297 | \r | |
298 | **/\r | |
299 | private JPanel getJContentPane() {\r | |
300 | if (jContentPane == null) {\r | |
301 | jArchCheckBox = new ArchCheckBox();\r | |
302 | jArchCheckBox.setBounds(new java.awt.Rectangle(140, 135, 340, 20));\r | |
303 | jArchCheckBox.setPreferredSize(new java.awt.Dimension(340, 20));\r | |
304 | jLabelFeatureFlag = new JLabel();\r | |
305 | jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 110, 120, 20));\r | |
306 | jLabelFeatureFlag.setText("Feature Flag");\r | |
307 | jLabelToolCode = new JLabel();\r | |
308 | jLabelToolCode.setBounds(new java.awt.Rectangle(15, 60, 120, 20));\r | |
309 | jLabelToolCode.setText("Tool Code");\r | |
310 | jLabelTagName = new JLabel();\r | |
311 | jLabelTagName.setBounds(new java.awt.Rectangle(15, 35, 120, 20));\r | |
312 | jLabelTagName.setText("Tag Name");\r | |
313 | jLabelArch = new JLabel();\r | |
314 | jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 120, 20));\r | |
315 | jLabelArch.setText("Sup Arch List");\r | |
316 | jLabelToolChainFamily = new JLabel();\r | |
317 | jLabelToolChainFamily.setBounds(new java.awt.Rectangle(15, 85, 120, 20));\r | |
318 | jLabelToolChainFamily.setText("Tool Chain Family");\r | |
319 | jLabelFileName = new JLabel();\r | |
320 | jLabelFileName.setText("File Name");\r | |
321 | jLabelFileName.setBounds(new java.awt.Rectangle(15, 10, 120, 20));\r | |
322 | \r | |
323 | jContentPane = new JPanel();\r | |
324 | jContentPane.setLayout(null);\r | |
325 | jContentPane.setPreferredSize(new java.awt.Dimension(490, 185));\r | |
326 | \r | |
327 | jContentPane.add(jLabelFileName, null);\r | |
328 | jContentPane.add(getJTextFieldSourceFilesDirectory(), null);\r | |
329 | jContentPane.add(getJButtonOpenFile(), null);\r | |
330 | jContentPane.add(jLabelToolChainFamily, null);\r | |
331 | jStarLabel1 = new StarLabel();\r | |
332 | jStarLabel1.setLocation(new java.awt.Point(0, 10));\r | |
333 | \r | |
334 | jContentPane.add(jStarLabel1, null);\r | |
335 | jContentPane.add(jLabelArch, null);\r | |
336 | jContentPane.add(jLabelTagName, null);\r | |
337 | jContentPane.add(getJTextFieldTagName(), null);\r | |
338 | jContentPane.add(jLabelToolCode, null);\r | |
339 | jContentPane.add(getJTextFieldToolCode(), null);\r | |
340 | jContentPane.add(getJTextFieldToolChainFamily(), null);\r | |
341 | jContentPane.add(jLabelFeatureFlag, null);\r | |
342 | jContentPane.add(getJTextFieldFeatureFlag(), null);\r | |
343 | jContentPane.add(jArchCheckBox, null);\r | |
344 | jContentPane.add(getJButtonOk(), null);\r | |
345 | jContentPane.add(getJButtonCancel(), null);\r | |
346 | }\r | |
347 | return jContentPane;\r | |
348 | }\r | |
349 | \r | |
350 | /* (non-Javadoc)\r | |
351 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r | |
352 | *\r | |
353 | * Override actionPerformed to listen all actions\r | |
354 | * \r | |
355 | */\r | |
356 | public void actionPerformed(ActionEvent arg0) {\r | |
357 | if (arg0.getSource() == jButtonOpenFile) {\r | |
358 | selectFile();\r | |
359 | }\r | |
360 | \r | |
361 | if (arg0.getSource() == jButtonOk) {\r | |
362 | if (checkAdd()) {\r | |
363 | getCurrentSourceFiles();\r | |
364 | this.returnType = DataType.RETURN_TYPE_OK;\r | |
365 | this.setVisible(false);\r | |
366 | }\r | |
367 | }\r | |
368 | \r | |
369 | if (arg0.getSource() == jButtonCancel) {\r | |
370 | this.returnType = DataType.RETURN_TYPE_CANCEL;\r | |
371 | this.setVisible(false);\r | |
372 | }\r | |
373 | }\r | |
374 | \r | |
375 | private SourceFilesIdentification getCurrentSourceFiles() {\r | |
376 | String name = this.jTextFieldFileName.getText();\r | |
377 | String tagName = this.jTextFieldTagName.getText();\r | |
378 | String toolCode = this.jTextFieldToolCode.getText();\r | |
379 | String tcf = this.jTextFieldToolChainFamily.getText();\r | |
380 | String featureFlag = this.jTextFieldFeatureFlag.getText();\r | |
381 | Vector<String> arch = this.jArchCheckBox.getSelectedItemsVector();\r | |
382 | sfid = new SourceFilesIdentification(name, tagName, toolCode, tcf, featureFlag, arch);\r | |
383 | return sfid;\r | |
384 | }\r | |
385 | \r | |
386 | /**\r | |
387 | Data validation for all fields\r | |
388 | \r | |
389 | @retval true - All datas are valid\r | |
390 | @retval false - At least one data is invalid\r | |
391 | \r | |
392 | **/\r | |
393 | public boolean checkAdd() {\r | |
394 | //\r | |
395 | // Check Filename\r | |
396 | //\r | |
397 | if (isEmpty(this.jTextFieldFileName.getText())) {\r | |
398 | Log.err("File Name couldn't be empty");\r | |
399 | return false;\r | |
400 | }\r | |
401 | if (!DataValidation.isFilename(this.jTextFieldFileName.getText())) {\r | |
402 | Log.err("Incorrect data type for File Name");\r | |
403 | return false;\r | |
404 | }\r | |
405 | \r | |
406 | //\r | |
407 | // Check TagName \r | |
408 | //\r | |
409 | if (!isEmpty(this.jTextFieldTagName.getText())) {\r | |
410 | if (!DataValidation.isTagName(this.jTextFieldTagName.getText())) {\r | |
411 | Log.err("Incorrect data type for Tag Name");\r | |
412 | return false;\r | |
413 | }\r | |
414 | }\r | |
415 | \r | |
416 | //\r | |
417 | // Check ToolCode \r | |
418 | //\r | |
419 | if (!isEmpty(this.jTextFieldToolCode.getText())) {\r | |
420 | if (!DataValidation.isToolCode(this.jTextFieldToolCode.getText())) {\r | |
421 | Log.err("Incorrect data type for Tool Code");\r | |
422 | return false;\r | |
423 | }\r | |
424 | }\r | |
425 | \r | |
426 | //\r | |
427 | // Check ToolChainFamily \r | |
428 | //\r | |
429 | if (!isEmpty(this.jTextFieldToolChainFamily.getText())) {\r | |
430 | if (!DataValidation.isToolChainFamily(this.jTextFieldToolChainFamily.getText())) {\r | |
431 | Log.err("Incorrect data type for Tool Chain Family");\r | |
432 | return false;\r | |
433 | }\r | |
434 | }\r | |
435 | \r | |
436 | //\r | |
437 | // Check FeatureFlag\r | |
438 | //\r | |
439 | if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {\r | |
440 | if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {\r | |
441 | Log.err("Incorrect data type for Feature Flag");\r | |
442 | return false;\r | |
443 | }\r | |
444 | }\r | |
445 | \r | |
446 | return true;\r | |
447 | }\r | |
448 | \r | |
449 | /**\r | |
450 | Display a file open browser to let user select file\r | |
451 | \r | |
452 | **/\r | |
453 | private void selectFile() {\r | |
454 | JFileChooser fc = new JFileChooser(Workspace.getCurrentWorkspace());\r | |
455 | \r | |
456 | int result = fc.showOpenDialog(new JPanel());\r | |
457 | if (result == JFileChooser.APPROVE_OPTION) {\r | |
458 | this.jTextFieldFileName.setText(fc.getSelectedFile().getName());\r | |
459 | }\r | |
460 | }\r | |
461 | \r | |
462 | public SourceFilesIdentification getSfid() {\r | |
463 | return sfid;\r | |
464 | }\r | |
465 | \r | |
466 | public void setSfid(SourceFilesIdentification sfid) {\r | |
467 | this.sfid = sfid;\r | |
468 | }\r | |
469 | }\r |