]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/module/ui/ModuleSourceFiles.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / module / ui / ModuleSourceFiles.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.packaging.module.ui;
16
17 import java.awt.event.ActionEvent;
18 import java.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.util.Vector;
21
22 import javax.swing.JButton;
23 import javax.swing.JCheckBox;
24 import javax.swing.JComboBox;
25 import javax.swing.JFileChooser;
26 import javax.swing.JLabel;
27 import javax.swing.JPanel;
28 import javax.swing.JTextField;
29
30 import org.tianocore.FilenameDocument;
31 import org.tianocore.SourceFilesDocument;
32 import org.tianocore.SupportedArchitectures;
33 import org.tianocore.ToolChains;
34 import org.tianocore.common.DataType;
35 import org.tianocore.common.DataValidation;
36 import org.tianocore.common.Log;
37 import org.tianocore.common.Tools;
38 import org.tianocore.packaging.common.ui.IDefaultMutableTreeNode;
39 import org.tianocore.packaging.common.ui.IInternalFrame;
40 import org.tianocore.packaging.common.ui.StarLabel;
41 import org.tianocore.packaging.workspace.common.Workspace;
42 import javax.swing.JScrollPane;
43 import javax.swing.JTextArea;
44
45 /**
46 The class is used to create, update SourceFile of MSA/MBD file
47 It extends IInternalFrame
48
49 @since ModuleEditor 1.0
50
51 **/
52 public class ModuleSourceFiles extends IInternalFrame implements ItemListener {
53
54 ///
55 /// Define class Serial Version UID
56 ///
57 private static final long serialVersionUID = -6765742852142775378L;
58
59 //
60 // Define class members
61 //
62 private SourceFilesDocument.SourceFiles sourceFiles = null;
63
64 private int location = -1;
65
66 private int intSelectedItemId = 0;
67
68 //
69 // 1 - Add; 2 - Update
70 //
71 private int operation = -1;
72
73 private Workspace ws = new Workspace();
74
75 private Vector<String> vFileName = new Vector<String>();
76
77 private Vector<String> vGuid = new Vector<String>();
78
79 private Vector<String> vPath = new Vector<String>();
80
81 private Vector<String> vFileType = new Vector<String>();
82
83 private Vector<String> vToolChain = new Vector<String>();
84
85 private Vector<String> vOverrideID = new Vector<String>();
86
87 private JPanel jContentPane = null;
88
89 private JButton jButtonOk = null;
90
91 private JButton jButtonCancel = null;
92
93 private JLabel jLabelFileName = null;
94
95 private JTextField jTextFieldFileName = null;
96
97 private JButton jButtonOpenFile = null;
98
99 private JLabel jLabelGuid = null;
100
101 private JTextField jTextFieldGuid = null;
102
103 private JButton jButtonGenerateGuid = null;
104
105 private JComboBox jComboBoxArch = null;
106
107 private JLabel jLabelPath = null;
108
109 private JTextField jTextFieldPath = null;
110
111 private JLabel jLabelFileType = null;
112
113 private JTextField jTextFieldFileType = null;
114
115 private JLabel jLabelOverrideID = null;
116
117 private JTextField jTextFieldOverrideID = null;
118
119 private StarLabel jStarLabel1 = null;
120
121 private JComboBox jComboBoxFileList = null;
122
123 private JButton jButtonAdd = null;
124
125 private JButton jButtonRemove = null;
126
127 private JButton jButtonUpdate = null;
128
129 private JCheckBox jCheckBoxArch = null;
130
131 private JLabel jLabelToolChain = null;
132
133 private JComboBox jComboBoxToolChain = null;
134
135 private JScrollPane jScrollPaneFileList = null;
136
137 private JTextArea jTextAreaFileList = null;
138
139 /**
140 This method initializes jButtonOk
141
142 @return javax.swing.JButton jButtonOk
143
144 **/
145 private JButton getJButton() {
146 if (jButtonOk == null) {
147 jButtonOk = new JButton();
148 jButtonOk.setText("OK");
149 jButtonOk.setBounds(new java.awt.Rectangle(290, 340, 90, 20));
150 jButtonOk.addActionListener(this);
151 }
152 return jButtonOk;
153 }
154
155 /**
156 This method initializes jButtonCancel
157
158 @return javax.swing.JButton jButtonCancel
159
160 **/
161 private JButton getJButton1() {
162 if (jButtonCancel == null) {
163 jButtonCancel = new JButton();
164 jButtonCancel.setText("Cancel");
165 jButtonCancel.setBounds(new java.awt.Rectangle(390, 340, 90, 20));
166 jButtonCancel.setPreferredSize(new java.awt.Dimension(90, 20));
167 jButtonCancel.addActionListener(this);
168 }
169 return jButtonCancel;
170 }
171
172 /**
173 This method initializes jTextFieldFileName
174
175 @return javax.swing.JTextField jTextFieldFileName
176
177 **/
178 private JTextField getJTextFieldSourceFilesDirectory() {
179 if (jTextFieldFileName == null) {
180 jTextFieldFileName = new JTextField();
181 jTextFieldFileName.setBounds(new java.awt.Rectangle(140,10,250,20));
182 }
183 return jTextFieldFileName;
184 }
185
186 /**
187 This method initializes jButtonOpenFile
188
189 @return javax.swing.JButton jButtonOpenFile
190
191 **/
192 private JButton getJButtonOpenFile() {
193 if (jButtonOpenFile == null) {
194 jButtonOpenFile = new JButton();
195 jButtonOpenFile.setText("Browse");
196 jButtonOpenFile.setBounds(new java.awt.Rectangle(395,10,85,20));
197 jButtonOpenFile.addActionListener(this);
198 }
199 return jButtonOpenFile;
200 }
201
202 /**
203 This method initializes jTextFieldGuid
204
205 @return javax.swing.JTextField jTextFieldGuid
206
207 **/
208 private JTextField getJTextFieldGuid() {
209 if (jTextFieldGuid == null) {
210 jTextFieldGuid = new JTextField();
211 jTextFieldGuid.setBounds(new java.awt.Rectangle(140,35,250,20));
212 }
213 return jTextFieldGuid;
214 }
215
216 /**
217 This method initializes jButtonGenerateGuid
218
219 @return javax.swing.JButton jButtonGenerateGuid
220
221 **/
222 private JButton getJButtonGenerateGuid() {
223 if (jButtonGenerateGuid == null) {
224 jButtonGenerateGuid = new JButton();
225 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(395,35,85,20));
226 jButtonGenerateGuid.setText("GEN");
227 jButtonGenerateGuid.addActionListener(this);
228 }
229 return jButtonGenerateGuid;
230 }
231
232 /**
233 This method initializes jComboBoxArch
234
235 @return javax.swing.JComboBox jComboBoxArch
236
237 **/
238 private JComboBox getJComboBoxArch() {
239 if (jComboBoxArch == null) {
240 jComboBoxArch = new JComboBox();
241 jComboBoxArch.setBounds(new java.awt.Rectangle(140, 160, 340, 20));
242 jComboBoxArch.setEnabled(false);
243 }
244 return jComboBoxArch;
245 }
246
247 /**
248 This method initializes jTextFieldPath
249
250 @return javax.swing.JTextField jTextFieldPath
251
252 **/
253 private JTextField getJTextFieldPath() {
254 if (jTextFieldPath == null) {
255 jTextFieldPath = new JTextField();
256 jTextFieldPath.setBounds(new java.awt.Rectangle(140, 60, 340, 20));
257 }
258 return jTextFieldPath;
259 }
260
261 /**
262 This method initializes jTextFieldFileType
263
264 @return javax.swing.JTextField jTextFieldFileType
265
266 **/
267 private JTextField getJTextFieldFileType() {
268 if (jTextFieldFileType == null) {
269 jTextFieldFileType = new JTextField();
270 jTextFieldFileType.setBounds(new java.awt.Rectangle(140, 85, 340, 20));
271 }
272 return jTextFieldFileType;
273 }
274
275 /**
276 This method initializes jTextFieldOverrideID
277
278 @return javax.swing.JTextField jTextFieldOverrideID
279
280 **/
281 private JTextField getJTextFieldOverrideID() {
282 if (jTextFieldOverrideID == null) {
283 jTextFieldOverrideID = new JTextField();
284 jTextFieldOverrideID.setBounds(new java.awt.Rectangle(140, 135, 50, 20));
285 }
286 return jTextFieldOverrideID;
287 }
288
289 /**
290 This method initializes jComboBoxFileList
291
292 @return javax.swing.JComboBox jComboBoxFileList
293
294 **/
295 private JComboBox getJComboBoxFileList() {
296 if (jComboBoxFileList == null) {
297 jComboBoxFileList = new JComboBox();
298 jComboBoxFileList.setBounds(new java.awt.Rectangle(15, 185, 210, 20));
299 jComboBoxFileList.addItemListener(this);
300 jComboBoxFileList.addActionListener(this);
301 }
302 return jComboBoxFileList;
303 }
304
305 /**
306 This method initializes jButtonAdd
307
308 @return javax.swing.JButton jButtonAdd
309
310 **/
311 private JButton getJButtonAdd() {
312 if (jButtonAdd == null) {
313 jButtonAdd = new JButton();
314 jButtonAdd.setBounds(new java.awt.Rectangle(230, 185, 80, 20));
315 jButtonAdd.setText("Add");
316 jButtonAdd.addActionListener(this);
317 }
318 return jButtonAdd;
319 }
320
321 /**
322 This method initializes jButtonRemove
323
324 @return javax.swing.JButton jButtonRemove
325
326 **/
327 private JButton getJButtonRemove() {
328 if (jButtonRemove == null) {
329 jButtonRemove = new JButton();
330 jButtonRemove.setBounds(new java.awt.Rectangle(400, 185, 80, 20));
331 jButtonRemove.setText("Remove");
332 jButtonRemove.addActionListener(this);
333 }
334 return jButtonRemove;
335 }
336
337 /**
338 This method initializes jButtonUpdate
339
340 @return javax.swing.JButton jButtonUpdate
341
342 **/
343 private JButton getJButtonUpdate() {
344 if (jButtonUpdate == null) {
345 jButtonUpdate = new JButton();
346 jButtonUpdate.setBounds(new java.awt.Rectangle(315, 185, 80, 20));
347 jButtonUpdate.setText("Update");
348 jButtonUpdate.addActionListener(this);
349 }
350 return jButtonUpdate;
351 }
352
353 /**
354 This method initializes jCheckBoxArch
355
356 @return javax.swing.JCheckBox jCheckBoxArch
357
358 **/
359 private JCheckBox getJCheckBoxArch() {
360 if (jCheckBoxArch == null) {
361 jCheckBoxArch = new JCheckBox();
362 jCheckBoxArch.setBounds(new java.awt.Rectangle(15, 160, 120, 20));
363 jCheckBoxArch.setText("Specific Arch");
364 jCheckBoxArch.addActionListener(this);
365 }
366 return jCheckBoxArch;
367 }
368
369 /**
370 This method initializes jComboBoxToolChain
371
372 @return javax.swing.JComboBox jComboBoxToolChain
373
374 **/
375 private JComboBox getJComboBoxToolChain() {
376 if (jComboBoxToolChain == null) {
377 jComboBoxToolChain = new JComboBox();
378 jComboBoxToolChain.setBounds(new java.awt.Rectangle(140, 110, 340, 20));
379 }
380 return jComboBoxToolChain;
381 }
382
383 /**
384 * This method initializes jScrollPaneFileList
385 *
386 * @return javax.swing.JScrollPane
387 */
388 private JScrollPane getJScrollPaneFileList() {
389 if (jScrollPaneFileList == null) {
390 jScrollPaneFileList = new JScrollPane();
391 jScrollPaneFileList.setBounds(new java.awt.Rectangle(15,210,465,240));
392 jScrollPaneFileList.setViewportView(getJTextAreaFileList());
393 }
394 return jScrollPaneFileList;
395 }
396
397 /**
398 * This method initializes jTextAreaFileList
399 *
400 * @return javax.swing.JTextArea
401 */
402 private JTextArea getJTextAreaFileList() {
403 if (jTextAreaFileList == null) {
404 jTextAreaFileList = new JTextArea();
405 jTextAreaFileList.setEditable(false);
406 }
407 return jTextAreaFileList;
408 }
409
410 public static void main(String[] args) {
411
412 }
413
414 /**
415 This is the default constructor
416
417 **/
418 public ModuleSourceFiles() {
419 super();
420 init();
421 this.setVisible(true);
422 }
423
424 /**
425 This is the override edit constructor
426
427 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
428
429 **/
430 public ModuleSourceFiles(SourceFilesDocument.SourceFiles inSourceFiles) {
431 super();
432 init(inSourceFiles);
433 this.setVisible(true);
434 }
435
436 /**
437 This is the override edit constructor
438
439 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
440 @param type The input data of node type
441 @param index The input data of node index
442 @param inOperation The input data of current operation type
443
444 **/
445 public ModuleSourceFiles(SourceFilesDocument.SourceFiles inSourceFiles, int type, int index, int inOperation) {
446 super();
447 init(inSourceFiles, type, index, inOperation);
448 this.operation = inOperation;
449 this.setVisible(true);
450 }
451
452 /**
453 This method initializes this
454
455 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
456
457 **/
458 private void init(SourceFilesDocument.SourceFiles inSourceFiles) {
459 init();
460 this.setSourceFiles(inSourceFiles);
461 }
462
463 /**
464 This method initializes this
465 Fill values to all fields if these values are not empty
466
467
468 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
469 @param type The input data of node type
470 @param index The input data of node index
471 @param inOperation The input data of current operation type
472
473 **/
474 private void init(SourceFilesDocument.SourceFiles inSourceFiles, int type, int index, int inOperation) {
475 init(inSourceFiles);
476 this.location = index;
477 this.operation = inOperation;
478
479 //
480 // When update
481 //
482 if (operation == 2) {
483 this.jCheckBoxArch.setEnabled(false);
484 this.jComboBoxArch.setEnabled(false);
485
486 if (type == IDefaultMutableTreeNode.SOURCEFILES_FILENAME) {
487 if (this.sourceFiles.getFilenameList().size() > 0) {
488 for (int indexI = 0; indexI < this.sourceFiles.getFilenameList().size(); indexI++) {
489 if (this.sourceFiles.getFilenameArray(indexI).getStringValue() != null) {
490 vFileName.addElement(this.sourceFiles.getFilenameArray(indexI).getStringValue());
491 } else {
492 vFileName.addElement("");
493 }
494 if (this.sourceFiles.getFilenameArray(indexI).getGuid() != null) {
495 vGuid.addElement(this.sourceFiles.getFilenameArray(indexI).getGuid());
496 } else {
497 vGuid.addElement("");
498 }
499 if (this.sourceFiles.getFilenameArray(indexI).getPath() != null) {
500 vPath.addElement(this.sourceFiles.getFilenameArray(indexI).getPath());
501 } else {
502 vPath.addElement("");
503 }
504 if (this.sourceFiles.getFilenameArray(indexI).getFileType() != null) {
505 vFileType.addElement(this.sourceFiles.getFilenameArray(indexI).getFileType());
506 } else {
507 vFileType.addElement("");
508 }
509 if (this.sourceFiles.getFilenameArray(indexI).getToolChain() != null) {
510 vToolChain.addElement(this.sourceFiles.getFilenameArray(indexI).getToolChain().toString());
511 } else {
512 vToolChain.addElement(DataType.EMPTY_SELECT_ITEM);
513 }
514 vOverrideID.addElement(String.valueOf(this.sourceFiles.getFilenameArray(indexI).getOverrideID()));
515 jComboBoxFileList.addItem(this.sourceFiles.getFilenameArray(indexI).getStringValue());
516 }
517 }
518 }
519 if (type == IDefaultMutableTreeNode.SOURCEFILES_ARCH_ITEM) {
520 this.jCheckBoxArch.setSelected(true);
521 this.jComboBoxArch.setSelectedItem(this.sourceFiles.getArchArray(index).getArchType().toString());
522 for (int indexI = 0; indexI < this.sourceFiles.getArchArray(index).getFilenameList().size(); indexI++) {
523 if (this.sourceFiles.getArchArray(index).getFilenameArray(indexI).getStringValue() != null) {
524 vFileName.addElement(this.sourceFiles.getArchArray(index).getFilenameArray(indexI)
525 .getStringValue());
526 } else {
527 vFileName.addElement("");
528 }
529 if (this.sourceFiles.getArchArray(index).getFilenameArray(indexI).getGuid() != null) {
530 vGuid.addElement(this.sourceFiles.getArchArray(index).getFilenameArray(indexI).getGuid());
531 } else {
532 vGuid.addElement("");
533 }
534 if (this.sourceFiles.getArchArray(index).getFilenameArray(indexI).getPath() != null) {
535 vPath.addElement(this.sourceFiles.getArchArray(index).getFilenameArray(indexI).getPath());
536 } else {
537 vPath.addElement("");
538 }
539 if (this.sourceFiles.getArchArray(index).getFilenameArray(indexI).getFileType() != null) {
540 vFileType.addElement(this.sourceFiles.getArchArray(index).getFilenameArray(indexI)
541 .getFileType());
542 } else {
543 vFileType.addElement("");
544 }
545 if (this.sourceFiles.getArchArray(index).getFilenameArray(indexI).getToolChain() != null) {
546 vToolChain.addElement(this.sourceFiles.getArchArray(index).getFilenameArray(indexI)
547 .getToolChain().toString());
548 } else {
549 vToolChain.addElement("");
550 }
551 vOverrideID.addElement(String.valueOf(this.sourceFiles.getArchArray(index).getFilenameArray(indexI)
552 .getOverrideID()));
553 jComboBoxFileList.addItem(this.sourceFiles.getArchArray(index).getFilenameArray(indexI)
554 .getStringValue());
555 }
556 }
557 //
558 // Update the file list
559 //
560 reloadFileListArea();
561 }
562 }
563
564 /**
565 This method initializes this
566
567 **/
568 private void init() {
569 this.setSize(500, 515);
570 this.setContentPane(getJContentPane());
571 this.setTitle("Source Files");
572 initFrame();
573 this.setViewMode(false);
574 }
575
576 /**
577 Disable all components when the mode is view
578
579 @param isView true - The view mode; false - The non-view mode
580
581 **/
582 public void setViewMode(boolean isView) {
583 this.jButtonOk.setVisible(false);
584 this.jButtonCancel.setVisible(false);
585 if (isView) {
586 this.jButtonOk.setEnabled(!isView);
587 this.jButtonCancel.setEnabled(!isView);
588 this.jTextFieldFileName.setEnabled(!isView);
589 this.jButtonOpenFile.setEnabled(!isView);
590 this.jTextFieldGuid.setEnabled(!isView);
591 this.jButtonGenerateGuid.setEnabled(!isView);
592 this.jTextFieldPath.setEnabled(!isView);
593 this.jTextFieldFileType.setEnabled(!isView);
594 this.jComboBoxToolChain.setEnabled(!isView);
595 this.jTextFieldOverrideID.setEnabled(!isView);
596
597 this.jButtonAdd.setEnabled(!isView);
598 this.jButtonRemove.setEnabled(!isView);
599 this.jButtonUpdate.setEnabled(!isView);
600 this.jCheckBoxArch.setEnabled(!isView);
601 }
602 }
603
604 /**
605 This method initializes jContentPane
606
607 @return javax.swing.JPanel jContentPane
608
609 **/
610 private JPanel getJContentPane() {
611 if (jContentPane == null) {
612 jLabelToolChain = new JLabel();
613 jLabelToolChain.setBounds(new java.awt.Rectangle(15, 110, 120, 20));
614 jLabelToolChain.setText("Tool Chain");
615 jLabelOverrideID = new JLabel();
616 jLabelOverrideID.setBounds(new java.awt.Rectangle(15, 135, 120, 20));
617 jLabelOverrideID.setText("Override ID");
618 jLabelFileType = new JLabel();
619 jLabelFileType.setBounds(new java.awt.Rectangle(15, 85, 120, 20));
620 jLabelFileType.setText("File Type");
621 jLabelPath = new JLabel();
622 jLabelPath.setBounds(new java.awt.Rectangle(15, 60, 120, 20));
623 jLabelPath.setText("Path");
624 jLabelGuid = new JLabel();
625 jLabelGuid.setBounds(new java.awt.Rectangle(15, 35, 120, 20));
626 jLabelGuid.setText("Guid");
627 jLabelFileName = new JLabel();
628 jLabelFileName.setText("File Name");
629 jLabelFileName.setBounds(new java.awt.Rectangle(15, 10, 120, 20));
630 jContentPane = new JPanel();
631 jContentPane.setLayout(null);
632 jContentPane.setSize(new java.awt.Dimension(480,400));
633 jContentPane.add(getJButton(), null);
634 jContentPane.add(getJButton1(), null);
635 jContentPane.add(jLabelFileName, null);
636 jContentPane.add(getJTextFieldSourceFilesDirectory(), null);
637 jContentPane.add(getJButtonOpenFile(), null);
638 jContentPane.add(jLabelGuid, null);
639 jContentPane.add(getJTextFieldGuid(), null);
640 jContentPane.add(getJButtonGenerateGuid(), null);
641 jContentPane.add(getJComboBoxArch(), null);
642 jContentPane.add(jLabelPath, null);
643 jContentPane.add(getJTextFieldPath(), null);
644 jContentPane.add(jLabelFileType, null);
645 jContentPane.add(getJTextFieldFileType(), null);
646 jContentPane.add(jLabelOverrideID, null);
647 jContentPane.add(getJTextFieldOverrideID(), null);
648 jStarLabel1 = new StarLabel();
649 jStarLabel1.setLocation(new java.awt.Point(0, 10));
650
651 jContentPane.add(jStarLabel1, null);
652 jContentPane.add(getJComboBoxFileList(), null);
653 jContentPane.add(getJButtonAdd(), null);
654 jContentPane.add(getJButtonRemove(), null);
655 jContentPane.add(getJButtonUpdate(), null);
656 jContentPane.add(getJCheckBoxArch(), null);
657 jContentPane.add(jLabelToolChain, null);
658 jContentPane.add(getJComboBoxToolChain(), null);
659
660 jContentPane.add(getJScrollPaneFileList(), null);
661 }
662 return jContentPane;
663 }
664
665 /* (non-Javadoc)
666 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
667 *
668 * Override actionPerformed to listen all actions
669 *
670 */
671 public void actionPerformed(ActionEvent arg0) {
672 if (arg0.getSource() == jButtonOk) {
673 this.setEdited(true);
674 this.save();
675 this.dispose();
676 }
677 if (arg0.getSource() == jButtonCancel) {
678 this.dispose();
679 }
680 if (arg0.getSource() == jButtonGenerateGuid) {
681 jTextFieldGuid.setText(Tools.generateUuidString());
682 }
683 if (arg0.getSource() == jButtonOpenFile) {
684 selectFile();
685 }
686 if (arg0.getSource() == jButtonAdd) {
687 if (!checkAdd()) {
688 return;
689 }
690 addToList();
691 }
692 if (arg0.getSource() == jButtonRemove) {
693 removeFromList();
694 }
695 if (arg0.getSource() == jButtonUpdate) {
696 if (!checkAdd()) {
697 return;
698 }
699 updateForList();
700 }
701
702 //
703 //When and only when checked Arch box then can choose different arch types
704 //
705 if (arg0.getSource() == jCheckBoxArch) {
706 if (this.jCheckBoxArch.isSelected()) {
707 this.jComboBoxArch.setEnabled(true);
708 } else {
709 this.jComboBoxArch.setEnabled(false);
710 }
711 }
712 }
713
714 /**
715 This method initializes Usage type and Arch type
716
717 **/
718 private void initFrame() {
719 jComboBoxArch.addItem("ALL");
720 jComboBoxArch.addItem("EBC");
721 jComboBoxArch.addItem("ARM");
722 jComboBoxArch.addItem("IA32");
723 jComboBoxArch.addItem("X64");
724 jComboBoxArch.addItem("IPF");
725 jComboBoxArch.addItem("PPC");
726
727 jComboBoxToolChain.addItem(DataType.EMPTY_SELECT_ITEM);
728 jComboBoxToolChain.addItem("MSFT");
729 jComboBoxToolChain.addItem("INTEL");
730 jComboBoxToolChain.addItem("GCC");
731 jComboBoxToolChain.addItem("CYGWIN");
732 }
733
734 /**
735 Add current item to Vector
736
737 **/
738 private void addToList() {
739 intSelectedItemId = vFileName.size();
740 vFileName.addElement(this.jTextFieldFileName.getText());
741 vGuid.addElement(this.jTextFieldGuid.getText());
742 vPath.addElement(this.jTextFieldPath.getText());
743 vFileType.addElement(this.jTextFieldFileType.getText());
744 vToolChain.addElement(this.jComboBoxToolChain.getSelectedItem().toString());
745 vOverrideID.addElement(this.jTextFieldOverrideID.getText());
746 jComboBoxFileList.addItem(this.jTextFieldFileName.getText());
747 jComboBoxFileList.setSelectedItem(this.jTextFieldFileName.getText());
748
749 //
750 // Reset select item index
751 //
752 intSelectedItemId = vFileName.size();
753
754 //
755 // Reload all fields of selected item
756 //
757 reloadFromList();
758 }
759
760 /**
761 Remove current item from Vector
762
763 **/
764 private void removeFromList() {
765 int intTempIndex = intSelectedItemId;
766 if (vFileName.size() < 1) {
767 return;
768 }
769
770 jComboBoxFileList.removeItemAt(intSelectedItemId);
771
772 vFileName.removeElementAt(intTempIndex);
773 vGuid.removeElementAt(intTempIndex);
774 vPath.removeElementAt(intTempIndex);
775 vFileType.removeElementAt(intTempIndex);
776 vToolChain.removeElementAt(intTempIndex);
777 vOverrideID.removeElementAt(intTempIndex);
778
779 //
780 // Reload all fields of selected item
781 //
782 reloadFromList();
783 }
784
785 /**
786 Update current item of Vector
787
788 **/
789 private void updateForList() {
790 //
791 // Backup selected item index
792 //
793 int intTempIndex = intSelectedItemId;
794 vFileName.setElementAt(this.jTextFieldFileName.getText(), intSelectedItemId);
795 vGuid.setElementAt(this.jTextFieldGuid.getText(), intSelectedItemId);
796 vPath.setElementAt(this.jTextFieldPath.getText(), intSelectedItemId);
797 vFileType.setElementAt(this.jTextFieldFileType.getText(), intSelectedItemId);
798 vToolChain.setElementAt(this.jComboBoxToolChain.getSelectedItem().toString(), intSelectedItemId);
799 vOverrideID.setElementAt(this.jTextFieldOverrideID.getText(), intSelectedItemId);
800 jComboBoxFileList.removeAllItems();
801 for (int index = 0; index < vFileName.size(); index++) {
802 jComboBoxFileList.addItem(vFileName.elementAt(index));
803 }
804
805 //
806 // Restore selected item index
807 //
808 intSelectedItemId = intTempIndex;
809
810 //
811 // Reset select item index
812 //
813 jComboBoxFileList.setSelectedIndex(intSelectedItemId);
814
815 //
816 // Reload all fields of selected item
817 //
818 reloadFromList();
819 }
820
821 /**
822 Refresh all fields' values of selected item of Vector
823
824 **/
825 private void reloadFromList() {
826 if (vFileName.size() > 0) {
827 //
828 // Get selected item index
829 //
830 intSelectedItemId = jComboBoxFileList.getSelectedIndex();
831
832 this.jTextFieldFileName.setText(vFileName.elementAt(intSelectedItemId).toString());
833 this.jTextFieldGuid.setText(vGuid.elementAt(intSelectedItemId).toString());
834 this.jTextFieldPath.setText(vPath.elementAt(intSelectedItemId).toString());
835 this.jTextFieldFileType.setText(vFileType.elementAt(intSelectedItemId).toString());
836 this.jComboBoxToolChain.setSelectedItem(vToolChain.elementAt(intSelectedItemId).toString());
837 this.jTextFieldOverrideID.setText(vOverrideID.elementAt(intSelectedItemId).toString());
838 } else {
839 this.jTextFieldFileName.setText("");
840 this.jTextFieldGuid.setText("");
841 this.jTextFieldPath.setText("");
842 this.jTextFieldFileType.setText("");
843 this.jComboBoxToolChain.setSelectedItem(DataType.EMPTY_SELECT_ITEM);
844 this.jTextFieldOverrideID.setText("");
845 }
846
847 reloadFileListArea();
848 }
849
850 /* (non-Javadoc)
851 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
852 *
853 * Reflesh the frame when selected item changed
854 *
855 */
856 public void itemStateChanged(ItemEvent arg0) {
857 if (arg0.getStateChange() == ItemEvent.SELECTED) {
858 reloadFromList();
859 }
860 }
861
862 /**
863 Get SourceFilesDocument.SourceFiles
864
865 @return SourceFilesDocument.SourceFiles
866
867 **/
868 public SourceFilesDocument.SourceFiles getSourceFiles() {
869 return sourceFiles;
870 }
871
872 /**
873 Set SourceFilesDocument.SourceFiles
874
875 @param sourceFiles The input data of SourceFilesDocument.SourceFiles
876
877 **/
878 public void setSourceFiles(SourceFilesDocument.SourceFiles sourceFiles) {
879 this.sourceFiles = sourceFiles;
880 }
881
882 /**
883 Data validation for all fields
884
885 @retval true - All datas are valid
886 @retval false - At least one data is invalid
887
888 **/
889 public boolean check() {
890 if (this.jComboBoxFileList.getItemCount() < 1) {
891 Log.err("Must have one file at least!");
892 return false;
893 }
894 return true;
895 }
896
897 /**
898 Data validation for all fields
899
900 @retval true - All datas are valid
901 @retval false - At least one data is invalid
902
903 **/
904 public boolean checkAdd() {
905 //
906 // Check if all required fields are not empty
907 //
908 if (isEmpty(this.jTextFieldFileName.getText())) {
909 Log.err("File Name couldn't be empty");
910 return false;
911 }
912
913 //
914 // Check if all fields have correct data types
915 //
916 if (!DataValidation.isFileName(this.jTextFieldFileName.getText())) {
917 Log.err("Incorrect data type for File Name");
918 return false;
919 }
920 if (!isEmpty(this.jTextFieldGuid.getText()) && !DataValidation.isGuid(this.jTextFieldGuid.getText())) {
921 Log.err("Incorrect data type for Guid");
922 return false;
923 }
924 if (!isEmpty(this.jTextFieldPath.getText()) && !DataValidation.isPath(this.jTextFieldPath.getText())) {
925 Log.err("Incorrect data type for Path");
926 return false;
927 }
928 if (!isEmpty(this.jTextFieldOverrideID.getText())
929 && !DataValidation.isOverrideID(this.jTextFieldOverrideID.getText())) {
930 Log.err("Incorrect data type for Override ID");
931 return false;
932 }
933
934 return true;
935 }
936
937 /**
938 Save all components of SourceFiles
939 if exists sourceFiles, set the value directly
940 if not exists sourceFiles, new an instance first
941
942 **/
943 public void save() {
944 try {
945 if (this.sourceFiles == null) {
946 sourceFiles = SourceFilesDocument.SourceFiles.Factory.newInstance();
947 }
948 //
949 //Save as file name
950 //
951 if (!this.jCheckBoxArch.isSelected()) {
952 if (this.operation == 2) { //Add new filename
953 //
954 //First remove all existed filename
955 //
956 if (sourceFiles.getFilenameList().size() > 0) {
957 for (int index = sourceFiles.getFilenameList().size() - 1; index >= 0; index--) {
958 sourceFiles.removeFilename(index);
959 }
960 }
961 }
962 for (int index = 0; index < vFileName.size(); index++) {
963 FilenameDocument.Filename filename = FilenameDocument.Filename.Factory.newInstance();
964 if (!isEmpty(vFileName.elementAt(index).toString())) {
965 filename.setStringValue(vFileName.elementAt(index).toString());
966 }
967 if (!isEmpty(vGuid.elementAt(index).toString())) {
968 filename.setGuid(vGuid.elementAt(index).toString());
969 }
970 if (!isEmpty(vPath.elementAt(index).toString())) {
971 filename.setPath(vPath.elementAt(index).toString());
972 }
973 if (!isEmpty(vFileType.elementAt(index).toString())) {
974 filename.setFileType(vFileType.elementAt(index).toString());
975 }
976 if (!vToolChain.elementAt(index).toString().equals(DataType.EMPTY_SELECT_ITEM)) {
977 filename.setToolChain(ToolChains.Enum.forString(vToolChain.elementAt(index).toString()));
978 }
979 if (!isEmpty(vOverrideID.elementAt(index).toString())) {
980 filename.setOverrideID(Integer.parseInt(vOverrideID.elementAt(index).toString()));
981 }
982 sourceFiles.addNewFilename();
983 sourceFiles.setFilenameArray(sourceFiles.getFilenameList().size() - 1, filename);
984 }
985 }
986 //
987 //Save as Arch
988 //
989 if (this.jCheckBoxArch.isSelected()) {
990 SourceFilesDocument.SourceFiles.Arch arch = SourceFilesDocument.SourceFiles.Arch.Factory.newInstance();
991 if (this.operation == 2) {
992 //
993 //First remove all existed filename
994 //
995 for (int index = sourceFiles.getArchArray(location).getFilenameList().size() - 1; index >= 0; index--) {
996 sourceFiles.getArchArray(location).removeFilename(index);
997 }
998 }
999 for (int index = 0; index < vFileName.size(); index++) {
1000 FilenameDocument.Filename filename = FilenameDocument.Filename.Factory.newInstance();
1001 if (!isEmpty(vFileName.elementAt(index).toString())) {
1002 filename.setStringValue(vFileName.elementAt(index).toString());
1003 }
1004 if (!isEmpty(vGuid.elementAt(index).toString())) {
1005 filename.setGuid(vGuid.elementAt(index).toString());
1006 }
1007 if (!isEmpty(vPath.elementAt(index).toString())) {
1008 filename.setPath(vPath.elementAt(index).toString());
1009 }
1010 if (!isEmpty(vFileType.elementAt(index).toString())) {
1011 filename.setFileType(vFileType.elementAt(index).toString());
1012 }
1013 if (!vToolChain.elementAt(index).toString().equals(DataType.EMPTY_SELECT_ITEM)) {
1014 filename.setToolChain(ToolChains.Enum.forString(vToolChain.elementAt(index).toString()));
1015 }
1016 if (!isEmpty(vOverrideID.elementAt(index).toString())) {
1017 filename.setOverrideID(Integer.parseInt(vOverrideID.elementAt(index).toString()));
1018 }
1019 arch.addNewFilename();
1020 arch.setFilenameArray(arch.getFilenameList().size() - 1, filename);
1021 }
1022 arch
1023 .setArchType(SupportedArchitectures.Enum.forString(this.jComboBoxArch.getSelectedItem().toString()));
1024 if (location > -1) {
1025 sourceFiles.setArchArray(location, arch);
1026 } else {
1027 sourceFiles.addNewArch();
1028 sourceFiles.setArchArray(sourceFiles.getArchList().size() - 1, arch);
1029 }
1030 }
1031 } catch (Exception e) {
1032 Log.err("Update Source Files", e.getMessage());
1033 }
1034 }
1035
1036 /**
1037 Display a file open browser to let user select file
1038
1039 **/
1040 private void selectFile() {
1041 JFileChooser fc = new JFileChooser(ws.getCurrentWorkspace());
1042
1043 int result = fc.showOpenDialog(new JPanel());
1044 if (result == JFileChooser.APPROVE_OPTION) {
1045 this.jTextFieldFileName.setText(fc.getSelectedFile().getName());
1046 }
1047 }
1048
1049 /**
1050 Update file list pane via the elements of Vector
1051
1052 **/
1053 private void reloadFileListArea() {
1054 String strFileList = "";
1055 for (int index = 0; index < vFileName.size(); index++) {
1056 strFileList = strFileList + vFileName.elementAt(index).toString() + DataType.UNXI_LINE_SEPARATOR;
1057 }
1058 this.jTextAreaFileList.setText(strFileList);
1059 }
1060 }