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;
99 This method initializes jButtonAdd
101 @return javax.swing.JButton jButtonAdd
104 private JButton
getJButtonAdd() {
105 if (jButtonAdd
== null) {
106 jButtonAdd
= new JButton();
107 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 220, 80, 20));
108 jButtonAdd
.setText("Add");
109 jButtonAdd
.addActionListener(this);
110 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(80, 20));
116 This method initializes jButtonRemove
118 @return javax.swing.JButton jButtonRemove
121 private JButton
getJButtonRemove() {
122 if (jButtonRemove
== null) {
123 jButtonRemove
= new JButton();
124 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 220, 80, 20));
125 jButtonRemove
.setText("Remove");
126 jButtonRemove
.addActionListener(this);
127 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(80, 20));
129 return jButtonRemove
;
133 This method initializes jButtonUpdate
135 @return javax.swing.JButton jButtonUpdate
138 private JButton
getJButtonUpdate() {
139 if (jButtonUpdate
== null) {
140 jButtonUpdate
= new JButton();
141 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 220, 80, 20));
142 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(80, 20));
143 jButtonUpdate
.setText("Edit");
144 jButtonUpdate
.addActionListener(this);
146 return jButtonUpdate
;
150 This method initializes jScrollPane
152 @return javax.swing.JScrollPane
154 private JScrollPane
getJScrollPane() {
155 if (jScrollPane
== null) {
156 jScrollPane
= new JScrollPane();
157 jScrollPane
.setViewportView(getJContentPane());
163 This method initializes jScrollPaneTable
165 @return javax.swing.JScrollPane
167 private JScrollPane
getJScrollPaneTable() {
168 if (jScrollPaneTable
== null) {
169 jScrollPaneTable
= new JScrollPane();
170 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
171 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
172 jScrollPaneTable
.setViewportView(getJTable());
174 return jScrollPaneTable
;
178 This method initializes jTable
180 @return javax.swing.JTable
182 private JTable
getJTable() {
183 if (jTable
== null) {
184 jTable
= new JTable();
185 model
= new IDefaultTableModel();
186 jTable
= new JTable(model
);
187 jTable
.setRowHeight(20);
189 model
.addColumn("Guid C_Name");
190 model
.addColumn("Type");
191 model
.addColumn("Usage");
193 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
194 jTable
.getSelectionModel().addListSelectionListener(this);
195 jTable
.getModel().addTableModelListener(this);
196 jTable
.addMouseListener(this);
201 public static void main(String
[] args
) {
206 This method initializes this
209 private void init() {
210 this.setSize(500, 515);
211 this.setContentPane(getJScrollPane());
212 this.setTitle("Ppis");
216 This method initializes this
217 Fill values to all fields if these values are not empty
219 @param inPackageDependencies
222 private void init(PPIs inPpis
) {
226 if (this.ppis
!= null) {
227 if (this.ppis
.getPpiList().size() > 0) {
228 for (int index
= 0; index
< this.ppis
.getPpiList().size(); index
++) {
229 String arg0
= ppis
.getPpiList().get(index
).getPpiCName();
230 String arg1
= ed
.getVPpiType().get(0);
232 if (ppis
.getPpiList().get(index
).getUsage() != null) {
233 arg2
= ppis
.getPpiList().get(index
).getUsage().toString();
236 String arg3
= ppis
.getPpiList().get(index
).getFeatureFlag();
237 Vector
<String
> arg4
= Tools
.convertListToVector(ppis
.getPpiList().get(index
).getSupArchList());
238 String arg5
= ppis
.getPpiList().get(index
).getHelpText();
240 id
= new PpisIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
244 if (this.ppis
.getPpiNotifyList().size() > 0) {
245 for (int index
= 0; index
< this.ppis
.getPpiNotifyList().size(); index
++) {
246 String arg0
= ppis
.getPpiNotifyList().get(index
).getPpiNotifyCName();
247 String arg1
= ed
.getVPpiType().get(1);
249 if (ppis
.getPpiNotifyList().get(index
).getUsage() != null) {
250 arg2
= ppis
.getPpiNotifyList().get(index
).getUsage().toString();
253 String arg3
= ppis
.getPpiNotifyList().get(index
).getFeatureFlag();
254 Vector
<String
> arg4
= Tools
255 .convertListToVector(ppis
.getPpiNotifyList().get(index
).getSupArchList());
256 String arg5
= ppis
.getPpiNotifyList().get(index
).getHelpText();
258 id
= new PpisIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
267 This is the default constructor
270 public ModulePpis() {
273 this.setVisible(true);
277 This is the override edit constructor
279 @param inPpis The input data of PPIsDocument.PPIs
282 public ModulePpis(OpeningModuleType inOmt
) {
285 this.msa
= omt
.getXmlMsa();
287 this.setVisible(true);
291 This method initializes jContentPane
293 @return javax.swing.JPanel jContentPane
296 private JPanel
getJContentPane() {
297 if (jContentPane
== null) {
298 jContentPane
= new JPanel();
299 jContentPane
.setLayout(null);
300 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
302 jContentPane
.add(getJButtonAdd(), null);
303 jContentPane
.add(getJButtonRemove(), null);
304 jContentPane
.add(getJButtonUpdate(), null);
305 jContentPane
.add(getJScrollPaneTable(), null);
310 private void showEdit(int index
) {
311 PpisDlg dlg
= new PpisDlg(vid
.getPpis(index
), new IFrame());
312 int result
= dlg
.showDialog();
313 if (result
== DataType
.RETURN_TYPE_OK
) {
315 this.vid
.addPpis(dlg
.getId());
317 this.vid
.setPpis(dlg
.getId(), index
);
323 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
332 private void clearAll() {
334 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
335 model
.removeRow(index
);
341 Read content of vector and put then into table
344 private void showTable() {
347 if (vid
.size() > 0) {
348 for (int index
= 0; index
< vid
.size(); index
++) {
349 model
.addRow(vid
.toStringVector(index
));
352 this.jTable
.repaint();
353 this.jTable
.updateUI();
357 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
359 * Override actionPerformed to listen all actions
362 public void actionPerformed(ActionEvent arg0
) {
363 if (arg0
.getSource() == jButtonAdd
) {
366 if (arg0
.getSource() == jButtonUpdate
) {
367 if (this.selectedRow
< 0) {
368 Log
.err("Please select one record first.");
371 showEdit(selectedRow
);
374 if (arg0
.getSource() == jButtonRemove
) {
375 if (jTable
.isEditing()) {
376 jTable
.getCellEditor().stopCellEditing();
378 if (selectedRow
> -1) {
379 this.model
.removeRow(selectedRow
);
380 this.vid
.removePpis(selectedRow
);
388 Save all components of PPIs
389 if exists ppis, set the value directly
390 if not exists ppis, new an instance first
395 int count
= this.vid
.size();
397 this.ppis
= PPIs
.Factory
.newInstance();
399 for (int index
= 0; index
< count
; index
++) {
400 if (vid
.getPpis(index
).getType().equals(ed
.getVPpiType().get(0))) {
401 Ppi p
= Ppi
.Factory
.newInstance();
402 if (!isEmpty(vid
.getPpis(index
).getName())) {
403 p
.setPpiCName(vid
.getPpis(index
).getName());
405 if (!isEmpty(vid
.getPpis(index
).getUsage())) {
406 p
.setUsage(PpiUsage
.Enum
.forString(vid
.getPpis(index
).getUsage()));
408 if (!isEmpty(vid
.getPpis(index
).getFeatureFlag())) {
409 p
.setFeatureFlag(vid
.getPpis(index
).getFeatureFlag());
411 if (vid
.getPpis(index
).getSupArchList() != null
412 && vid
.getPpis(index
).getSupArchList().size() > 0) {
413 p
.setSupArchList(vid
.getPpis(index
).getSupArchList());
415 if (!isEmpty(vid
.getPpis(index
).getHelp())) {
416 p
.setHelpText(vid
.getPpis(index
).getHelp());
418 this.ppis
.addNewPpi();
419 this.ppis
.setPpiArray(ppis
.getPpiList().size() - 1, p
);
421 if (vid
.getPpis(index
).getType().equals(ed
.getVPpiType().get(1))) {
422 PpiNotify p
= PpiNotify
.Factory
.newInstance();
423 if (!isEmpty(vid
.getPpis(index
).getName())) {
424 p
.setPpiNotifyCName(vid
.getPpis(index
).getName());
426 if (!isEmpty(vid
.getPpis(index
).getUsage())) {
427 p
.setUsage(PpiNotifyUsage
.Enum
.forString(vid
.getPpis(index
).getUsage()));
429 if (!isEmpty(vid
.getPpis(index
).getFeatureFlag())) {
430 p
.setFeatureFlag(vid
.getPpis(index
).getFeatureFlag());
432 if (vid
.getPpis(index
).getSupArchList() != null
433 && vid
.getPpis(index
).getSupArchList().size() > 0) {
434 p
.setSupArchList(vid
.getPpis(index
).getSupArchList());
436 if (!isEmpty(vid
.getPpis(index
).getHelp())) {
437 p
.setHelpText(vid
.getPpis(index
).getHelp());
439 this.ppis
.addNewPpiNotify();
440 this.ppis
.setPpiNotifyArray(ppis
.getPpiNotifyList().size() - 1, p
);
445 this.msa
.setPPIs(ppis
);
446 this.omt
.setSaved(false);
447 } catch (Exception e
) {
449 Log
.err("Update Ppis", e
.getMessage());
454 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
457 public void valueChanged(ListSelectionEvent arg0
) {
458 if (arg0
.getValueIsAdjusting()) {
461 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
462 if (lsm
.isSelectionEmpty()) {
465 selectedRow
= lsm
.getMinSelectionIndex();
470 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
473 public void mouseClicked(MouseEvent arg0
) {
474 if (arg0
.getClickCount() == 2) {
475 if (this.selectedRow
< 0) {
478 showEdit(selectedRow
);
484 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
486 * Override componentResized to resize all components when frame's size is changed
488 public void componentResized(ComponentEvent arg0
) {
489 int intCurrentWidth
= this.getJContentPane().getWidth();
490 int intCurrentHeight
= this.getJContentPane().getHeight();
491 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
492 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
494 resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
);
495 relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
496 DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
497 relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
498 DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
499 relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
500 DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);