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.model.common.IIdentifiableEntity;
|
22
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
23
|
|
24
|
/**
|
25
|
* <p>
|
26
|
* Abstract AbstractCdmEntityWizardPage class.
|
27
|
* </p>
|
28
|
*
|
29
|
* @author n.hoffmann
|
30
|
* @created Jun 1, 2010
|
31
|
*/
|
32
|
public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
|
33
|
implements IPropertyChangeListener {
|
34
|
|
35
|
protected CdmFormFactory formFactory;
|
36
|
protected T entity;
|
37
|
|
38
|
AbstractCdmDetailElement<T> detailElement;
|
39
|
|
40
|
/**
|
41
|
* <p>
|
42
|
* Constructor for AbstractCdmEntityWizardPage.
|
43
|
* </p>
|
44
|
*
|
45
|
* @param formFactory
|
46
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
|
47
|
* object.
|
48
|
* @param conversation
|
49
|
* a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
|
50
|
* object.
|
51
|
* @param entity
|
52
|
* a T object.
|
53
|
* @param <T>
|
54
|
* a T object.
|
55
|
*/
|
56
|
protected AbstractCdmEntityWizardPage(CdmFormFactory formFactory, T entity) {
|
57
|
super("page");
|
58
|
this.formFactory = formFactory;
|
59
|
this.entity = entity;
|
60
|
setDescription(getEntityTitle());
|
61
|
|
62
|
formFactory.addPropertyChangeListener(this);
|
63
|
setPageComplete(false);
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* @return
|
68
|
*/
|
69
|
private String getEntityTitle() {
|
70
|
if (entity instanceof IIdentifiableEntity) {
|
71
|
((IIdentifiableEntity) entity).getTitleCache();
|
72
|
}
|
73
|
return "";
|
74
|
}
|
75
|
|
76
|
/** {@inheritDoc} */
|
77
|
@Override
|
78
|
public void createControl(Composite parent) {
|
79
|
ScrolledForm scrolledForm = formFactory.createScrolledForm(parent);
|
80
|
scrolledForm.getBody().setLayout(LayoutConstants.LAYOUT());
|
81
|
|
82
|
Composite control = formFactory.createComposite(scrolledForm.getBody());
|
83
|
control.setLayoutData(LayoutConstants.FILL());
|
84
|
|
85
|
TableWrapLayout layout = LayoutConstants.LAYOUT(2, false);
|
86
|
layout.horizontalSpacing = 5;
|
87
|
layout.bottomMargin = 25;
|
88
|
control.setLayout(layout);
|
89
|
WizardPageRootElement rootElement = new WizardPageRootElement(
|
90
|
formFactory, control);
|
91
|
|
92
|
Color bgColor = getShell().getBackground();
|
93
|
|
94
|
detailElement = createElement(rootElement);
|
95
|
|
96
|
rootElement.setBackground(bgColor);
|
97
|
control.setBackground(bgColor);
|
98
|
scrolledForm.setBackground(bgColor);
|
99
|
|
100
|
setControl(scrolledForm);
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* <p>
|
105
|
* Getter for the field <code>entity</code>.
|
106
|
* </p>
|
107
|
*
|
108
|
* @return a T object.
|
109
|
*/
|
110
|
public T getEntity() {
|
111
|
return entity;
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Creates the detail element for this wizard page
|
116
|
*
|
117
|
* @param rootElement
|
118
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
119
|
* object.
|
120
|
* @return a
|
121
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
122
|
* object.
|
123
|
*/
|
124
|
public abstract AbstractCdmDetailElement<T> createElement(
|
125
|
ICdmFormElement rootElement);
|
126
|
|
127
|
protected class WizardPageRootElement extends RootElement {
|
128
|
|
129
|
public WizardPageRootElement(CdmFormFactory formFactory, Composite layoutComposite) {
|
130
|
super(formFactory, layoutComposite);
|
131
|
|
132
|
}
|
133
|
|
134
|
@Override
|
135
|
public void refresh() {
|
136
|
super.refresh();
|
137
|
this.removeElements();
|
138
|
detailElement = createElement(this);
|
139
|
((Composite) getControl()).layout();
|
140
|
}
|
141
|
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
public void propertyChange(PropertyChangeEvent event) {
|
146
|
if (event.getSource() == getDetailElement()) {
|
147
|
checkComplete();
|
148
|
}
|
149
|
else if(event.getSource() instanceof AbstractCdmDetailElement){
|
150
|
//check if parent element is set as detail element
|
151
|
ICdmFormElement formElement = (ICdmFormElement) event.getSource();
|
152
|
while(formElement.getParentElement()!=null){
|
153
|
if(formElement.getParentElement() == getDetailElement()){
|
154
|
checkComplete();
|
155
|
return;
|
156
|
}
|
157
|
formElement = formElement.getParentElement();
|
158
|
}
|
159
|
}
|
160
|
}
|
161
|
|
162
|
/**
|
163
|
* Should check whether the wizard is complete in a sense that it contains
|
164
|
* sane data. Should setPageComplete to true if that is the case.
|
165
|
*/
|
166
|
protected void checkComplete() {
|
167
|
setPageComplete(titleCacheIsNotEmpty());
|
168
|
}
|
169
|
|
170
|
protected boolean titleCacheIsNotEmpty() {
|
171
|
if (getEntity() instanceof IIdentifiableEntity) {
|
172
|
IIdentifiableEntity entity = (IIdentifiableEntity) getEntity();
|
173
|
return !StringUtils.isEmpty(entity.getTitleCache());
|
174
|
}
|
175
|
return true;
|
176
|
}
|
177
|
|
178
|
|
179
|
/** {@inheritDoc} */
|
180
|
@Override
|
181
|
public void dispose() {
|
182
|
if (detailElement != null) {
|
183
|
detailElement.removeElements();
|
184
|
}
|
185
|
formFactory.removePropertyChangeListener(this);
|
186
|
super.dispose();
|
187
|
}
|
188
|
|
189
|
/**
|
190
|
* <p>
|
191
|
* Getter for the field <code>detailElement</code>.
|
192
|
* </p>
|
193
|
*
|
194
|
* @return a
|
195
|
* {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
|
196
|
* object.
|
197
|
*/
|
198
|
public AbstractCdmDetailElement<T> getDetailElement() {
|
199
|
return detailElement;
|
200
|
}
|
201
|
|
202
|
|
203
|
}
|