3 The file is used to create, update Ppi of MSA/MBD file
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
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.
15 package org
.tianocore
.frameworkwizard
.module
.ui
;
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
;
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
;
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
;
50 The class is used to create, update Ppi of MSA/MBD file
51 It extends IInternalFrame
54 public class ModulePpis
extends IInternalFrame
{
57 /// Define class Serial Version UID
59 private static final long serialVersionUID
= -4284901202357037724L;
62 //Define class members
64 private JPanel jContentPane
= null;
66 private JButton jButtonAdd
= null;
68 private JButton jButtonRemove
= null;
70 private JButton jButtonUpdate
= null;
72 private JScrollPane jScrollPane
= null;
74 private JScrollPane jScrollPaneTable
= null;
76 private JTable jTable
= null;
82 private OpeningModuleType omt
= null;
84 private ModuleSurfaceArea msa
= null;
86 private PPIsDocument
.PPIs ppis
= null;
88 private PpisIdentification id
= null;
90 private PpisVector vid
= new PpisVector();
92 private EnumerationData ed
= new EnumerationData();
94 private IDefaultTableModel model
= null;
96 private int selectedRow
= -1;
98 private IFrame parentFrame
= null;
101 This method initializes jButtonAdd
103 @return javax.swing.JButton jButtonAdd
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));
118 This method initializes jButtonRemove
120 @return javax.swing.JButton jButtonRemove
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));
131 return jButtonRemove
;
135 This method initializes jButtonUpdate
137 @return javax.swing.JButton jButtonUpdate
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);
148 return jButtonUpdate
;
152 This method initializes jScrollPane
154 @return javax.swing.JScrollPane
156 private JScrollPane
getJScrollPane() {
157 if (jScrollPane
== null) {
158 jScrollPane
= new JScrollPane();
159 jScrollPane
.setViewportView(getJContentPane());
165 This method initializes jScrollPaneTable
167 @return javax.swing.JScrollPane
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());
176 return jScrollPaneTable
;
180 This method initializes jTable
182 @return javax.swing.JTable
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);
191 model
.addColumn("Guid C_Name");
192 model
.addColumn("Type");
193 model
.addColumn("Usage");
195 jTable
.setSelectionMode(ListSelectionModel
.MULTIPLE_INTERVAL_SELECTION
);
196 jTable
.getSelectionModel().addListSelectionListener(this);
197 jTable
.getModel().addTableModelListener(this);
198 jTable
.addMouseListener(this);
203 public static void main(String
[] args
) {
208 This method initializes this
211 private void init() {
212 this.setSize(500, 515);
213 this.setContentPane(getJScrollPane());
214 this.setTitle("Ppis");
218 This method initializes this
219 Fill values to all fields if these values are not empty
221 @param inPackageDependencies
224 private void init(PPIs inPpis
) {
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);
234 if (ppis
.getPpiList().get(index
).getUsage() != null) {
235 arg2
= ppis
.getPpiList().get(index
).getUsage().toString();
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();
242 id
= new PpisIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
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);
251 if (ppis
.getPpiNotifyList().get(index
).getUsage() != null) {
252 arg2
= ppis
.getPpiNotifyList().get(index
).getUsage().toString();
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();
260 id
= new PpisIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
269 This is the default constructor
272 public ModulePpis() {
275 this.setVisible(true);
279 This is the override edit constructor
281 @param inPpis The input data of PPIsDocument.PPIs
284 public ModulePpis(OpeningModuleType inOmt
, IFrame iFrame
) {
287 this.msa
= omt
.getXmlMsa();
288 this.parentFrame
= iFrame
;
290 this.setVisible(true);
294 This method initializes jContentPane
296 @return javax.swing.JPanel jContentPane
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));
305 jContentPane
.add(getJButtonAdd(), null);
306 jContentPane
.add(getJButtonRemove(), null);
307 jContentPane
.add(getJButtonUpdate(), null);
308 jContentPane
.add(getJScrollPaneTable(), null);
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
) {
318 this.vid
.addPpis(dlg
.getId());
320 this.vid
.setPpis(dlg
.getId(), index
);
326 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
335 private void clearAll() {
337 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
338 model
.removeRow(index
);
344 Read content of vector and put then into table
347 private void showTable() {
350 if (vid
.size() > 0) {
351 for (int index
= 0; index
< vid
.size(); index
++) {
352 model
.addRow(vid
.toStringVector(index
));
355 this.jTable
.repaint();
356 this.jTable
.updateUI();
360 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
362 * Override actionPerformed to listen all actions
365 public void actionPerformed(ActionEvent arg0
) {
366 if (arg0
.getSource() == jButtonAdd
) {
369 if (arg0
.getSource() == jButtonUpdate
) {
370 if (this.selectedRow
< 0) {
371 Log
.wrn("Update Ppis", "Please select one record first.");
374 showEdit(selectedRow
);
377 if (arg0
.getSource() == jButtonRemove
) {
378 if (jTable
.isEditing()) {
379 jTable
.getCellEditor().stopCellEditing();
382 int selectedRows
[] = this.jTable
.getSelectedRows();
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
]);
396 Save all components of PPIs
397 if exists ppis, set the value directly
398 if not exists ppis, new an instance first
403 int count
= this.vid
.size();
405 this.ppis
= PPIs
.Factory
.newInstance();
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());
413 if (!isEmpty(vid
.getPpis(index
).getUsage())) {
414 p
.setUsage(PpiUsage
.Enum
.forString(vid
.getPpis(index
).getUsage()));
416 if (!isEmpty(vid
.getPpis(index
).getFeatureFlag())) {
417 p
.setFeatureFlag(vid
.getPpis(index
).getFeatureFlag());
419 if (vid
.getPpis(index
).getSupArchList() != null
420 && vid
.getPpis(index
).getSupArchList().size() > 0) {
421 p
.setSupArchList(vid
.getPpis(index
).getSupArchList());
423 if (!isEmpty(vid
.getPpis(index
).getHelp())) {
424 p
.setHelpText(vid
.getPpis(index
).getHelp());
426 this.ppis
.addNewPpi();
427 this.ppis
.setPpiArray(ppis
.getPpiList().size() - 1, p
);
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());
434 if (!isEmpty(vid
.getPpis(index
).getUsage())) {
435 p
.setUsage(PpiNotifyUsage
.Enum
.forString(vid
.getPpis(index
).getUsage()));
437 if (!isEmpty(vid
.getPpis(index
).getFeatureFlag())) {
438 p
.setFeatureFlag(vid
.getPpis(index
).getFeatureFlag());
440 if (vid
.getPpis(index
).getSupArchList() != null
441 && vid
.getPpis(index
).getSupArchList().size() > 0) {
442 p
.setSupArchList(vid
.getPpis(index
).getSupArchList());
444 if (!isEmpty(vid
.getPpis(index
).getHelp())) {
445 p
.setHelpText(vid
.getPpis(index
).getHelp());
447 this.ppis
.addNewPpiNotify();
448 this.ppis
.setPpiNotifyArray(ppis
.getPpiNotifyList().size() - 1, p
);
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());
462 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
465 public void valueChanged(ListSelectionEvent arg0
) {
466 if (arg0
.getValueIsAdjusting()) {
469 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
470 if (lsm
.isSelectionEmpty()) {
473 selectedRow
= lsm
.getMinSelectionIndex();
478 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
481 public void mouseClicked(MouseEvent arg0
) {
482 if (arg0
.getClickCount() == 2) {
483 if (this.selectedRow
< 0) {
486 showEdit(selectedRow
);
492 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
494 * Override componentResized to resize all components when frame's size is changed
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
;
502 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
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
);