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