fa0963d6d8e847c308cd0728d5cdd8c0ef7494b4
[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.Tools;
33 import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;
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 iCheckBoxListArch.setToolTipText("<html>Deselecting a checkbox will restrict this module<br>" +
140 "for use with the selected architectures, <br>" +
141 "based on the list of items that are checked. <br>" +
142 "If all boxes are checked, <br>" +
143 "then the module will support all <br>" +
144 "current AND FUTURE architectures</html>");
145 }
146 return iCheckBoxListArch;
147 }
148
149 /**
150 * This method initializes jComboBoxBinaryModule
151 *
152 * @return javax.swing.JComboBox
153 */
154 private JComboBox getJComboBoxBinaryModule() {
155 if (jComboBoxBinaryModule == null) {
156 jComboBoxBinaryModule = new JComboBox();
157 jComboBoxBinaryModule.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
158 jComboBoxBinaryModule.setPreferredSize(new java.awt.Dimension(320, 20));
159 jComboBoxBinaryModule.addFocusListener(this);
160 jComboBoxBinaryModule.setToolTipText("<html>Modules are either source modules <br>" +
161 "which can be compiled or binary <br>" +
162 "modules which are linked. <br>" +
163 "A module cannot contain both. <br>" +
164 "The GUID numbers should be identical <br>" +
165 "for a binary and source MSA, <br>" +
166 "but the BINARY MSA should have <br>" +
167 "a higher version number.</html>");
168 }
169 return jComboBoxBinaryModule;
170 }
171
172 /**
173 * This method initializes jTextFieldOutputFileBasename
174 *
175 * @return javax.swing.JTextField
176 */
177 private JTextField getJTextFieldOutputFileBasename() {
178 if (jTextFieldOutputFileBasename == null) {
179 jTextFieldOutputFileBasename = new JTextField();
180 jTextFieldOutputFileBasename.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
181 jTextFieldOutputFileBasename.setPreferredSize(new java.awt.Dimension(320, 20));
182 jTextFieldOutputFileBasename.addFocusListener(this);
183 jTextFieldOutputFileBasename.setToolTipText("Enter a single word for generated output file names");
184 }
185 return jTextFieldOutputFileBasename;
186 }
187
188 /**
189 This method initializes jScrollPaneArch
190
191 @return javax.swing.JScrollPane
192
193 **/
194 private JScrollPane getJScrollPaneArch() {
195 if (jScrollPaneArch == null) {
196 jScrollPaneArch = new JScrollPane();
197 jScrollPaneArch.setBounds(new java.awt.Rectangle(160, 60, 320, 80));
198 jScrollPaneArch.setPreferredSize(new java.awt.Dimension(320, 60));
199 jScrollPaneArch.setViewportView(getICheckBoxListSupportedArchitectures());
200 }
201 return jScrollPaneArch;
202 }
203
204 /**
205
206 @param args
207
208 **/
209 public static void main(String[] args) {
210 // TODO Auto-generated method stub
211
212 }
213
214 /**
215 * This is the default constructor
216 */
217 public ModuleDefinitions() {
218 super();
219 init();
220 this.setVisible(true);
221 }
222
223 /**
224 This is the override edit constructor
225
226 @param inMsa
227
228 **/
229 public ModuleDefinitions(OpeningModuleType inOmt) {
230 super();
231 this.omt = inOmt;
232 this.msa = omt.getXmlMsa();
233 if (msa.getModuleDefinitions() != null) {
234 this.cf = msa.getModuleDefinitions().getClonedFrom();
235 }
236 init(msa.getModuleDefinitions());
237 this.setVisible(true);
238 }
239
240 /**
241 * This method initializes this
242 *
243 * @return void
244 */
245 private void init() {
246 this.setContentPane(getJScrollPane());
247 this.setTitle("Module Definitions");
248 initFrame();
249 this.setPreferredSize(new java.awt.Dimension(490, 520));
250 }
251
252 /**
253 This method initializes this
254 Fill values to all fields if these values are not empty
255
256 @param inMsaHeader The input data of MsaHeaderDocument.MsaHeader
257
258 **/
259 private void init(ModuleDefinitionsDocument.ModuleDefinitions inMd) {
260 init();
261 if (inMd != null) {
262 this.md = inMd;
263 if (md.getSupportedArchitectures() != null) {
264 this.iCheckBoxListArch.initCheckedItem(true, Tools.convertListToVector(md.getSupportedArchitectures()));
265 }
266 if (md.getBinaryModule()) {
267 this.jComboBoxBinaryModule.setSelectedIndex(1);
268 } else {
269 this.jComboBoxBinaryModule.setSelectedIndex(0);
270 }
271 if (md.getOutputFileBasename() != null) {
272 this.jTextFieldOutputFileBasename.setText(md.getOutputFileBasename());
273 }
274 }
275 }
276
277 /**
278 This method initializes Module type and Compontent type
279
280 **/
281 private void initFrame() {
282 EnumerationData ed = new EnumerationData();
283 this.iCheckBoxListArch.setAllItems(ed.getVSupportedArchitectures());
284 Tools.generateComboBoxByVector(jComboBoxBinaryModule, ed.getVBoolean());
285 }
286
287 private boolean check() {
288 if (isEmpty(this.jTextFieldOutputFileBasename.getText())) {
289 Log.wrn("Update Definitions", "Output File Basename couldn't be empty!");
290 return false;
291 }
292 if (!DataValidation.isOutputFileBasename(this.jTextFieldOutputFileBasename.getText())) {
293 Log.wrn("Update Definitions", "Incorrect data type for Output File Basename");
294 return false;
295 }
296 return true;
297 }
298
299 /* (non-Javadoc)
300 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
301 *
302 * Override componentResized to resize all components when frame's size is changed
303 */
304 public void componentResized(ComponentEvent arg0) {
305 int intCurrentWidth = this.getJContentPane().getWidth();
306 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;
307
308 resizeComponentWidth(this.jScrollPaneArch, intCurrentWidth, intPreferredWidth);
309 resizeComponentWidth(this.jComboBoxBinaryModule, intCurrentWidth, intPreferredWidth);
310 resizeComponentWidth(this.jTextFieldOutputFileBasename, intCurrentWidth, intPreferredWidth);
311 }
312
313 /**
314 Save all components of Module Definitions
315 if exists Module Definitions, set the value directly
316 if not exists Module Definitions, new an instance first
317
318 **/
319 public void save() {
320 check();
321 try {
322 if (this.md == null) {
323 md = ModuleDefinitionsDocument.ModuleDefinitions.Factory.newInstance();
324 }
325
326 if (!isEmpty(this.jTextFieldOutputFileBasename.getText())) {
327 md.setOutputFileBasename(this.jTextFieldOutputFileBasename.getText());
328 }
329
330 if (this.jComboBoxBinaryModule.getSelectedIndex() == 0) {
331 md.setBinaryModule(false);
332 } else {
333 md.setBinaryModule(true);
334 }
335
336 //
337 // Set ClonedFrom field
338 //
339 if (this.cf != null) {
340 md.setClonedFrom(this.cf);
341 }
342
343 //
344 // Save Arch list
345 //
346 md.setSupportedArchitectures(this.iCheckBoxListArch.getAllCheckedItemsString());
347
348 msa.setModuleDefinitions(md);
349
350 this.omt.setSaved(false);
351
352 } catch (Exception e) {
353 Log.err("Save Module Definitions", e.getMessage());
354 }
355 }
356
357 public void focusLost(FocusEvent arg0) {
358 this.save();
359 if (arg0.getSource() == this.jTextFieldOutputFileBasename) {
360 }
361 }
362 }