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
.event
.ActionEvent
;
20 import java
.util
.Vector
;
22 import javax
.swing
.JButton
;
23 import javax
.swing
.JComboBox
;
24 import javax
.swing
.JFileChooser
;
25 import javax
.swing
.JLabel
;
26 import javax
.swing
.JPanel
;
27 import javax
.swing
.JTextField
;
29 import org
.tianocore
.ModuleSurfaceAreaDocument
;
30 import org
.tianocore
.MsaHeaderDocument
;
31 import org
.tianocore
.SpdHeaderDocument
;
32 import org
.tianocore
.PackageSurfaceAreaDocument
.PackageSurfaceArea
;
33 import org
.tianocore
.PlatformHeaderDocument
.PlatformHeader
;
34 import org
.tianocore
.PlatformSurfaceAreaDocument
.PlatformSurfaceArea
;
35 import org
.tianocore
.frameworkwizard
.common
.DataType
;
36 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
37 import org
.tianocore
.frameworkwizard
.common
.IFileFilter
;
38 import org
.tianocore
.frameworkwizard
.common
.Log
;
39 import org
.tianocore
.frameworkwizard
.common
.SaveFile
;
40 import org
.tianocore
.frameworkwizard
.common
.Tools
;
41 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
42 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
43 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
44 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
45 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
46 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
47 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
48 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
50 public class SelectModuleBelong
extends IDialog
{
56 private static final long serialVersionUID
= 4171355136991448972L;
58 private JPanel jContentPane
= null;
60 private JComboBox jComboBoxExistingPackage
= null;
62 private JButton jButtonOk
= null;
64 private JButton jButtonCancel
= null;
66 private Vector
<PackageIdentification
> packages
= null;
68 private JLabel jLabelPackage
= null;
70 private JLabel jLabelFilePath
= null;
72 private JTextField jTextFieldFilePath
= null;
74 private JButton jButtonBrowse
= null;
76 private JLabel jLabelName
= null;
78 private JTextField jTextFieldName
= null;
80 private JLabel jLabelGuid
= null;
82 private JTextField jTextFieldGuid
= null;
84 private JButton jButtonGen
= null;
86 private JLabel jLabelVersion
= null;
88 private JTextField jTextFieldVersion
= null;
90 private StarLabel jStarLabel1
= null;
92 private StarLabel jStarLabel2
= null;
94 private StarLabel jStarLabel3
= null;
96 private StarLabel jStarLabel4
= null;
98 private StarLabel jStarLabel5
= null;
100 private WorkspaceTools wt
= new WorkspaceTools();
102 private ModuleIdentification mid
= null;
104 private PackageIdentification pid
= null;
106 private PlatformIdentification fid
= null;
108 private int mode
= -1;
111 * This method initializes jComboBoxExistingPackage
113 * @return javax.swing.JComboBox
115 private JComboBox
getJComboBoxExistingPackage() {
116 if (jComboBoxExistingPackage
== null) {
117 jComboBoxExistingPackage
= new JComboBox();
118 jComboBoxExistingPackage
.setBounds(new java
.awt
.Rectangle(140, 10, 340, 20));
120 return jComboBoxExistingPackage
;
124 * This method initializes jButtonNext
126 * @return javax.swing.JButton
128 private JButton
getJButtonOk() {
129 if (jButtonOk
== null) {
130 jButtonOk
= new JButton();
131 jButtonOk
.setBounds(new java
.awt
.Rectangle(310, 140, 80, 20));
132 jButtonOk
.setText("Ok");
133 jButtonOk
.addActionListener(this);
139 * This method initializes jButtonCancel
141 * @return javax.swing.JButton
143 private JButton
getJButtonCancel() {
144 if (jButtonCancel
== null) {
145 jButtonCancel
= new JButton();
146 jButtonCancel
.setBounds(new java
.awt
.Rectangle(395, 140, 80, 20));
147 jButtonCancel
.setText("Cancel");
148 jButtonCancel
.addActionListener(this);
150 return jButtonCancel
;
154 * This method initializes jTextFieldFilePath
156 * @return javax.swing.JTextField
158 private JTextField
getJTextFieldFilePath() {
159 if (jTextFieldFilePath
== null) {
160 jTextFieldFilePath
= new JTextField();
161 jTextFieldFilePath
.setBounds(new java
.awt
.Rectangle(140, 35, 250, 20));
163 return jTextFieldFilePath
;
167 * This method initializes jButtonBrowse
169 * @return javax.swing.JButton
171 private JButton
getJButtonBrowse() {
172 if (jButtonBrowse
== null) {
173 jButtonBrowse
= new JButton();
174 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(395, 35, 85, 20));
175 jButtonBrowse
.setText("Browse");
176 jButtonBrowse
.addActionListener(this);
178 return jButtonBrowse
;
182 * This method initializes jTextFieldModuleName
184 * @return javax.swing.JTextField
186 private JTextField
getJTextFieldName() {
187 if (jTextFieldName
== null) {
188 jTextFieldName
= new JTextField();
189 jTextFieldName
.setBounds(new java
.awt
.Rectangle(140, 60, 340, 20));
191 return jTextFieldName
;
195 * This method initializes jTextFieldGuid
197 * @return javax.swing.JTextField
199 private JTextField
getJTextFieldGuid() {
200 if (jTextFieldGuid
== null) {
201 jTextFieldGuid
= new JTextField();
202 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(140, 85, 250, 20));
204 return jTextFieldGuid
;
208 * This method initializes jButtonGen
210 * @return javax.swing.JButton
212 private JButton
getJButtonGen() {
213 if (jButtonGen
== null) {
214 jButtonGen
= new JButton();
215 jButtonGen
.setBounds(new java
.awt
.Rectangle(395, 85, 85, 20));
216 jButtonGen
.setText("GEN");
217 jButtonGen
.addActionListener(this);
223 * This method initializes jTextFieldVersion
225 * @return javax.swing.JTextField
227 private JTextField
getJTextFieldVersion() {
228 if (jTextFieldVersion
== null) {
229 jTextFieldVersion
= new JTextField();
230 jTextFieldVersion
.setBounds(new java
.awt
.Rectangle(140, 110, 340, 20));
232 return jTextFieldVersion
;
238 public static void main(String
[] args
) {
239 SelectModuleBelong smb
= new SelectModuleBelong();
240 smb
.setVisible(true);
244 * This is the default constructor
246 public SelectModuleBelong() {
252 * This is the default constructor
254 public SelectModuleBelong(IFrame parentFrame
, boolean modal
, int fileType
) {
255 super(parentFrame
, modal
);
256 this.mode
= fileType
;
258 initExistingPackage();
259 if (mode
!= DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
260 this.jStarLabel1
.setVisible(false);
261 this.jLabelPackage
.setVisible(false);
262 this.jComboBoxExistingPackage
.setVisible(false);
267 * This method initializes this
271 private void init() {
272 this.setSize(500, 200);
273 this.setContentPane(getJContentPane());
274 this.setTitle("New");
279 * This method initializes jContentPane
281 * @return javax.swing.JPanel
283 private JPanel
getJContentPane() {
284 if (jContentPane
== null) {
285 jLabelVersion
= new JLabel();
286 jLabelVersion
.setBounds(new java
.awt
.Rectangle(15, 110, 120, 20));
287 jLabelVersion
.setText("Version");
288 jLabelGuid
= new JLabel();
289 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 85, 120, 20));
290 jLabelGuid
.setText("Guid");
291 jLabelName
= new JLabel();
292 jLabelName
.setBounds(new java
.awt
.Rectangle(15, 60, 120, 20));
293 jLabelName
.setText("Name");
294 jLabelFilePath
= new JLabel();
295 jLabelFilePath
.setBounds(new java
.awt
.Rectangle(15, 35, 120, 20));
296 jLabelFilePath
.setText("File Path");
297 jLabelPackage
= new JLabel();
298 jLabelPackage
.setBounds(new java
.awt
.Rectangle(15, 10, 120, 20));
299 jLabelPackage
.setText("Choose Package");
300 jContentPane
= new JPanel();
301 jContentPane
.setLayout(null);
302 jContentPane
.setSize(new java
.awt
.Dimension(490, 175));
303 jContentPane
.add(getJComboBoxExistingPackage(), null);
304 jContentPane
.add(getJButtonOk(), null);
305 jContentPane
.add(getJButtonCancel(), null);
306 jContentPane
.add(jLabelPackage
, null);
307 jContentPane
.add(jLabelFilePath
, null);
308 jContentPane
.add(getJTextFieldFilePath(), null);
309 jContentPane
.add(getJButtonBrowse(), null);
310 jContentPane
.add(jLabelName
, null);
311 jContentPane
.add(getJTextFieldName(), null);
312 jContentPane
.add(jLabelGuid
, null);
313 jContentPane
.add(getJTextFieldGuid(), null);
314 jContentPane
.add(getJButtonGen(), null);
315 jContentPane
.add(jLabelVersion
, null);
316 jContentPane
.add(getJTextFieldVersion(), null);
318 jStarLabel1
= new StarLabel();
319 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
320 jStarLabel2
= new StarLabel();
321 jStarLabel2
.setLocation(new java
.awt
.Point(0, 35));
322 jStarLabel3
= new StarLabel();
323 jStarLabel3
.setLocation(new java
.awt
.Point(0, 60));
324 jStarLabel4
= new StarLabel();
325 jStarLabel4
.setLocation(new java
.awt
.Point(0, 85));
326 jStarLabel5
= new StarLabel();
327 jStarLabel5
.setLocation(new java
.awt
.Point(0, 110));
328 jContentPane
.add(jStarLabel1
, null);
329 jContentPane
.add(jStarLabel2
, null);
330 jContentPane
.add(jStarLabel3
, null);
331 jContentPane
.add(jStarLabel4
, null);
332 jContentPane
.add(jStarLabel5
, null);
338 Query all existing packages and fill them into combox
341 private void initExistingPackage() {
342 packages
= wt
.getAllPackages();
343 for (int index
= 0; index
< packages
.size(); index
++) {
344 this.jComboBoxExistingPackage
.addItem(packages
.elementAt(index
).getName());
349 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
351 * Override actionPerformed to listen all actions
353 public void actionPerformed(ActionEvent arg0
) {
354 if (arg0
.getSource() == jButtonCancel
) {
355 this.setVisible(false);
356 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
359 if (arg0
.getSource() == jButtonOk
) {
365 this.setVisible(false);
366 this.returnType
= DataType
.RETURN_TYPE_OK
;
369 if (arg0
.getSource() == this.jButtonGen
) {
370 this.jTextFieldGuid
.setText(Tools
.generateUuidString());
373 if (arg0
.getSource() == this.jButtonBrowse
) {
374 JFileChooser fc
= new JFileChooser();
375 fc
.setAcceptAllFileFilterUsed(false);
377 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
378 fc
.setCurrentDirectory(new File(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex())
380 fc
.addChoosableFileFilter(new IFileFilter(DataType
.MODULE_SURFACE_AREA_EXT
));
382 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
383 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
384 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PACKAGE_SURFACE_AREA_EXT
));
386 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
387 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
388 fc
.addChoosableFileFilter(new IFileFilter(DataType
.PLATFORM_SURFACE_AREA_EXT
));
390 int result
= fc
.showSaveDialog(new JPanel());
391 if (result
== JFileChooser
.APPROVE_OPTION
) {
392 this.jTextFieldFilePath
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(), mode
));
398 Data validation for all fields
400 @retval true - All datas are valid
401 @retval false - At least one data is invalid
404 public boolean check() {
406 // Check if all required fields are not empty
408 if (isEmpty(this.jTextFieldFilePath
.getText())) {
409 Log
.err("File Path couldn't be empty");
412 if (isEmpty(this.jTextFieldName
.getText())) {
413 Log
.err("Name couldn't be empty");
416 if (isEmpty(this.jTextFieldGuid
.getText())) {
417 Log
.err("Guid Value couldn't be empty");
420 if (isEmpty(this.jTextFieldVersion
.getText())) {
421 Log
.err("Version couldn't be empty");
426 // Check if all fields have correct data types
428 if (!DataValidation
.isBaseName(this.jTextFieldName
.getText())) {
429 Log
.err("Incorrect data type for Base Name");
432 if (!DataValidation
.isGuid((this.jTextFieldGuid
).getText())) {
433 Log
.err("Incorrect data type for Guid");
437 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
439 // Check if the module is already existed in current package
441 String packagePath
= packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()).getPath();
442 String modulePath
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
443 Vector
<String
> msaFile
= wt
.getAllModulesOfPackage(packagePath
);
445 for (int index
= 0; index
< msaFile
.size(); index
++) {
446 if (msaFile
.elementAt(index
).equals(modulePath
)) {
447 Log
.err("This module is already existing in selected package");
453 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
455 // Check if the package is already existed in database
457 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
458 Vector
<PackageIdentification
> vPackageList
= wt
.getAllPackages();
459 if (vPackageList
!= null && vPackageList
.size() > 0) {
460 for (int index
= 0; index
< vPackageList
.size(); index
++) {
461 if (vPackageList
.get(index
).getPath().equals(path
)) {
462 Log
.err("This package is already existing in database");
469 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
471 // Check if the platform is already existed in database
473 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
474 Vector
<PlatformIdentification
> vPlatfromList
= wt
.getAllPlatforms();
475 if (vPlatfromList
!= null && vPlatfromList
.size() > 0) {
476 for (int index
= 0; index
< vPlatfromList
.size(); index
++) {
477 if (vPlatfromList
.get(index
).getPath().equals(path
)) {
478 Log
.err("This platform is already existing in database");
493 if (mode
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
496 if (mode
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
499 if (mode
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
505 Save all components of Msa Header
508 private void saveModule() {
509 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= null;
510 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
516 MsaHeaderDocument
.MsaHeader msaHeader
= null;
518 msa
= ModuleSurfaceAreaDocument
.ModuleSurfaceArea
.Factory
.newInstance();
519 msaHeader
= MsaHeaderDocument
.MsaHeader
.Factory
.newInstance();
521 msaHeader
.setModuleName(this.jTextFieldName
.getText());
522 msaHeader
.setGuidValue(this.jTextFieldGuid
.getText());
523 msaHeader
.setVersion(this.jTextFieldVersion
.getText());
525 msa
.setMsaHeader(msaHeader
);
526 } catch (Exception e
) {
527 Log
.err("Save ModuleSurfaceArea Document", e
.getMessage());
535 SaveFile
.saveMsaFile(path
, msa
);
537 } catch (Exception e
) {
538 Log
.err("Save Module to file system", e
.getMessage());
543 // Save to identification
545 mid
= new ModuleIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
546 this.jTextFieldVersion
.getText(), path
);
547 mid
.setPackageId(packages
.elementAt(this.jComboBoxExistingPackage
.getSelectedIndex()));
551 Save all components of Spd Header
554 private void savePackage() {
555 PackageSurfaceArea spd
= null;
556 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
562 SpdHeaderDocument
.SpdHeader spdHeader
= null;
564 spd
= PackageSurfaceArea
.Factory
.newInstance();
565 spdHeader
= SpdHeaderDocument
.SpdHeader
.Factory
.newInstance();
567 spdHeader
.setPackageName(this.jTextFieldName
.getText());
568 spdHeader
.setGuidValue(this.jTextFieldGuid
.getText());
569 spdHeader
.setVersion(this.jTextFieldVersion
.getText());
571 spd
.setSpdHeader(spdHeader
);
572 } catch (Exception e
) {
573 Log
.err("Save PackageSurfaceArea Document", e
.getMessage());
581 SaveFile
.saveSpdFile(path
, spd
);
583 } catch (Exception e
) {
584 Log
.err("Save Package to file system", e
.getMessage());
589 // Save to identification
591 pid
= new PackageIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
592 this.jTextFieldVersion
.getText(), path
);
596 Save all components of Fpd Header
599 private void savePlatform() {
600 PlatformSurfaceArea fpd
= null;
601 String path
= Tools
.convertPathToCurrentOsType(this.jTextFieldFilePath
.getText());
607 PlatformHeader fpdHeader
= null;
609 fpd
= PlatformSurfaceArea
.Factory
.newInstance();
610 fpdHeader
= PlatformHeader
.Factory
.newInstance();
612 fpdHeader
.setPlatformName(this.jTextFieldName
.getText());
613 fpdHeader
.setGuidValue(this.jTextFieldGuid
.getText());
614 fpdHeader
.setVersion(this.jTextFieldVersion
.getText());
616 fpd
.setPlatformHeader(fpdHeader
);
617 } catch (Exception e
) {
618 Log
.err("Save FrameworkPlatformDescription Document", e
.getMessage());
626 SaveFile
.saveFpdFile(path
, fpd
);
628 } catch (Exception e
) {
629 Log
.err("Save Platform to file system", e
.getMessage());
634 // Save to identification
636 fid
= new PlatformIdentification(this.jTextFieldName
.getText(), this.jTextFieldGuid
.getText(),
637 this.jTextFieldVersion
.getText(), path
);
640 public ModuleIdentification
getMid() {
644 public void setMid(ModuleIdentification mid
) {
648 public PlatformIdentification
getFid() {
652 public void setFid(PlatformIdentification fid
) {
656 public PackageIdentification
getPid() {
660 public void setPid(PackageIdentification pid
) {