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