3 The file is used to setup tool chain configuration
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
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.awt
.event
.WindowEvent
;
20 import java
.io
.IOException
;
22 import javax
.swing
.JButton
;
23 import javax
.swing
.JFileChooser
;
24 import javax
.swing
.JLabel
;
25 import javax
.swing
.JPanel
;
26 import javax
.swing
.JScrollPane
;
27 import javax
.swing
.JTable
;
28 import javax
.swing
.JTextField
;
29 import javax
.swing
.ListSelectionModel
;
30 import javax
.swing
.event
.ListSelectionEvent
;
31 import javax
.swing
.event
.ListSelectionListener
;
32 import javax
.swing
.event
.TableModelEvent
;
33 import javax
.swing
.event
.TableModelListener
;
34 import javax
.swing
.table
.DefaultTableModel
;
35 import javax
.swing
.table
.TableModel
;
37 import org
.tianocore
.frameworkwizard
.common
.DataType
;
38 import org
.tianocore
.frameworkwizard
.common
.IFileFilter
;
39 import org
.tianocore
.frameworkwizard
.common
.Log
;
40 import org
.tianocore
.frameworkwizard
.common
.Tools
;
41 import org
.tianocore
.frameworkwizard
.common
.Identifications
.ToolChainConfigId
;
42 import org
.tianocore
.frameworkwizard
.common
.Identifications
.ToolChainConfigVector
;
43 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
44 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
46 public class ToolChainConfig
extends IFrame
implements ListSelectionListener
, TableModelListener
{
49 /// Define Class Members
51 private static final long serialVersionUID
= 1486930966278269085L;
53 private JPanel jContentPane
= null;
55 private JScrollPane jScrollPane
= null;
57 private DefaultTableModel model
= null;
59 private JTable jTable
= null;
61 private JButton jButtonOpen
= null;
63 private JButton jButtonSave
= null;
65 private JButton jButtonClose
= null;
67 private String toolsDir
= Tools
.addFileSeparator(Workspace
.getCurrentWorkspace()) + "Tools"
68 + DataType
.FILE_SEPARATOR
+ "Conf";
70 private String currentFile
= Tools
.addFileSeparator(toolsDir
) + "tools_def.template";
72 private ToolChainConfigVector vtcc
= new ToolChainConfigVector();
74 private JLabel jLabelName
= null;
76 private JTextField jTextFieldName
= null;
78 private JLabel jLabelValue
= null;
80 private JTextField jTextFieldValue
= null;
82 private JButton jButtonAdd
= null;
84 private JButton jButtonRemove
= null;
86 private int selectedRow
= -1;
88 private JButton jButtonHelp
= null;
90 private static ToolChainConfig tcc
= null;
92 private ToolChainConfigHelp tcch
= null;
95 This method initializes jScrollPane
97 @return javax.swing.JScrollPane
100 private JScrollPane
getJScrollPane() {
101 if (jScrollPane
== null) {
102 jScrollPane
= new JScrollPane();
103 jScrollPane
.setBounds(new java
.awt
.Rectangle(15, 15, 555, 345));
104 jScrollPane
.setViewportView(getJTable());
110 This method initializes jTable
112 @return javax.swing.JTable
115 private JTable
getJTable() {
116 if (jTable
== null) {
117 model
= new DefaultTableModel();
118 jTable
= new JTable(model
);
119 jTable
.setRowHeight(20);
121 model
.addColumn("Property");
122 model
.addColumn("Value");
124 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
125 jTable
.getSelectionModel().addListSelectionListener(this);
126 jTable
.getModel().addTableModelListener(this);
132 This method initializes jButtonOpen
134 @return javax.swing.JButton
137 private JButton
getJButtonOpen() {
138 if (jButtonOpen
== null) {
139 jButtonOpen
= new JButton();
140 jButtonOpen
.setBounds(new java
.awt
.Rectangle(40, 405, 120, 20));
141 jButtonOpen
.setText("Open File");
142 jButtonOpen
.addActionListener(this);
148 This method initializes jButtonSave
150 @return javax.swing.JButton
153 private JButton
getJButtonSave() {
154 if (jButtonSave
== null) {
155 jButtonSave
= new JButton();
156 jButtonSave
.setBounds(new java
.awt
.Rectangle(170, 405, 120, 20));
157 jButtonSave
.setText("Save File");
158 jButtonSave
.addActionListener(this);
164 This method initializes jButtonClose
166 @return javax.swing.JButton
169 private JButton
getJButtonClose() {
170 if (jButtonClose
== null) {
171 jButtonClose
= new JButton();
172 jButtonClose
.setBounds(new java
.awt
.Rectangle(490, 405, 80, 20));
173 jButtonClose
.setText("Close");
174 jButtonClose
.addActionListener(this);
180 This method initializes jTextFieldName
182 @return javax.swing.JTextField
185 private JTextField
getJTextFieldName() {
186 if (jTextFieldName
== null) {
187 jTextFieldName
= new JTextField();
188 jTextFieldName
.setBounds(new java
.awt
.Rectangle(60, 365, 140, 20));
190 return jTextFieldName
;
194 This method initializes jTextFieldValue
196 @return javax.swing.JTextField
199 private JTextField
getJTextFieldValue() {
200 if (jTextFieldValue
== null) {
201 jTextFieldValue
= new JTextField();
202 jTextFieldValue
.setBounds(new java
.awt
.Rectangle(250, 365, 140, 20));
204 return jTextFieldValue
;
208 This method initializes jButtonAdd
210 @return javax.swing.JButton
213 private JButton
getJButtonAdd() {
214 if (jButtonAdd
== null) {
215 jButtonAdd
= new JButton();
216 jButtonAdd
.setBounds(new java
.awt
.Rectangle(400, 365, 80, 20));
217 jButtonAdd
.setText("Add");
218 jButtonAdd
.addActionListener(this);
224 This method initializes jButtonRemove
226 @return javax.swing.JButton
229 private JButton
getJButtonRemove() {
230 if (jButtonRemove
== null) {
231 jButtonRemove
= new JButton();
232 jButtonRemove
.setBounds(new java
.awt
.Rectangle(490, 365, 80, 20));
233 jButtonRemove
.setText("Remove");
234 jButtonRemove
.addActionListener(this);
236 return jButtonRemove
;
240 * This method initializes jButtonHelp
242 * @return javax.swing.JButton
244 private JButton
getJButtonHelp() {
245 if (jButtonHelp
== null) {
246 jButtonHelp
= new JButton();
247 jButtonHelp
.setBounds(new java
.awt
.Rectangle(300,405,120,20));
248 jButtonHelp
.setText("Help");
249 jButtonHelp
.addActionListener(this);
259 public static void main(String
[] args
) {
260 // TODO Auto-generated method stub
264 public static ToolChainConfig
getInstance() {
266 tcc
= new ToolChainConfig();
272 * This is the default constructor
274 public ToolChainConfig() {
280 This method initializes this
283 private void init() {
284 this.setSize(600, 480);
285 this.setContentPane(getJContentPane());
286 this.setTitle("Tool Chain Configuration");
292 File f
= new File(currentFile
);
296 vtcc
.parseFile(this.currentFile
);
297 this.setTitle("Tool Chain Configuration" + " [" + currentFile
+ "]");
298 } catch (IOException e
) {
299 Log
.log(this.currentFile
+ "Read Error", e
.getMessage());
303 Log
.log("File Open Error: ", this.currentFile
+ " File Not Found");
310 This method initializes jContentPane
312 @return javax.swing.JPanel
315 private JPanel
getJContentPane() {
316 if (jContentPane
== null) {
317 jLabelValue
= new JLabel();
318 jLabelValue
.setBounds(new java
.awt
.Rectangle(205, 365, 40, 20));
319 jLabelValue
.setText("Value");
320 jLabelName
= new JLabel();
321 jLabelName
.setBounds(new java
.awt
.Rectangle(15, 365, 40, 20));
322 jLabelName
.setText("Name");
323 jContentPane
= new JPanel();
324 jContentPane
.setLayout(null);
325 jContentPane
.add(getJScrollPane(), null);
326 jContentPane
.add(getJButtonOpen(), null);
327 jContentPane
.add(getJButtonSave(), null);
328 jContentPane
.add(getJButtonClose(), null);
329 jContentPane
.add(jLabelName
, null);
330 jContentPane
.add(getJTextFieldName(), null);
331 jContentPane
.add(jLabelValue
, null);
332 jContentPane
.add(getJTextFieldValue(), null);
333 jContentPane
.add(getJButtonAdd(), null);
334 jContentPane
.add(getJButtonRemove(), null);
335 jContentPane
.add(getJButtonHelp(), null);
341 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
343 * Override actionPerformed to listen all actions
345 public void actionPerformed(ActionEvent arg0
) {
346 if (arg0
.getSource() == jButtonClose
) {
350 if (arg0
.getSource() == jButtonOpen
) {
351 JFileChooser fc
= new JFileChooser();
352 fc
.setAcceptAllFileFilterUsed(false);
353 IFileFilter iff
= new IFileFilter(DataType
.TEXT_FILE_EXT
);
354 fc
.addChoosableFileFilter(iff
);
355 fc
.setCurrentDirectory(new File(toolsDir
));
357 int result
= fc
.showOpenDialog(new JPanel());
358 if (result
== JFileChooser
.APPROVE_OPTION
) {
361 vtcc
.parseFile(fc
.getSelectedFile().getPath());
362 currentFile
= fc
.getSelectedFile().getPath();
363 this.setTitle("Tool Chain Configuration" + " [" + currentFile
+ "]");
364 } catch (IOException e
) {
365 Log
.wrn(this.currentFile
+ "Read Error", e
.getMessage());
366 Log
.err(this.currentFile
+ "Read Error", e
.getMessage());
373 if (arg0
.getSource() == jButtonSave
) {
374 JFileChooser fc
= new JFileChooser();
375 fc
.setAcceptAllFileFilterUsed(false);
376 IFileFilter iff
= new IFileFilter(DataType
.TEXT_FILE_EXT
);
377 fc
.addChoosableFileFilter(iff
);
378 fc
.setCurrentDirectory(new File(toolsDir
));
380 int result
= fc
.showSaveDialog(new JPanel());
381 if (result
== JFileChooser
.APPROVE_OPTION
) {
382 currentFile
= fc
.getSelectedFile().getPath();
384 vtcc
.saveFile(currentFile
);
385 } catch (IOException e
) {
386 Log
.wrn(this.currentFile
+ "Write Error", e
.getMessage());
387 Log
.err(this.currentFile
+ "Write Error", e
.getMessage());
393 if (arg0
.getSource() == jButtonAdd
) {
395 String
[] row
= { jTextFieldName
.getText(), jTextFieldValue
.getText() };
396 this.vtcc
.addToolChainConfigs(new ToolChainConfigId(row
[0], row
[1]));
397 this.model
.addRow(row
);
401 if (arg0
.getSource() == jButtonRemove
) {
402 if (jTable
.isEditing()) {
403 jTable
.getCellEditor().stopCellEditing();
405 if (selectedRow
> -1) {
406 this.model
.removeRow(selectedRow
);
407 this.vtcc
.removeToolChainConfigs(selectedRow
);
412 if (arg0
.getSource() == jButtonHelp
) {
413 tcch
= ToolChainConfigHelp
.getInstance();
414 tcch
.setVisible(true);
419 Read content of vector and put then into table
422 private void showTable() {
425 if (vtcc
.size() > 0) {
426 for (int index
= 0; index
< vtcc
.size(); index
++) {
427 model
.addRow(vtcc
.toStringVector(index
));
430 this.jTable
.repaint();
431 this.jTable
.updateUI();
432 //this.jScrollPane.setViewportView(this.jTable);
439 private void clearAll() {
441 for (int index
= model
.getRowCount() - 1; index
>= 0; index
--) {
442 model
.removeRow(index
);
448 Check if name or value is empty
453 private boolean check() {
454 if (isEmpty(this.jTextFieldName
.getText())) {
455 Log
.wrn("Add Tool Chain", "The Property Name must be entered!");
459 if (isEmpty(this.jTextFieldValue
.getText())) {
460 Log
.wrn("Add Tool Chain", "The Property Value must be entered!");
467 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
470 public void valueChanged(ListSelectionEvent arg0
) {
471 if (arg0
.getValueIsAdjusting()) {
474 ListSelectionModel lsm
= (ListSelectionModel
) arg0
.getSource();
475 if (lsm
.isSelectionEmpty()) {
478 selectedRow
= lsm
.getMinSelectionIndex();
482 public void tableChanged(TableModelEvent arg0
) {
483 int row
= arg0
.getFirstRow();
484 TableModel m
= (TableModel
)arg0
.getSource();
485 if (arg0
.getType() == TableModelEvent
.UPDATE
){
486 this.vtcc
.getToolChainConfigs(row
).setName(m
.getValueAt(row
, 0).toString());
487 this.vtcc
.getToolChainConfigs(row
).setValue(m
.getValueAt(row
, 1).toString());
492 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
494 * Override windowClosing to popup warning message to confirm quit
497 public void windowClosing(WindowEvent arg0
) {
501 private void exit() {
502 this.setVisible(false);