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, 90, 20));
100 jButtonAdd
.setPreferredSize(new Dimension(90, 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, 90, 20));
117 jButtonRemove
.setText("Remove");
118 jButtonRemove
.setPreferredSize(new Dimension(90, 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, 90, 20));
134 jButtonUpdate
.setText("Edit");
135 jButtonUpdate
.setPreferredSize(new Dimension(90, 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 (vLibraryClass
.getLibraryClass(index
).getSupModuleList() != null
322 && vLibraryClass
.getLibraryClass(index
).getSupModuleList().size() > 0) {
323 mLibraryClass
.setSupModuleList(vLibraryClass
.getLibraryClass(index
).getSupModuleList());
325 if (!isEmpty(vLibraryClass
.getLibraryClass(index
).getHelp())) {
326 mLibraryClass
.setHelpText(vLibraryClass
.getLibraryClass(index
).getHelp());
329 this.lcd
.addNewLibraryClass();
330 this.lcd
.setLibraryClassArray(index
, mLibraryClass
);
334 if (msa
.getLibraryClassDefinitions() == null) {
335 this.msa
.addNewLibraryClassDefinitions();
337 this.msa
.setLibraryClassDefinitions(this.lcd
);
339 this.omt
.setSaved(false);
340 } catch (Exception e
) {
341 Log
.wrn("Update Library Class Definitions", e
.getMessage());
342 Log
.err("Update Library Class Definitions", e
.getMessage());
346 private void showEdit(int index
) {
347 LibraryClassDefsDlg mcdd
= new LibraryClassDefsDlg(vLibraryClass
.getLibraryClass(index
), new IFrame(), omt
.getId());
348 int result
= mcdd
.showDialog();
349 if (result
== DataType
.RETURN_TYPE_OK
) {
351 this.vLibraryClass
.addLibraryClass(mcdd
.getLcid());
353 this.vLibraryClass
.setLibraryClass(mcdd
.getLcid(), index
);
359 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
365 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
367 * Override actionPerformed to listen all actions
370 public void actionPerformed(ActionEvent arg0
) {
371 if (arg0
.getSource() == jButtonAdd
) {
374 if (arg0
.getSource() == jButtonUpdate
) {
375 if (this.selectedRow
< 0) {
376 Log
.wrn("Update Library Class Definitions", "Please select one record first.");
379 showEdit(selectedRow
);
382 if (arg0
.getSource() == jButtonRemove
) {
383 if (jTable
.isEditing()) {
384 jTable
.getCellEditor().stopCellEditing();
386 if (selectedRow
> -1) {
387 this.model
.removeRow(selectedRow
);
388 this.vLibraryClass
.removeLibraryClass(selectedRow
);
399 private void clearAll() {
401 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
402 model
.removeRow(index
);
408 Read content of vector and put then into table
411 private void showTable() {
414 if (vLibraryClass
.size() > 0) {
415 for (int index
= 0; index
< vLibraryClass
.size(); index
++) {
416 model
.addRow(vLibraryClass
.toStringVector(index
));
419 this.jTable
.repaint();
420 this.jTable
.updateUI();
421 //this.jScrollPane.setViewportView(this.jTable);
425 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
428 public void valueChanged(ListSelectionEvent arg0
) {
429 if (arg0
.getValueIsAdjusting()) {
432 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
433 if (lsm
.isSelectionEmpty()) {
436 selectedRow
= lsm
.getMinSelectionIndex();
441 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
444 public void mouseClicked(MouseEvent arg0
) {
445 if (arg0
.getClickCount() == 2) {
446 if (this.selectedRow
< 0) {
449 showEdit(selectedRow
);
455 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
457 * Override componentResized to resize all components when frame's size is changed
459 public void componentResized(ComponentEvent arg0
) {
460 int intCurrentWidth
= this.getJContentPane().getWidth();
461 int intCurrentHeight
= this.getJContentPane().getHeight();
462 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
463 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
465 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
467 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
468 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
469 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
470 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
471 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
472 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
473 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
474 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
475 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);