3 The file is used to create, update Library Class Definition 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
.LibraryClassDefinitionsDocument
;
31 import org
.tianocore
.LibraryUsage
;
32 import org
.tianocore
.ModuleSurfaceAreaDocument
;
33 import org
.tianocore
.LibraryClassDefinitionsDocument
.LibraryClassDefinitions
;
34 import org
.tianocore
.LibraryClassDocument
.LibraryClass
;
35 import org
.tianocore
.frameworkwizard
.common
.DataType
;
36 import org
.tianocore
.frameworkwizard
.common
.IDefaultTableModel
;
37 import org
.tianocore
.frameworkwizard
.common
.Log
;
38 import org
.tianocore
.frameworkwizard
.common
.Tools
;
39 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
40 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
41 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
42 import org
.tianocore
.frameworkwizard
.module
.Identifications
.LibraryClass
.LibraryClassIdentification
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.LibraryClass
.LibraryClassVector
;
44 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.LibraryClassDefsDlg
;
47 The class is used to create, update Library Class Definition of MSA/MBD file
48 It extends IInternalFrame
51 public class ModuleLibraryClassDefinitions
extends IInternalFrame
{
54 /// Define class Serial Version UID
56 private static final long serialVersionUID
= -1743248695411382857L;
59 //Define class members
61 private JPanel jContentPane
= null;
63 private JButton jButtonAdd
= null;
65 private JButton jButtonRemove
= null;
67 private JButton jButtonUpdate
= null;
69 private JScrollPane jScrollPane
= null;
71 private JScrollPane jScrollPaneTable
= null;
73 private JTable jTable
= null;
78 private ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= null;
80 private LibraryClassDefinitions lcd
= null;
82 private LibraryClassVector vLibraryClass
= new LibraryClassVector();
84 private OpeningModuleType omt
= null;
86 private IDefaultTableModel model
= null;
88 private int selectedRow
= -1;
90 private IFrame parentFrame
= null;
93 This method initializes jButtonAdd
95 @return javax.swing.JButton jButtonAdd
98 private JButton
getJButtonAdd() {
99 if (jButtonAdd
== null) {
100 jButtonAdd
= new JButton();
101 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 330, 90, 20));
102 jButtonAdd
.setPreferredSize(new Dimension(90, 20));
103 jButtonAdd
.setText("Add");
104 jButtonAdd
.addActionListener(this);
110 This method initializes jButtonRemove
112 @return javax.swing.JButton jButtonRemove
115 private JButton
getJButtonRemove() {
116 if (jButtonRemove
== null) {
117 jButtonRemove
= new JButton();
118 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 330, 90, 20));
119 jButtonRemove
.setText("Remove");
120 jButtonRemove
.setPreferredSize(new Dimension(90, 20));
121 jButtonRemove
.addActionListener(this);
123 return jButtonRemove
;
127 This method initializes jButtonUpdate
129 @return javax.swing.JButton jButtonUpdate
132 private JButton
getJButtonUpdate() {
133 if (jButtonUpdate
== null) {
134 jButtonUpdate
= new JButton();
135 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 330, 90, 20));
136 jButtonUpdate
.setText("Edit");
137 jButtonUpdate
.setPreferredSize(new Dimension(90, 20));
138 jButtonUpdate
.addActionListener(this);
140 return jButtonUpdate
;
144 This method initializes jScrollPane
146 @return javax.swing.JScrollPane
148 private JScrollPane
getJScrollPane() {
149 if (jScrollPane
== null) {
150 jScrollPane
= new JScrollPane();
151 jScrollPane
.setViewportView(getJContentPane());
157 This method initializes jScrollPaneTable
159 @return javax.swing.JScrollPane
161 private JScrollPane
getJScrollPaneTable() {
162 if (jScrollPaneTable
== null) {
163 jScrollPaneTable
= new JScrollPane();
164 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
165 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
166 jScrollPaneTable
.setViewportView(getJTable());
168 return jScrollPaneTable
;
172 This method initializes jTable
174 @return javax.swing.JTable
176 private JTable
getJTable() {
177 if (jTable
== null) {
178 jTable
= new JTable();
179 model
= new IDefaultTableModel();
180 jTable
= new JTable(model
);
181 jTable
.setRowHeight(20);
183 model
.addColumn("Library Class Name");
184 model
.addColumn("Usage");
186 jTable
.setSelectionMode(ListSelectionModel
.MULTIPLE_INTERVAL_SELECTION
);
187 jTable
.getSelectionModel().addListSelectionListener(this);
188 jTable
.getModel().addTableModelListener(this);
189 jTable
.addMouseListener(this);
194 public static void main(String
[] args
) {
199 This is the default constructor
202 public ModuleLibraryClassDefinitions() {
205 this.setVisible(true);
209 This is the override edit constructor
214 public ModuleLibraryClassDefinitions(OpeningModuleType inOmt
, IFrame iFrame
) {
217 this.msa
= omt
.getXmlMsa();
218 this.parentFrame
= iFrame
;
219 init(msa
.getLibraryClassDefinitions());
220 this.setVisible(true);
224 This method initializes this
225 Fill values to all fields if these values are not empty
227 @param inLibraryClassDefinitions The input data of LibraryClassDefinitionsDocument.LibraryClassDefinitions
230 private void init(LibraryClassDefinitionsDocument
.LibraryClassDefinitions inLibraryClassDefinitions
) {
232 this.lcd
= inLibraryClassDefinitions
;
233 if (this.lcd
!= null) {
234 if (this.lcd
.getLibraryClassList().size() > 0) {
235 for (int index
= 0; index
< this.lcd
.getLibraryClassList().size(); index
++) {
236 String name
= lcd
.getLibraryClassList().get(index
).getKeyword();
238 if (lcd
.getLibraryClassList().get(index
).getUsage() != null) {
239 usage
= lcd
.getLibraryClassList().get(index
).getUsage().toString();
241 String version
= lcd
.getLibraryClassList().get(index
).getRecommendedInstanceVersion();
242 String guid
= lcd
.getLibraryClassList().get(index
).getRecommendedInstanceGuid();
243 String featureFlag
= lcd
.getLibraryClassList().get(index
).getFeatureFlag();
244 Vector
<String
> arch
= Tools
.convertListToVector(lcd
.getLibraryClassList().get(index
)
246 Vector
<String
> module
= Tools
.convertListToVector(lcd
.getLibraryClassList().get(index
)
247 .getSupModuleList());
248 String help
= lcd
.getLibraryClassList().get(index
).getHelpText();
249 LibraryClassIdentification lcid
= new LibraryClassIdentification(name
, usage
, version
, guid
, arch
,
250 featureFlag
, module
, help
);
251 vLibraryClass
.addLibraryClass(lcid
);
262 This method initializes this
265 private void init() {
266 this.setContentPane(getJScrollPane());
267 this.setTitle("Library Class Definitions");
268 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 515));
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);
292 Save all components of Mbd Header
293 if exists mbdHeader, set the value directly
294 if not exists mbdHeader, new an instance first
299 int intLibraryCount
= this.vLibraryClass
.size();
301 lcd
= LibraryClassDefinitions
.Factory
.newInstance();
302 if (intLibraryCount
> 0) {
303 for (int index
= 0; index
< intLibraryCount
; index
++) {
304 LibraryClass mLibraryClass
= LibraryClass
.Factory
.newInstance();
306 mLibraryClass
.setKeyword(vLibraryClass
.getLibraryClass(index
).getLibraryClassName());
308 .setUsage(LibraryUsage
.Enum
.forString(vLibraryClass
.getLibraryClass(index
).getUsage()));
309 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getRecommendedInstanceVersion())) {
310 mLibraryClass
.setRecommendedInstanceVersion(vLibraryClass
.getLibraryClass(index
)
311 .getRecommendedInstanceVersion());
313 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getRecommendedInstanceGuid())) {
314 mLibraryClass
.setRecommendedInstanceGuid(vLibraryClass
.getLibraryClass(index
)
315 .getRecommendedInstanceGuid());
317 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getFeatureFlag())) {
318 mLibraryClass
.setFeatureFlag(vLibraryClass
.getLibraryClass(index
).getFeatureFlag());
320 if (vLibraryClass
.getLibraryClass(index
).getSupArchList() != null
321 && vLibraryClass
.getLibraryClass(index
).getSupArchList().size() > 0) {
322 mLibraryClass
.setSupArchList(vLibraryClass
.getLibraryClass(index
).getSupArchList());
324 if (vLibraryClass
.getLibraryClass(index
).getSupModuleList() != null
325 && vLibraryClass
.getLibraryClass(index
).getSupModuleList().size() > 0) {
326 mLibraryClass
.setSupModuleList(vLibraryClass
.getLibraryClass(index
).getSupModuleList());
328 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getHelp())) {
329 mLibraryClass
.setHelpText(vLibraryClass
.getLibraryClass(index
).getHelp());
332 this.lcd
.addNewLibraryClass();
333 this.lcd
.setLibraryClassArray(index
, mLibraryClass
);
337 if (msa
.getLibraryClassDefinitions() == null) {
338 this.msa
.addNewLibraryClassDefinitions();
340 this.msa
.setLibraryClassDefinitions(this.lcd
);
342 this.omt
.setSaved(false);
343 } catch (Exception e
) {
344 Log
.wrn("Update Library Class Definitions", e
.getMessage());
345 Log
.err("Update Library Class Definitions", e
.getMessage());
349 private void showEdit(int index
) {
350 LibraryClassDefsDlg mcdd
= new LibraryClassDefsDlg(vLibraryClass
.getLibraryClass(index
), this.parentFrame
, omt
.getId());
351 int result
= mcdd
.showDialog();
352 if (result
== DataType
.RETURN_TYPE_OK
) {
354 this.vLibraryClass
.addLibraryClass(mcdd
.getLcid());
356 this.vLibraryClass
.setLibraryClass(mcdd
.getLcid(), index
);
362 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
368 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
370 * Override actionPerformed to listen all actions
373 public void actionPerformed(ActionEvent arg0
) {
374 if (arg0
.getSource() == jButtonAdd
) {
377 if (arg0
.getSource() == jButtonUpdate
) {
378 if (this.selectedRow
< 0) {
379 Log
.wrn("Update Library Class Definitions", "Please select one record first.");
382 showEdit(selectedRow
);
385 if (arg0
.getSource() == jButtonRemove
) {
386 if (jTable
.isEditing()) {
387 jTable
.getCellEditor().stopCellEditing();
390 int selectedRows
[] = this.jTable
.getSelectedRows();
392 if (selectedRows
!= null) {
393 for (int index
= selectedRows
.length
- 1; index
> -1; index
--) {
394 this.model
.removeRow(selectedRows
[index
]);
395 this.vLibraryClass
.removeLibraryClass(selectedRows
[index
]);
407 private void clearAll() {
409 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
410 model
.removeRow(index
);
416 Read content of vector and put then into table
419 private void showTable() {
422 if (vLibraryClass
.size() > 0) {
423 for (int index
= 0; index
< vLibraryClass
.size(); index
++) {
424 model
.addRow(vLibraryClass
.toStringVector(index
));
427 this.jTable
.repaint();
428 this.jTable
.updateUI();
429 //this.jScrollPane.setViewportView(this.jTable);
433 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
436 public void valueChanged(ListSelectionEvent arg0
) {
437 if (arg0
.getValueIsAdjusting()) {
440 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
441 if (lsm
.isSelectionEmpty()) {
444 selectedRow
= lsm
.getMinSelectionIndex();
449 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
452 public void mouseClicked(MouseEvent arg0
) {
453 if (arg0
.getClickCount() == 2) {
454 if (this.selectedRow
< 0) {
457 showEdit(selectedRow
);
463 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
465 * Override componentResized to resize all components when frame's size is changed
467 public void componentResized(ComponentEvent arg0
) {
468 int intCurrentWidth
= this.getJContentPane().getWidth();
469 int intCurrentHeight
= this.getJContentPane().getHeight();
470 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
471 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
473 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
475 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
476 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
477 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
478 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
479 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
480 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
481 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
482 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
483 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);