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