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
.MsaHeaderDocument
;
32 import org
.tianocore
.SpdHeaderDocument
;
33 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
34 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
35 import org
.tianocore
.PlatformHeaderDocument
.PlatformHeader
;
36 import org
.tianocore
.PlatformSurfaceAreaDocument
.PlatformSurfaceArea
;
37 import org
.tianocore
.frameworkwizard
.common
.DataType
;
38 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
39 import org
.tianocore
.frameworkwizard
.common
.IFileFilter
;
40 import org
.tianocore
.frameworkwizard
.common
.Log
;
41 import org
.tianocore
.frameworkwizard
.common
.SaveFile
;
42 import org
.tianocore
.frameworkwizard
.common
.Tools
;
43 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
44 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
45 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
46 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
47 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
48 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
49 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
50 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
51 import javax
.swing
.JRadioButton
;
53 public class SelectModuleBelong
extends IDialog
{
59 private static final long serialVersionUID
= 4171355136991448972L;
61 private JPanel jContentPane
= null;
63 private JComboBox jComboBoxExistingPackage
= null;
65 private JButton jButtonOk
= null;
67 private JButton jButtonCancel
= null;
69 private Vector
<PackageIdentification
> packages
= null;
71 private JLabel jLabelPackage
= null;
73 private JLabel jLabelFilePath
= null;
75 private JTextField jTextFieldFilePath
= null;
77 private JButton jButtonBrowse
= null;
79 private JLabel jLabelName
= null;
81 private JTextField jTextFieldName
= null;
83 private JLabel jLabelGuid
= null;
85 private JTextField jTextFieldGuid
= null;
87 private JButton jButtonGen
= null;
89 private JLabel jLabelVersion
= null;
91 private JTextField jTextFieldVersion
= null;
93 private StarLabel jStarLabel1
= null;
95 private StarLabel jStarLabel2
= null;
97 private StarLabel jStarLabel3
= null;
99 private StarLabel jStarLabel4
= null;
101 private StarLabel jStarLabel5
= null;
103 private ButtonGroup bg
= new ButtonGroup();
105 private WorkspaceTools wt
= new WorkspaceTools();
107 private ModuleIdentification mid
= null;
109 private PackageIdentification pid
= null;
111 private PlatformIdentification fid
= null;
113 private ModuleSurfaceArea msa
= null;
115 private PackageSurfaceArea spd
= null;
117 private PlatformSurfaceArea fpd
= null;
119 private int mode
= -1;
121 private JLabel jLabelIsLibrary
= null;
123 private JRadioButton jRadioButtonYes
= null;
125 private JRadioButton jRadioButtonNo
= null;
128 * This method initializes jComboBoxExistingPackage
130 * @return javax.swing.JComboBox
132 private JComboBox
getJComboBoxExistingPackage() {
133 if (jComboBoxExistingPackage
== null) {
134 jComboBoxExistingPackage
= new JComboBox();
135 jComboBoxExistingPackage
.setBounds(new java
.awt
.Rectangle(140, 10, 340, 20));
137 return jComboBoxExistingPackage
;
141 * This method initializes jButtonNext
143 * @return javax.swing.JButton
145 private JButton
getJButtonOk() {
146 if (jButtonOk
== null) {
147 jButtonOk
= new JButton();
148 jButtonOk
.setBounds(new java
.awt
.Rectangle(310, 165, 80, 20));
149 jButtonOk
.setText("Ok");
150 jButtonOk
.addActionListener(this);
156 * This method initializes jButtonCancel
158 * @return javax.swing.JButton
160 private JButton
getJButtonCancel() {
161 if (jButtonCancel
== null) {
162 jButtonCancel
= new JButton();
163 jButtonCancel
.setBounds(new java
.awt
.Rectangle(395, 165, 80, 20));
164 jButtonCancel
.setText("Cancel");
165 jButtonCancel
.addActionListener(this);
167 return jButtonCancel
;
171 * This method initializes jTextFieldFilePath
173 * @return javax.swing.JTextField
175 private JTextField
getJTextFieldFilePath() {
176 if (jTextFieldFilePath
== null) {
177 jTextFieldFilePath
= new JTextField();
178 jTextFieldFilePath
.setBounds(new java
.awt
.Rectangle(140, 60, 250, 20));
180 return jTextFieldFilePath
;
184 * This method initializes jButtonBrowse
186 * @return javax.swing.JButton
188 private JButton
getJButtonBrowse() {
189 if (jButtonBrowse
== null) {
190 jButtonBrowse
= new JButton();
191 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(395, 60, 85, 20));
192 jButtonBrowse
.setText("Browse");
193 jButtonBrowse
.addActionListener(this);
195 return jButtonBrowse
;
199 * This method initializes jTextFieldModuleName
201 * @return javax.swing.JTextField
203 private JTextField
getJTextFieldName() {
204 if (jTextFieldName
== null) {
205 jTextFieldName
= new JTextField();
206 jTextFieldName
.setBounds(new java
.awt
.Rectangle(140, 85, 340, 20));
208 return jTextFieldName
;
212 * This method initializes jTextFieldGuid
214 * @return javax.swing.JTextField
216 private JTextField
getJTextFieldGuid() {
217 if (jTextFieldGuid
== null) {
218 jTextFieldGuid
= new JTextField();
219 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(140, 110, 250, 20));
221 return jTextFieldGuid
;
225 * This method initializes jButtonGen
227 * @return javax.swing.JButton
229 private JButton
getJButtonGen() {
230 if (jButtonGen
== null) {
231 jButtonGen
= new JButton();
232 jButtonGen
.setBounds(new java
.awt
.Rectangle(395, 110, 85, 20));
233 jButtonGen
.setText("GEN");
234 jButtonGen
.addActionListener(this);
240 * This method initializes jTextFieldVersion
242 * @return javax.swing.JTextField
244 private JTextField
getJTextFieldVersion() {
245 if (jTextFieldVersion
== null) {
246 jTextFieldVersion
= new JTextField();
247 jTextFieldVersion
.setBounds(new java
.awt
.Rectangle(140, 135, 340, 20));
249 return jTextFieldVersion
;
253 * This method initializes jRadioButtonYes
255 * @return javax.swing.JRadioButton
257 private JRadioButton
getJRadioButtonYes() {
258 if (jRadioButtonYes
== null) {
259 jRadioButtonYes
= new JRadioButton();
260 jRadioButtonYes
.setBounds(new java
.awt
.Rectangle(140, 35, 100, 20));
261 jRadioButtonYes
.setSelected(false);
262 jRadioButtonYes
.setText("Yes");
264 return jRadioButtonYes
;
268 * This method initializes jRadioButtonNo
270 * @return javax.swing.JRadioButton
272 private JRadioButton
getJRadioButtonNo() {
273 if (jRadioButtonNo
== null) {
274 jRadioButtonNo
= new JRadioButton();
275 jRadioButtonNo
.setBounds(new java
.awt
.Rectangle(300, 35, 110, 20));
276 jRadioButtonNo
.setSelected(true);
277 jRadioButtonNo
.setText("No");
279 return jRadioButtonNo
;
285 public static void main(String
[] args
) {
286 SelectModuleBelong smb
= new SelectModuleBelong();
287 smb
.setVisible(true);
291 * This is the default constructor
293 public SelectModuleBelong() {
299 * This is the default constructor
301 public SelectModuleBelong(IFrame parentFrame
, boolean modal
, int fileType
) {
302 super(parentFrame
, modal
);
303 this.mode
= fileType
;
305 initExistingPackage();
306 if (mode
!= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
307 this.jStarLabel1
.setVisible(false);
308 this.jLabelPackage
.setVisible(false);
309 this.jComboBoxExistingPackage
.setVisible(false);
310 this.jLabelIsLibrary
.setVisible(false);
311 this.jRadioButtonYes
.setVisible(false);
312 this.jRadioButtonNo
.setVisible(false);
313 upLocation(this.jStarLabel2
, 50);
314 upLocation(this.jStarLabel3
, 50);
315 upLocation(this.jStarLabel4
, 50);
316 upLocation(this.jStarLabel5
, 50);
317 upLocation(this.jLabelFilePath
, 50);
318 upLocation(this.jLabelName
, 50);
319 upLocation(this.jLabelGuid
, 50);
320 upLocation(this.jLabelVersion
, 50);
321 upLocation(this.jTextFieldFilePath
, 50);
322 upLocation(this.jTextFieldName
, 50);
323 upLocation(this.jTextFieldGuid
, 50);
324 upLocation(this.jTextFieldVersion
, 50);
325 upLocation(this.jButtonBrowse
, 50);
326 upLocation(this.jButtonGen
, 50);
331 * This method initializes this
335 private void init() {
336 this.setSize(500, 230);
337 this.setContentPane(getJContentPane());
338 this.setTitle("New");
343 * This method initializes jContentPane
345 * @return javax.swing.JPanel
347 private JPanel
getJContentPane() {
348 if (jContentPane
== null) {
349 jLabelIsLibrary
= new JLabel();
350 jLabelIsLibrary
.setBounds(new java
.awt
.Rectangle(15, 35, 120, 20));
351 jLabelIsLibrary
.setText("Is a Library");
352 jLabelVersion
= new JLabel();
353 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 135, 120, 20));
354 jLabelVersion
.setText("Version");
355 jLabelGuid
= new JLabel();
356 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 110, 120, 20));
357 jLabelGuid
.setText("Guid");
358 jLabelName
= new JLabel();
359 jLabelName
.setBounds(new java
.awt
.Rectangle(15, 85, 120, 20));
360 jLabelName
.setText("Name");
361 jLabelFilePath
= new JLabel();
362 jLabelFilePath
.setBounds(new java
.awt
.Rectangle(15, 60, 120, 20));
363 jLabelFilePath
.setText("File Path");
364 jLabelPackage
= new JLabel();
365 jLabelPackage
.setBounds(new java
.awt
.Rectangle(15, 10, 120, 20));
366 jLabelPackage
.setText("Choose Package");
367 jContentPane
= new JPanel();
368 jContentPane
.setLayout(null);
369 jContentPane
.setSize(new java
.awt
.Dimension(490, 198));
370 jContentPane
.add(getJComboBoxExistingPackage(), null);
371 jContentPane
.add(getJButtonOk(), null);
372 jContentPane
.add(getJButtonCancel(), null);
373 jContentPane
.add(jLabelPackage
, null);
374 jContentPane
.add(jLabelFilePath
, null);
375 jContentPane
.add(getJTextFieldFilePath(), null);
376 jContentPane
.add(getJButtonBrowse(), null);
377 jContentPane
.add(jLabelName
, null);
378 jContentPane
.add(getJTextFieldName(), null);
379 jContentPane
.add(jLabelGuid
, null);
380 jContentPane
.add(getJTextFieldGuid(), null);
381 jContentPane
.add(getJButtonGen(), null);
382 jContentPane
.add(jLabelVersion
, null);
383 jContentPane
.add(getJTextFieldVersion(), null);
385 jStarLabel1
= new StarLabel();
386 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
387 jStarLabel2
= new StarLabel();
388 jStarLabel2
.setLocation(new java
.awt
.Point(0, 60));
389 jStarLabel3
= new StarLabel();
390 jStarLabel3
.setLocation(new java
.awt
.Point(0, 85));
391 jStarLabel4
= new StarLabel();
392 jStarLabel4
.setLocation(new java
.awt
.Point(0, 110));
393 jStarLabel5
= new StarLabel();
394 jStarLabel5
.setLocation(new java
.awt
.Point(0, 135));
395 jContentPane
.add(jStarLabel1
, null);
396 jContentPane
.add(jStarLabel2
, null);
397 jContentPane
.add(jStarLabel3
, null);
398 jContentPane
.add(jStarLabel4
, null);
399 jContentPane
.add(jStarLabel5
, null);
400 jContentPane
.add(jLabelIsLibrary
, null);
401 jContentPane
.add(getJRadioButtonYes(), null);
402 jContentPane
.add(getJRadioButtonNo(), null);
403 bg
.add(getJRadioButtonNo());
404 bg
.add(getJRadioButtonYes());
410 Query all existing packages and fill them into combox
413 private void initExistingPackage() {
414 packages
= wt
.getAllPackages();
415 for (int index
= 0; index
< packages
.size(); index
++) {
416 this.jComboBoxExistingPackage
.addItem(packages
.elementAt(index
).getName());
421 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
423 * Override actionPerformed to listen all actions
425 public void actionPerformed(ActionEvent arg0
) {
426 if (arg0
.getSource() == jButtonCancel
) {
427 this.setVisible(false);
428 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
431 if (arg0
.getSource() == jButtonOk
) {
437 this.setVisible(false);
438 this.returnType
= DataType
.RETURN_TYPE_OK
;
441 if (arg0
.getSource() == this.jButtonGen
) {
442 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
445 if (arg0
.getSource() == this.jButtonBrowse
) {
446 JFileChooser fc
= new JFileChooser();
447 fc
.setAcceptAllFileFilterUsed(false);
449 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
450 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
452 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
454 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
455 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
456 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
458 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
459 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
460 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
462 int result
= fc
.showSaveDialog(new JPanel());
463 if (result
== JFileChooser
.APPROVE_OPTION
) {
464 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
470 Data validation for all fields
472 @retval true - All datas are valid
473 @retval false - At least one data is invalid
476 public boolean check() {
478 // Check if all required fields are not empty
480 if (isEmpty(this.jTextFieldFilePath
.getText())) {
481 Log
.wrn("New File", "File Path couldn't be empty");
484 if (isEmpty(this.jTextFieldName
.getText())) {
485 Log
.wrn("New File", "Name couldn't be empty");
488 if (isEmpty(this.jTextFieldGuid
.getText())) {
489 Log
.wrn("New File", "Guid Value couldn't be empty");
492 if (isEmpty(this.jTextFieldVersion
.getText())) {
493 Log
.wrn("New File", "Version couldn't be empty");
498 // Check if all fields have correct data types
500 if (!DataValidation
.isBaseName(this.jTextFieldName
.getText())) {
501 Log
.wrn("New File", "Incorrect data type for Base Name");
504 if (!DataValidation
.isGuid((this.jTextFieldGuid
).getText())) {
505 Log
.wrn("New File", "Incorrect data type for Guid");
509 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
511 // Check if the module is already existed in current package
513 String packagePath
= packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath();
514 String modulePath
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
515 Vector
<String
> msaFile
= wt
.getAllModulesOfPackage(packagePath
);
517 for (int index
= 0; index
< msaFile
.size(); index
++) {
518 if (msaFile
.elementAt(index
).equals(modulePath
)) {
519 Log
.wrn("New File", "This module is already existing in selected package");
525 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
527 // Check if the package is already existed in database
529 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
530 Vector
<PackageIdentification
> vPackageList
= wt
.getAllPackages();
531 if (vPackageList
!= null && vPackageList
.size() > 0) {
532 for (int index
= 0; index
< vPackageList
.size(); index
++) {
533 if (vPackageList
.get(index
).getPath().equals(path
)) {
534 Log
.wrn("New File", "This package is already existing in database");
541 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
543 // Check if the platform is already existed in database
545 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
546 Vector
<PlatformIdentification
> vPlatfromList
= wt
.getAllPlatforms();
547 if (vPlatfromList
!= null && vPlatfromList
.size() > 0) {
548 for (int index
= 0; index
< vPlatfromList
.size(); index
++) {
549 if (vPlatfromList
.get(index
).getPath().equals(path
)) {
550 Log
.wrn("New File", "This platform is already existing in database");
565 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
568 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
571 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
577 Save all components of Msa Header
580 private void saveModule() {
582 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
588 MsaHeaderDocument
.MsaHeader msaHeader
= null;
590 msa
= ModuleSurfaceArea
.Factory
.newInstance();
591 msaHeader
= MsaHeaderDocument
.MsaHeader
.Factory
.newInstance();
593 msaHeader
.setModuleName(this.jTextFieldName
.getText());
594 msaHeader
.setGuidValue(this.jTextFieldGuid
.getText());
595 msaHeader
.setVersion(this.jTextFieldVersion
.getText());
597 msa
.setMsaHeader(msaHeader
);
598 } catch (Exception e
) {
599 Log
.err("Save ModuleSurfaceArea Document", e
.getMessage());
607 SaveFile
.saveMsaFile(path
, msa
);
608 } catch (Exception e
) {
609 Log
.wrn("Save Module to file system", e
.getMessage());
610 Log
.err("Save Module to file system", e
.getMessage());
615 // Save to identification
617 mid
= new ModuleIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
618 this.jTextFieldVersion
.getText(), path
, jRadioButtonYes
.isSelected());
619 mid
.setPackageId(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()));
623 Save all components of Spd Header
626 private void savePackage() {
628 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
634 SpdHeaderDocument
.SpdHeader spdHeader
= null;
636 spd
= PackageSurfaceArea
.Factory
.newInstance();
637 spdHeader
= SpdHeaderDocument
.SpdHeader
.Factory
.newInstance();
639 spdHeader
.setPackageName(this.jTextFieldName
.getText());
640 spdHeader
.setGuidValue(this.jTextFieldGuid
.getText());
641 spdHeader
.setVersion(this.jTextFieldVersion
.getText());
643 spd
.setSpdHeader(spdHeader
);
644 } catch (Exception e
) {
645 Log
.wrn("Save PackageSurfaceArea Document", e
.getMessage());
653 SaveFile
.saveSpdFile(path
, spd
);
655 } catch (Exception e
) {
656 Log
.wrn("Save Package to file system", e
.getMessage());
657 Log
.err("Save Package to file system", e
.getMessage());
662 // Save to identification
664 pid
= new PackageIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
665 this.jTextFieldVersion
.getText(), path
);
669 Save all components of Fpd Header
672 private void savePlatform() {
674 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
680 PlatformHeader fpdHeader
= null;
682 fpd
= PlatformSurfaceArea
.Factory
.newInstance();
683 fpdHeader
= PlatformHeader
.Factory
.newInstance();
685 fpdHeader
.setPlatformName(this.jTextFieldName
.getText());
686 fpdHeader
.setGuidValue(this.jTextFieldGuid
.getText());
687 fpdHeader
.setVersion(this.jTextFieldVersion
.getText());
689 fpd
.setPlatformHeader(fpdHeader
);
690 } catch (Exception e
) {
691 Log
.wrn("Save FrameworkPlatformDescription Document", e
.getMessage());
699 SaveFile
.saveFpdFile(path
, fpd
);
701 } catch (Exception e
) {
702 Log
.wrn("Save Platform to file system", e
.getMessage());
703 Log
.err("Save Platform to file system", e
.getMessage());
708 // Save to identification
710 fid
= new PlatformIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
711 this.jTextFieldVersion
.getText(), path
);
714 public ModuleIdentification
getMid() {
718 public PlatformIdentification
getFid() {
722 public PackageIdentification
getPid() {
726 private void upLocation(Component c
, int size
) {
727 c
.setLocation(c
.getLocation().x
, c
.getLocation().y
- size
);
730 public PlatformSurfaceArea
getFpd() {
734 public ModuleSurfaceArea
getMsa() {
738 public PackageSurfaceArea
getSpd() {