|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
package org.ejtools.adwt;
|
|
8
|
|
|
|
9
|
|
import java.awt.Component;
|
|
10
|
|
import java.awt.Dimension;
|
|
11
|
|
import java.awt.Frame;
|
|
12
|
|
import java.awt.GridBagConstraints;
|
|
13
|
|
import java.awt.GridBagLayout;
|
|
14
|
|
import java.awt.Insets;
|
|
15
|
|
import java.awt.event.ActionEvent;
|
|
16
|
|
import java.awt.event.ActionListener;
|
|
17
|
|
import java.beans.MethodDescriptor;
|
|
18
|
|
import java.beans.ParameterDescriptor;
|
|
19
|
|
import java.beans.PropertyEditor;
|
|
20
|
|
import java.beans.PropertyEditorManager;
|
|
21
|
|
import java.lang.reflect.InvocationTargetException;
|
|
22
|
|
import java.util.Vector;
|
|
23
|
|
|
|
24
|
|
import javax.swing.JButton;
|
|
25
|
|
import javax.swing.JDialog;
|
|
26
|
|
import javax.swing.JLabel;
|
|
27
|
|
import javax.swing.JOptionPane;
|
|
28
|
|
import javax.swing.JPanel;
|
|
29
|
|
|
|
30
|
|
import com.dreambean.awt.GenericPropertyCustomizer;
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
|
37
|
|
public class GenericMethodDialog extends JDialog
|
|
38
|
|
implements ActionListener
|
|
39
|
|
{
|
|
40
|
|
|
|
41
|
|
protected Vector editors;
|
|
42
|
|
|
|
43
|
|
protected MethodDescriptor md;
|
|
44
|
|
|
|
45
|
|
protected Object obj;
|
|
46
|
|
|
|
47
|
|
|
|
48
|
|
|
|
49
|
0
|
public GenericMethodDialog()
|
|
50
|
|
{
|
|
51
|
0
|
super();
|
|
52
|
|
}
|
|
53
|
|
|
|
54
|
|
|
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
|
61
|
|
|
|
62
|
0
|
public GenericMethodDialog(Object obj1, MethodDescriptor methoddescriptor, Frame frame)
|
|
63
|
|
{
|
|
64
|
0
|
super(frame, true);
|
|
65
|
0
|
editors = new Vector();
|
|
66
|
0
|
obj = obj1;
|
|
67
|
0
|
md = methoddescriptor;
|
|
68
|
0
|
JPanel jpanel = (JPanel) getContentPane();
|
|
69
|
0
|
jpanel.setLayout(new GridBagLayout());
|
|
70
|
0
|
try
|
|
71
|
|
{
|
|
72
|
0
|
GridBagConstraints gridbagconstraints = new GridBagConstraints();
|
|
73
|
0
|
gridbagconstraints.insets = new Insets(5, 5, 5, 5);
|
|
74
|
0
|
gridbagconstraints.anchor = 11;
|
|
75
|
0
|
gridbagconstraints.weighty = 1.0D;
|
|
76
|
0
|
ParameterDescriptor aparameterdescriptor[] = null;
|
|
77
|
0
|
Class aclass[] = methoddescriptor.getMethod().getParameterTypes();
|
|
78
|
0
|
if (methoddescriptor.getParameterDescriptors() != null)
|
|
79
|
|
{
|
|
80
|
0
|
aparameterdescriptor = methoddescriptor.getParameterDescriptors();
|
|
81
|
|
}
|
|
82
|
|
else
|
|
83
|
|
{
|
|
84
|
0
|
aparameterdescriptor = new ParameterDescriptor[aclass.length];
|
|
85
|
0
|
for (int i = 0; i < aclass.length; i++)
|
|
86
|
|
{
|
|
87
|
0
|
aparameterdescriptor[i] = new ParameterDescriptor();
|
|
88
|
0
|
aparameterdescriptor[i].setName(aclass[i].getName());
|
|
89
|
|
}
|
|
90
|
|
|
|
91
|
|
}
|
|
92
|
0
|
JLabel jlabel = new JLabel(methoddescriptor.getDisplayName());
|
|
93
|
0
|
gridbagconstraints.gridwidth = 0;
|
|
94
|
0
|
((GridBagLayout) jpanel.getLayout()).setConstraints(jlabel, gridbagconstraints);
|
|
95
|
0
|
jpanel.add(jlabel);
|
|
96
|
0
|
for (int j = 0; j < aparameterdescriptor.length; j++)
|
|
97
|
|
{
|
|
98
|
0
|
PropertyEditor propertyeditor = null;
|
|
99
|
0
|
String s = (String) aparameterdescriptor[j].getValue("propertyeditor");
|
|
100
|
0
|
if (s != null)
|
|
101
|
|
{
|
|
102
|
0
|
try
|
|
103
|
|
{
|
|
104
|
0
|
propertyeditor = (PropertyEditor) Class.forName(s).newInstance();
|
|
105
|
|
}
|
|
106
|
|
catch (Exception _ex)
|
|
107
|
|
{
|
|
108
|
0
|
continue;
|
|
109
|
|
}
|
|
110
|
|
}
|
|
111
|
|
else
|
|
112
|
|
{
|
|
113
|
0
|
propertyeditor = PropertyEditorManager.findEditor(aclass[j]);
|
|
114
|
|
}
|
|
115
|
0
|
if (propertyeditor != null)
|
|
116
|
|
{
|
|
117
|
0
|
JLabel jlabel1 = new JLabel(aparameterdescriptor[j].getDisplayName() + ":", 4);
|
|
118
|
0
|
gridbagconstraints.gridwidth = -1;
|
|
119
|
0
|
gridbagconstraints.fill = 0;
|
|
120
|
0
|
gridbagconstraints.weightx = 0.0D;
|
|
121
|
0
|
((GridBagLayout) jpanel.getLayout()).setConstraints(jlabel1, gridbagconstraints);
|
|
122
|
0
|
jpanel.add(jlabel1);
|
|
123
|
0
|
if (propertyeditor.getTags() != null)
|
|
124
|
|
{
|
|
125
|
0
|
propertyeditor.setAsText(propertyeditor.getTags()[0]);
|
|
126
|
|
}
|
|
127
|
|
else
|
|
128
|
|
{
|
|
129
|
0
|
try
|
|
130
|
|
{
|
|
131
|
0
|
propertyeditor.setValue(aclass[j].newInstance());
|
|
132
|
|
}
|
|
133
|
|
catch (Exception _ex)
|
|
134
|
|
{
|
|
135
|
|
}
|
|
136
|
|
}
|
|
137
|
0
|
Object obj2;
|
|
138
|
0
|
if (propertyeditor.supportsCustomEditor())
|
|
139
|
|
{
|
|
140
|
0
|
obj2 = propertyeditor.getCustomEditor();
|
|
141
|
|
}
|
|
142
|
|
else
|
|
143
|
|
{
|
|
144
|
0
|
String as[] = propertyeditor.getTags();
|
|
145
|
0
|
if (as != null)
|
|
146
|
|
{
|
|
147
|
0
|
obj2 = new GenericPropertyCustomizer(propertyeditor, as);
|
|
148
|
|
}
|
|
149
|
|
else
|
|
150
|
|
{
|
|
151
|
0
|
obj2 = new GenericPropertyCustomizer(propertyeditor);
|
|
152
|
|
}
|
|
153
|
|
}
|
|
154
|
0
|
gridbagconstraints.gridwidth = 0;
|
|
155
|
0
|
gridbagconstraints.fill = 2;
|
|
156
|
0
|
gridbagconstraints.weightx = 1.0D;
|
|
157
|
0
|
((GridBagLayout) jpanel.getLayout()).setConstraints(((Component) (obj2)), gridbagconstraints);
|
|
158
|
0
|
jpanel.add(((Component) (obj2)));
|
|
159
|
0
|
editors.addElement(propertyeditor);
|
|
160
|
|
}
|
|
161
|
0
|
gridbagconstraints.weighty = 1.0D;
|
|
162
|
|
}
|
|
163
|
0
|
gridbagconstraints.gridwidth = 0;
|
|
164
|
0
|
JPanel jpanel1 = new JPanel();
|
|
165
|
|
|
|
166
|
0
|
JButton jbutton = new JButton("Ok");
|
|
167
|
0
|
jpanel1.add(jbutton);
|
|
168
|
0
|
jbutton.addActionListener(this);
|
|
169
|
0
|
JButton jbutton1 = new JButton("Cancel");
|
|
170
|
0
|
jpanel1.add(jbutton1);
|
|
171
|
0
|
jbutton1.addActionListener(this);
|
|
172
|
0
|
((GridBagLayout) jpanel.getLayout()).setConstraints(jpanel1, gridbagconstraints);
|
|
173
|
0
|
jpanel.add(jpanel1);
|
|
174
|
0
|
pack();
|
|
175
|
0
|
if (getWidth() < 300)
|
|
176
|
|
{
|
|
177
|
0
|
setSize(new Dimension(300, getHeight()));
|
|
178
|
|
}
|
|
179
|
0
|
setLocationRelativeTo(frame);
|
|
180
|
0
|
setVisible(true);
|
|
181
|
|
}
|
|
182
|
|
catch (Exception exception)
|
|
183
|
|
{
|
|
184
|
0
|
System.out.println("Exception occurred");
|
|
185
|
0
|
exception.printStackTrace();
|
|
186
|
|
}
|
|
187
|
|
}
|
|
188
|
|
|
|
189
|
|
|
|
190
|
|
|
|
191
|
|
|
|
192
|
|
|
|
193
|
|
|
|
194
|
|
|
|
195
|
0
|
public void actionPerformed(ActionEvent actionevent)
|
|
196
|
|
{
|
|
197
|
0
|
if (actionevent.getActionCommand().equals("Ok"))
|
|
198
|
|
{
|
|
199
|
0
|
Object aobj[] = new Object[editors.size()];
|
|
200
|
0
|
for (int i = 0; i < aobj.length; i++)
|
|
201
|
|
{
|
|
202
|
0
|
aobj[i] = ((PropertyEditor) editors.elementAt(i)).getValue();
|
|
203
|
|
}
|
|
204
|
0
|
try
|
|
205
|
|
{
|
|
206
|
0
|
Object obj1 = md.getMethod().invoke(obj, aobj);
|
|
207
|
0
|
if (obj1 != null)
|
|
208
|
|
{
|
|
209
|
0
|
JOptionPane.showMessageDialog(this, obj1.toString(), "Result", 1);
|
|
210
|
|
}
|
|
211
|
|
}
|
|
212
|
|
catch (InvocationTargetException invocationtargetexception)
|
|
213
|
|
{
|
|
214
|
0
|
invocationtargetexception.getTargetException().printStackTrace();
|
|
215
|
0
|
JOptionPane.showMessageDialog(this, invocationtargetexception.getTargetException().getMessage(), "Error", 0);
|
|
216
|
|
}
|
|
217
|
|
catch (Exception exception)
|
|
218
|
|
{
|
|
219
|
0
|
System.err.println(exception);
|
|
220
|
0
|
JOptionPane.showMessageDialog(this, "An exception occured. Check log for details", "Error", 0);
|
|
221
|
|
}
|
|
222
|
|
}
|
|
223
|
0
|
setVisible(false);
|
|
224
|
|
}
|
|
225
|
|
}
|
|
226
|
|
|