]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleSourceFiles.java
1. Change ToolCode from text field to drop down list, and user can enter their custom...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / ModuleSourceFiles.java
1 /** @file
2
3 The file is used to create, update SourceFile of MSA/MBD file
4
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
10
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.
13
14 **/
15 package org.tianocore.frameworkwizard.module.ui;
16
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;
22
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;
30
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;
45
46 /**
47 The class is used to create, update SourceFile of MSA/MBD file
48 It extends IInternalFrame
49
50 **/
51 public class ModuleSourceFiles extends IInternalFrame {
52
53 ///
54 /// Define class Serial Version UID
55 ///
56 private static final long serialVersionUID = -6765742852142775378L;
57
58 //
59 // Define class members
60 //
61 private SourceFilesDocument.SourceFiles sourceFiles = null;
62
63 private JPanel jContentPane = null;
64
65 private JButton jButtonAdd = null;
66
67 private JButton jButtonRemove = null;
68
69 private JButton jButtonUpdate = null;
70
71 private JCheckBox jCheckBoxArch = null;
72
73 private JScrollPane jScrollPane = null;
74
75 private JScrollPane jScrollPaneTable = null;
76
77 private JTable jTable = null;
78
79 //
80 // Not used by UI
81 //
82 private OpeningModuleType omt = null;
83
84 private ModuleSurfaceArea msa = null;
85
86 private SourceFilesVector vSourceFiles = new SourceFilesVector();
87
88 private IDefaultTableModel model = null;
89
90 private int selectedRow = -1;
91
92 /**
93 This method initializes jButtonAdd
94
95 @return javax.swing.JButton jButtonAdd
96
97 **/
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));
105 }
106 return jButtonAdd;
107 }
108
109 /**
110 This method initializes jButtonRemove
111
112 @return javax.swing.JButton jButtonRemove
113
114 **/
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));
122 }
123 return jButtonRemove;
124 }
125
126 /**
127 This method initializes jButtonUpdate
128
129 @return javax.swing.JButton jButtonUpdate
130
131 **/
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);
139 }
140 return jButtonUpdate;
141 }
142
143 /**
144 This method initializes jScrollPane
145
146 @return javax.swing.JScrollPane
147 */
148 private JScrollPane getJScrollPane() {
149 if (jScrollPane == null) {
150 jScrollPane = new JScrollPane();
151 jScrollPane.setViewportView(getJContentPane());
152 }
153 return jScrollPane;
154 }
155
156 /**
157 * This method initializes jScrollPaneTable
158 *
159 * @return javax.swing.JScrollPane
160 */
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());
167 }
168 return jScrollPaneTable;
169 }
170
171 /**
172 * This method initializes jTable
173 *
174 * @return javax.swing.JTable
175 */
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);
182
183 model.addColumn("File Name");
184 model.addColumn("Tag Name");
185 model.addColumn("Tool Code");
186 model.addColumn("Tool Chain Family");
187
188 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
189 jTable.getSelectionModel().addListSelectionListener(this);
190 jTable.getModel().addTableModelListener(this);
191 jTable.addMouseListener(this);
192 }
193 return jTable;
194 }
195
196 public static void main(String[] args) {
197
198 }
199
200 /**
201 This is the default constructor
202
203 **/
204 public ModuleSourceFiles() {
205 super();
206 init();
207 this.setVisible(true);
208 }
209
210 /**
211 This is the override edit constructor
212
213 @param
214
215 **/
216 public ModuleSourceFiles(OpeningModuleType inOmt) {
217 super();
218 this.omt = inOmt;
219 this.msa = omt.getXmlMsa();
220 init(msa.getSourceFiles());
221 this.setVisible(true);
222 }
223
224 /**
225 This method initializes this
226 Fill values to all fields if these values are not empty
227
228
229 @param inSourceFiles The input data of SourceFilesDocument.SourceFiles
230
231 **/
232 private void init(SourceFilesDocument.SourceFiles inSourceFiles) {
233 init();
234 this.sourceFiles = inSourceFiles;
235
236 if (this.sourceFiles != null) {
237 if (this.sourceFiles.getFilenameList().size() > 0) {
238 for (int index = 0; index < this.sourceFiles.getFilenameList().size(); index++) {
239 String name = sourceFiles.getFilenameList().get(index).getStringValue();
240 String tagName = sourceFiles.getFilenameList().get(index).getTagName();
241 String toolCode = sourceFiles.getFilenameList().get(index).getToolCode();
242 String tcf = sourceFiles.getFilenameList().get(index).getToolChainFamily();
243 String featureFlag = sourceFiles.getFilenameList().get(index).getFeatureFlag();
244 Vector<String> arch = Tools.convertListToVector(sourceFiles.getFilenameList().get(index)
245 .getSupArchList());
246 SourceFilesIdentification sfid = new SourceFilesIdentification(name, tagName, toolCode, tcf,
247 featureFlag, arch);
248 vSourceFiles.addSourceFiles(sfid);
249 }
250 }
251 }
252 showTable();
253 }
254
255 /**
256 This method initializes this
257
258 **/
259 private void init() {
260 this.setSize(500, 515);
261 this.setContentPane(getJScrollPane());
262 this.setTitle("Source Files");
263 this.setViewMode(false);
264 }
265
266 /**
267 Disable all components when the mode is view
268
269 @param isView true - The view mode; false - The non-view mode
270
271 **/
272 public void setViewMode(boolean isView) {
273 if (isView) {
274 this.jButtonAdd.setEnabled(!isView);
275 this.jButtonRemove.setEnabled(!isView);
276 this.jButtonUpdate.setEnabled(!isView);
277 this.jCheckBoxArch.setEnabled(!isView);
278 }
279 }
280
281 /**
282 This method initializes jContentPane
283
284 @return javax.swing.JPanel jContentPane
285
286 **/
287 private JPanel getJContentPane() {
288 if (jContentPane == null) {
289 jContentPane = new JPanel();
290 jContentPane.setLayout(null);
291 jContentPane.setPreferredSize(new java.awt.Dimension(490, 490));
292
293 jContentPane.add(getJButtonAdd(), null);
294 jContentPane.add(getJButtonRemove(), null);
295 jContentPane.add(getJButtonUpdate(), null);
296 jContentPane.add(getJScrollPaneTable(), null);
297 }
298 return jContentPane;
299 }
300
301 /**
302 Save all components of SourceFiles
303 if exists sourceFiles, set the value directly
304 if not exists sourceFiles, new an instance first
305
306 **/
307 public void save() {
308 try {
309 //
310 //Save as file name
311 //
312 int count = this.vSourceFiles.size();
313
314 this.sourceFiles = SourceFiles.Factory.newInstance();
315 if (count > 0) {
316 for (int index = 0; index < count; index++) {
317 Filename mFilename = Filename.Factory.newInstance();
318 if (!isEmpty(vSourceFiles.getSourceFiles(index).getFilename())) {
319 mFilename.setStringValue(vSourceFiles.getSourceFiles(index).getFilename());
320 }
321 if (!isEmpty(vSourceFiles.getSourceFiles(index).getTagName())) {
322 mFilename.setTagName(vSourceFiles.getSourceFiles(index).getTagName());
323 }
324 if (!isEmpty(vSourceFiles.getSourceFiles(index).getToolCode())) {
325 mFilename.setToolCode(vSourceFiles.getSourceFiles(index).getToolCode());
326 }
327 if (!isEmpty(vSourceFiles.getSourceFiles(index).getToolChainFamily())) {
328 mFilename.setToolChainFamily(vSourceFiles.getSourceFiles(index).getToolChainFamily());
329 }
330 if (!isEmpty(vSourceFiles.getSourceFiles(index).getFeatureFlag())) {
331 mFilename.setFeatureFlag(vSourceFiles.getSourceFiles(index).getFeatureFlag());
332 }
333 if (vSourceFiles.getSourceFiles(index).getSupArchList() != null
334 && vSourceFiles.getSourceFiles(index).getSupArchList().size() > 0) {
335 mFilename.setSupArchList(vSourceFiles.getSourceFiles(index).getSupArchList());
336 }
337
338 this.sourceFiles.addNewFilename();
339 this.sourceFiles.setFilenameArray(index, mFilename);
340 }
341 }
342 this.msa.setSourceFiles(sourceFiles);
343 this.omt.setSaved(false);
344 } catch (Exception e) {
345 Log.wrn("Update Source Files", e.getMessage());
346 Log.err("Update Source Files", e.getMessage());
347 }
348 }
349
350 private void showEdit(int index) {
351 SourceFilesDlg sfd = new SourceFilesDlg(this.vSourceFiles.getSourceFiles(index), new IFrame(), omt.getId()
352 .getPath());
353 int result = sfd.showDialog();
354 if (result == DataType.RETURN_TYPE_OK) {
355 if (index == -1) {
356 for (int indexI = 0; indexI < sfd.getSfid().length; indexI++) {
357 this.vSourceFiles.addSourceFiles(sfd.getSfid()[indexI]);
358 }
359 } else {
360 this.vSourceFiles.setSourceFiles(sfd.getSfid()[0], index);
361 }
362 this.showTable();
363 this.save();
364 sfd.dispose();
365 }
366 if (result == DataType.RETURN_TYPE_CANCEL) {
367 sfd.dispose();
368 }
369 }
370
371 /* (non-Javadoc)
372 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
373 *
374 * Override actionPerformed to listen all actions
375 *
376 */
377 public void actionPerformed(ActionEvent arg0) {
378 if (arg0.getSource() == jButtonAdd) {
379 showEdit(-1);
380 }
381 if (arg0.getSource() == jButtonUpdate) {
382 if (this.selectedRow < 0) {
383 Log.wrn("Update Source Files", "Please select one record first.");
384 return;
385 }
386 showEdit(selectedRow);
387 }
388
389 if (arg0.getSource() == jButtonRemove) {
390 if (jTable.isEditing()) {
391 jTable.getCellEditor().stopCellEditing();
392 }
393 if (selectedRow > -1) {
394 this.model.removeRow(selectedRow);
395 this.vSourceFiles.removeSourceFiles(selectedRow);
396 selectedRow = -1;
397 this.save();
398 }
399 }
400 }
401
402 /**
403 Clear all table rows
404
405 **/
406 private void clearAll() {
407 if (model != null) {
408 for (int index = model.getRowCount() - 1; index >= 0; index--) {
409 model.removeRow(index);
410 }
411 }
412 }
413
414 /**
415 Read content of vector and put then into table
416
417 **/
418 private void showTable() {
419 clearAll();
420
421 if (vSourceFiles.size() > 0) {
422 for (int index = 0; index < vSourceFiles.size(); index++) {
423 model.addRow(vSourceFiles.toStringVector(index));
424 }
425 }
426 this.jTable.repaint();
427 this.jTable.updateUI();
428 //this.jScrollPane.setViewportView(this.jTable);
429 }
430
431 /* (non-Javadoc)
432 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
433 *
434 */
435 public void valueChanged(ListSelectionEvent arg0) {
436 if (arg0.getValueIsAdjusting()) {
437 return;
438 }
439 ListSelectionModel lsm = (ListSelectionModel) arg0.getSource();
440 if (lsm.isSelectionEmpty()) {
441 return;
442 } else {
443 selectedRow = lsm.getMinSelectionIndex();
444 }
445 }
446
447 /* (non-Javadoc)
448 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
449 *
450 */
451 public void mouseClicked(MouseEvent arg0) {
452 if (arg0.getClickCount() == 2) {
453 if (this.selectedRow < 0) {
454 return;
455 } else {
456 showEdit(selectedRow);
457 }
458 }
459 }
460
461 /* (non-Javadoc)
462 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
463 *
464 * Override componentResized to resize all components when frame's size is changed
465 */
466 public void componentResized(ComponentEvent arg0) {
467 int intCurrentWidth = this.getJContentPane().getWidth();
468 int intCurrentHeight = this.getJContentPane().getHeight();
469 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;
470 int intPreferredHeight = this.getJContentPane().getPreferredSize().height;
471
472 resizeComponent(this.jScrollPaneTable, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight);
473 relocateComponent(this.jButtonAdd, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,
474 DataType.SPACE_TO_RIGHT_FOR_ADD_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_ADD_BUTTON);
475 relocateComponent(this.jButtonRemove, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,
476 DataType.SPACE_TO_RIGHT_FOR_REMOVE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_REMOVE_BUTTON);
477 relocateComponent(this.jButtonUpdate, intCurrentWidth, intCurrentHeight, intPreferredWidth, intPreferredHeight,
478 DataType.SPACE_TO_RIGHT_FOR_UPDATE_BUTTON, DataType.SPACE_TO_BOTTOM_FOR_UPDATE_BUTTON);
479 }
480 }