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.editor;
|
11
|
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.eclipse.core.runtime.Assert;
|
14
|
import org.eclipse.swt.widgets.Composite;
|
15
|
import org.eclipse.ui.forms.widgets.FormToolkit;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
18
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
19
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
20
|
import eu.etaxonomy.cdm.model.description.Feature;
|
21
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
22
|
import eu.etaxonomy.cdm.model.media.ImageFile;
|
23
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
24
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
25
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
26
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
27
|
import eu.etaxonomy.taxeditor.editor.description.CommonNameComposite;
|
28
|
import eu.etaxonomy.taxeditor.editor.description.DescriptionElementComposite;
|
29
|
import eu.etaxonomy.taxeditor.editor.description.DescriptionFeatureGroupComposite;
|
30
|
import eu.etaxonomy.taxeditor.editor.description.DescriptionGroupComposite;
|
31
|
import eu.etaxonomy.taxeditor.editor.description.DescriptionLabelComposite;
|
32
|
import eu.etaxonomy.taxeditor.editor.description.DistributionComposite;
|
33
|
import eu.etaxonomy.taxeditor.editor.description.DistributionFeatureGroupComposite;
|
34
|
import eu.etaxonomy.taxeditor.editor.description.TaxonDescriptionEditor;
|
35
|
import eu.etaxonomy.taxeditor.editor.images.GalleryLabelComposite;
|
36
|
import eu.etaxonomy.taxeditor.editor.images.ImageComposite;
|
37
|
import eu.etaxonomy.taxeditor.editor.images.ImagesGroupComposite;
|
38
|
import eu.etaxonomy.taxeditor.editor.images.TaxonHasNoImagesComposite;
|
39
|
import eu.etaxonomy.taxeditor.editor.images.TaxonImageEditor;
|
40
|
import eu.etaxonomy.taxeditor.editor.name.AcceptedNameComposite;
|
41
|
import eu.etaxonomy.taxeditor.editor.name.ConceptComposite;
|
42
|
import eu.etaxonomy.taxeditor.editor.name.ConceptGroupComposite;
|
43
|
import eu.etaxonomy.taxeditor.editor.name.HomotypicalGroupComposite;
|
44
|
import eu.etaxonomy.taxeditor.editor.name.MisappliedGroupComposite;
|
45
|
import eu.etaxonomy.taxeditor.editor.name.MisappliedNameComposite;
|
46
|
import eu.etaxonomy.taxeditor.editor.name.SynonymComposite;
|
47
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
48
|
|
49
|
/**
|
50
|
* @author p.ciardelli
|
51
|
* @created 08.01.2009
|
52
|
* @version 1.0
|
53
|
*/
|
54
|
public class FreeTextElementFactory implements IFreeTextElementFactory {
|
55
|
private static final Logger logger = Logger
|
56
|
.getLogger(FreeTextElementFactory.class);
|
57
|
|
58
|
private static IFreeTextElementFactory factory;
|
59
|
|
60
|
public static IFreeTextElementFactory getDefault() {
|
61
|
if (factory == null) {
|
62
|
factory = new FreeTextElementFactory();
|
63
|
}
|
64
|
return factory;
|
65
|
}
|
66
|
|
67
|
public Composite createAcceptedTaxon(AbstractTaxonEditor editor) {
|
68
|
// Create a homotypic group composite for the accepted taxon
|
69
|
HomotypicalGroup group = editor.getTaxon().getHomotypicGroup();
|
70
|
Assert.isNotNull(group, "Taxon does not have a homotypic group");
|
71
|
Composite groupComposite = createHomotypicalGroup(editor, group);
|
72
|
|
73
|
// Create a name composite for the accepted taxon
|
74
|
Composite acceptedNameComposite = new AcceptedNameComposite(editor, groupComposite);
|
75
|
|
76
|
// Return the name composite
|
77
|
return acceptedNameComposite;
|
78
|
}
|
79
|
|
80
|
public Composite createSynonym(TaxonNameEditor editor, Synonym synonym) {
|
81
|
// Get the synonym's homotypic group
|
82
|
HomotypicalGroup group = synonym.getHomotypicGroup();
|
83
|
Assert.isNotNull(group, "Synonym does not have a homotypic group");
|
84
|
|
85
|
// If the group doesn't yet have a composite, create one and add it to the repository
|
86
|
Composite groupComposite = editor.getHomotypicGroup(group);
|
87
|
if (groupComposite == null) {
|
88
|
groupComposite = createHomotypicalGroup(editor, group);
|
89
|
}
|
90
|
|
91
|
// Create a synonym composite in the homotypical group
|
92
|
Composite synonymComposite = new SynonymComposite(editor, groupComposite, synonym);
|
93
|
|
94
|
return synonymComposite;
|
95
|
}
|
96
|
|
97
|
|
98
|
public Composite createMisappliedName(TaxonNameEditor editor, Taxon misappliedName) {
|
99
|
|
100
|
// If there is no composite for misapplied names,
|
101
|
// create one and add it to the repository
|
102
|
Composite groupComposite = editor.getMisappliedGroup();
|
103
|
if (groupComposite == null) {
|
104
|
groupComposite = createMisappliedGroup(editor);
|
105
|
}
|
106
|
|
107
|
// Create the name's composite
|
108
|
Composite composite = new MisappliedNameComposite(editor, groupComposite, misappliedName);
|
109
|
|
110
|
return composite;
|
111
|
}
|
112
|
|
113
|
|
114
|
public Composite createMisappliedGroup(TaxonNameEditor editor) {
|
115
|
// Create the group composite
|
116
|
Composite groupComposite = new MisappliedGroupComposite(editor, editor.getTopLevelComposite());
|
117
|
groupComposite.addFocusListener(new CompositeBorderDecorator(groupComposite, editor.getManagedForm()));
|
118
|
|
119
|
// Put the group composite before concept group composite, if any
|
120
|
Composite conceptGroupComposite = editor.getConceptGroup();
|
121
|
if (conceptGroupComposite != null) {
|
122
|
groupComposite.moveAbove(conceptGroupComposite);
|
123
|
}
|
124
|
|
125
|
return groupComposite;
|
126
|
}
|
127
|
|
128
|
public Composite createHomotypicalGroup(AbstractTaxonEditor editor, HomotypicalGroup group) {
|
129
|
|
130
|
// Create the group composite
|
131
|
Composite groupComposite = new HomotypicalGroupComposite(editor, editor.getTopLevelComposite(), group);
|
132
|
// groupComposite.addFocusListener(new CompositeBorderDecorator(groupComposite, editor.getManagedForm()));
|
133
|
|
134
|
groupComposite.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
|
135
|
editor.getManagedForm().getToolkit().paintBordersFor(groupComposite.getParent());
|
136
|
|
137
|
return groupComposite;
|
138
|
}
|
139
|
|
140
|
public Composite createConcept(TaxonNameEditor editor, TaxonRelationship relationship) {
|
141
|
// If there is no composite for misapplied names,
|
142
|
// create one and add it to the repository
|
143
|
Composite groupComposite = editor.getConceptGroup();
|
144
|
if (groupComposite == null) {
|
145
|
groupComposite = createConceptGroup(editor);
|
146
|
}
|
147
|
|
148
|
// Create the name's composite
|
149
|
Composite composite = ConceptComposite.getNewInstance(editor, groupComposite, relationship);
|
150
|
|
151
|
return composite;
|
152
|
}
|
153
|
|
154
|
|
155
|
public Composite createConceptGroup(TaxonNameEditor editor) {
|
156
|
// Create the group composite
|
157
|
Composite groupComposite = new ConceptGroupComposite(editor, editor.getTopLevelComposite());
|
158
|
groupComposite.addFocusListener(new CompositeBorderDecorator(groupComposite, editor.getManagedForm()));
|
159
|
|
160
|
// Put the group composite after misapplied group composite, if any
|
161
|
Composite misappliedGroupComposite = editor.getMisappliedGroup();
|
162
|
if (misappliedGroupComposite != null) {
|
163
|
groupComposite.moveBelow(misappliedGroupComposite);
|
164
|
}
|
165
|
|
166
|
return groupComposite;
|
167
|
|
168
|
}
|
169
|
|
170
|
|
171
|
/*********************** DESCRIPTION **********************************/
|
172
|
|
173
|
public Composite createDescriptionLabel(AbstractTaxonEditor editor, TaxonDescription description) {
|
174
|
|
175
|
// Create a group composite for the description
|
176
|
Composite groupComposite = createDescriptionGroup(editor, description);
|
177
|
|
178
|
// Create label composite
|
179
|
Composite labelComposite =
|
180
|
new DescriptionLabelComposite(editor, groupComposite, description);
|
181
|
|
182
|
// Return the label composite
|
183
|
return labelComposite;
|
184
|
}
|
185
|
|
186
|
|
187
|
public Composite createDescriptionElement(TaxonDescriptionEditor editor, TaxonDescription description,
|
188
|
DescriptionElementBase element) {
|
189
|
|
190
|
// Get the element's feature
|
191
|
Feature feature = element.getFeature();
|
192
|
Assert.isNotNull(feature, "Element does not have a feature.");
|
193
|
|
194
|
// If the feature doesn't yet have a composite, create one
|
195
|
Composite groupComposite = editor.getDescriptionFeatureGroup(description, feature);
|
196
|
if (groupComposite == null) {
|
197
|
groupComposite = createDescriptionFeatureGroup(editor, description, feature);
|
198
|
}
|
199
|
|
200
|
// Create an element composite in the feature group according to its type
|
201
|
Composite elementComposite = null;
|
202
|
if (element.isInstanceOf(CommonTaxonName.class)) {
|
203
|
elementComposite =
|
204
|
new CommonNameComposite(editor, groupComposite, (CommonTaxonName) element);
|
205
|
}else if(element.isInstanceOf(Distribution.class)){
|
206
|
elementComposite =
|
207
|
new DistributionComposite(editor, groupComposite, (Distribution) element);
|
208
|
} else {
|
209
|
elementComposite =
|
210
|
new DescriptionElementComposite(editor, groupComposite, element);
|
211
|
}
|
212
|
|
213
|
return elementComposite;
|
214
|
}
|
215
|
|
216
|
|
217
|
public Composite createDescriptionGroup(AbstractTaxonEditor editor,
|
218
|
TaxonDescription description) {
|
219
|
// Create the group composite
|
220
|
GroupComposite groupComposite = new DescriptionGroupComposite(editor.getTopLevelComposite(), editor, description);
|
221
|
groupComposite.addFocusListener(new CompositeBorderDecorator(groupComposite, editor.getManagedForm()));
|
222
|
// groupComposite.setDroppable(false);
|
223
|
|
224
|
return groupComposite;
|
225
|
}
|
226
|
|
227
|
|
228
|
public Composite createDescriptionFeatureGroup(TaxonDescriptionEditor editor,
|
229
|
TaxonDescription description, Feature feature) {
|
230
|
|
231
|
// Description label should be created before adding features
|
232
|
Composite descriptionGroupComposite = editor.getDescriptionGroup(description);
|
233
|
Assert.isNotNull(descriptionGroupComposite,
|
234
|
"Description group must be created - usually by creating its label - before adding features.");
|
235
|
|
236
|
// Create the group composite
|
237
|
Composite groupComposite;
|
238
|
if(feature.equals(Feature.DISTRIBUTION())){
|
239
|
groupComposite = new DistributionFeatureGroupComposite
|
240
|
(editor, descriptionGroupComposite, description, feature);
|
241
|
}else{
|
242
|
groupComposite= new DescriptionFeatureGroupComposite
|
243
|
(editor, descriptionGroupComposite, description, feature);
|
244
|
}
|
245
|
groupComposite.addFocusListener(new CompositeBorderDecorator(groupComposite, editor.getManagedForm()));
|
246
|
|
247
|
return groupComposite;
|
248
|
}
|
249
|
|
250
|
/********************* IMAGES *************************/
|
251
|
|
252
|
|
253
|
public Composite createGalleryLabel(AbstractTaxonEditor editor, TaxonDescription imageGallery) {
|
254
|
|
255
|
// Create a group composite for the description
|
256
|
Composite groupComposite = createDescriptionGroup(editor, imageGallery);
|
257
|
|
258
|
// Create label composite
|
259
|
Composite labelComposite =
|
260
|
new GalleryLabelComposite(editor, groupComposite, imageGallery);
|
261
|
|
262
|
// Return the label composite
|
263
|
return labelComposite;
|
264
|
}
|
265
|
|
266
|
/* (non-Javadoc)
|
267
|
* @see eu.etaxonomy.taxeditor.editor.IFreeTextElementFactory#createImageElement(org.eclipse.ui.forms.ManagedForm, eu.etaxonomy.cdm.model.taxon.Taxon, java.net.URL)
|
268
|
*/
|
269
|
public Composite createImageElement(TaxonImageEditor editor, ImageFile imageFile) {
|
270
|
|
271
|
// Get the group composite for all images
|
272
|
GroupComposite groupComposite = editor.getImageGroup();
|
273
|
if (groupComposite == null) {
|
274
|
groupComposite = createImagesGroup(editor);
|
275
|
}
|
276
|
|
277
|
// Create the image composite
|
278
|
GroupedComposite imageComposite = new ImageComposite(editor, groupComposite, imageFile);
|
279
|
imageComposite.addFocusListener(new CompositeBorderDecorator(imageComposite, editor.getManagedForm()));
|
280
|
|
281
|
return imageComposite;
|
282
|
}
|
283
|
|
284
|
/**
|
285
|
* @param taxon
|
286
|
* @param form2
|
287
|
* @return
|
288
|
*/
|
289
|
private GroupComposite createImagesGroup(AbstractTaxonEditor editor) {
|
290
|
|
291
|
// Create the group composite
|
292
|
GroupComposite groupComposite = new ImagesGroupComposite(editor.getTopLevelComposite(), editor);
|
293
|
|
294
|
return groupComposite;
|
295
|
}
|
296
|
}
|