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