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;
95 private IFrame parentFrame
= null;
98 This method initializes jButtonAdd
100 @return javax.swing.JButton jButtonAdd
103 private JButton
getJButtonAdd() {
104 if (jButtonAdd
== null) {
105 jButtonAdd
= new JButton();
106 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 195, 90, 20));
107 jButtonAdd
.setText("Add");
108 jButtonAdd
.addActionListener(this);
109 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
115 This method initializes jButtonRemove
117 @return javax.swing.JButton jButtonRemove
120 private JButton
getJButtonRemove() {
121 if (jButtonRemove
== null) {
122 jButtonRemove
= new JButton();
123 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 195, 90, 20));
124 jButtonRemove
.setText("Remove");
125 jButtonRemove
.addActionListener(this);
126 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
128 return jButtonRemove
;
132 This method initializes jButtonUpdate
134 @return javax.swing.JButton jButtonUpdate
137 private JButton
getJButtonUpdate() {
138 if (jButtonUpdate
== null) {
139 jButtonUpdate
= new JButton();
140 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 195, 90, 20));
141 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
142 jButtonUpdate
.setText("Edit");
143 jButtonUpdate
.addActionListener(this);
145 return jButtonUpdate
;
149 This method initializes jScrollPane
151 @return javax.swing.JScrollPane
153 private JScrollPane
getJScrollPane() {
154 if (jScrollPane
== null) {
155 jScrollPane
= new JScrollPane();
156 jScrollPane
.setViewportView(getJContentPane());
162 This method initializes jScrollPaneTable
164 @return javax.swing.JScrollPane
166 private JScrollPane
getJScrollPaneTable() {
167 if (jScrollPaneTable
== null) {
168 jScrollPaneTable
= new JScrollPane();
169 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
170 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
171 jScrollPaneTable
.setViewportView(getJTable());
173 return jScrollPaneTable
;
177 This method initializes jTable
179 @return javax.swing.JTable
181 private JTable
getJTable() {
182 if (jTable
== null) {
183 jTable
= new JTable();
184 model
= new IDefaultTableModel();
185 jTable
= new JTable(model
);
186 jTable
.setRowHeight(20);
188 model
.addColumn("Data Hub C_Name");
189 model
.addColumn("Usage");
191 jTable
.setSelectionMode(ListSelectionModel
.MULTIPLE_INTERVAL_SELECTION
);
192 jTable
.getSelectionModel().addListSelectionListener(this);
193 jTable
.getModel().addTableModelListener(this);
194 jTable
.addMouseListener(this);
199 public static void main(String
[] args
) {
204 This method initializes this
207 private void init() {
208 this.setSize(500, 515);
209 this.setContentPane(getJScrollPane());
210 this.setTitle("Data Hubs");
214 This method initializes this
215 Fill values to all fields if these values are not empty
217 @param inPackageDependencies
220 private void init(DataHubs inDataHubs
) {
222 this.dataHubs
= inDataHubs
;
224 if (this.dataHubs
!= null) {
225 if (this.dataHubs
.getDataHubRecordList().size() > 0) {
226 for (int index
= 0; index
< this.dataHubs
.getDataHubRecordList().size(); index
++) {
227 String arg0
= dataHubs
.getDataHubRecordList().get(index
).getDataHubCName();
229 if (dataHubs
.getDataHubRecordList().get(index
).getUsage() != null) {
230 arg1
= dataHubs
.getDataHubRecordList().get(index
).getUsage().toString();
233 String arg2
= dataHubs
.getDataHubRecordList().get(index
).getFeatureFlag();
234 Vector
<String
> arg3
= Tools
.convertListToVector(dataHubs
.getDataHubRecordList().get(index
)
236 String arg4
= dataHubs
.getDataHubRecordList().get(index
).getHelpText();
238 id
= new DataHubsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
);
247 This is the default constructor
250 public ModuleDataHubs() {
253 this.setVisible(true);
257 This is the override edit constructor
259 @param inDataHubs The input DataHubsDocument.DataHubs
262 public ModuleDataHubs(OpeningModuleType inOmt
, IFrame iFrame
) {
265 this.msa
= omt
.getXmlMsa();
266 this.parentFrame
= iFrame
;
267 init(msa
.getDataHubs());
268 this.setVisible(true);
272 This method initializes jContentPane
274 @return javax.swing.JPanel jContentPane
277 private JPanel
getJContentPane() {
278 if (jContentPane
== null) {
279 jContentPane
= new JPanel();
280 jContentPane
.setLayout(null);
281 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
283 jContentPane
.add(getJButtonAdd(), null);
284 jContentPane
.add(getJButtonRemove(), null);
285 jContentPane
.add(getJButtonUpdate(), null);
286 jContentPane
.add(getJScrollPaneTable(), null);
291 private void showEdit(int index
) {
292 DataHubsDlg dlg
= new DataHubsDlg(vid
.getDataHubs(index
), this.parentFrame
, omt
.getId());
293 int result
= dlg
.showDialog();
294 if (result
== DataType
.RETURN_TYPE_OK
) {
296 this.vid
.addDataHubs(dlg
.getId());
298 this.vid
.setDataHubs(dlg
.getId(), index
);
304 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
313 private void clearAll() {
315 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
316 model
.removeRow(index
);
322 Read content of vector and put then into table
325 private void showTable() {
328 if (vid
.size() > 0) {
329 for (int index
= 0; index
< vid
.size(); index
++) {
330 model
.addRow(vid
.toStringVector(index
));
333 this.jTable
.repaint();
334 this.jTable
.updateUI();
338 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
340 * Override actionPerformed to listen all actions
343 public void actionPerformed(ActionEvent arg0
) {
344 if (arg0
.getSource() == jButtonAdd
) {
347 if (arg0
.getSource() == jButtonUpdate
) {
348 if (this.selectedRow
< 0) {
349 Log
.wrn("Update Data Hubs", "Please select one record first.");
352 showEdit(selectedRow
);
355 if (arg0
.getSource() == jButtonRemove
) {
356 if (jTable
.isEditing()) {
357 jTable
.getCellEditor().stopCellEditing();
360 int selectedRows
[] = this.jTable
.getSelectedRows();
362 if (selectedRows
!= null) {
363 for (int index
= selectedRows
.length
- 1; index
> -1; index
--) {
364 this.model
.removeRow(selectedRows
[index
]);
365 this.vid
.removeDataHubs(selectedRows
[index
]);
374 Save all components of DataHubs
375 if exists dataHubs, set the value directly
376 if not exists dataHubs, new an instance first
381 int count
= this.vid
.size();
383 this.dataHubs
= DataHubs
.Factory
.newInstance();
385 for (int index
= 0; index
< count
; index
++) {
386 DataHubRecord p
= DataHubRecord
.Factory
.newInstance();
387 if (!isEmpty(vid
.getDataHubs(index
).getName())) {
388 p
.setDataHubCName(vid
.getDataHubs(index
).getName());
390 if (!isEmpty(vid
.getDataHubs(index
).getUsage())) {
391 p
.setUsage(DataHubUsage
.Enum
.forString(vid
.getDataHubs(index
).getUsage()));
393 if (!isEmpty(vid
.getDataHubs(index
).getFeatureFlag())) {
394 p
.setFeatureFlag(vid
.getDataHubs(index
).getFeatureFlag());
396 if (vid
.getDataHubs(index
).getSupArchList() != null
397 && vid
.getDataHubs(index
).getSupArchList().size() > 0) {
398 p
.setSupArchList(vid
.getDataHubs(index
).getSupArchList());
400 if (!isEmpty(vid
.getDataHubs(index
).getHelp())) {
401 p
.setHelpText(vid
.getDataHubs(index
).getHelp());
403 this.dataHubs
.addNewDataHubRecord();
404 this.dataHubs
.setDataHubRecordArray(dataHubs
.getDataHubRecordList().size() - 1, p
);
408 this.msa
.setDataHubs(dataHubs
);
409 this.omt
.setSaved(false);
410 } catch (Exception e
) {
411 Log
.wrn("Update Data Hubs", e
.getMessage());
412 Log
.err("Update Data Hubs", e
.getMessage());
417 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
420 public void valueChanged(ListSelectionEvent arg0
) {
421 if (arg0
.getValueIsAdjusting()) {
424 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
425 if (lsm
.isSelectionEmpty()) {
428 selectedRow
= lsm
.getMinSelectionIndex();
433 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
436 public void mouseClicked(MouseEvent arg0
) {
437 if (arg0
.getClickCount() == 2) {
438 if (this.selectedRow
< 0) {
441 showEdit(selectedRow
);
447 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
449 * Override componentResized to resize all components when frame's size is changed
451 public void componentResized(ComponentEvent arg0
) {
452 int intCurrentWidth
= this.getJContentPane().getWidth();
453 int intCurrentHeight
= this.getJContentPane().getHeight();
454 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
455 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
457 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
459 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
460 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
461 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
462 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
463 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
464 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
465 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
466 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
467 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);