1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.ui.element;
|
11
|
|
12
|
import org.apache.commons.lang3.StringUtils;
|
13
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
14
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
15
|
import org.eclipse.jface.wizard.WizardPage;
|
16
|
import org.eclipse.swt.graphics.Color;
|
17
|
import org.eclipse.swt.widgets.Composite;
|
18
|
import org.eclipse.ui.forms.widgets.ScrolledForm;
|
19
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
22
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
23
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
24
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
25
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
26
|
|
27
|
/**
|
28
|
* <p>
|
29
|
* Abstract AbstractCdmEntityWizardPage class.
|
30
|
* </p>
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @created Jun 1, 2010
|
34
|
*/
|
35
|
public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
|
36
|
implements IConversationEnabled, IPropertyChangeListener {
|
37
|
|
38
|
protected CdmFormFactory formFactory;
|
39
|
protected T entity;
|
40
|
|
41
|
AbstractCdmDetailElement<T> detailElement;
|
42
|
private final ConversationHolder conversation;
|
43
|
|
44
|
/**
|
45
|
* <p>
|
46
|
* Constructor for AbstractCdmEntityWizardPage.
|
47
|
* </p>
|
48
|
*
|
49
|
* @param formFactory
|
50
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
|
51
|
* object.
|
52
|
* @param conversation
|
53
|
* a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
54
|
* object.
|
55
|
* @param entity
|
56
|
* a T object.
|
57
|
* @param <T>
|
58
|
* a T object.
|
59
|
*/
|
60
|
protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory,
|
61
|
ConversationHolder conversation, T entity) {
|
62
|
super("page");
|
63
|
this.formFactory = formFactory;
|
64
|
this.entity = entity;
|
65
|
this.conversation = conversation;
|
66
|
setDescription(getEntityTitle());
|
67
|
|
68
|
formFactory.addPropertyChangeListener(this);
|
69
|
setPageComplete(false);
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* @return
|
74
|
*/
|
75
|
private String getEntityTitle() {
|
76
|
if (entity instanceof IIdentifiableEntity) {
|
77
|
((IIdentifiableEntity) entity).getTitleCache();
|
78
|
}
|
79
|
return "";
|
80
|
}
|
81
|
|
82
|
/** {@inheritDoc} */
|
83
|
@Override
|
84
|
public void createControl(Composite parent) {
|
85
|
ScrolledForm scrolledForm = formFactory.createScrolledForm(parent);
|
86
|
scrolledForm.getBody().setLayout(LayoutConstants.LAYOUT());
|
87
|
|
88
|
Composite control = formFactory.createComposite(scrolledForm.getBody());
|
89
|
control.setLayoutData(LayoutConstants.FILL());
|
90
|
|
91
|
TableWrapLayout layout = LayoutConstants.LAYOUT(2, false);
|
92
|
layout.horizontalSpacing = 5;
|
93
|
layout.bottomMargin = 25;
|
94
|
control.setLayout(layout);
|
95
|
WizardPageRootElement rootElement = new WizardPageRootElement(
|
96
|
formFactory, control, getConversationHolder());
|
97
|
|
98
|
Color bgColor = getShell().getBackground();
|
99
|
|
100
|
detailElement = createElement(rootElement);
|
101
|
|
102
|
rootElement.setBackground(bgColor);
|
103
|
control.setBackground(bgColor);
|
104
|
scrolledForm.setBackground(bgColor);
|
105
|
|
106
|
setControl(scrolledForm);
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* <p>
|
111
|
* Getter for the field <code>entity</code>.
|
112
|
* </p>
|
113
|
*
|
114
|
* @return a T object.
|
115
|
*/
|
116
|
public T getEntity() {
|
117
|
return entity;
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Creates the detail element for this wizard page
|
122
|
*
|
123
|
* @param rootElement
|
124
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
125
|
* object.
|
126
|
* @return a
|
127
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
128
|
* object.
|
129
|
*/
|
130
|
public abstract AbstractCdmDetailElement<T> createElement(
|
131
|
ICdmFormElement rootElement);
|
132
|
|
133
|
protected class WizardPageRootElement extends RootElement implements
|
134
|
IConversationEnabled {
|
135
|
|
136
|
private final ConversationHolder conversation;
|
137
|
|
138
|
public WizardPageRootElement(CdmFormFactory formFactory,
|
139
|
Composite layoutComposite, ConversationHolder conversation) {
|
140
|
super(formFactory, layoutComposite);
|
141
|
this.conversation = conversation;
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
public void refresh() {
|
146
|
super.refresh();
|
147
|
this.removeElements();
|
148
|
detailElement = createElement(this);
|
149
|
((Composite) getControl()).layout();
|
150
|
}
|
151
|
|
152
|
@Override
|
153
|
public ConversationHolder getConversationHolder() {
|
154
|
return conversation;
|
155
|
}
|
156
|
|
157
|
@Override
|
158
|
public void update(CdmDataChangeMap changeEvents) {
|
159
|
}
|
160
|
}
|
161
|
|
162
|
@Override
|
163
|
public void propertyChange(PropertyChangeEvent event) {
|
164
|
if (event.getSource() == getDetailElement()) {
|
165
|
checkComplete();
|
166
|
}
|
167
|
else if(event.getSource() instanceof AbstractCdmDetailElement){
|
168
|
//check if parent element is set as detail element
|
169
|
ICdmFormElement formElement = (ICdmFormElement) event.getSource();
|
170
|
while(formElement.getParentElement()!=null){
|
171
|
if(formElement.getParentElement() == getDetailElement()){
|
172
|
checkComplete();
|
173
|
return;
|
174
|
}
|
175
|
formElement = formElement.getParentElement();
|
176
|
}
|
177
|
}
|
178
|
}
|
179
|
|
180
|
/**
|
181
|
* Should check whether the wizard is complete in a sense that it contains
|
182
|
* sane data. Should setPageComplete to true if that is the case.
|
183
|
*/
|
184
|
protected void checkComplete() {
|
185
|
setPageComplete(titleCacheIsNotEmpty());
|
186
|
}
|
187
|
|
188
|
protected boolean titleCacheIsNotEmpty() {
|
189
|
if (getEntity() instanceof IIdentifiableEntity) {
|
190
|
IIdentifiableEntity entity = (IIdentifiableEntity) getEntity();
|
191
|
return !StringUtils.isEmpty(entity.getTitleCache());
|
192
|
}
|
193
|
return true;
|
194
|
}
|
195
|
|
196
|
/**
|
197
|
* <p>
|
198
|
* getConversationHolder
|
199
|
* </p>
|
200
|
*
|
201
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
202
|
* object.
|
203
|
*/
|
204
|
@Override
|
205
|
public ConversationHolder getConversationHolder() {
|
206
|
return conversation;
|
207
|
}
|
208
|
|
209
|
/** {@inheritDoc} */
|
210
|
@Override
|
211
|
public void dispose() {
|
212
|
if (detailElement != null) {
|
213
|
detailElement.removeElements();
|
214
|
}
|
215
|
formFactory.removePropertyChangeListener(this);
|
216
|
super.dispose();
|
217
|
}
|
218
|
|
219
|
/**
|
220
|
* <p>
|
221
|
* Getter for the field <code>detailElement</code>.
|
222
|
* </p>
|
223
|
*
|
224
|
* @return a
|
225
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
226
|
* object.
|
227
|
*/
|
228
|
public AbstractCdmDetailElement<T> getDetailElement() {
|
229
|
return detailElement;
|
230
|
}
|
231
|
|
232
|
/** {@inheritDoc} */
|
233
|
@Override
|
234
|
public void update(CdmDataChangeMap changeEvents) {
|
235
|
}
|
236
|
}
|