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
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
23
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
24
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
25
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
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
|
TableWrapLayout layout = LayoutConstants.LAYOUT(2, false);
|
101
|
layout.horizontalSpacing = 5;
|
102
|
control.setLayout(layout);
|
103
|
WizardPageRootElement rootElement = new WizardPageRootElement(
|
104
|
formFactory, control, getConversationHolder());
|
105
|
|
106
|
Color bgColor = getShell().getBackground();
|
107
|
|
108
|
detailElement = createElement(rootElement);
|
109
|
|
110
|
rootElement.setBackground(bgColor);
|
111
|
control.setBackground(bgColor);
|
112
|
scrolledForm.setBackground(bgColor);
|
113
|
|
114
|
setControl(scrolledForm);
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* <p>
|
119
|
* Getter for the field <code>entity</code>.
|
120
|
* </p>
|
121
|
*
|
122
|
* @return a T object.
|
123
|
*/
|
124
|
public T getEntity() {
|
125
|
return entity;
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Creates the detail element for this wizard page
|
130
|
*
|
131
|
* @param rootElement
|
132
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
133
|
* object.
|
134
|
* @return a
|
135
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
136
|
* object.
|
137
|
*/
|
138
|
public abstract AbstractCdmDetailElement<T> createElement(
|
139
|
ICdmFormElement rootElement);
|
140
|
|
141
|
protected class WizardPageRootElement extends RootElement implements
|
142
|
IConversationEnabled {
|
143
|
|
144
|
private final ConversationHolder conversation;
|
145
|
|
146
|
public WizardPageRootElement(CdmFormFactory formFactory,
|
147
|
Composite layoutComposite, ConversationHolder conversation) {
|
148
|
super(formFactory, layoutComposite);
|
149
|
this.conversation = conversation;
|
150
|
}
|
151
|
|
152
|
@Override
|
153
|
public void refresh() {
|
154
|
super.refresh();
|
155
|
this.removeElements();
|
156
|
detailElement = createElement(this);
|
157
|
((Composite) getControl()).layout();
|
158
|
}
|
159
|
|
160
|
@Override
|
161
|
public ConversationHolder getConversationHolder() {
|
162
|
return conversation;
|
163
|
}
|
164
|
|
165
|
@Override
|
166
|
public void update(CdmDataChangeMap changeEvents) {
|
167
|
}
|
168
|
}
|
169
|
|
170
|
@Override
|
171
|
public void propertyChange(PropertyChangeEvent event) {
|
172
|
if (event.getSource() == getDetailElement()) {
|
173
|
checkComplete();
|
174
|
}
|
175
|
else if(event.getSource() instanceof AbstractCdmDetailElement){
|
176
|
//check if parent element is set as detail element
|
177
|
ICdmFormElement formElement = (ICdmFormElement) event.getSource();
|
178
|
while(formElement.getParentElement()!=null){
|
179
|
if(formElement.getParentElement() == getDetailElement()){
|
180
|
checkComplete();
|
181
|
return;
|
182
|
}
|
183
|
formElement = formElement.getParentElement();
|
184
|
}
|
185
|
}
|
186
|
}
|
187
|
|
188
|
/**
|
189
|
* Should check whether the wizard is complete in a sense that it contains
|
190
|
* sane data. Should setPageComplete to true if that is the case.
|
191
|
*/
|
192
|
protected void checkComplete() {
|
193
|
setPageComplete(titleCacheIsNotEmpty());
|
194
|
}
|
195
|
|
196
|
private boolean titleCacheIsNotEmpty() {
|
197
|
if (getEntity() instanceof IIdentifiableEntity) {
|
198
|
IIdentifiableEntity entity = (IIdentifiableEntity) getEntity();
|
199
|
return !StringUtils.isEmpty(entity.getTitleCache());
|
200
|
}
|
201
|
return true;
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
* <p>
|
206
|
* getConversationHolder
|
207
|
* </p>
|
208
|
*
|
209
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
210
|
* object.
|
211
|
*/
|
212
|
@Override
|
213
|
public ConversationHolder getConversationHolder() {
|
214
|
return conversation;
|
215
|
}
|
216
|
|
217
|
/** {@inheritDoc} */
|
218
|
@Override
|
219
|
public void dispose() {
|
220
|
if (detailElement != null) {
|
221
|
detailElement.removeElements();
|
222
|
}
|
223
|
formFactory.removePropertyChangeListener(this);
|
224
|
super.dispose();
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* <p>
|
229
|
* Getter for the field <code>detailElement</code>.
|
230
|
* </p>
|
231
|
*
|
232
|
* @return a
|
233
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
234
|
* object.
|
235
|
*/
|
236
|
public AbstractCdmDetailElement<T> getDetailElement() {
|
237
|
return detailElement;
|
238
|
}
|
239
|
|
240
|
/** {@inheritDoc} */
|
241
|
@Override
|
242
|
public void update(CdmDataChangeMap changeEvents) {
|
243
|
}
|
244
|
}
|