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