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;
100 private IFrame parentFrame
= null;
103 This method initializes jButtonAdd
105 @return javax.swing.JButton jButtonAdd
108 private JButton
getJButtonAdd() {
109 if (jButtonAdd
== null) {
110 jButtonAdd
= new JButton();
111 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 220, 90, 20));
112 jButtonAdd
.setText("Add");
113 jButtonAdd
.addActionListener(this);
114 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
120 This method initializes jButtonRemove
122 @return javax.swing.JButton jButtonRemove
125 private JButton
getJButtonRemove() {
126 if (jButtonRemove
== null) {
127 jButtonRemove
= new JButton();
128 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 220, 90, 20));
129 jButtonRemove
.setText("Remove");
130 jButtonRemove
.addActionListener(this);
131 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
133 return jButtonRemove
;
137 This method initializes jButtonUpdate
139 @return javax.swing.JButton jButtonUpdate
142 private JButton
getJButtonUpdate() {
143 if (jButtonUpdate
== null) {
144 jButtonUpdate
= new JButton();
145 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 220, 90, 20));
146 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
147 jButtonUpdate
.setText("Edit");
148 jButtonUpdate
.addActionListener(this);
150 return jButtonUpdate
;
154 This method initializes jScrollPane
156 @return javax.swing.JScrollPane
158 private JScrollPane
getJScrollPane() {
159 if (jScrollPane
== null) {
160 jScrollPane
= new JScrollPane();
161 jScrollPane
.setViewportView(getJContentPane());
167 This method initializes jScrollPaneTable
169 @return javax.swing.JScrollPane
171 private JScrollPane
getJScrollPaneTable() {
172 if (jScrollPaneTable
== null) {
173 jScrollPaneTable
= new JScrollPane();
174 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
175 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
176 jScrollPaneTable
.setViewportView(getJTable());
178 return jScrollPaneTable
;
182 This method initializes jTable
184 @return javax.swing.JTable
186 private JTable
getJTable() {
187 if (jTable
== null) {
188 jTable
= new JTable();
189 model
= new IDefaultTableModel();
190 jTable
= new JTable(model
);
191 jTable
.setRowHeight(20);
193 model
.addColumn("Guid C_Name");
194 model
.addColumn("Type");
195 model
.addColumn("Usage");
197 jTable
.setSelectionMode(ListSelectionModel
.MULTIPLE_INTERVAL_SELECTION
);
198 jTable
.getSelectionModel().addListSelectionListener(this);
199 jTable
.getModel().addTableModelListener(this);
200 jTable
.addMouseListener(this);
205 public static void main(String
[] args
) {
210 This method initializes this
213 private void init() {
214 this.setSize(500, 515);
215 this.setContentPane(getJScrollPane());
216 this.setTitle("Protocols");
220 This method initializes this
221 Fill values to all fields if these values are not empty
223 @param inPackageDependencies
226 private void init(Protocols inProtocols
) {
228 this.protocols
= inProtocols
;
230 if (this.protocols
!= null) {
231 if (this.protocols
.getProtocolList().size() > 0) {
232 for (int index
= 0; index
< this.protocols
.getProtocolList().size(); index
++) {
233 String arg0
= protocols
.getProtocolList().get(index
).getProtocolCName();
234 String arg1
= ed
.getVProtocolType().get(0);
236 if (protocols
.getProtocolList().get(index
).getUsage() != null) {
237 arg2
= protocols
.getProtocolList().get(index
).getUsage().toString();
240 String arg3
= protocols
.getProtocolList().get(index
).getFeatureFlag();
241 Vector
<String
> arg4
= Tools
.convertListToVector(protocols
.getProtocolList().get(index
)
243 String arg5
= protocols
.getProtocolList().get(index
).getHelpText();
244 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
245 vid
.addProtocols(id
);
248 if (this.protocols
.getProtocolNotifyList().size() > 0) {
249 for (int index
= 0; index
< this.protocols
.getProtocolNotifyList().size(); index
++) {
250 String arg0
= protocols
.getProtocolNotifyList().get(index
).getProtocolNotifyCName();
251 String arg1
= ed
.getVProtocolType().get(1);
253 if (protocols
.getProtocolNotifyList().get(index
).getUsage() != null) {
254 arg2
= protocols
.getProtocolNotifyList().get(index
).getUsage().toString();
257 String arg3
= protocols
.getProtocolNotifyList().get(index
).getFeatureFlag();
258 Vector
<String
> arg4
= Tools
.convertListToVector(protocols
.getProtocolNotifyList().get(index
)
260 String arg5
= protocols
.getProtocolNotifyList().get(index
).getHelpText();
261 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
262 vid
.addProtocols(id
);
270 This is the default constructor
273 public ModuleProtocols() {
276 this.setVisible(true);
280 This is the override edit constructor
282 @param inProtocol The input data of ProtocolsDocument.Protocols
285 public ModuleProtocols(OpeningModuleType inOmt
, IFrame iFrame
) {
288 this.msa
= omt
.getXmlMsa();
289 this.parentFrame
= iFrame
;
290 init(msa
.getProtocols());
291 this.setVisible(true);
295 This method initializes jContentPane
297 @return javax.swing.JPanel jContentPane
300 private JPanel
getJContentPane() {
301 if (jContentPane
== null) {
302 jContentPane
= new JPanel();
303 jContentPane
.setLayout(null);
304 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
306 jContentPane
.add(getJButtonAdd(), null);
307 jContentPane
.add(getJButtonRemove(), null);
308 jContentPane
.add(getJButtonUpdate(), null);
309 jContentPane
.add(getJScrollPaneTable(), null);
314 private void showEdit(int index
) {
315 ProtocolsDlg dlg
= new ProtocolsDlg(vid
.getProtocols(index
), this.parentFrame
, omt
.getId());
316 int result
= dlg
.showDialog();
317 if (result
== DataType
.RETURN_TYPE_OK
) {
319 this.vid
.addProtocols(dlg
.getId());
321 this.vid
.setProtocols(dlg
.getId(), index
);
327 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
336 private void clearAll() {
338 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
339 model
.removeRow(index
);
345 Read content of vector and put then into table
348 private void showTable() {
351 if (vid
.size() > 0) {
352 for (int index
= 0; index
< vid
.size(); index
++) {
353 model
.addRow(vid
.toStringVector(index
));
356 this.jTable
.repaint();
357 this.jTable
.updateUI();
361 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
363 * Override actionPerformed to listen all actions
366 public void actionPerformed(ActionEvent arg0
) {
367 if (arg0
.getSource() == jButtonAdd
) {
370 if (arg0
.getSource() == jButtonUpdate
) {
371 if (this.selectedRow
< 0) {
372 Log
.wrn("Update Protocols", "Please select one record first.");
375 showEdit(selectedRow
);
378 if (arg0
.getSource() == jButtonRemove
) {
379 if (jTable
.isEditing()) {
380 jTable
.getCellEditor().stopCellEditing();
383 int selectedRows
[] = this.jTable
.getSelectedRows();
385 if (selectedRows
!= null) {
386 for (int index
= selectedRows
.length
- 1; index
> -1; index
--) {
387 this.model
.removeRow(selectedRows
[index
]);
388 this.vid
.removeProtocols(selectedRows
[index
]);
397 Save all components of Protocols
398 if exists protocols, set the value directly
399 if not exists protocols, new an instance first
404 int count
= this.vid
.size();
406 this.protocols
= Protocols
.Factory
.newInstance();
408 for (int index
= 0; index
< count
; index
++) {
409 if (vid
.getProtocols(index
).getType().equals(ed
.getVProtocolType().get(0))) {
410 Protocol p
= Protocol
.Factory
.newInstance();
411 if (!isEmpty(vid
.getProtocols(index
).getName())) {
412 p
.setProtocolCName(vid
.getProtocols(index
).getName());
414 if (!isEmpty(vid
.getProtocols(index
).getUsage())) {
415 p
.setUsage(ProtocolUsage
.Enum
.forString(vid
.getProtocols(index
).getUsage()));
417 if (!isEmpty(vid
.getProtocols(index
).getFeatureFlag())) {
418 p
.setFeatureFlag(vid
.getProtocols(index
).getFeatureFlag());
420 if (vid
.getProtocols(index
).getSupArchList() != null
421 && vid
.getProtocols(index
).getSupArchList().size() > 0) {
422 p
.setSupArchList(vid
.getProtocols(index
).getSupArchList());
424 if (!isEmpty(vid
.getProtocols(index
).getHelp())) {
425 p
.setHelpText(vid
.getProtocols(index
).getHelp());
427 this.protocols
.addNewProtocol();
428 this.protocols
.setProtocolArray(protocols
.getProtocolList().size() - 1, p
);
430 if (vid
.getProtocols(index
).getType().equals(ed
.getVProtocolType().get(1))) {
431 ProtocolNotify p
= ProtocolNotify
.Factory
.newInstance();
432 if (!isEmpty(vid
.getProtocols(index
).getName())) {
433 p
.setProtocolNotifyCName(vid
.getProtocols(index
).getName());
435 if (!isEmpty(vid
.getProtocols(index
).getUsage())) {
436 p
.setUsage(ProtocolNotifyUsage
.Enum
.forString(vid
.getProtocols(index
).getUsage()));
438 if (!isEmpty(vid
.getProtocols(index
).getFeatureFlag())) {
439 p
.setFeatureFlag(vid
.getProtocols(index
).getFeatureFlag());
441 if (vid
.getProtocols(index
).getSupArchList() != null
442 && vid
.getProtocols(index
).getSupArchList().size() > 0) {
443 p
.setSupArchList(vid
.getProtocols(index
).getSupArchList());
445 if (!isEmpty(vid
.getProtocols(index
).getHelp())) {
446 p
.setHelpText(vid
.getProtocols(index
).getHelp());
448 this.protocols
.addNewProtocolNotify();
449 this.protocols
.setProtocolNotifyArray(protocols
.getProtocolNotifyList().size() - 1, p
);
454 this.msa
.setProtocols(protocols
);
455 this.omt
.setSaved(false);
456 } catch (Exception e
) {
457 Log
.wrn("Update Protocols", e
.getMessage());
458 Log
.err("Update Protocols", e
.getMessage());
463 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
466 public void valueChanged(ListSelectionEvent arg0
) {
467 if (arg0
.getValueIsAdjusting()) {
470 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
471 if (lsm
.isSelectionEmpty()) {
474 selectedRow
= lsm
.getMinSelectionIndex();
479 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
482 public void mouseClicked(MouseEvent arg0
) {
483 if (arg0
.getClickCount() == 2) {
484 if (this.selectedRow
< 0) {
487 showEdit(selectedRow
);
493 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
495 * Override componentResized to resize all components when frame's size is changed
497 public void componentResized(ComponentEvent arg0
) {
498 int intCurrentWidth
= this.getJContentPane().getWidth();
499 int intCurrentHeight
= this.getJContentPane().getHeight();
500 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
501 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
503 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
505 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
506 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
507 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
508 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
509 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
510 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
511 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
512 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
513 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);