3 The file is used to create, update Protocol 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.
16 package org
.tianocore
.frameworkwizard
.module
.ui
;
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
.Vector
;
24 import javax
.swing
.JButton
;
25 import javax
.swing
.JPanel
;
26 import javax
.swing
.JScrollPane
;
27 import javax
.swing
.JTable
;
28 import javax
.swing
.ListSelectionModel
;
29 import javax
.swing
.event
.ListSelectionEvent
;
31 import org
.tianocore
.ProtocolNotifyUsage
;
32 import org
.tianocore
.ProtocolUsage
;
33 import org
.tianocore
.ProtocolsDocument
;
34 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
35 import org
.tianocore
.ProtocolsDocument
.Protocols
;
36 import org
.tianocore
.ProtocolsDocument
.Protocols
.Protocol
;
37 import org
.tianocore
.ProtocolsDocument
.Protocols
.ProtocolNotify
;
38 import org
.tianocore
.frameworkwizard
.common
.DataType
;
39 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
40 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
41 import org
.tianocore
.frameworkwizard
.common
.Log
;
42 import org
.tianocore
.frameworkwizard
.common
.Tools
;
43 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
44 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
45 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
46 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Protocols
.ProtocolsIdentification
;
47 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Protocols
.ProtocolsVector
;
48 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.ProtocolsDlg
;
51 The class is used to create, update Protocol of MSA/MBD file
52 It extends IInternalFrame
57 public class ModuleProtocols
extends IInternalFrame
{
60 /// Define class Serial Version UID
62 private static final long serialVersionUID
= -9084913640747858848L;
65 //Define class members
67 private JPanel jContentPane
= null;
69 private JButton jButtonAdd
= null;
71 private JButton jButtonRemove
= null;
73 private JButton jButtonUpdate
= null;
75 private JScrollPane jScrollPane
= null;
77 private JScrollPane jScrollPaneTable
= null;
79 private JTable jTable
= null;
84 private OpeningModuleType omt
= null;
86 private ModuleSurfaceArea msa
= null;
88 private ProtocolsDocument
.Protocols protocols
= null;
90 private ProtocolsIdentification id
= null;
92 private ProtocolsVector vid
= new ProtocolsVector();
94 private EnumerationData ed
= new EnumerationData();
96 private IDefaultTableModel model
= null;
98 private int selectedRow
= -1;
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, 80, 20));
110 jButtonAdd
.setText("Add");
111 jButtonAdd
.addActionListener(this);
112 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(80, 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, 80, 20));
127 jButtonRemove
.setText("Remove");
128 jButtonRemove
.addActionListener(this);
129 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(80, 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, 80, 20));
144 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(80, 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
.SINGLE_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("Protocols");
218 This method initializes this
219 Fill values to all fields if these values are not empty
221 @param inPackageDependencies
224 private void init(Protocols inProtocols
) {
226 this.protocols
= inProtocols
;
228 if (this.protocols
!= null) {
229 if (this.protocols
.getProtocolList().size() > 0) {
230 for (int index
= 0; index
< this.protocols
.getProtocolList().size(); index
++) {
231 String arg0
= protocols
.getProtocolList().get(index
).getProtocolCName();
232 String arg1
= ed
.getVProtocolType().get(0);
234 if (protocols
.getProtocolList().get(index
).getUsage() != null) {
235 arg2
= protocols
.getProtocolList().get(index
).getUsage().toString();
238 String arg3
= protocols
.getProtocolList().get(index
).getFeatureFlag();
239 Vector
<String
> arg4
= Tools
.convertListToVector(protocols
.getProtocolList().get(index
)
241 String arg5
= protocols
.getProtocolList().get(index
).getHelpText();
242 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
243 vid
.addProtocols(id
);
246 if (this.protocols
.getProtocolNotifyList().size() > 0) {
247 for (int index
= 0; index
< this.protocols
.getProtocolNotifyList().size(); index
++) {
248 String arg0
= protocols
.getProtocolNotifyList().get(index
).getProtocolNotifyCName();
249 String arg1
= ed
.getVProtocolType().get(1);
251 if (protocols
.getProtocolNotifyList().get(index
).getUsage() != null) {
252 arg2
= protocols
.getProtocolNotifyList().get(index
).getUsage().toString();
255 String arg3
= protocols
.getProtocolNotifyList().get(index
).getFeatureFlag();
256 Vector
<String
> arg4
= Tools
.convertListToVector(protocols
.getProtocolNotifyList().get(index
)
258 String arg5
= protocols
.getProtocolNotifyList().get(index
).getHelpText();
259 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
260 vid
.addProtocols(id
);
268 This is the default constructor
271 public ModuleProtocols() {
274 this.setVisible(true);
278 This is the override edit constructor
280 @param inProtocol The input data of ProtocolsDocument.Protocols
283 public ModuleProtocols(OpeningModuleType inOmt
) {
286 this.msa
= omt
.getXmlMsa();
287 init(msa
.getProtocols());
288 this.setVisible(true);
292 This method initializes jContentPane
294 @return javax.swing.JPanel jContentPane
297 private JPanel
getJContentPane() {
298 if (jContentPane
== null) {
299 jContentPane
= new JPanel();
300 jContentPane
.setLayout(null);
301 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
303 jContentPane
.add(getJButtonAdd(), null);
304 jContentPane
.add(getJButtonRemove(), null);
305 jContentPane
.add(getJButtonUpdate(), null);
306 jContentPane
.add(getJScrollPaneTable(), null);
311 private void showEdit(int index
) {
312 ProtocolsDlg dlg
= new ProtocolsDlg(vid
.getProtocols(index
), new IFrame(), omt
.getId());
313 int result
= dlg
.showDialog();
314 if (result
== DataType
.RETURN_TYPE_OK
) {
316 this.vid
.addProtocols(dlg
.getId());
318 this.vid
.setProtocols(dlg
.getId(), index
);
324 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
333 private void clearAll() {
335 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
336 model
.removeRow(index
);
342 Read content of vector and put then into table
345 private void showTable() {
348 if (vid
.size() > 0) {
349 for (int index
= 0; index
< vid
.size(); index
++) {
350 model
.addRow(vid
.toStringVector(index
));
353 this.jTable
.repaint();
354 this.jTable
.updateUI();
358 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
360 * Override actionPerformed to listen all actions
363 public void actionPerformed(ActionEvent arg0
) {
364 if (arg0
.getSource() == jButtonAdd
) {
367 if (arg0
.getSource() == jButtonUpdate
) {
368 if (this.selectedRow
< 0) {
369 Log
.wrn("Update Protocols", "Please select one record first.");
372 showEdit(selectedRow
);
375 if (arg0
.getSource() == jButtonRemove
) {
376 if (jTable
.isEditing()) {
377 jTable
.getCellEditor().stopCellEditing();
379 if (selectedRow
> -1) {
380 this.model
.removeRow(selectedRow
);
381 this.vid
.removeProtocols(selectedRow
);
389 Save all components of Protocols
390 if exists protocols, set the value directly
391 if not exists protocols, new an instance first
396 int count
= this.vid
.size();
398 this.protocols
= Protocols
.Factory
.newInstance();
400 for (int index
= 0; index
< count
; index
++) {
401 if (vid
.getProtocols(index
).getType().equals(ed
.getVProtocolType().get(0))) {
402 Protocol p
= Protocol
.Factory
.newInstance();
403 if (!isEmpty(vid
.getProtocols(index
).getName())) {
404 p
.setProtocolCName(vid
.getProtocols(index
).getName());
406 if (!isEmpty(vid
.getProtocols(index
).getUsage())) {
407 p
.setUsage(ProtocolUsage
.Enum
.forString(vid
.getProtocols(index
).getUsage()));
409 if (!isEmpty(vid
.getProtocols(index
).getFeatureFlag())) {
410 p
.setFeatureFlag(vid
.getProtocols(index
).getFeatureFlag());
412 if (vid
.getProtocols(index
).getSupArchList() != null
413 && vid
.getProtocols(index
).getSupArchList().size() > 0) {
414 p
.setSupArchList(vid
.getProtocols(index
).getSupArchList());
416 if (!isEmpty(vid
.getProtocols(index
).getHelp())) {
417 p
.setHelpText(vid
.getProtocols(index
).getHelp());
419 this.protocols
.addNewProtocol();
420 this.protocols
.setProtocolArray(protocols
.getProtocolList().size() - 1, p
);
422 if (vid
.getProtocols(index
).getType().equals(ed
.getVProtocolType().get(1))) {
423 ProtocolNotify p
= ProtocolNotify
.Factory
.newInstance();
424 if (!isEmpty(vid
.getProtocols(index
).getName())) {
425 p
.setProtocolNotifyCName(vid
.getProtocols(index
).getName());
427 if (!isEmpty(vid
.getProtocols(index
).getUsage())) {
428 p
.setUsage(ProtocolNotifyUsage
.Enum
.forString(vid
.getProtocols(index
).getUsage()));
430 if (!isEmpty(vid
.getProtocols(index
).getFeatureFlag())) {
431 p
.setFeatureFlag(vid
.getProtocols(index
).getFeatureFlag());
433 if (vid
.getProtocols(index
).getSupArchList() != null
434 && vid
.getProtocols(index
).getSupArchList().size() > 0) {
435 p
.setSupArchList(vid
.getProtocols(index
).getSupArchList());
437 if (!isEmpty(vid
.getProtocols(index
).getHelp())) {
438 p
.setHelpText(vid
.getProtocols(index
).getHelp());
440 this.protocols
.addNewProtocolNotify();
441 this.protocols
.setProtocolNotifyArray(protocols
.getProtocolNotifyList().size() - 1, p
);
446 this.msa
.setProtocols(protocols
);
447 this.omt
.setSaved(false);
448 } catch (Exception e
) {
449 Log
.wrn("Update Protocols", e
.getMessage());
450 Log
.err("Update Protocols", e
.getMessage());
455 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
458 public void valueChanged(ListSelectionEvent arg0
) {
459 if (arg0
.getValueIsAdjusting()) {
462 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
463 if (lsm
.isSelectionEmpty()) {
466 selectedRow
= lsm
.getMinSelectionIndex();
471 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
474 public void mouseClicked(MouseEvent arg0
) {
475 if (arg0
.getClickCount() == 2) {
476 if (this.selectedRow
< 0) {
479 showEdit(selectedRow
);
485 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
487 * Override componentResized to resize all components when frame's size is changed
489 public void componentResized(ComponentEvent arg0
) {
490 int intCurrentWidth
= this.getJContentPane().getWidth();
491 int intCurrentHeight
= this.getJContentPane().getHeight();
492 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
493 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
495 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
497 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
498 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
499 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
500 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
501 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
502 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
503 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
504 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
505 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);