]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModulePpis.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 / 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.MULTIPLE_INTERVAL_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
382 int selectedRows[] = this.jTable.getSelectedRows();
383
384 if (selectedRows != null) {
385 for (int index = selectedRows.length - 1; index > -1; index--) {
386 this.model.removeRow(selectedRows[index]);
387 this.vid.removePpis(selectedRows[index]);
388 }
389 selectedRow = -1;
390 this.save();
391 }
392 }
393 }
394
395 /**
396 Save all components of PPIs
397 if exists ppis, set the value directly
398 if not exists ppis, new an instance first
399
400 **/
401 public void save() {
402 try {
403 int count = this.vid.size();
404
405 this.ppis = PPIs.Factory.newInstance();
406 if (count > 0) {
407 for (int index = 0; index < count; index++) {
408 if (vid.getPpis(index).getType().equals(ed.getVPpiType().get(0))) {
409 Ppi p = Ppi.Factory.newInstance();
410 if (!isEmpty(vid.getPpis(index).getName())) {
411 p.setPpiCName(vid.getPpis(index).getName());
412 }
413 if (!isEmpty(vid.getPpis(index).getUsage())) {
414 p.setUsage(PpiUsage.Enum.forString(vid.getPpis(index).getUsage()));
415 }
416 if (!isEmpty(vid.getPpis(index).getFeatureFlag())) {
417 p.setFeatureFlag(vid.getPpis(index).getFeatureFlag());
418 }
419 if (vid.getPpis(index).getSupArchList() != null
420 && vid.getPpis(index).getSupArchList().size() > 0) {
421 p.setSupArchList(vid.getPpis(index).getSupArchList());
422 }
423 if (!isEmpty(vid.getPpis(index).getHelp())) {
424 p.setHelpText(vid.getPpis(index).getHelp());
425 }
426 this.ppis.addNewPpi();
427 this.ppis.setPpiArray(ppis.getPpiList().size() - 1, p);
428 }
429 if (vid.getPpis(index).getType().equals(ed.getVPpiType().get(1))) {
430 PpiNotify p = PpiNotify.Factory.newInstance();
431 if (!isEmpty(vid.getPpis(index).getName())) {
432 p.setPpiNotifyCName(vid.getPpis(index).getName());
433 }
434 if (!isEmpty(vid.getPpis(index).getUsage())) {
435 p.setUsage(PpiNotifyUsage.Enum.forString(vid.getPpis(index).getUsage()));
436 }
437 if (!isEmpty(vid.getPpis(index).getFeatureFlag())) {
438 p.setFeatureFlag(vid.getPpis(index).getFeatureFlag());
439 }
440 if (vid.getPpis(index).getSupArchList() != null
441 && vid.getPpis(index).getSupArchList().size() > 0) {
442 p.setSupArchList(vid.getPpis(index).getSupArchList());
443 }
444 if (!isEmpty(vid.getPpis(index).getHelp())) {
445 p.setHelpText(vid.getPpis(index).getHelp());
446 }
447 this.ppis.addNewPpiNotify();
448 this.ppis.setPpiNotifyArray(ppis.getPpiNotifyList().size() - 1, p);
449 }
450 }
451 }
452
453 this.msa.setPPIs(ppis);
454 this.omt.setSaved(false);
455 } catch (Exception e) {
456 Log.wrn("Update Ppis", e.getMessage());
457 Log.err("Update Ppis", e.getMessage());
458 }
459 }
460
461 /* (non-Javadoc)
462 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
463 *
464 */
465 public void valueChanged(ListSelectionEvent arg0) {
466 if (arg0.getValueIsAdjusting()) {
467 return;
468 }
469 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();
470 if (lsm.isSelectionEmpty()) {
471 return;
472 } else {
473 selectedRow = lsm.getMinSelectionIndex();
474 }
475 }
476
477 /* (non-Javadoc)
478 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
479 *
480 */
481 public void mouseClicked(MouseEvent arg0) {
482 if (arg0.getClickCount() == 2) {
483 if (this.selectedRow < 0) {
484 return;
485 } else {
486 showEdit(selectedRow);
487 }
488 }
489 }
490
491 /* (non-Javadoc)
492 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
493 *
494 * Override componentResized to resize all components when frame's size is changed
495 */
496 public void componentResized(ComponentEvent arg0) {
497 int intCurrentWidth = this.getJContentPane().getWidth();
498 int intCurrentHeight = this.getJContentPane().getHeight();
499 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;
500 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;
501
502 Tools.resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth,
503 intPreferredHeight);
504 Tools.relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth,
505 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON,
506 DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);
507 Tools.relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth,
508 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON,
509 DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);
510 Tools.relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth,
511 intPreferredHeight, DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON,
512 DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);
513 }
514 }