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