c16ade35 |
1 | /** @file\r |
2 | Java class GuidEditor.\r |
3 | \r |
4 | Copyright (c) 2006, Intel Corporation\r |
5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r |
8 | http://opensource.org/licenses/bsd-license.php\r |
9 | \r |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
12 | \r |
13 | **/\r |
14 | package org.tianocore.frameworkwizard.platform.ui;\r |
15 | \r |
16 | import java.awt.Component;\r |
17 | import java.awt.event.ActionEvent;\r |
18 | import java.awt.event.ActionListener;\r |
19 | import java.util.Vector;\r |
20 | \r |
21 | import javax.swing.AbstractCellEditor;\r |
22 | import javax.swing.JButton;\r |
23 | import javax.swing.JFrame;\r |
24 | import javax.swing.JTable;\r |
25 | import javax.swing.table.TableCellEditor;\r |
26 | \r |
27 | \r |
28 | /**\r |
29 | Editor for table cell with GUID value.\r |
30 | @since PackageEditor 1.0\r |
31 | **/\r |
32 | public class ListEditor extends AbstractCellEditor implements TableCellEditor, ActionListener {\r |
33 | \r |
34 | /**\r |
35 | * \r |
36 | */\r |
37 | private static final long serialVersionUID = 1L;\r |
38 | String archs;\r |
39 | JButton button;\r |
40 | static JFrame frame;\r |
41 | GenListDialog dialog;\r |
42 | protected static final String EDIT = "edit";\r |
43 | \r |
44 | public ListEditor() {\r |
45 | \r |
46 | button = new JButton();\r |
47 | button.setActionCommand(EDIT);\r |
48 | button.addActionListener(this);\r |
49 | button.setBorderPainted(false);\r |
50 | \r |
51 | \r |
52 | dialog = new GenListDialog(this);\r |
53 | \r |
54 | }\r |
55 | \r |
56 | public ListEditor(Vector<String> v) {\r |
57 | this();\r |
58 | dialog.initList(v);\r |
59 | }\r |
60 | \r |
61 | /* (non-Javadoc)\r |
62 | * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)\r |
63 | */\r |
64 | public Component getTableCellEditorComponent(JTable arg0, Object arg1, boolean arg2, int arg3, int arg4) {\r |
65 | // TODO Auto-generated method stub\r |
66 | archs = (String)arg1;\r |
67 | return button;\r |
68 | }\r |
69 | \r |
70 | /* (non-Javadoc)\r |
71 | * @see javax.swing.CellEditor#getCellEditorValue()\r |
72 | */\r |
73 | public Object getCellEditorValue() {\r |
74 | // TODO Auto-generated method stub\r |
75 | return archs;\r |
76 | }\r |
77 | \r |
78 | /* (non-Javadoc)\r |
79 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)\r |
80 | */\r |
81 | public void actionPerformed(ActionEvent arg0) {\r |
82 | // TODO Auto-generated method stub\r |
83 | if (EDIT.equals(arg0.getActionCommand())) {\r |
84 | //The user has clicked the cell, so\r |
85 | //bring up the dialog.\r |
86 | button.setText(archs);\r |
87 | dialog.setList(archs);\r |
88 | dialog.setVisible(true);\r |
89 | \r |
90 | //Make the renderer reappear.\r |
91 | fireEditingStopped();\r |
92 | }\r |
93 | else { //User pressed dialog's "OK" button.\r |
94 | Vector<String> v = dialog.getList();\r |
95 | String s = " ";\r |
96 | for (int i = 0; i < v.size(); ++i) {\r |
97 | s += v.get(i);\r |
98 | s += " ";\r |
99 | }\r |
100 | archs = s.trim();\r |
101 | }\r |
102 | \r |
103 | }\r |
104 | \r |
105 | }\r |