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;
91 This method initializes jButtonAdd
93 @return javax.swing.JButton jButtonAdd
96 private JButton
getJButtonAdd() {
97 if (jButtonAdd
== null) {
98 jButtonAdd
= new JButton();
99 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 330, 80, 20));
100 jButtonAdd
.setPreferredSize(new Dimension(80, 20));
101 jButtonAdd
.setText("Add");
102 jButtonAdd
.addActionListener(this);
108 This method initializes jButtonRemove
110 @return javax.swing.JButton jButtonRemove
113 private JButton
getJButtonRemove() {
114 if (jButtonRemove
== null) {
115 jButtonRemove
= new JButton();
116 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 330, 80, 20));
117 jButtonRemove
.setText("Remove");
118 jButtonRemove
.setPreferredSize(new Dimension(80, 20));
119 jButtonRemove
.addActionListener(this);
121 return jButtonRemove
;
125 This method initializes jButtonUpdate
127 @return javax.swing.JButton jButtonUpdate
130 private JButton
getJButtonUpdate() {
131 if (jButtonUpdate
== null) {
132 jButtonUpdate
= new JButton();
133 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 330, 80, 20));
134 jButtonUpdate
.setText("Edit");
135 jButtonUpdate
.setPreferredSize(new Dimension(80, 20));
136 jButtonUpdate
.addActionListener(this);
138 return jButtonUpdate
;
142 This method initializes jScrollPane
144 @return javax.swing.JScrollPane
146 private JScrollPane
getJScrollPane() {
147 if (jScrollPane
== null) {
148 jScrollPane
= new JScrollPane();
149 jScrollPane
.setViewportView(getJContentPane());
155 This method initializes jScrollPaneTable
157 @return javax.swing.JScrollPane
159 private JScrollPane
getJScrollPaneTable() {
160 if (jScrollPaneTable
== null) {
161 jScrollPaneTable
= new JScrollPane();
162 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
163 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
164 jScrollPaneTable
.setViewportView(getJTable());
166 return jScrollPaneTable
;
170 This method initializes jTable
172 @return javax.swing.JTable
174 private JTable
getJTable() {
175 if (jTable
== null) {
176 jTable
= new JTable();
177 model
= new IDefaultTableModel();
178 jTable
= new JTable(model
);
179 jTable
.setRowHeight(20);
181 model
.addColumn("Library Class Name");
182 model
.addColumn("Usage");
184 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
185 jTable
.getSelectionModel().addListSelectionListener(this);
186 jTable
.getModel().addTableModelListener(this);
187 jTable
.addMouseListener(this);
192 public static void main(String
[] args
) {
197 This is the default constructor
200 public ModuleLibraryClassDefinitions() {
203 this.setVisible(true);
207 This is the override edit constructor
212 public ModuleLibraryClassDefinitions(OpeningModuleType inOmt
) {
215 this.msa
= omt
.getXmlMsa();
216 init(msa
.getLibraryClassDefinitions());
217 this.setVisible(true);
221 This method initializes this
222 Fill values to all fields if these values are not empty
224 @param inLibraryClassDefinitions The input data of LibraryClassDefinitionsDocument.LibraryClassDefinitions
227 private void init(LibraryClassDefinitionsDocument
.LibraryClassDefinitions inLibraryClassDefinitions
) {
229 this.lcd
= inLibraryClassDefinitions
;
230 if (this.lcd
!= null) {
231 if (this.lcd
.getLibraryClassList().size() > 0) {
232 for (int index
= 0; index
< this.lcd
.getLibraryClassList().size(); index
++) {
233 String name
= lcd
.getLibraryClassList().get(index
).getKeyword();
235 if (lcd
.getLibraryClassList().get(index
).getUsage() != null) {
236 usage
= lcd
.getLibraryClassList().get(index
).getUsage().toString();
238 String version
= lcd
.getLibraryClassList().get(index
).getRecommendedInstanceVersion();
239 String guid
= lcd
.getLibraryClassList().get(index
).getRecommendedInstanceGuid();
240 String featureFlag
= lcd
.getLibraryClassList().get(index
).getFeatureFlag();
241 Vector
<String
> arch
= Tools
.convertListToVector(lcd
.getLibraryClassList().get(index
)
243 Vector
<String
> module
= Tools
.convertListToVector(lcd
.getLibraryClassList().get(index
)
244 .getSupModuleList());
245 String help
= lcd
.getLibraryClassList().get(index
).getHelpText();
246 LibraryClassIdentification lcid
= new LibraryClassIdentification(name
, usage
, version
, guid
, arch
,
247 featureFlag
, module
, help
);
248 vLibraryClass
.addLibraryClass(lcid
);
259 This method initializes this
262 private void init() {
263 this.setContentPane(getJScrollPane());
264 this.setTitle("Library Class Definitions");
265 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 515));
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);
289 Save all components of Mbd Header
290 if exists mbdHeader, set the value directly
291 if not exists mbdHeader, new an instance first
296 int intLibraryCount
= this.vLibraryClass
.size();
298 lcd
= LibraryClassDefinitions
.Factory
.newInstance();
299 if (intLibraryCount
> 0) {
300 for (int index
= 0; index
< intLibraryCount
; index
++) {
301 LibraryClass mLibraryClass
= LibraryClass
.Factory
.newInstance();
303 mLibraryClass
.setKeyword(vLibraryClass
.getLibraryClass(index
).getLibraryClassName());
305 .setUsage(LibraryUsage
.Enum
.forString(vLibraryClass
.getLibraryClass(index
).getUsage()));
306 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getRecommendedInstanceVersion())) {
307 mLibraryClass
.setRecommendedInstanceVersion(vLibraryClass
.getLibraryClass(index
)
308 .getRecommendedInstanceVersion());
310 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getRecommendedInstanceGuid())) {
311 mLibraryClass
.setRecommendedInstanceGuid(vLibraryClass
.getLibraryClass(index
)
312 .getRecommendedInstanceGuid());
314 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getFeatureFlag())) {
315 mLibraryClass
.setFeatureFlag(vLibraryClass
.getLibraryClass(index
).getFeatureFlag());
317 if (vLibraryClass
.getLibraryClass(index
).getSupArchList() != null
318 && vLibraryClass
.getLibraryClass(index
).getSupArchList().size() > 0) {
319 mLibraryClass
.setSupArchList(vLibraryClass
.getLibraryClass(index
).getSupArchList());
321 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getHelp())) {
322 mLibraryClass
.setHelpText(vLibraryClass
.getLibraryClass(index
).getHelp());
325 this.lcd
.addNewLibraryClass();
326 this.lcd
.setLibraryClassArray(index
, mLibraryClass
);
330 if (msa
.getLibraryClassDefinitions() == null) {
331 this.msa
.addNewLibraryClassDefinitions();
333 this.msa
.setLibraryClassDefinitions(this.lcd
);
335 this.omt
.setSaved(false);
336 } catch (Exception e
) {
337 Log
.wrn("Update Library Class Definitions", e
.getMessage());
338 Log
.err("Update Library Class Definitions", e
.getMessage());
342 private void showEdit(int index
) {
343 LibraryClassDefsDlg mcdd
= new LibraryClassDefsDlg(vLibraryClass
.getLibraryClass(index
), new IFrame());
344 int result
= mcdd
.showDialog();
345 if (result
== DataType
.RETURN_TYPE_OK
) {
347 this.vLibraryClass
.addLibraryClass(mcdd
.getLcid());
349 this.vLibraryClass
.setLibraryClass(mcdd
.getLcid(), index
);
355 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
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 Library Class Definitions", "Please select one record first.");
375 showEdit(selectedRow
);
378 if (arg0
.getSource() == jButtonRemove
) {
379 if (jTable
.isEditing()) {
380 jTable
.getCellEditor().stopCellEditing();
382 if (selectedRow
> -1) {
383 this.model
.removeRow(selectedRow
);
384 this.vLibraryClass
.removeLibraryClass(selectedRow
);
395 private void clearAll() {
397 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
398 model
.removeRow(index
);
404 Read content of vector and put then into table
407 private void showTable() {
410 if (vLibraryClass
.size() > 0) {
411 for (int index
= 0; index
< vLibraryClass
.size(); index
++) {
412 model
.addRow(vLibraryClass
.toStringVector(index
));
415 this.jTable
.repaint();
416 this.jTable
.updateUI();
417 //this.jScrollPane.setViewportView(this.jTable);
421 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
424 public void valueChanged(ListSelectionEvent arg0
) {
425 if (arg0
.getValueIsAdjusting()) {
428 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
429 if (lsm
.isSelectionEmpty()) {
432 selectedRow
= lsm
.getMinSelectionIndex();
437 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
440 public void mouseClicked(MouseEvent arg0
) {
441 if (arg0
.getClickCount() == 2) {
442 if (this.selectedRow
< 0) {
445 showEdit(selectedRow
);
451 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
453 * Override componentResized to resize all components when frame's size is changed
455 public void componentResized(ComponentEvent arg0
) {
456 int intCurrentWidth
= this.getJContentPane().getWidth();
457 int intCurrentHeight
= this.getJContentPane().getHeight();
458 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
459 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
461 resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
);
462 relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
463 DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
464 relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
465 DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
466 relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
467 DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);