3 The file is used to create, update SourceFile 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
.JCheckBox
;
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
.SourceFilesDocument
;
32 import org
.tianocore
.FilenameDocument
.Filename
;
33 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
34 import org
.tianocore
.SourceFilesDocument
.SourceFiles
;
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
.SourceFiles
.SourceFilesIdentification
;
43 import org
.tianocore
.frameworkwizard
.module
.Identifications
.SourceFiles
.SourceFilesVector
;
44 import org
.tianocore
.frameworkwizard
.module
.ui
.dialog
.SourceFilesDlg
;
47 The class is used to create, update SourceFile of MSA/MBD file
48 It extends IInternalFrame
51 public class ModuleSourceFiles
extends IInternalFrame
{
54 /// Define class Serial Version UID
56 private static final long serialVersionUID
= -6765742852142775378L;
59 // Define class members
61 private SourceFilesDocument
.SourceFiles sourceFiles
= null;
63 private JPanel jContentPane
= null;
65 private JButton jButtonAdd
= null;
67 private JButton jButtonRemove
= null;
69 private JButton jButtonUpdate
= null;
71 private JCheckBox jCheckBoxArch
= null;
73 private JScrollPane jScrollPane
= null;
75 private JScrollPane jScrollPaneTable
= null;
77 private JTable jTable
= null;
82 private OpeningModuleType omt
= null;
84 private ModuleSurfaceArea msa
= null;
86 private SourceFilesVector vSourceFiles
= new SourceFilesVector();
88 private IDefaultTableModel model
= null;
90 private int selectedRow
= -1;
92 private IFrame parentFrame
= null;
95 This method initializes jButtonAdd
97 @return javax.swing.JButton jButtonAdd
100 private JButton
getJButtonAdd() {
101 if (jButtonAdd
== null) {
102 jButtonAdd
= new JButton();
103 jButtonAdd
.setBounds(new java
.awt
.Rectangle(230, 220, 90, 20));
104 jButtonAdd
.setText("Add");
105 jButtonAdd
.addActionListener(this);
106 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(90, 20));
112 This method initializes jButtonRemove
114 @return javax.swing.JButton jButtonRemove
117 private JButton
getJButtonRemove() {
118 if (jButtonRemove
== null) {
119 jButtonRemove
= new JButton();
120 jButtonRemove
.setBounds(new java
.awt
.Rectangle(400, 220, 90, 20));
121 jButtonRemove
.setText("Remove");
122 jButtonRemove
.addActionListener(this);
123 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(90, 20));
125 return jButtonRemove
;
129 This method initializes jButtonUpdate
131 @return javax.swing.JButton jButtonUpdate
134 private JButton
getJButtonUpdate() {
135 if (jButtonUpdate
== null) {
136 jButtonUpdate
= new JButton();
137 jButtonUpdate
.setBounds(new java
.awt
.Rectangle(315, 220, 90, 20));
138 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(90, 20));
139 jButtonUpdate
.setText("Edit");
140 jButtonUpdate
.addActionListener(this);
142 return jButtonUpdate
;
146 This method initializes jScrollPane
148 @return javax.swing.JScrollPane
150 private JScrollPane
getJScrollPane() {
151 if (jScrollPane
== null) {
152 jScrollPane
= new JScrollPane();
153 jScrollPane
.setViewportView(getJContentPane());
159 * This method initializes jScrollPaneTable
161 * @return javax.swing.JScrollPane
163 private JScrollPane
getJScrollPaneTable() {
164 if (jScrollPaneTable
== null) {
165 jScrollPaneTable
= new JScrollPane();
166 jScrollPaneTable
.setBounds(new java
.awt
.Rectangle(15, 10, 470, 420));
167 jScrollPaneTable
.setPreferredSize(new Dimension(470, 420));
168 jScrollPaneTable
.setViewportView(getJTable());
170 return jScrollPaneTable
;
174 * This method initializes jTable
176 * @return javax.swing.JTable
178 private JTable
getJTable() {
179 if (jTable
== null) {
180 jTable
= new JTable();
181 model
= new IDefaultTableModel();
182 jTable
= new JTable(model
);
183 jTable
.setRowHeight(20);
185 model
.addColumn("File Name");
186 model
.addColumn("Tag Name");
187 model
.addColumn("Tool Code");
188 model
.addColumn("Tool Chain Family");
190 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
191 jTable
.getSelectionModel().addListSelectionListener(this);
192 jTable
.getModel().addTableModelListener(this);
193 jTable
.addMouseListener(this);
198 public static void main(String
[] args
) {
203 This is the default constructor
206 public ModuleSourceFiles() {
209 this.setVisible(true);
213 This is the override edit constructor
218 public ModuleSourceFiles(OpeningModuleType inOmt
, IFrame iFrame
) {
221 this.msa
= omt
.getXmlMsa();
222 this.parentFrame
= iFrame
;
223 init(msa
.getSourceFiles());
224 this.setVisible(true);
228 This method initializes this
229 Fill values to all fields if these values are not empty
232 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
235 private void init(SourceFilesDocument
.SourceFiles inSourceFiles
) {
237 this.sourceFiles
= inSourceFiles
;
239 if (this.sourceFiles
!= null) {
240 if (this.sourceFiles
.getFilenameList().size() > 0) {
241 for (int index
= 0; index
< this.sourceFiles
.getFilenameList().size(); index
++) {
242 String name
= sourceFiles
.getFilenameList().get(index
).getStringValue();
243 String tagName
= sourceFiles
.getFilenameList().get(index
).getTagName();
244 String toolCode
= sourceFiles
.getFilenameList().get(index
).getToolCode();
245 String tcf
= sourceFiles
.getFilenameList().get(index
).getToolChainFamily();
246 String featureFlag
= sourceFiles
.getFilenameList().get(index
).getFeatureFlag();
247 Vector
<String
> arch
= Tools
.convertListToVector(sourceFiles
.getFilenameList().get(index
)
249 SourceFilesIdentification sfid
= new SourceFilesIdentification(name
, tagName
, toolCode
, tcf
,
251 vSourceFiles
.addSourceFiles(sfid
);
259 This method initializes this
262 private void init() {
263 this.setSize(500, 515);
264 this.setContentPane(getJScrollPane());
265 this.setTitle("Source Files");
266 this.setViewMode(false);
270 Disable all components when the mode is view
272 @param isView true - The view mode; false - The non-view mode
275 public void setViewMode(boolean isView
) {
277 this.jButtonAdd
.setEnabled(!isView
);
278 this.jButtonRemove
.setEnabled(!isView
);
279 this.jButtonUpdate
.setEnabled(!isView
);
280 this.jCheckBoxArch
.setEnabled(!isView
);
285 This method initializes jContentPane
287 @return javax.swing.JPanel jContentPane
290 private JPanel
getJContentPane() {
291 if (jContentPane
== null) {
292 jContentPane
= new JPanel();
293 jContentPane
.setLayout(null);
294 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
296 jContentPane
.add(getJButtonAdd(), null);
297 jContentPane
.add(getJButtonRemove(), null);
298 jContentPane
.add(getJButtonUpdate(), null);
299 jContentPane
.add(getJScrollPaneTable(), null);
305 Save all components of SourceFiles
306 if exists sourceFiles, set the value directly
307 if not exists sourceFiles, new an instance first
315 int count
= this.vSourceFiles
.size();
317 this.sourceFiles
= SourceFiles
.Factory
.newInstance();
319 for (int index
= 0; index
< count
; index
++) {
320 Filename mFilename
= Filename
.Factory
.newInstance();
321 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getFilename())) {
322 mFilename
.setStringValue(vSourceFiles
.getSourceFiles(index
).getFilename());
324 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getTagName())) {
325 mFilename
.setTagName(vSourceFiles
.getSourceFiles(index
).getTagName());
327 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getToolCode())) {
328 mFilename
.setToolCode(vSourceFiles
.getSourceFiles(index
).getToolCode());
330 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getToolChainFamily())) {
331 mFilename
.setToolChainFamily(vSourceFiles
.getSourceFiles(index
).getToolChainFamily());
333 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getFeatureFlag())) {
334 mFilename
.setFeatureFlag(vSourceFiles
.getSourceFiles(index
).getFeatureFlag());
336 if (vSourceFiles
.getSourceFiles(index
).getSupArchList() != null
337 && vSourceFiles
.getSourceFiles(index
).getSupArchList().size() > 0) {
338 mFilename
.setSupArchList(vSourceFiles
.getSourceFiles(index
).getSupArchList());
341 this.sourceFiles
.addNewFilename();
342 this.sourceFiles
.setFilenameArray(index
, mFilename
);
345 this.msa
.setSourceFiles(sourceFiles
);
346 this.omt
.setSaved(false);
347 } catch (Exception e
) {
348 Log
.wrn("Update Source Files", e
.getMessage());
349 Log
.err("Update Source Files", e
.getMessage());
353 private void showEdit(int index
) {
354 SourceFilesDlg sfd
= new SourceFilesDlg(this.vSourceFiles
.getSourceFiles(index
), this.parentFrame
, omt
.getId());
355 int result
= sfd
.showDialog();
356 if (result
== DataType
.RETURN_TYPE_OK
) {
358 for (int indexI
= 0; indexI
< sfd
.getSfid().length
; indexI
++) {
359 this.vSourceFiles
.addSourceFiles(sfd
.getSfid()[indexI
]);
362 this.vSourceFiles
.setSourceFiles(sfd
.getSfid()[0], index
);
368 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
374 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
376 * Override actionPerformed to listen all actions
379 public void actionPerformed(ActionEvent arg0
) {
380 if (arg0
.getSource() == jButtonAdd
) {
383 if (arg0
.getSource() == jButtonUpdate
) {
384 if (this.selectedRow
< 0) {
385 Log
.wrn("Update Source Files", "Please select one record first.");
388 showEdit(selectedRow
);
391 if (arg0
.getSource() == jButtonRemove
) {
392 if (jTable
.isEditing()) {
393 jTable
.getCellEditor().stopCellEditing();
395 if (selectedRow
> -1) {
396 this.model
.removeRow(selectedRow
);
397 this.vSourceFiles
.removeSourceFiles(selectedRow
);
408 private void clearAll() {
410 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
411 model
.removeRow(index
);
417 Read content of vector and put then into table
420 private void showTable() {
423 if (vSourceFiles
.size() > 0) {
424 for (int index
= 0; index
< vSourceFiles
.size(); index
++) {
425 model
.addRow(vSourceFiles
.toStringVector(index
));
428 this.jTable
.repaint();
429 this.jTable
.updateUI();
430 //this.jScrollPane.setViewportView(this.jTable);
434 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
437 public void valueChanged(ListSelectionEvent arg0
) {
438 if (arg0
.getValueIsAdjusting()) {
441 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
442 if (lsm
.isSelectionEmpty()) {
445 selectedRow
= lsm
.getMinSelectionIndex();
450 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
453 public void mouseClicked(MouseEvent arg0
) {
454 if (arg0
.getClickCount() == 2) {
455 if (this.selectedRow
< 0) {
458 showEdit(selectedRow
);
464 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
466 * Override componentResized to resize all components when frame's size is changed
468 public void componentResized(ComponentEvent arg0
) {
469 int intCurrentWidth
= this.getJContentPane().getWidth();
470 int intCurrentHeight
= this.getJContentPane().getHeight();
471 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
472 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
474 Tools
.resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
476 Tools
.relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
477 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
,
478 DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
479 Tools
.relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
480 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
,
481 DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
482 Tools
.relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
,
483 intPreferredHeight
, DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
,
484 DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);