]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleBootModes.java
Fixed a spelling error and changed the Package Headers Tab title to be Package Header...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / ModuleBootModes.java
1 /** @file
2
3 The file is used to create, update BootModes of MSA/MBD 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
16 package org.tianocore.frameworkwizard.module.ui;
17
18 import java.awt.Dimension;
19 import java.awt.event.ActionEvent;
20 import java.awt.event.ComponentEvent;
21 import java.awt.event.MouseEvent;
22 import java.util.Vector;
23
24 import javax.swing.JButton;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTable;
28 import javax.swing.ListSelectionModel;
29 import javax.swing.event.ListSelectionEvent;
30
31 import org.tianocore.BootModeNames;
32 import org.tianocore.BootModeUsage;
33 import org.tianocore.BootModesDocument;
34 import org.tianocore.BootModesDocument.BootModes;
35 import org.tianocore.BootModesDocument.BootModes.BootMode;
36 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
37 import org.tianocore.frameworkwizard.common.DataType;
38 import org.tianocore.frameworkwizard.common.IDefaultTableModel;
39 import org.tianocore.frameworkwizard.common.Log;
40 import org.tianocore.frameworkwizard.common.Tools;
41 import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;
42 import org.tianocore.frameworkwizard.common.ui.IFrame;
43 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
44 import org.tianocore.frameworkwizard.module.Identifications.BootModes.BootModesIdentification;
45 import org.tianocore.frameworkwizard.module.Identifications.BootModes.BootModesVector;
46 import org.tianocore.frameworkwizard.module.ui.dialog.BootModesDlg;
47
48 /**
49 The class is used to create, update BootModes of MSA/MBD file
50 It extends IInternalFrame
51
52
53
54 **/
55 public class ModuleBootModes extends IInternalFrame {
56
57 ///
58 /// Define class Serial Version UID
59 ///
60 private static final long serialVersionUID = -3888558623432442561L;
61
62 //
63 //Define class members
64 //
65 private JPanel jContentPane = null;
66
67 private JButton jButtonAdd = null;
68
69 private JButton jButtonRemove = null;
70
71 private JButton jButtonUpdate = null;
72
73 private JScrollPane jScrollPane = null;
74
75 private JScrollPane jScrollPaneTable = null;
76
77 private JTable jTable = null;
78
79 //
80 // Not used by UI
81 //
82 private OpeningModuleType omt = null;
83
84 private ModuleSurfaceArea msa = null;
85
86 private BootModesDocument.BootModes bootModes = null;
87
88 private BootModesIdentification id = null;
89
90 private BootModesVector vid = new BootModesVector();
91
92 private IDefaultTableModel model = null;
93
94 private int selectedRow = -1;
95
96 /**
97 This method initializes jButtonAdd
98
99 @return javax.swing.JButton jButtonAdd
100
101 **/
102 private JButton getJButtonAdd() {
103 if (jButtonAdd == null) {
104 jButtonAdd = new JButton();
105 jButtonAdd.setBounds(new java.awt.Rectangle(230, 195, 80, 20));
106 jButtonAdd.setText("Add");
107 jButtonAdd.addActionListener(this);
108 jButtonAdd.setPreferredSize(new java.awt.Dimension(80, 20));
109 }
110 return jButtonAdd;
111 }
112
113 /**
114 This method initializes jButtonRemove
115
116 @return javax.swing.JButton jButtonRemove
117
118 **/
119 private JButton getJButtonRemove() {
120 if (jButtonRemove == null) {
121 jButtonRemove = new JButton();
122 jButtonRemove.setBounds(new java.awt.Rectangle(400, 195, 80, 20));
123 jButtonRemove.setText("Remove");
124 jButtonRemove.addActionListener(this);
125 jButtonRemove.setPreferredSize(new java.awt.Dimension(80, 20));
126 }
127 return jButtonRemove;
128 }
129
130 /**
131 This method initializes jButtonUpdate
132
133 @return javax.swing.JButton jButtonUpdate
134
135 **/
136 private JButton getJButtonUpdate() {
137 if (jButtonUpdate == null) {
138 jButtonUpdate = new JButton();
139 jButtonUpdate.setBounds(new java.awt.Rectangle(315, 195, 80, 20));
140 jButtonUpdate.setPreferredSize(new java.awt.Dimension(80, 20));
141 jButtonUpdate.setText("Edit");
142 jButtonUpdate.addActionListener(this);
143 }
144 return jButtonUpdate;
145 }
146
147 /**
148 This method initializes jScrollPane
149
150 @return javax.swing.JScrollPane
151 */
152 private JScrollPane getJScrollPane() {
153 if (jScrollPane == null) {
154 jScrollPane = new JScrollPane();
155 jScrollPane.setViewportView(getJContentPane());
156 }
157 return jScrollPane;
158 }
159
160 /**
161 This method initializes jScrollPaneTable
162
163 @return javax.swing.JScrollPane
164 **/
165 private JScrollPane getJScrollPaneTable() {
166 if (jScrollPaneTable == null) {
167 jScrollPaneTable = new JScrollPane();
168 jScrollPaneTable.setBounds(new java.awt.Rectangle(15, 10, 470, 420));
169 jScrollPaneTable.setPreferredSize(new Dimension(470, 420));
170 jScrollPaneTable.setViewportView(getJTable());
171 }
172 return jScrollPaneTable;
173 }
174
175 /**
176 This method initializes jTable
177
178 @return javax.swing.JTable
179 **/
180 private JTable getJTable() {
181 if (jTable == null) {
182 jTable = new JTable();
183 model = new IDefaultTableModel();
184 jTable = new JTable(model);
185 jTable.setRowHeight(20);
186
187 model.addColumn("Name");
188 model.addColumn("Usage");
189
190 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
191 jTable.getSelectionModel().addListSelectionListener(this);
192 jTable.getModel().addTableModelListener(this);
193 jTable.addMouseListener(this);
194 }
195 return jTable;
196 }
197
198 public static void main(String[] args) {
199 }
200
201 /**
202 This method initializes this
203
204 **/
205 private void init() {
206 this.setSize(500, 515);
207 this.setContentPane(getJScrollPane());
208 this.setTitle("Boot Modes");
209 }
210
211 /**
212 This method initializes this
213 Fill values to all fields if these values are not empty
214
215 @param inBootModes
216
217 **/
218 private void init(BootModes inBootModes) {
219 init();
220 this.bootModes = inBootModes;
221
222 if (this.bootModes != null) {
223 if (this.bootModes.getBootModeList().size() > 0) {
224 for (int index = 0; index < this.bootModes.getBootModeList().size(); index++) {
225 String arg0 = null;
226 if (bootModes.getBootModeList().get(index).getBootModeName() != null) {
227 arg0 = bootModes.getBootModeList().get(index).getBootModeName().toString();
228 }
229 String arg1 = null;
230 if (bootModes.getBootModeList().get(index).getUsage() != null) {
231 arg1 = bootModes.getBootModeList().get(index).getUsage().toString();
232 }
233
234 String arg2 = bootModes.getBootModeList().get(index).getFeatureFlag();
235 Vector<String> arg3 = Tools.convertListToVector(bootModes.getBootModeList().get(index)
236 .getSupArchList());
237 String arg4 = bootModes.getBootModeList().get(index).getHelpText();
238
239 id = new BootModesIdentification(arg0, arg1, arg2, arg3, arg4);
240 vid.addBootModes(id);
241 }
242 }
243 }
244 showTable();
245 }
246
247 /**
248 This is the default constructor
249
250 **/
251 public ModuleBootModes() {
252 super();
253 init();
254 this.setVisible(true);
255 }
256
257 /**
258 This is the override edit constructor
259
260 @param inBootModes The input BootModesDocument.BootModes
261
262 **/
263 public ModuleBootModes(OpeningModuleType inOmt) {
264 super();
265 this.omt = inOmt;
266 this.msa = omt.getXmlMsa();
267 init(msa.getBootModes());
268 this.setVisible(true);
269 }
270
271 /**
272 This method initializes jContentPane
273
274 @return javax.swing.JPanel jContentPane
275
276 **/
277 private JPanel getJContentPane() {
278 if (jContentPane == null) {
279 jContentPane = new JPanel();
280 jContentPane.setLayout(null);
281 jContentPane.setPreferredSize(new java.awt.Dimension(490, 490));
282
283 jContentPane.add(getJButtonAdd(), null);
284 jContentPane.add(getJButtonRemove(), null);
285 jContentPane.add(getJButtonUpdate(), null);
286 jContentPane.add(getJScrollPaneTable(), null);
287 }
288 return jContentPane;
289 }
290
291 private void showEdit(int index) {
292 BootModesDlg dlg = new BootModesDlg(vid.getBootModes(index), new IFrame());
293 int result = dlg.showDialog();
294 if (result == DataType.RETURN_TYPE_OK) {
295 if (index == -1) {
296 this.vid.addBootModes(dlg.getId());
297 } else {
298 this.vid.setBootModes(dlg.getId(), index);
299 }
300 this.showTable();
301 this.save();
302 dlg.dispose();
303 }
304 if (result == DataType.RETURN_TYPE_CANCEL) {
305 dlg.dispose();
306 }
307 }
308
309 /**
310 Clear all table rows
311
312 **/
313 private void clearAll() {
314 if (model != null) {
315 for (int index = model.getRowCount() - 1; index >= 0; index--) {
316 model.removeRow(index);
317 }
318 }
319 }
320
321 /**
322 Read content of vector and put then into table
323
324 **/
325 private void showTable() {
326 clearAll();
327
328 if (vid.size() > 0) {
329 for (int index = 0; index < vid.size(); index++) {
330 model.addRow(vid.toStringVector(index));
331 }
332 }
333 this.jTable.repaint();
334 this.jTable.updateUI();
335 }
336
337 /* (non-Javadoc)
338 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
339 *
340 * Override actionPerformed to listen all actions
341 *
342 */
343 public void actionPerformed(ActionEvent arg0) {
344 if (arg0.getSource() == jButtonAdd) {
345 showEdit(-1);
346 }
347 if (arg0.getSource() == jButtonUpdate) {
348 if (this.selectedRow < 0) {
349 Log.err("Please select one record first.");
350 return;
351 }
352 showEdit(selectedRow);
353 }
354
355 if (arg0.getSource() == jButtonRemove) {
356 if (jTable.isEditing()) {
357 jTable.getCellEditor().stopCellEditing();
358 }
359 if (selectedRow > -1) {
360 this.model.removeRow(selectedRow);
361 this.vid.removeBootModes(selectedRow);
362 selectedRow = -1;
363 this.save();
364 }
365 }
366 }
367
368 /**
369 Save all components of Mbd Header
370 if exists bootModes, set the value directly
371 if not exists bootModes, new an instance first
372
373 **/
374 public void save() {
375 try {
376 int count = this.vid.size();
377
378 this.bootModes = BootModes.Factory.newInstance();
379 if (count > 0) {
380 for (int index = 0; index < count; index++) {
381 BootMode p = BootMode.Factory.newInstance();
382 if (!isEmpty(vid.getBootModes(index).getName())) {
383 p.setBootModeName(BootModeNames.Enum.forString(vid.getBootModes(index).getName()));
384 }
385 if (!isEmpty(vid.getBootModes(index).getUsage())) {
386 p.setUsage(BootModeUsage.Enum.forString(vid.getBootModes(index).getUsage()));
387 }
388 if (!isEmpty(vid.getBootModes(index).getFeatureFlag())) {
389 p.setFeatureFlag(vid.getBootModes(index).getFeatureFlag());
390 }
391 if (vid.getBootModes(index).getSupArchList() != null
392 && vid.getBootModes(index).getSupArchList().size() > 0) {
393 p.setSupArchList(vid.getBootModes(index).getSupArchList());
394 }
395 if (!isEmpty(vid.getBootModes(index).getHelp())) {
396 p.setHelpText(vid.getBootModes(index).getHelp());
397 }
398 this.bootModes.addNewBootMode();
399 this.bootModes.setBootModeArray(bootModes.getBootModeList().size() - 1, p);
400 }
401 }
402
403 this.msa.setBootModes(bootModes);
404 this.omt.setSaved(false);
405 } catch (Exception e) {
406 Log.err("Update Boot Modes", e.getMessage());
407 }
408 }
409
410 /* (non-Javadoc)
411 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
412 *
413 */
414 public void valueChanged(ListSelectionEvent arg0) {
415 if (arg0.getValueIsAdjusting()) {
416 return;
417 }
418 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();
419 if (lsm.isSelectionEmpty()) {
420 return;
421 } else {
422 selectedRow = lsm.getMinSelectionIndex();
423 }
424 }
425
426 /* (non-Javadoc)
427 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
428 *
429 */
430 public void mouseClicked(MouseEvent arg0) {
431 if (arg0.getClickCount() == 2) {
432 if (this.selectedRow < 0) {
433 return;
434 } else {
435 showEdit(selectedRow);
436 }
437 }
438 }
439
440 /* (non-Javadoc)
441 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
442 *
443 * Override componentResized to resize all components when frame's size is changed
444 */
445 public void componentResized(ComponentEvent arg0) {
446 int intCurrentWidth = this.getJContentPane().getWidth();
447 int intCurrentHeight = this.getJContentPane().getHeight();
448 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;
449 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;
450
451 resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight);
452 relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,
453 DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);
454 relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,
455 DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);
456 relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,
457 DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);
458 }
459 }