1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
/*******************************************************************************
* Copyright (c) 2010 BestSolution.at and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.classes;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Set;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.e4.internal.tools.wizards.classes.AbstractNewClassPage.JavaClass;
import org.eclipse.e4.internal.tools.wizards.classes.templates.PartTemplate;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class NewPartClassWizard extends AbstractNewClassWizard {
private String initialString;
public NewPartClassWizard(String contributionURI) {
this.initialString = contributionURI;
}
public NewPartClassWizard() {
// Intentially left empty
}
@Override
public void addPages() {
addPage(new AbstractNewClassPage("Classinformation", "New Part",
"Create a new part class", root, ResourcesPlugin.getWorkspace()
.getRoot(), initialString) {
@Override
protected void createFields(Composite parent, DataBindingContext dbc) {
IWidgetValueProperty textProp = WidgetProperties
.text(SWT.Modify);
IWidgetValueProperty enabledProp = WidgetProperties.enabled();
{
Label l = new Label(parent, SWT.NONE);
l.setText("PostContruct Method");
Text t = new Text(parent, SWT.BORDER);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
dbc.bindValue(textProp.observe(t),
BeanProperties.value("postConstructMethodName")
.observe(getClazz()));
dbc.bindValue(
enabledProp.observe(t),
BeanProperties.value("usePostConstruct").observe(
getClazz()));
Button b = new Button(parent, SWT.CHECK);
dbc.bindValue(
WidgetProperties.selection().observe(b),
BeanProperties.value("usePostConstruct").observe(
getClazz()));
}
{
Label l = new Label(parent, SWT.NONE);
l.setText("Predestroy Method");
Text t = new Text(parent, SWT.BORDER);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
dbc.bindValue(textProp.observe(t),
BeanProperties.value("preDestroyMethodName")
.observe(getClazz()));
dbc.bindValue(
enabledProp.observe(t),
BeanProperties.value("usePredestroy").observe(
getClazz()));
Button b = new Button(parent, SWT.CHECK);
dbc.bindValue(
WidgetProperties.selection().observe(b),
BeanProperties.value("usePredestroy").observe(
getClazz()));
}
{
Label l = new Label(parent, SWT.NONE);
l.setText("Focus Method");
Text t = new Text(parent, SWT.BORDER);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
dbc.bindValue(textProp.observe(t),
BeanProperties.value("focusMethodName")
.observe(getClazz()));
dbc.bindValue(
enabledProp.observe(t),
BeanProperties.value("useFocus").observe(
getClazz()));
Button b = new Button(parent, SWT.CHECK);
dbc.bindValue(
WidgetProperties.selection().observe(b),
BeanProperties.value("useFocus").observe(
getClazz()));
}
{
Label l = new Label(parent, SWT.NONE);
l.setText("Persist Method");
Text t = new Text(parent, SWT.BORDER);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
dbc.bindValue(textProp.observe(t),
BeanProperties.value("persistMethodName")
.observe(getClazz()));
dbc.bindValue(
enabledProp.observe(t),
BeanProperties.value("usePersist").observe(
getClazz()));
Button b = new Button(parent, SWT.CHECK);
dbc.bindValue(
WidgetProperties.selection().observe(b),
BeanProperties.value("usePersist").observe(
getClazz()));
}
}
@Override
protected JavaClass createInstance() {
return new PartClass(root);
}
});
}
@Override
protected Set<String> getRequiredBundles() {
Set<String> rv = super.getRequiredBundles();
PartClass cl = (PartClass)getDomainClass();
if( cl.usePostConstruct || cl.usePredestroy ) {
rv.add("javax.annotation");
} else if( cl.useFocus || cl.usePersist ) {
rv.add("org.eclipse.e4.ui.di");
}
return rv;
}
@Override
protected String getContent() {
PartTemplate template = new PartTemplate();
return template.generate(getDomainClass());
}
public static class PartClass extends JavaClass {
private PropertyChangeSupport support = new PropertyChangeSupport(this);
private boolean usePostConstruct;
private String postConstructMethodName = "postConstruct";
private boolean usePredestroy;
private String preDestroyMethodName = "preDestroy";
private boolean useFocus = true;
private String focusMethodName = "onFocus";
private boolean usePersist;
private String persistMethodName = "save";
public PartClass(IPackageFragmentRoot fragmentRoot) {
super(fragmentRoot);
}
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
support.addPropertyChangeListener(listener);
}
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
support.removePropertyChangeListener(listener);
}
public boolean isUsePostConstruct() {
return usePostConstruct;
}
public void setUsePostConstruct(boolean usePostConstruct) {
support.firePropertyChange("usePostConstruct",
this.usePostConstruct,
this.usePostConstruct = usePostConstruct);
}
public String getPostConstructMethodName() {
return postConstructMethodName;
}
public void setPostConstructMethodName(String postConstructMethodName) {
support.firePropertyChange("postConstructMethodName",
this.postConstructMethodName,
this.postConstructMethodName = postConstructMethodName);
}
public boolean isUsePredestroy() {
return usePredestroy;
}
public void setUsePredestroy(boolean usePredestroy) {
support.firePropertyChange("usePredestroy", this.usePredestroy,
this.usePredestroy = usePredestroy);
}
public String getPreDestroyMethodName() {
return preDestroyMethodName;
}
public void setPreDestroyMethodName(String preDestroyMethodName) {
support.firePropertyChange("preDestroyMethodName",
this.preDestroyMethodName,
this.preDestroyMethodName = preDestroyMethodName);
}
public boolean isUseFocus() {
return useFocus;
}
public void setUseFocus(boolean useFocus) {
support.firePropertyChange("useFocus", this.useFocus,
this.useFocus = useFocus);
}
public String getFocusMethodName() {
return focusMethodName;
}
public void setFocusMethodName(String focusMethodName) {
support.firePropertyChange("focusMethodName", this.focusMethodName,
this.focusMethodName = focusMethodName);
}
public boolean isUsePersist() {
return usePersist;
}
public void setUsePersist(boolean usePersist) {
support.firePropertyChange("usePersist", this.usePersist,
this.usePersist = usePersist);
}
public String getPersistMethodName() {
return persistMethodName;
}
public void setPersistMethodName(String persistMethodName) {
support.firePropertyChange("persistMethodName",
this.persistMethodName,
this.persistMethodName = persistMethodName);
}
}
}
|