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;
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, 220, 80, 20));
102 jButtonAdd
.setText("Add");
103 jButtonAdd
.addActionListener(this);
104 jButtonAdd
.setPreferredSize(new java
.awt
.Dimension(80, 20));
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, 220, 80, 20));
119 jButtonRemove
.setText("Remove");
120 jButtonRemove
.addActionListener(this);
121 jButtonRemove
.setPreferredSize(new java
.awt
.Dimension(80, 20));
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, 220, 80, 20));
136 jButtonUpdate
.setPreferredSize(new java
.awt
.Dimension(80, 20));
137 jButtonUpdate
.setText("Edit");
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("File Name");
185 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
186 jTable
.getSelectionModel().addListSelectionListener(this);
187 jTable
.getModel().addTableModelListener(this);
188 jTable
.addMouseListener(this);
193 public static void main(String
[] args
) {
198 This is the default constructor
201 public ModuleSourceFiles() {
204 this.setVisible(true);
208 This is the override edit constructor
213 public ModuleSourceFiles(OpeningModuleType inOmt
) {
216 this.msa
= omt
.getXmlMsa();
217 init(msa
.getSourceFiles());
218 this.setVisible(true);
222 This method initializes this
223 Fill values to all fields if these values are not empty
226 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
229 private void init(SourceFilesDocument
.SourceFiles inSourceFiles
) {
231 this.sourceFiles
= inSourceFiles
;
233 if (this.sourceFiles
!= null) {
234 if (this.sourceFiles
.getFilenameList().size() > 0) {
235 for (int index
= 0; index
< this.sourceFiles
.getFilenameList().size(); index
++) {
236 String name
= sourceFiles
.getFilenameList().get(index
).getStringValue();
237 String tagName
= sourceFiles
.getFilenameList().get(index
).getTagName();
238 String toolCode
= sourceFiles
.getFilenameList().get(index
).getToolCode();
239 String tcf
= sourceFiles
.getFilenameList().get(index
).getToolChainFamily();
240 String featureFlag
= sourceFiles
.getFilenameList().get(index
).getFeatureFlag();
241 Vector
<String
> arch
= Tools
.convertListToVector(sourceFiles
.getFilenameList().get(index
)
243 SourceFilesIdentification sfid
= new SourceFilesIdentification(name
, tagName
, toolCode
, tcf
,
245 vSourceFiles
.addSourceFiles(sfid
);
253 This method initializes this
256 private void init() {
257 this.setSize(500, 515);
258 this.setContentPane(getJScrollPane());
259 this.setTitle("Source Files");
260 this.setViewMode(false);
264 Disable all components when the mode is view
266 @param isView true - The view mode; false - The non-view mode
269 public void setViewMode(boolean isView
) {
271 this.jButtonAdd
.setEnabled(!isView
);
272 this.jButtonRemove
.setEnabled(!isView
);
273 this.jButtonUpdate
.setEnabled(!isView
);
274 this.jCheckBoxArch
.setEnabled(!isView
);
279 This method initializes jContentPane
281 @return javax.swing.JPanel jContentPane
284 private JPanel
getJContentPane() {
285 if (jContentPane
== null) {
286 jContentPane
= new JPanel();
287 jContentPane
.setLayout(null);
288 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 490));
290 jContentPane
.add(getJButtonAdd(), null);
291 jContentPane
.add(getJButtonRemove(), null);
292 jContentPane
.add(getJButtonUpdate(), null);
293 jContentPane
.add(getJScrollPaneTable(), null);
299 Save all components of SourceFiles
300 if exists sourceFiles, set the value directly
301 if not exists sourceFiles, new an instance first
309 int count
= this.vSourceFiles
.size();
311 this.sourceFiles
= SourceFiles
.Factory
.newInstance();
313 for (int index
= 0; index
< count
; index
++) {
314 Filename mFilename
= Filename
.Factory
.newInstance();
315 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getFilename())) {
316 mFilename
.setStringValue(vSourceFiles
.getSourceFiles(index
).getFilename());
318 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getTagName())) {
319 mFilename
.setTagName(vSourceFiles
.getSourceFiles(index
).getTagName());
321 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getToolCode())) {
322 mFilename
.setToolCode(vSourceFiles
.getSourceFiles(index
).getToolCode());
324 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getToolChainFamily())) {
325 mFilename
.setToolChainFamily(vSourceFiles
.getSourceFiles(index
).getToolChainFamily());
327 if (!isEmpty(vSourceFiles
.getSourceFiles(index
).getFeatureFlag())) {
328 mFilename
.setFeatureFlag(vSourceFiles
.getSourceFiles(index
).getFeatureFlag());
330 if (vSourceFiles
.getSourceFiles(index
).getSupArchList() != null
331 && vSourceFiles
.getSourceFiles(index
).getSupArchList().size() > 0) {
332 mFilename
.setSupArchList(vSourceFiles
.getSourceFiles(index
).getSupArchList());
335 this.sourceFiles
.addNewFilename();
336 this.sourceFiles
.setFilenameArray(index
, mFilename
);
339 this.msa
.setSourceFiles(sourceFiles
);
340 this.omt
.setSaved(false);
341 } catch (Exception e
) {
342 Log
.err("Update Source Files", e
.getMessage());
346 private void showEdit(int index
) {
347 SourceFilesDlg sfd
= new SourceFilesDlg(this.vSourceFiles
.getSourceFiles(index
), new IFrame(), omt
.getId().getPath());
348 int result
= sfd
.showDialog();
349 if (result
== DataType
.RETURN_TYPE_OK
) {
351 for (int indexI
= 0; indexI
< sfd
.getSfid().length
; indexI
++) {
352 this.vSourceFiles
.addSourceFiles(sfd
.getSfid()[indexI
]);
355 this.vSourceFiles
.setSourceFiles(sfd
.getSfid()[0], index
);
361 if (result
== DataType
.RETURN_TYPE_CANCEL
) {
367 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
369 * Override actionPerformed to listen all actions
372 public void actionPerformed(ActionEvent arg0
) {
373 if (arg0
.getSource() == jButtonAdd
) {
376 if (arg0
.getSource() == jButtonUpdate
) {
377 if (this.selectedRow
< 0) {
378 Log
.err("Please select one record first.");
381 showEdit(selectedRow
);
384 if (arg0
.getSource() == jButtonRemove
) {
385 if (jTable
.isEditing()) {
386 jTable
.getCellEditor().stopCellEditing();
388 if (selectedRow
> -1) {
389 this.model
.removeRow(selectedRow
);
390 this.vSourceFiles
.removeSourceFiles(selectedRow
);
401 private void clearAll() {
403 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
404 model
.removeRow(index
);
410 Read content of vector and put then into table
413 private void showTable() {
416 if (vSourceFiles
.size() > 0) {
417 for (int index
= 0; index
< vSourceFiles
.size(); index
++) {
418 model
.addRow(vSourceFiles
.toStringVector(index
));
421 this.jTable
.repaint();
422 this.jTable
.updateUI();
423 //this.jScrollPane.setViewportView(this.jTable);
427 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
430 public void valueChanged(ListSelectionEvent arg0
) {
431 if (arg0
.getValueIsAdjusting()) {
434 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
435 if (lsm
.isSelectionEmpty()) {
438 selectedRow
= lsm
.getMinSelectionIndex();
443 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
446 public void mouseClicked(MouseEvent arg0
) {
447 if (arg0
.getClickCount() == 2) {
448 if (this.selectedRow
< 0) {
451 showEdit(selectedRow
);
457 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
459 * Override componentResized to resize all components when frame's size is changed
461 public void componentResized(ComponentEvent arg0
) {
462 int intCurrentWidth
= this.getJContentPane().getWidth();
463 int intCurrentHeight
= this.getJContentPane().getHeight();
464 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
465 int intPreferredHeight
= this.getJContentPane().getPreferredSize().height
;
467 resizeComponent(this.jScrollPaneTable
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
);
468 relocateComponent(this.jButtonAdd
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
469 DataType
.SPACE_TO_RIGHT_FOR_ADD_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_ADD_BUTTON
);
470 relocateComponent(this.jButtonRemove
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
471 DataType
.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON
);
472 relocateComponent(this.jButtonUpdate
, intCurrentWidth
, intCurrentHeight
, intPreferredWidth
, intPreferredHeight
,
473 DataType
.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON
, DataType
.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON
);