3 The file is used to let user choose to create module in an existing package
4 or to create a new package first.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.frameworkwizard
;
18 import java
.awt
.Component
;
19 import java
.awt
.event
.ActionEvent
;
21 import java
.util
.Vector
;
23 import javax
.swing
.ButtonGroup
;
24 import javax
.swing
.JButton
;
25 import javax
.swing
.JComboBox
;
26 import javax
.swing
.JFileChooser
;
27 import javax
.swing
.JLabel
;
28 import javax
.swing
.JPanel
;
29 import javax
.swing
.JTextField
;
31 import org
.tianocore
.ModuleTypeDef
;
32 import org
.tianocore
.MsaHeaderDocument
;
33 import org
.tianocore
.SpdHeaderDocument
;
34 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
35 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
36 import org
.tianocore
.PlatformHeaderDocument
.PlatformHeader
;
37 import org
.tianocore
.PlatformSurfaceAreaDocument
.PlatformSurfaceArea
;
38 import org
.tianocore
.frameworkwizard
.common
.DataType
;
39 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
40 import org
.tianocore
.frameworkwizard
.common
.IFileFilter
;
41 import org
.tianocore
.frameworkwizard
.common
.Log
;
42 import org
.tianocore
.frameworkwizard
.common
.SaveFile
;
43 import org
.tianocore
.frameworkwizard
.common
.Tools
;
44 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
45 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
46 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
47 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
48 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
49 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
50 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
51 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
52 import javax
.swing
.JRadioButton
;
54 public class SelectModuleBelong
extends IDialog
{
60 private static final long serialVersionUID
= 4171355136991448972L;
62 private JPanel jContentPane
= null;
64 private JComboBox jComboBoxExistingPackage
= null;
66 private JButton jButtonOk
= null;
68 private JButton jButtonCancel
= null;
70 private Vector
<PackageIdentification
> packages
= null;
72 private JLabel jLabelPackage
= null;
74 private JLabel jLabelFilePath
= null;
76 private JTextField jTextFieldFilePath
= null;
78 private JButton jButtonBrowse
= null;
80 private JLabel jLabelName
= null;
82 private JTextField jTextFieldName
= null;
84 private JLabel jLabelGuid
= null;
86 private JTextField jTextFieldGuid
= null;
88 private JButton jButtonGen
= null;
90 private JLabel jLabelVersion
= null;
92 private JTextField jTextFieldVersion
= null;
94 private StarLabel jStarLabel1
= null;
96 private StarLabel jStarLabel2
= null;
98 private StarLabel jStarLabel3
= null;
100 private StarLabel jStarLabel4
= null;
102 private StarLabel jStarLabel5
= null;
104 private ButtonGroup bg
= new ButtonGroup();
106 private WorkspaceTools wt
= new WorkspaceTools();
108 private ModuleIdentification mid
= null;
110 private PackageIdentification pid
= null;
112 private PlatformIdentification fid
= null;
114 private ModuleSurfaceArea msa
= null;
116 private PackageSurfaceArea spd
= null;
118 private PlatformSurfaceArea fpd
= null;
120 private int mode
= -1;
122 private JLabel jLabelIsLibrary
= null;
124 private JRadioButton jRadioButtonYes
= null;
126 private JRadioButton jRadioButtonNo
= null;
129 * This method initializes jComboBoxExistingPackage
131 * @return javax.swing.JComboBox
133 private JComboBox
getJComboBoxExistingPackage() {
134 if (jComboBoxExistingPackage
== null) {
135 jComboBoxExistingPackage
= new JComboBox();
136 jComboBoxExistingPackage
.setBounds(new java
.awt
.Rectangle(140, 10, 340, 20));
138 return jComboBoxExistingPackage
;
142 * This method initializes jButtonNext
144 * @return javax.swing.JButton
146 private JButton
getJButtonOk() {
147 if (jButtonOk
== null) {
148 jButtonOk
= new JButton();
149 jButtonOk
.setBounds(new java
.awt
.Rectangle(310, 165, 80, 20));
150 jButtonOk
.setText("Ok");
151 jButtonOk
.addActionListener(this);
157 * This method initializes jButtonCancel
159 * @return javax.swing.JButton
161 private JButton
getJButtonCancel() {
162 if (jButtonCancel
== null) {
163 jButtonCancel
= new JButton();
164 jButtonCancel
.setBounds(new java
.awt
.Rectangle(395, 165, 80, 20));
165 jButtonCancel
.setText("Cancel");
166 jButtonCancel
.addActionListener(this);
168 return jButtonCancel
;
172 * This method initializes jTextFieldFilePath
174 * @return javax.swing.JTextField
176 private JTextField
getJTextFieldFilePath() {
177 if (jTextFieldFilePath
== null) {
178 jTextFieldFilePath
= new JTextField();
179 jTextFieldFilePath
.setBounds(new java
.awt
.Rectangle(140, 60, 250, 20));
181 return jTextFieldFilePath
;
185 * This method initializes jButtonBrowse
187 * @return javax.swing.JButton
189 private JButton
getJButtonBrowse() {
190 if (jButtonBrowse
== null) {
191 jButtonBrowse
= new JButton();
192 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(395, 60, 85, 20));
193 jButtonBrowse
.setText("Browse");
194 jButtonBrowse
.addActionListener(this);
196 return jButtonBrowse
;
200 * This method initializes jTextFieldModuleName
202 * @return javax.swing.JTextField
204 private JTextField
getJTextFieldName() {
205 if (jTextFieldName
== null) {
206 jTextFieldName
= new JTextField();
207 jTextFieldName
.setBounds(new java
.awt
.Rectangle(140, 85, 340, 20));
209 return jTextFieldName
;
213 * This method initializes jTextFieldGuid
215 * @return javax.swing.JTextField
217 private JTextField
getJTextFieldGuid() {
218 if (jTextFieldGuid
== null) {
219 jTextFieldGuid
= new JTextField();
220 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(140, 110, 250, 20));
222 return jTextFieldGuid
;
226 * This method initializes jButtonGen
228 * @return javax.swing.JButton
230 private JButton
getJButtonGen() {
231 if (jButtonGen
== null) {
232 jButtonGen
= new JButton();
233 jButtonGen
.setBounds(new java
.awt
.Rectangle(395, 110, 85, 20));
234 jButtonGen
.setText("GEN");
235 jButtonGen
.addActionListener(this);
241 * This method initializes jTextFieldVersion
243 * @return javax.swing.JTextField
245 private JTextField
getJTextFieldVersion() {
246 if (jTextFieldVersion
== null) {
247 jTextFieldVersion
= new JTextField();
248 jTextFieldVersion
.setBounds(new java
.awt
.Rectangle(140, 135, 340, 20));
250 return jTextFieldVersion
;
254 * This method initializes jRadioButtonYes
256 * @return javax.swing.JRadioButton
258 private JRadioButton
getJRadioButtonYes() {
259 if (jRadioButtonYes
== null) {
260 jRadioButtonYes
= new JRadioButton();
261 jRadioButtonYes
.setBounds(new java
.awt
.Rectangle(140, 35, 100, 20));
262 jRadioButtonYes
.setSelected(false);
263 jRadioButtonYes
.setText("Yes");
265 return jRadioButtonYes
;
269 * This method initializes jRadioButtonNo
271 * @return javax.swing.JRadioButton
273 private JRadioButton
getJRadioButtonNo() {
274 if (jRadioButtonNo
== null) {
275 jRadioButtonNo
= new JRadioButton();
276 jRadioButtonNo
.setBounds(new java
.awt
.Rectangle(300, 35, 110, 20));
277 jRadioButtonNo
.setSelected(true);
278 jRadioButtonNo
.setText("No");
280 return jRadioButtonNo
;
286 public static void main(String
[] args
) {
287 SelectModuleBelong smb
= new SelectModuleBelong();
288 smb
.setVisible(true);
292 * This is the default constructor
294 public SelectModuleBelong() {
300 * This is the default constructor
302 public SelectModuleBelong(IFrame parentFrame
, boolean modal
, int fileType
) {
303 super(parentFrame
, modal
);
304 this.mode
= fileType
;
306 initExistingPackage();
307 if (mode
!= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
308 this.jStarLabel1
.setVisible(false);
309 this.jLabelPackage
.setVisible(false);
310 this.jComboBoxExistingPackage
.setVisible(false);
311 this.jLabelIsLibrary
.setVisible(false);
312 this.jRadioButtonYes
.setVisible(false);
313 this.jRadioButtonNo
.setVisible(false);
314 upLocation(this.jStarLabel2
, 50);
315 upLocation(this.jStarLabel3
, 50);
316 upLocation(this.jStarLabel4
, 50);
317 upLocation(this.jStarLabel5
, 50);
318 upLocation(this.jLabelFilePath
, 50);
319 upLocation(this.jLabelName
, 50);
320 upLocation(this.jLabelGuid
, 50);
321 upLocation(this.jLabelVersion
, 50);
322 upLocation(this.jTextFieldFilePath
, 50);
323 upLocation(this.jTextFieldName
, 50);
324 upLocation(this.jTextFieldGuid
, 50);
325 upLocation(this.jTextFieldVersion
, 50);
326 upLocation(this.jButtonBrowse
, 50);
327 upLocation(this.jButtonGen
, 50);
332 * This method initializes this
336 private void init() {
337 this.setSize(500, 230);
338 this.setContentPane(getJContentPane());
339 this.setTitle("New");
344 * This method initializes jContentPane
346 * @return javax.swing.JPanel
348 private JPanel
getJContentPane() {
349 if (jContentPane
== null) {
350 jLabelIsLibrary
= new JLabel();
351 jLabelIsLibrary
.setBounds(new java
.awt
.Rectangle(15, 35, 120, 20));
352 jLabelIsLibrary
.setText("Is this a Library");
353 jLabelVersion
= new JLabel();
354 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 135, 120, 20));
355 jLabelVersion
.setText("Version");
356 jLabelGuid
= new JLabel();
357 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 110, 120, 20));
358 jLabelGuid
.setText("Guid");
359 jLabelName
= new JLabel();
360 jLabelName
.setBounds(new java
.awt
.Rectangle(15, 85, 120, 20));
361 jLabelName
.setText("Module Name");
362 jLabelFilePath
= new JLabel();
363 jLabelFilePath
.setBounds(new java
.awt
.Rectangle(15, 60, 120, 20));
364 jLabelFilePath
.setText("File Path");
365 jLabelPackage
= new JLabel();
366 jLabelPackage
.setBounds(new java
.awt
.Rectangle(15, 10, 120, 20));
367 jLabelPackage
.setText("Choose a Package");
368 jContentPane
= new JPanel();
369 jContentPane
.setLayout(null);
370 jContentPane
.setSize(new java
.awt
.Dimension(490, 198));
371 jContentPane
.add(getJComboBoxExistingPackage(), null);
372 jContentPane
.add(getJButtonOk(), null);
373 jContentPane
.add(getJButtonCancel(), null);
374 jContentPane
.add(jLabelPackage
, null);
375 jContentPane
.add(jLabelFilePath
, null);
376 jContentPane
.add(getJTextFieldFilePath(), null);
377 jContentPane
.add(getJButtonBrowse(), null);
378 jContentPane
.add(jLabelName
, null);
379 jContentPane
.add(getJTextFieldName(), null);
380 jContentPane
.add(jLabelGuid
, null);
381 jContentPane
.add(getJTextFieldGuid(), null);
382 jContentPane
.add(getJButtonGen(), null);
383 jContentPane
.add(jLabelVersion
, null);
384 jContentPane
.add(getJTextFieldVersion(), null);
386 jStarLabel1
= new StarLabel();
387 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
388 jStarLabel2
= new StarLabel();
389 jStarLabel2
.setLocation(new java
.awt
.Point(0, 60));
390 jStarLabel3
= new StarLabel();
391 jStarLabel3
.setLocation(new java
.awt
.Point(0, 85));
392 jStarLabel4
= new StarLabel();
393 jStarLabel4
.setLocation(new java
.awt
.Point(0, 110));
394 jStarLabel5
= new StarLabel();
395 jStarLabel5
.setLocation(new java
.awt
.Point(0, 135));
396 jContentPane
.add(jStarLabel1
, null);
397 jContentPane
.add(jStarLabel2
, null);
398 jContentPane
.add(jStarLabel3
, null);
399 jContentPane
.add(jStarLabel4
, null);
400 jContentPane
.add(jStarLabel5
, null);
401 jContentPane
.add(jLabelIsLibrary
, null);
402 jContentPane
.add(getJRadioButtonYes(), null);
403 jContentPane
.add(getJRadioButtonNo(), null);
404 bg
.add(getJRadioButtonNo());
405 bg
.add(getJRadioButtonYes());
411 Query all existing packages and fill them into combox
414 private void initExistingPackage() {
415 packages
= wt
.getAllPackages();
416 for (int index
= 0; index
< packages
.size(); index
++) {
417 this.jComboBoxExistingPackage
.addItem(packages
.elementAt(index
).getName());
422 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
424 * Override actionPerformed to listen all actions
426 public void actionPerformed(ActionEvent arg0
) {
427 if (arg0
.getSource() == jButtonCancel
) {
428 this.setVisible(false);
429 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
432 if (arg0
.getSource() == jButtonOk
) {
438 this.setVisible(false);
439 this.returnType
= DataType
.RETURN_TYPE_OK
;
442 if (arg0
.getSource() == this.jButtonGen
) {
443 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
446 if (arg0
.getSource() == this.jButtonBrowse
) {
447 JFileChooser fc
= new JFileChooser();
448 fc
.setAcceptAllFileFilterUsed(false);
450 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
451 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
453 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
455 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
456 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
457 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
459 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
460 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
461 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
463 int result
= fc
.showSaveDialog(new JPanel());
464 if (result
== JFileChooser
.APPROVE_OPTION
) {
465 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
471 Data validation for all fields
473 @retval true - All datas are valid
474 @retval false - At least one data is invalid
477 public boolean check() {
479 // Check if all required fields are not empty
481 if (isEmpty(this.jTextFieldFilePath
.getText())) {
482 Log
.wrn("New File", "A File Path must be entered!");
485 if (isEmpty(this.jTextFieldName
.getText())) {
486 Log
.wrn("New File", "A Name must be entered");
489 if (isEmpty(this.jTextFieldGuid
.getText())) {
490 Log
.wrn("New File", "The Guid must be entered!");
493 if (isEmpty(this.jTextFieldVersion
.getText())) {
494 Log
.wrn("New File", "A Version number must be entered!");
499 // Check if all fields have correct data types
501 if (!DataValidation
.isBaseName(this.jTextFieldName
.getText())) {
502 Log
.wrn("New File", "Incorrect data type for the Name!");
505 if (!DataValidation
.isGuid((this.jTextFieldGuid
).getText())) {
506 Log
.wrn("New File", "Incorrect data type for Guid, which must be in registry format! (8-4-4-4-12)");
510 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
512 // Check if the module is already existed in current package
514 String packagePath
= packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath();
515 String modulePath
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
516 Vector
<String
> msaFile
= wt
.getAllModulesOfPackage(packagePath
);
518 for (int index
= 0; index
< msaFile
.size(); index
++) {
519 if (msaFile
.elementAt(index
).equals(modulePath
)) {
520 Log
.wrn("New File", "This module is already exists in the selected package!");
526 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
528 // Check if the package is already existed in database
530 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
531 Vector
<PackageIdentification
> vPackageList
= wt
.getAllPackages();
532 if (vPackageList
!= null && vPackageList
.size() > 0) {
533 for (int index
= 0; index
< vPackageList
.size(); index
++) {
534 if (vPackageList
.get(index
).getPath().equals(path
)) {
535 Log
.wrn("New File", "This package is already exists in this workspace!");
542 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
544 // Check if the platform is already existed in database
546 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
547 Vector
<PlatformIdentification
> vPlatfromList
= wt
.getAllPlatforms();
548 if (vPlatfromList
!= null && vPlatfromList
.size() > 0) {
549 for (int index
= 0; index
< vPlatfromList
.size(); index
++) {
550 if (vPlatfromList
.get(index
).getPath().equals(path
)) {
551 Log
.wrn("New File", "This platform is already exists in this workspace!");
566 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
569 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
572 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
578 Save all components of Msa Header
581 private void saveModule() {
583 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
589 MsaHeaderDocument
.MsaHeader msaHeader
= null;
591 msa
= ModuleSurfaceArea
.Factory
.newInstance();
592 msaHeader
= MsaHeaderDocument
.MsaHeader
.Factory
.newInstance();
594 msaHeader
.setModuleName(this.jTextFieldName
.getText());
595 msaHeader
.setGuidValue(this.jTextFieldGuid
.getText());
596 msaHeader
.setVersion(this.jTextFieldVersion
.getText());
597 msaHeader
.setModuleType(ModuleTypeDef
.BASE
);
599 msa
.setMsaHeader(msaHeader
);
600 } catch (Exception e
) {
601 Log
.err("Save ModuleSurfaceArea Document", e
.getMessage());
609 SaveFile
.saveMsaFile(path
, msa
);
610 } catch (Exception e
) {
611 Log
.wrn("Save Module to file system", e
.getMessage());
612 Log
.err("Save Module to file system", e
.getMessage());
617 // Save to identification
619 mid
= new ModuleIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
620 this.jTextFieldVersion
.getText(), path
, jRadioButtonYes
.isSelected());
621 mid
.setPackageId(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()));
625 Save all components of Spd Header
628 private void savePackage() {
630 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
636 SpdHeaderDocument
.SpdHeader spdHeader
= null;
638 spd
= PackageSurfaceArea
.Factory
.newInstance();
639 spdHeader
= SpdHeaderDocument
.SpdHeader
.Factory
.newInstance();
641 spdHeader
.setPackageName(this.jTextFieldName
.getText());
642 spdHeader
.setGuidValue(this.jTextFieldGuid
.getText());
643 spdHeader
.setVersion(this.jTextFieldVersion
.getText());
645 spd
.setSpdHeader(spdHeader
);
646 } catch (Exception e
) {
647 Log
.wrn("Save Package Surface Area Description Document", e
.getMessage());
655 SaveFile
.saveSpdFile(path
, spd
);
657 } catch (Exception e
) {
658 Log
.wrn("Save Package to file system", e
.getMessage());
659 Log
.err("Save Package to file system", e
.getMessage());
664 // Save to identification
666 pid
= new PackageIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
667 this.jTextFieldVersion
.getText(), path
);
671 Save all components of Fpd Header
674 private void savePlatform() {
676 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
682 PlatformHeader fpdHeader
= null;
684 fpd
= PlatformSurfaceArea
.Factory
.newInstance();
685 fpdHeader
= PlatformHeader
.Factory
.newInstance();
687 fpdHeader
.setPlatformName(this.jTextFieldName
.getText());
688 fpdHeader
.setGuidValue(this.jTextFieldGuid
.getText());
689 fpdHeader
.setVersion(this.jTextFieldVersion
.getText());
691 fpd
.setPlatformHeader(fpdHeader
);
692 } catch (Exception e
) {
693 Log
.wrn("Save Framework Platform Description Document", e
.getMessage());
701 SaveFile
.saveFpdFile(path
, fpd
);
703 } catch (Exception e
) {
704 Log
.wrn("Save Platform to file system", e
.getMessage());
705 Log
.err("Save Platform to file system", e
.getMessage());
710 // Save to identification
712 fid
= new PlatformIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
713 this.jTextFieldVersion
.getText(), path
);
716 public ModuleIdentification
getMid() {
720 public PlatformIdentification
getFid() {
724 public PackageIdentification
getPid() {
728 private void upLocation(Component c
, int size
) {
729 c
.setLocation(c
.getLocation().x
, c
.getLocation().y
- size
);
732 public PlatformSurfaceArea
getFpd() {
736 public ModuleSurfaceArea
getMsa() {
740 public PackageSurfaceArea
getSpd() {