3 The file is used to create, update DataHub 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
.DataHubUsage
;
32 import org
.tianocore
.DataHubsDocument
;
33 import org
.tianocore
.DataHubsDocument
.DataHubs
;
34 import org
.tianocore
.DataHubsDocument
.DataHubs
.DataHubRecord
;
35 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
36 import org
.tianocore
.frameworkwizard
.common
.DataType
;
37 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
38 import org
.tianocore
.frameworkwizard
.common
.Log
;
39 import org
.tianocore
.frameworkwizard
.common
.Tools
;
40 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
41 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
42 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.DataHubs
.DataHubsIdentification
;
44 import org
.tianocore
.frameworkwizard
.module
.Identifications
.DataHubs
.DataHubsVector
;
45 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.DataHubsDlg
;
48 The class is used to create, update DataHub of MSA/MBD file
49 It extends IInternalFrame
54 public class ModuleDataHubs
extends IInternalFrame
{
57 /// Define class Serial Version UID
59 private static final long serialVersionUID
= -3667906991966638892L;
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;
81 private OpeningModuleType omt
= null;
83 private ModuleSurfaceArea msa
= null;
85 private DataHubsDocument
.DataHubs dataHubs
= null;
87 private DataHubsIdentification id
= null;
89 private DataHubsVector vid
= new DataHubsVector();
91 private IDefaultTableModel model
= null;
93 private int selectedRow
= -1;
96 This method initializes jButtonAdd
98 @return javax.swing.JButton jButtonAdd
101 private JButton
getJButtonAdd() {
102 if (jButtonAdd
== null) {
103 jButtonAdd
= new JButton();
104 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 195, 90, 20));
105 jButtonAdd
.setText("Add");
106 jButtonAdd
.addActionListener(this);
107 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
113 This method initializes jButtonRemove
115 @return javax.swing.JButton jButtonRemove
118 private JButton
getJButtonRemove() {
119 if (jButtonRemove
== null) {
120 jButtonRemove
= new JButton();
121 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 195, 90, 20));
122 jButtonRemove
.setText("Remove");
123 jButtonRemove
.addActionListener(this);
124 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
126 return jButtonRemove
;
130 This method initializes jButtonUpdate
132 @return javax.swing.JButton jButtonUpdate
135 private JButton
getJButtonUpdate() {
136 if (jButtonUpdate
== null) {
137 jButtonUpdate
= new JButton();
138 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 195, 90, 20));
139 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
140 jButtonUpdate
.setText("Edit");
141 jButtonUpdate
.addActionListener(this);
143 return jButtonUpdate
;
147 This method initializes jScrollPane
149 @return javax.swing.JScrollPane
151 private JScrollPane
getJScrollPane() {
152 if (jScrollPane
== null) {
153 jScrollPane
= new JScrollPane();
154 jScrollPane
.setViewportView(getJContentPane());
160 This method initializes jScrollPaneTable
162 @return javax.swing.JScrollPane
164 private JScrollPane
getJScrollPaneTable() {
165 if (jScrollPaneTable
== null) {
166 jScrollPaneTable
= new JScrollPane();
167 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
168 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
169 jScrollPaneTable
.setViewportView(getJTable());
171 return jScrollPaneTable
;
175 This method initializes jTable
177 @return javax.swing.JTable
179 private JTable
getJTable() {
180 if (jTable
== null) {
181 jTable
= new JTable();
182 model
= new IDefaultTableModel();
183 jTable
= new JTable(model
);
184 jTable
.setRowHeight(20);
186 model
.addColumn("Data Hub C_Name");
187 model
.addColumn("Usage");
189 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
190 jTable
.getSelectionModel().addListSelectionListener(this);
191 jTable
.getModel().addTableModelListener(this);
192 jTable
.addMouseListener(this);
197 public static void main(String
[] args
) {
202 This method initializes this
205 private void init() {
206 this.setSize(500, 515);
207 this.setContentPane(getJScrollPane());
208 this.setTitle("Data Hubs");
212 This method initializes this
213 Fill values to all fields if these values are not empty
215 @param inPackageDependencies
218 private void init(DataHubs inDataHubs
) {
220 this.dataHubs
= inDataHubs
;
222 if (this.dataHubs
!= null) {
223 if (this.dataHubs
.getDataHubRecordList().size() > 0) {
224 for (int index
= 0; index
< this.dataHubs
.getDataHubRecordList().size(); index
++) {
225 String arg0
= dataHubs
.getDataHubRecordList().get(index
).getDataHubCName();
227 if (dataHubs
.getDataHubRecordList().get(index
).getUsage() != null) {
228 arg1
= dataHubs
.getDataHubRecordList().get(index
).getUsage().toString();
231 String arg2
= dataHubs
.getDataHubRecordList().get(index
).getFeatureFlag();
232 Vector
<String
> arg3
= Tools
.convertListToVector(dataHubs
.getDataHubRecordList().get(index
)
234 String arg4
= dataHubs
.getDataHubRecordList().get(index
).getHelpText();
236 id
= new DataHubsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
245 This is the default constructor
248 public ModuleDataHubs() {
251 this.setVisible(true);
255 This is the override edit constructor
257 @param inDataHubs The input DataHubsDocument.DataHubs
260 public ModuleDataHubs(OpeningModuleType inOmt
) {
263 this.msa
= omt
.getXmlMsa();
264 init(msa
.getDataHubs());
265 this.setVisible(true);
269 This method initializes jContentPane
271 @return javax.swing.JPanel jContentPane
274 private JPanel
getJContentPane() {
275 if (jContentPane
== null) {
276 jContentPane
= new JPanel();
277 jContentPane
.setLayout(null);
278 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
280 jContentPane
.add(getJButtonAdd(), null);
281 jContentPane
.add(getJButtonRemove(), null);
282 jContentPane
.add(getJButtonUpdate(), null);
283 jContentPane
.add(getJScrollPaneTable(), null);
288 private void showEdit(int index
) {
289 DataHubsDlg dlg
= new DataHubsDlg(vid
.getDataHubs(index
), new IFrame(), omt
.getId());
290 int result
= dlg
.showDialog();
291 if (result
== DataType
.RETURN_TYPE_OK
) {
293 this.vid
.addDataHubs(dlg
.getId());
295 this.vid
.setDataHubs(dlg
.getId(), index
);
301 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
310 private void clearAll() {
312 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
313 model
.removeRow(index
);
319 Read content of vector and put then into table
322 private void showTable() {
325 if (vid
.size() > 0) {
326 for (int index
= 0; index
< vid
.size(); index
++) {
327 model
.addRow(vid
.toStringVector(index
));
330 this.jTable
.repaint();
331 this.jTable
.updateUI();
335 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
337 * Override actionPerformed to listen all actions
340 public void actionPerformed(ActionEvent arg0
) {
341 if (arg0
.getSource() == jButtonAdd
) {
344 if (arg0
.getSource() == jButtonUpdate
) {
345 if (this.selectedRow
< 0) {
346 Log
.wrn("Update Data Hubs", "Please select one record first.");
349 showEdit(selectedRow
);
352 if (arg0
.getSource() == jButtonRemove
) {
353 if (jTable
.isEditing()) {
354 jTable
.getCellEditor().stopCellEditing();
356 if (selectedRow
> -1) {
357 this.model
.removeRow(selectedRow
);
358 this.vid
.removeDataHubs(selectedRow
);
366 Save all components of DataHubs
367 if exists dataHubs, set the value directly
368 if not exists dataHubs, new an instance first
373 int count
= this.vid
.size();
375 this.dataHubs
= DataHubs
.Factory
.newInstance();
377 for (int index
= 0; index
< count
; index
++) {
378 DataHubRecord p
= DataHubRecord
.Factory
.newInstance();
379 if (!isEmpty(vid
.getDataHubs(index
).getName())) {
380 p
.setDataHubCName(vid
.getDataHubs(index
).getName());
382 if (!isEmpty(vid
.getDataHubs(index
).getUsage())) {
383 p
.setUsage(DataHubUsage
.Enum
.forString(vid
.getDataHubs(index
).getUsage()));
385 if (!isEmpty(vid
.getDataHubs(index
).getFeatureFlag())) {
386 p
.setFeatureFlag(vid
.getDataHubs(index
).getFeatureFlag());
388 if (vid
.getDataHubs(index
).getSupArchList() != null
389 && vid
.getDataHubs(index
).getSupArchList().size() > 0) {
390 p
.setSupArchList(vid
.getDataHubs(index
).getSupArchList());
392 if (!isEmpty(vid
.getDataHubs(index
).getHelp())) {
393 p
.setHelpText(vid
.getDataHubs(index
).getHelp());
395 this.dataHubs
.addNewDataHubRecord();
396 this.dataHubs
.setDataHubRecordArray(dataHubs
.getDataHubRecordList().size() - 1, p
);
400 this.msa
.setDataHubs(dataHubs
);
401 this.omt
.setSaved(false);
402 } catch (Exception e
) {
403 Log
.wrn("Update Data Hubs", e
.getMessage());
404 Log
.err("Update Data Hubs", e
.getMessage());
409 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
412 public void valueChanged(ListSelectionEvent arg0
) {
413 if (arg0
.getValueIsAdjusting()) {
416 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
417 if (lsm
.isSelectionEmpty()) {
420 selectedRow
= lsm
.getMinSelectionIndex();
425 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
428 public void mouseClicked(MouseEvent arg0
) {
429 if (arg0
.getClickCount() == 2) {
430 if (this.selectedRow
< 0) {
433 showEdit(selectedRow
);
439 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
441 * Override componentResized to resize all components when frame's size is changed
443 public void componentResized(ComponentEvent arg0
) {
444 int intCurrentWidth
= this.getJContentPane().getWidth();
445 int intCurrentHeight
= this.getJContentPane().getHeight();
446 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
447 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
449 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
451 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
452 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
453 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
454 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
455 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
456 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
457 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
458 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
459 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);