]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleDefinitions.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / ModuleDefinitions.java
1 /** @file
2
3 The file is used to create, update Module Definitions of MSA 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.frameworkwizard.module.ui;
16
17 import java.awt.event.ComponentEvent;
18 import java.awt.event.FocusEvent;
19
20 import javax.swing.JPanel;
21 import javax.swing.JScrollPane;
22 import javax.swing.JLabel;
23 import javax.swing.JTextField;
24 import javax.swing.JComboBox;
25
26 import org.tianocore.ModuleDefinitionsDocument;
27 import org.tianocore.ModuleSurfaceAreaDocument;
28 import org.tianocore.ModuleDefinitionsDocument.ModuleDefinitions.ClonedFrom;
29 import org.tianocore.frameworkwizard.common.DataValidation;
30 import org.tianocore.frameworkwizard.common.EnumerationData;
31 import org.tianocore.frameworkwizard.common.Log;
32 import org.tianocore.frameworkwizard.common.OpeningModuleType;
33 import org.tianocore.frameworkwizard.common.Tools;
34 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
35 import org.tianocore.frameworkwizard.common.ui.StarLabel;
36 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;
37
38 public class ModuleDefinitions extends IInternalFrame {
39
40 ///
41 /// Define class Serial Version UID
42 ///
43 private static final long serialVersionUID = 5860378543553036323L;
44
45 private JScrollPane jScrollPane = null;
46
47 private JPanel jContentPane = null;
48
49 private JLabel jLabelArch = null;
50
51 private ICheckBoxList iCheckBoxListArch = null;
52
53 private JLabel jLabelBinaryModule = null;
54
55 private JComboBox jComboBoxBinaryModule = null;
56
57 private JLabel jLabelOutputFileBasename = null;
58
59 private JTextField jTextFieldOutputFileBasename = null;
60
61 private JScrollPane jScrollPaneArch = null;
62
63 private StarLabel jStarLabel1 = null;
64
65 private StarLabel jStarLabel2 = null;
66
67 private StarLabel jStarLabel3 = null;
68
69 private OpeningModuleType omt = null;
70
71 private ClonedFrom cf = null;
72
73 private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;
74
75 private ModuleDefinitionsDocument.ModuleDefinitions md = null;
76
77 /**
78 * This method initializes jScrollPane
79 *
80 * @return javax.swing.JScrollPane
81 */
82 private JScrollPane getJScrollPane() {
83 if (jScrollPane == null) {
84 jScrollPane = new JScrollPane();
85 jScrollPane.setViewportView(getJContentPane());
86 }
87 return jScrollPane;
88 }
89
90 /**
91 * This method initializes jPanel
92 *
93 * @return javax.swing.JPanel
94 */
95 private JPanel getJContentPane() {
96 if (jContentPane == null) {
97 jLabelOutputFileBasename = new JLabel();
98 jLabelOutputFileBasename.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
99 jLabelOutputFileBasename.setText("Output File Basename");
100 jLabelBinaryModule = new JLabel();
101 jLabelBinaryModule.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
102 jLabelBinaryModule.setText("Binary Module");
103 jLabelArch = new JLabel();
104 jLabelArch.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
105 jLabelArch.setText("Supported Architectures");
106 jStarLabel1 = new StarLabel();
107 jStarLabel1.setLocation(new java.awt.Point(0, 10));
108 jStarLabel2 = new StarLabel();
109 jStarLabel2.setLocation(new java.awt.Point(0, 35));
110 jStarLabel3 = new StarLabel();
111 jStarLabel3.setLocation(new java.awt.Point(0, 60));
112
113 jContentPane = new JPanel();
114 jContentPane.setLayout(null);
115 jContentPane.setPreferredSize(new java.awt.Dimension(490, 150));
116
117 jContentPane.add(jLabelArch, null);
118 jContentPane.add(getJScrollPaneArch(), null);
119 jContentPane.add(jLabelBinaryModule, null);
120 jContentPane.add(getJComboBoxBinaryModule(), null);
121 jContentPane.add(jLabelOutputFileBasename, null);
122 jContentPane.add(getJTextFieldOutputFileBasename(), null);
123 jContentPane.add(jStarLabel1, null);
124 jContentPane.add(jStarLabel2, null);
125 jContentPane.add(jStarLabel3, null);
126 }
127 return jContentPane;
128 }
129
130 /**
131 This method initializes iCheckBoxListArch
132
133 @return ICheckBoxList
134 **/
135 private ICheckBoxList getICheckBoxListSupportedArchitectures() {
136 if (iCheckBoxListArch == null) {
137 iCheckBoxListArch = new ICheckBoxList();
138 iCheckBoxListArch.addFocusListener(this);
139 }
140 return iCheckBoxListArch;
141 }
142
143 /**
144 * This method initializes jComboBoxBinaryModule
145 *
146 * @return javax.swing.JComboBox
147 */
148 private JComboBox getJComboBoxBinaryModule() {
149 if (jComboBoxBinaryModule == null) {
150 jComboBoxBinaryModule = new JComboBox();
151 jComboBoxBinaryModule.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
152 jComboBoxBinaryModule.setPreferredSize(new java.awt.Dimension(320, 20));
153 jComboBoxBinaryModule.addFocusListener(this);
154 jComboBoxBinaryModule.setToolTipText("Modules are either source modules which can be compiled or binary modules which are linked. A module cannot contain both. The GUID numbers should be identical for a binary and source MSA, but the BINARY MSA should have a higher version number.");
155 }
156 return jComboBoxBinaryModule;
157 }
158
159 /**
160 * This method initializes jTextFieldOutputFileBasename
161 *
162 * @return javax.swing.JTextField
163 */
164 private JTextField getJTextFieldOutputFileBasename() {
165 if (jTextFieldOutputFileBasename == null) {
166 jTextFieldOutputFileBasename = new JTextField();
167 jTextFieldOutputFileBasename.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
168 jTextFieldOutputFileBasename.setPreferredSize(new java.awt.Dimension(320, 20));
169 jTextFieldOutputFileBasename.addFocusListener(this);
170 jTextFieldOutputFileBasename.setToolTipText("Enter a single word for generated output file names");
171 }
172 return jTextFieldOutputFileBasename;
173 }
174
175 /**
176 This method initializes jScrollPaneArch
177
178 @return javax.swing.JScrollPane
179
180 **/
181 private JScrollPane getJScrollPaneArch() {
182 if (jScrollPaneArch == null) {
183 jScrollPaneArch = new JScrollPane();
184 jScrollPaneArch.setBounds(new java.awt.Rectangle(160, 60, 320, 80));
185 jScrollPaneArch.setPreferredSize(new java.awt.Dimension(320, 60));
186 jScrollPaneArch.setViewportView(getICheckBoxListSupportedArchitectures());
187 }
188 return jScrollPaneArch;
189 }
190
191 /**
192
193 @param args
194
195 **/
196 public static void main(String[] args) {
197 // TODO Auto-generated method stub
198
199 }
200
201 /**
202 * This is the default constructor
203 */
204 public ModuleDefinitions() {
205 super();
206 init();
207 this.setVisible(true);
208 }
209
210 /**
211 This is the override edit constructor
212
213 @param inMsa
214
215 **/
216 public ModuleDefinitions(OpeningModuleType inOmt) {
217 super();
218 this.omt = inOmt;
219 this.msa = omt.getXmlMsa();
220 if (msa.getModuleDefinitions() != null) {
221 this.cf = msa.getModuleDefinitions().getClonedFrom();
222 }
223 init(msa.getModuleDefinitions());
224 this.setVisible(true);
225 }
226
227 /**
228 * This method initializes this
229 *
230 * @return void
231 */
232 private void init() {
233 this.setContentPane(getJScrollPane());
234 this.setTitle("Module Definitions");
235 initFrame();
236 this.setPreferredSize(new java.awt.Dimension(490, 520));
237 }
238
239 /**
240 This method initializes this
241 Fill values to all fields if these values are not empty
242
243 @param inMsaHeader The input data of MsaHeaderDocument.MsaHeader
244
245 **/
246 private void init(ModuleDefinitionsDocument.ModuleDefinitions inMd) {
247 init();
248 if (inMd != null) {
249 this.md = inMd;
250 if (md.getSupportedArchitectures() != null) {
251 this.iCheckBoxListArch.initCheckedItem(true, Tools.convertListToVector(md.getSupportedArchitectures()));
252 }
253 if (md.getBinaryModule()) {
254 this.jComboBoxBinaryModule.setSelectedIndex(1);
255 } else {
256 this.jComboBoxBinaryModule.setSelectedIndex(0);
257 }
258 if (md.getOutputFileBasename() != null) {
259 this.jTextFieldOutputFileBasename.setText(md.getOutputFileBasename());
260 }
261 }
262 }
263
264 /**
265 This method initializes Module type and Compontent type
266
267 **/
268 private void initFrame() {
269 EnumerationData ed = new EnumerationData();
270 this.iCheckBoxListArch.setAllItems(ed.getVSupportedArchitectures());
271 Tools.generateComboBoxByVector(jComboBoxBinaryModule, ed.getVBoolean());
272 }
273
274 private boolean check() {
275 if (isEmpty(this.jTextFieldOutputFileBasename.getText())) {
276 Log.err("Output File Basename couldn't be empty!");
277 return false;
278 }
279 if (!DataValidation.isOutputFileBasename(this.jTextFieldOutputFileBasename.getText())) {
280 Log.err("Incorrect data type for Output File Basename");
281 return false;
282 }
283 return true;
284 }
285
286 /* (non-Javadoc)
287 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
288 *
289 * Override componentResized to resize all components when frame's size is changed
290 */
291 public void componentResized(ComponentEvent arg0) {
292 int intCurrentWidth = this.getJContentPane().getWidth();
293 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;
294
295 resizeComponentWidth(this.jScrollPaneArch, intCurrentWidth, intPreferredWidth);
296 resizeComponentWidth(this.jComboBoxBinaryModule, intCurrentWidth, intPreferredWidth);
297 resizeComponentWidth(this.jTextFieldOutputFileBasename, intCurrentWidth, intPreferredWidth);
298 }
299
300 /**
301 Save all components of Module Definitions
302 if exists Module Definitions, set the value directly
303 if not exists Module Definitions, new an instance first
304
305 **/
306 public void save() {
307 check();
308 try {
309 if (this.md == null) {
310 md = ModuleDefinitionsDocument.ModuleDefinitions.Factory.newInstance();
311 }
312
313 if (!isEmpty(this.jTextFieldOutputFileBasename.getText())) {
314 md.setOutputFileBasename(this.jTextFieldOutputFileBasename.getText());
315 }
316
317 if (this.jComboBoxBinaryModule.getSelectedIndex() == 0) {
318 md.setBinaryModule(false);
319 } else {
320 md.setBinaryModule(true);
321 }
322
323 //
324 // Set ClonedFrom field
325 //
326 if (this.cf != null) {
327 md.setClonedFrom(this.cf);
328 }
329
330 //
331 // Save Arch list
332 //
333 md.setSupportedArchitectures(this.iCheckBoxListArch.getAllCheckedItemsString());
334
335 msa.setModuleDefinitions(md);
336
337 this.omt.setSaved(false);
338
339 } catch (Exception e) {
340 Log.err("Save Module Definitions", e.getMessage());
341 }
342 }
343
344 public void focusLost(FocusEvent arg0) {
345 this.save();
346 }
347 }