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