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.lang.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
|
* @version 1.0
|
35
|
*/
|
36
|
public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
|
37
|
implements IConversationEnabled, IPropertyChangeListener {
|
38
|
|
39
|
protected CdmFormFactory formFactory;
|
40
|
protected T entity;
|
41
|
|
42
|
AbstractCdmDetailElement<T> detailElement;
|
43
|
private final ConversationHolder conversation;
|
44
|
|
45
|
/**
|
46
|
* <p>
|
47
|
* Constructor for AbstractCdmEntityWizardPage.
|
48
|
* </p>
|
49
|
*
|
50
|
* @param formFactory
|
51
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
|
52
|
* object.
|
53
|
* @param conversation
|
54
|
* a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
55
|
* object.
|
56
|
* @param entity
|
57
|
* a T object.
|
58
|
* @param <T>
|
59
|
* a T object.
|
60
|
*/
|
61
|
protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory,
|
62
|
ConversationHolder conversation, T entity) {
|
63
|
super("page");
|
64
|
this.formFactory = formFactory;
|
65
|
this.entity = entity;
|
66
|
this.conversation = conversation;
|
67
|
setDescription(getEntityTitle());
|
68
|
|
69
|
formFactory.addPropertyChangeListener(this);
|
70
|
setPageComplete(false);
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* @return
|
75
|
*/
|
76
|
private String getEntityTitle() {
|
77
|
if (entity instanceof IIdentifiableEntity) {
|
78
|
((IIdentifiableEntity) entity).getTitleCache();
|
79
|
}
|
80
|
return "";
|
81
|
}
|
82
|
|
83
|
/*
|
84
|
* (non-Javadoc)
|
85
|
*
|
86
|
* @see
|
87
|
* org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
|
88
|
* .Composite)
|
89
|
*/
|
90
|
/** {@inheritDoc} */
|
91
|
@Override
|
92
|
public void createControl(Composite parent) {
|
93
|
ScrolledForm scrolledForm = formFactory.createScrolledForm(parent);
|
94
|
scrolledForm.getBody().setLayout(LayoutConstants.LAYOUT());
|
95
|
|
96
|
Composite control = formFactory.createComposite(scrolledForm.getBody());
|
97
|
control.setLayoutData(LayoutConstants.FILL());
|
98
|
|
99
|
TableWrapLayout layout = LayoutConstants.LAYOUT(2, false);
|
100
|
layout.horizontalSpacing = 5;
|
101
|
control.setLayout(layout);
|
102
|
WizardPageRootElement rootElement = new WizardPageRootElement(
|
103
|
formFactory, control, getConversationHolder());
|
104
|
|
105
|
Color bgColor = getShell().getBackground();
|
106
|
|
107
|
detailElement = createElement(rootElement);
|
108
|
|
109
|
rootElement.setBackground(bgColor);
|
110
|
control.setBackground(bgColor);
|
111
|
scrolledForm.setBackground(bgColor);
|
112
|
|
113
|
setControl(scrolledForm);
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* <p>
|
118
|
* Getter for the field <code>entity</code>.
|
119
|
* </p>
|
120
|
*
|
121
|
* @return a T object.
|
122
|
*/
|
123
|
public T getEntity() {
|
124
|
return entity;
|
125
|
}
|
126
|
|
127
|
/**
|
128
|
* Creates the detail element for this wizard page
|
129
|
*
|
130
|
* @param rootElement
|
131
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
132
|
* object.
|
133
|
* @return a
|
134
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
135
|
* object.
|
136
|
*/
|
137
|
public abstract AbstractCdmDetailElement<T> createElement(
|
138
|
ICdmFormElement rootElement);
|
139
|
|
140
|
protected class WizardPageRootElement extends RootElement implements
|
141
|
IConversationEnabled {
|
142
|
|
143
|
private final ConversationHolder conversation;
|
144
|
|
145
|
public WizardPageRootElement(CdmFormFactory formFactory,
|
146
|
Composite layoutComposite, ConversationHolder conversation) {
|
147
|
super(formFactory, layoutComposite);
|
148
|
this.conversation = conversation;
|
149
|
}
|
150
|
|
151
|
@Override
|
152
|
public void refresh() {
|
153
|
super.refresh();
|
154
|
this.removeElements();
|
155
|
detailElement = createElement(this);
|
156
|
((Composite) getControl()).layout();
|
157
|
}
|
158
|
|
159
|
@Override
|
160
|
public ConversationHolder getConversationHolder() {
|
161
|
return conversation;
|
162
|
}
|
163
|
|
164
|
@Override
|
165
|
public void update(CdmDataChangeMap changeEvents) {
|
166
|
}
|
167
|
}
|
168
|
|
169
|
@Override
|
170
|
public void propertyChange(PropertyChangeEvent event) {
|
171
|
if (event.getSource() == getDetailElement()) {
|
172
|
checkComplete();
|
173
|
}
|
174
|
else if(event.getSource() instanceof AbstractCdmDetailElement){
|
175
|
//check if parent element is set as detail element
|
176
|
ICdmFormElement formElement = (ICdmFormElement) event.getSource();
|
177
|
while(formElement.getParentElement()!=null){
|
178
|
if(formElement.getParentElement() == getDetailElement()){
|
179
|
checkComplete();
|
180
|
return;
|
181
|
}
|
182
|
formElement = formElement.getParentElement();
|
183
|
}
|
184
|
}
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* Should check whether the wizard is complete in a sense that it contains
|
189
|
* sane data. Should setPageComplete to true if that is the case.
|
190
|
*/
|
191
|
protected void checkComplete() {
|
192
|
setPageComplete(titleCacheIsNotEmpty());
|
193
|
}
|
194
|
|
195
|
private boolean titleCacheIsNotEmpty() {
|
196
|
if (getEntity() instanceof IIdentifiableEntity) {
|
197
|
IIdentifiableEntity entity = (IIdentifiableEntity) getEntity();
|
198
|
return !StringUtils.isEmpty(entity.getTitleCache());
|
199
|
}
|
200
|
return true;
|
201
|
}
|
202
|
|
203
|
/**
|
204
|
* <p>
|
205
|
* getConversationHolder
|
206
|
* </p>
|
207
|
*
|
208
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
209
|
* object.
|
210
|
*/
|
211
|
@Override
|
212
|
public ConversationHolder getConversationHolder() {
|
213
|
return conversation;
|
214
|
}
|
215
|
|
216
|
/** {@inheritDoc} */
|
217
|
@Override
|
218
|
public void dispose() {
|
219
|
if (detailElement != null) {
|
220
|
detailElement.removeElements();
|
221
|
}
|
222
|
formFactory.removePropertyChangeListener(this);
|
223
|
super.dispose();
|
224
|
}
|
225
|
|
226
|
/**
|
227
|
* <p>
|
228
|
* Getter for the field <code>detailElement</code>.
|
229
|
* </p>
|
230
|
*
|
231
|
* @return a
|
232
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
233
|
* object.
|
234
|
*/
|
235
|
public AbstractCdmDetailElement<T> getDetailElement() {
|
236
|
return detailElement;
|
237
|
}
|
238
|
|
239
|
/** {@inheritDoc} */
|
240
|
@Override
|
241
|
public void update(CdmDataChangeMap changeEvents) {
|
242
|
}
|
243
|
}
|