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
.ModuleSurfaceAreaDocument
;
32 import org
.tianocore
.MsaHeaderDocument
;
33 import org
.tianocore
.SpdHeaderDocument
;
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 int mode
= -1;
115 private JLabel jLabelIsLibrary
= null;
117 private JRadioButton jRadioButtonYes
= null;
119 private JRadioButton jRadioButtonNo
= null;
122 * This method initializes jComboBoxExistingPackage
124 * @return javax.swing.JComboBox
126 private JComboBox
getJComboBoxExistingPackage() {
127 if (jComboBoxExistingPackage
== null) {
128 jComboBoxExistingPackage
= new JComboBox();
129 jComboBoxExistingPackage
.setBounds(new java
.awt
.Rectangle(140, 10, 340, 20));
131 return jComboBoxExistingPackage
;
135 * This method initializes jButtonNext
137 * @return javax.swing.JButton
139 private JButton
getJButtonOk() {
140 if (jButtonOk
== null) {
141 jButtonOk
= new JButton();
142 jButtonOk
.setBounds(new java
.awt
.Rectangle(310, 165, 80, 20));
143 jButtonOk
.setText("Ok");
144 jButtonOk
.addActionListener(this);
150 * This method initializes jButtonCancel
152 * @return javax.swing.JButton
154 private JButton
getJButtonCancel() {
155 if (jButtonCancel
== null) {
156 jButtonCancel
= new JButton();
157 jButtonCancel
.setBounds(new java
.awt
.Rectangle(395, 165, 80, 20));
158 jButtonCancel
.setText("Cancel");
159 jButtonCancel
.addActionListener(this);
161 return jButtonCancel
;
165 * This method initializes jTextFieldFilePath
167 * @return javax.swing.JTextField
169 private JTextField
getJTextFieldFilePath() {
170 if (jTextFieldFilePath
== null) {
171 jTextFieldFilePath
= new JTextField();
172 jTextFieldFilePath
.setBounds(new java
.awt
.Rectangle(140, 60, 250, 20));
174 return jTextFieldFilePath
;
178 * This method initializes jButtonBrowse
180 * @return javax.swing.JButton
182 private JButton
getJButtonBrowse() {
183 if (jButtonBrowse
== null) {
184 jButtonBrowse
= new JButton();
185 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(395, 60, 85, 20));
186 jButtonBrowse
.setText("Browse");
187 jButtonBrowse
.addActionListener(this);
189 return jButtonBrowse
;
193 * This method initializes jTextFieldModuleName
195 * @return javax.swing.JTextField
197 private JTextField
getJTextFieldName() {
198 if (jTextFieldName
== null) {
199 jTextFieldName
= new JTextField();
200 jTextFieldName
.setBounds(new java
.awt
.Rectangle(140, 85, 340, 20));
202 return jTextFieldName
;
206 * This method initializes jTextFieldGuid
208 * @return javax.swing.JTextField
210 private JTextField
getJTextFieldGuid() {
211 if (jTextFieldGuid
== null) {
212 jTextFieldGuid
= new JTextField();
213 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(140, 110, 250, 20));
215 return jTextFieldGuid
;
219 * This method initializes jButtonGen
221 * @return javax.swing.JButton
223 private JButton
getJButtonGen() {
224 if (jButtonGen
== null) {
225 jButtonGen
= new JButton();
226 jButtonGen
.setBounds(new java
.awt
.Rectangle(395, 110, 85, 20));
227 jButtonGen
.setText("GEN");
228 jButtonGen
.addActionListener(this);
234 * This method initializes jTextFieldVersion
236 * @return javax.swing.JTextField
238 private JTextField
getJTextFieldVersion() {
239 if (jTextFieldVersion
== null) {
240 jTextFieldVersion
= new JTextField();
241 jTextFieldVersion
.setBounds(new java
.awt
.Rectangle(140, 135, 340, 20));
243 return jTextFieldVersion
;
247 * This method initializes jRadioButtonYes
249 * @return javax.swing.JRadioButton
251 private JRadioButton
getJRadioButtonYes() {
252 if (jRadioButtonYes
== null) {
253 jRadioButtonYes
= new JRadioButton();
254 jRadioButtonYes
.setBounds(new java
.awt
.Rectangle(140, 35, 100, 20));
255 jRadioButtonYes
.setSelected(false);
256 jRadioButtonYes
.setText("Yes");
258 return jRadioButtonYes
;
262 * This method initializes jRadioButtonNo
264 * @return javax.swing.JRadioButton
266 private JRadioButton
getJRadioButtonNo() {
267 if (jRadioButtonNo
== null) {
268 jRadioButtonNo
= new JRadioButton();
269 jRadioButtonNo
.setBounds(new java
.awt
.Rectangle(300, 35, 110, 20));
270 jRadioButtonNo
.setSelected(true);
271 jRadioButtonNo
.setText("No");
273 return jRadioButtonNo
;
279 public static void main(String
[] args
) {
280 SelectModuleBelong smb
= new SelectModuleBelong();
281 smb
.setVisible(true);
285 * This is the default constructor
287 public SelectModuleBelong() {
293 * This is the default constructor
295 public SelectModuleBelong(IFrame parentFrame
, boolean modal
, int fileType
) {
296 super(parentFrame
, modal
);
297 this.mode
= fileType
;
299 initExistingPackage();
300 if (mode
!= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
301 this.jStarLabel1
.setVisible(false);
302 this.jLabelPackage
.setVisible(false);
303 this.jComboBoxExistingPackage
.setVisible(false);
304 this.jLabelIsLibrary
.setVisible(false);
305 this.jRadioButtonYes
.setVisible(false);
306 this.jRadioButtonNo
.setVisible(false);
307 upLocation(this.jStarLabel2
, 50);
308 upLocation(this.jStarLabel3
, 50);
309 upLocation(this.jStarLabel4
, 50);
310 upLocation(this.jStarLabel5
, 50);
311 upLocation(this.jLabelFilePath
, 50);
312 upLocation(this.jLabelName
, 50);
313 upLocation(this.jLabelGuid
, 50);
314 upLocation(this.jLabelVersion
, 50);
315 upLocation(this.jTextFieldFilePath
, 50);
316 upLocation(this.jTextFieldName
, 50);
317 upLocation(this.jTextFieldGuid
, 50);
318 upLocation(this.jTextFieldVersion
, 50);
319 upLocation(this.jButtonBrowse
, 50);
320 upLocation(this.jButtonGen
, 50);
325 * This method initializes this
329 private void init() {
330 this.setSize(500, 230);
331 this.setContentPane(getJContentPane());
332 this.setTitle("New");
337 * This method initializes jContentPane
339 * @return javax.swing.JPanel
341 private JPanel
getJContentPane() {
342 if (jContentPane
== null) {
343 jLabelIsLibrary
= new JLabel();
344 jLabelIsLibrary
.setBounds(new java
.awt
.Rectangle(15, 35, 120, 20));
345 jLabelIsLibrary
.setText("Is a Library");
346 jLabelVersion
= new JLabel();
347 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 135, 120, 20));
348 jLabelVersion
.setText("Version");
349 jLabelGuid
= new JLabel();
350 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 110, 120, 20));
351 jLabelGuid
.setText("Guid");
352 jLabelName
= new JLabel();
353 jLabelName
.setBounds(new java
.awt
.Rectangle(15, 85, 120, 20));
354 jLabelName
.setText("Name");
355 jLabelFilePath
= new JLabel();
356 jLabelFilePath
.setBounds(new java
.awt
.Rectangle(15, 60, 120, 20));
357 jLabelFilePath
.setText("File Path");
358 jLabelPackage
= new JLabel();
359 jLabelPackage
.setBounds(new java
.awt
.Rectangle(15, 10, 120, 20));
360 jLabelPackage
.setText("Choose Package");
361 jContentPane
= new JPanel();
362 jContentPane
.setLayout(null);
363 jContentPane
.setSize(new java
.awt
.Dimension(490, 198));
364 jContentPane
.add(getJComboBoxExistingPackage(), null);
365 jContentPane
.add(getJButtonOk(), null);
366 jContentPane
.add(getJButtonCancel(), null);
367 jContentPane
.add(jLabelPackage
, null);
368 jContentPane
.add(jLabelFilePath
, null);
369 jContentPane
.add(getJTextFieldFilePath(), null);
370 jContentPane
.add(getJButtonBrowse(), null);
371 jContentPane
.add(jLabelName
, null);
372 jContentPane
.add(getJTextFieldName(), null);
373 jContentPane
.add(jLabelGuid
, null);
374 jContentPane
.add(getJTextFieldGuid(), null);
375 jContentPane
.add(getJButtonGen(), null);
376 jContentPane
.add(jLabelVersion
, null);
377 jContentPane
.add(getJTextFieldVersion(), null);
379 jStarLabel1
= new StarLabel();
380 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
381 jStarLabel2
= new StarLabel();
382 jStarLabel2
.setLocation(new java
.awt
.Point(0, 60));
383 jStarLabel3
= new StarLabel();
384 jStarLabel3
.setLocation(new java
.awt
.Point(0, 85));
385 jStarLabel4
= new StarLabel();
386 jStarLabel4
.setLocation(new java
.awt
.Point(0, 110));
387 jStarLabel5
= new StarLabel();
388 jStarLabel5
.setLocation(new java
.awt
.Point(0, 135));
389 jContentPane
.add(jStarLabel1
, null);
390 jContentPane
.add(jStarLabel2
, null);
391 jContentPane
.add(jStarLabel3
, null);
392 jContentPane
.add(jStarLabel4
, null);
393 jContentPane
.add(jStarLabel5
, null);
394 jContentPane
.add(jLabelIsLibrary
, null);
395 jContentPane
.add(getJRadioButtonYes(), null);
396 jContentPane
.add(getJRadioButtonNo(), null);
397 bg
.add(getJRadioButtonNo());
398 bg
.add(getJRadioButtonYes());
404 Query all existing packages and fill them into combox
407 private void initExistingPackage() {
408 packages
= wt
.getAllPackages();
409 for (int index
= 0; index
< packages
.size(); index
++) {
410 this.jComboBoxExistingPackage
.addItem(packages
.elementAt(index
).getName());
415 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
417 * Override actionPerformed to listen all actions
419 public void actionPerformed(ActionEvent arg0
) {
420 if (arg0
.getSource() == jButtonCancel
) {
421 this.setVisible(false);
422 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
425 if (arg0
.getSource() == jButtonOk
) {
431 this.setVisible(false);
432 this.returnType
= DataType
.RETURN_TYPE_OK
;
435 if (arg0
.getSource() == this.jButtonGen
) {
436 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
439 if (arg0
.getSource() == this.jButtonBrowse
) {
440 JFileChooser fc
= new JFileChooser();
441 fc
.setAcceptAllFileFilterUsed(false);
443 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
444 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
446 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
448 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
449 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
450 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
452 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
453 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
454 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
456 int result
= fc
.showSaveDialog(new JPanel());
457 if (result
== JFileChooser
.APPROVE_OPTION
) {
458 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
464 Data validation for all fields
466 @retval true - All datas are valid
467 @retval false - At least one data is invalid
470 public boolean check() {
472 // Check if all required fields are not empty
474 if (isEmpty(this.jTextFieldFilePath
.getText())) {
475 Log
.err("File Path couldn't be empty");
478 if (isEmpty(this.jTextFieldName
.getText())) {
479 Log
.err("Name couldn't be empty");
482 if (isEmpty(this.jTextFieldGuid
.getText())) {
483 Log
.err("Guid Value couldn't be empty");
486 if (isEmpty(this.jTextFieldVersion
.getText())) {
487 Log
.err("Version couldn't be empty");
492 // Check if all fields have correct data types
494 if (!DataValidation
.isBaseName(this.jTextFieldName
.getText())) {
495 Log
.err("Incorrect data type for Base Name");
498 if (!DataValidation
.isGuid((this.jTextFieldGuid
).getText())) {
499 Log
.err("Incorrect data type for Guid");
503 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
505 // Check if the module is already existed in current package
507 String packagePath
= packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath();
508 String modulePath
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
509 Vector
<String
> msaFile
= wt
.getAllModulesOfPackage(packagePath
);
511 for (int index
= 0; index
< msaFile
.size(); index
++) {
512 if (msaFile
.elementAt(index
).equals(modulePath
)) {
513 Log
.err("This module is already existing in selected package");
519 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
521 // Check if the package is already existed in database
523 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
524 Vector
<PackageIdentification
> vPackageList
= wt
.getAllPackages();
525 if (vPackageList
!= null && vPackageList
.size() > 0) {
526 for (int index
= 0; index
< vPackageList
.size(); index
++) {
527 if (vPackageList
.get(index
).getPath().equals(path
)) {
528 Log
.err("This package is already existing in database");
535 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
537 // Check if the platform is already existed in database
539 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
540 Vector
<PlatformIdentification
> vPlatfromList
= wt
.getAllPlatforms();
541 if (vPlatfromList
!= null && vPlatfromList
.size() > 0) {
542 for (int index
= 0; index
< vPlatfromList
.size(); index
++) {
543 if (vPlatfromList
.get(index
).getPath().equals(path
)) {
544 Log
.err("This platform is already existing in database");
559 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
562 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
565 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
571 Save all components of Msa Header
574 private void saveModule() {
575 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= null;
576 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
582 MsaHeaderDocument
.MsaHeader msaHeader
= null;
584 msa
= ModuleSurfaceAreaDocument
.ModuleSurfaceArea
.Factory
.newInstance();
585 msaHeader
= MsaHeaderDocument
.MsaHeader
.Factory
.newInstance();
587 msaHeader
.setModuleName(this.jTextFieldName
.getText());
588 msaHeader
.setGuidValue(this.jTextFieldGuid
.getText());
589 msaHeader
.setVersion(this.jTextFieldVersion
.getText());
591 msa
.setMsaHeader(msaHeader
);
592 } catch (Exception e
) {
593 Log
.err("Save ModuleSurfaceArea Document", e
.getMessage());
601 SaveFile
.saveMsaFile(path
, msa
);
603 } catch (Exception e
) {
604 Log
.err("Save Module to file system", e
.getMessage());
609 // Save to identification
611 mid
= new ModuleIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
612 this.jTextFieldVersion
.getText(), path
, jRadioButtonYes
.isSelected());
613 mid
.setPackageId(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()));
617 Save all components of Spd Header
620 private void savePackage() {
621 PackageSurfaceArea spd
= null;
622 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
628 SpdHeaderDocument
.SpdHeader spdHeader
= null;
630 spd
= PackageSurfaceArea
.Factory
.newInstance();
631 spdHeader
= SpdHeaderDocument
.SpdHeader
.Factory
.newInstance();
633 spdHeader
.setPackageName(this.jTextFieldName
.getText());
634 spdHeader
.setGuidValue(this.jTextFieldGuid
.getText());
635 spdHeader
.setVersion(this.jTextFieldVersion
.getText());
637 spd
.setSpdHeader(spdHeader
);
638 } catch (Exception e
) {
639 Log
.err("Save PackageSurfaceArea Document", e
.getMessage());
647 SaveFile
.saveSpdFile(path
, spd
);
649 } catch (Exception e
) {
650 Log
.err("Save Package to file system", e
.getMessage());
655 // Save to identification
657 pid
= new PackageIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
658 this.jTextFieldVersion
.getText(), path
);
662 Save all components of Fpd Header
665 private void savePlatform() {
666 PlatformSurfaceArea fpd
= null;
667 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
673 PlatformHeader fpdHeader
= null;
675 fpd
= PlatformSurfaceArea
.Factory
.newInstance();
676 fpdHeader
= PlatformHeader
.Factory
.newInstance();
678 fpdHeader
.setPlatformName(this.jTextFieldName
.getText());
679 fpdHeader
.setGuidValue(this.jTextFieldGuid
.getText());
680 fpdHeader
.setVersion(this.jTextFieldVersion
.getText());
682 fpd
.setPlatformHeader(fpdHeader
);
683 } catch (Exception e
) {
684 Log
.err("Save FrameworkPlatformDescription Document", e
.getMessage());
692 SaveFile
.saveFpdFile(path
, fpd
);
694 } catch (Exception e
) {
695 Log
.err("Save Platform to file system", e
.getMessage());
700 // Save to identification
702 fid
= new PlatformIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
703 this.jTextFieldVersion
.getText(), path
);
706 public ModuleIdentification
getMid() {
710 public void setMid(ModuleIdentification mid
) {
714 public PlatformIdentification
getFid() {
718 public void setFid(PlatformIdentification fid
) {
722 public PackageIdentification
getPid() {
726 public void setPid(PackageIdentification pid
) {
730 private void upLocation(Component c
, int size
) {
731 c
.setLocation(c
.getLocation().x
, c
.getLocation().y
- size
);