2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
;
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
;
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
;
54 public class FreeTextElementFactory
implements IFreeTextElementFactory
{
55 private static final Logger logger
= Logger
56 .getLogger(FreeTextElementFactory
.class);
58 private static IFreeTextElementFactory factory
;
60 public static IFreeTextElementFactory
getDefault() {
61 if (factory
== null) {
62 factory
= new FreeTextElementFactory();
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
);
73 // Create a name composite for the accepted taxon
74 Composite acceptedNameComposite
= new AcceptedNameComposite(editor
, groupComposite
);
76 // Return the name composite
77 return acceptedNameComposite
;
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");
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
);
91 // Create a synonym composite in the homotypical group
92 Composite synonymComposite
= new SynonymComposite(editor
, groupComposite
, synonym
);
94 return synonymComposite
;
98 public Composite
createMisappliedName(TaxonNameEditor editor
, Taxon misappliedName
) {
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
);
107 // Create the name's composite
108 Composite composite
= new MisappliedNameComposite(editor
, groupComposite
, misappliedName
);
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()));
119 // Put the group composite before concept group composite, if any
120 Composite conceptGroupComposite
= editor
.getConceptGroup();
121 if (conceptGroupComposite
!= null) {
122 groupComposite
.moveAbove(conceptGroupComposite
);
125 return groupComposite
;
128 public Composite
createHomotypicalGroup(AbstractTaxonEditor editor
, HomotypicalGroup group
) {
130 // Create the group composite
131 Composite groupComposite
= new HomotypicalGroupComposite(editor
, editor
.getTopLevelComposite(), group
);
132 // groupComposite.addFocusListener(new CompositeBorderDecorator(groupComposite, editor.getManagedForm()));
134 groupComposite
.setData(FormToolkit
.KEY_DRAW_BORDER
, FormToolkit
.TEXT_BORDER
);
135 editor
.getManagedForm().getToolkit().paintBordersFor(groupComposite
.getParent());
137 return groupComposite
;
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
);
148 // Create the name's composite
149 Composite composite
= ConceptComposite
.getNewInstance(editor
, groupComposite
, relationship
);
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()));
160 // Put the group composite after misapplied group composite, if any
161 Composite misappliedGroupComposite
= editor
.getMisappliedGroup();
162 if (misappliedGroupComposite
!= null) {
163 groupComposite
.moveBelow(misappliedGroupComposite
);
166 return groupComposite
;
171 /*********************** DESCRIPTION **********************************/
173 public Composite
createDescriptionLabel(AbstractTaxonEditor editor
, TaxonDescription description
) {
175 // Create a group composite for the description
176 Composite groupComposite
= createDescriptionGroup(editor
, description
);
178 // Create label composite
179 Composite labelComposite
=
180 new DescriptionLabelComposite(editor
, groupComposite
, description
);
182 // Return the label composite
183 return labelComposite
;
187 public Composite
createDescriptionElement(TaxonDescriptionEditor editor
, TaxonDescription description
,
188 DescriptionElementBase element
) {
190 // Get the element's feature
191 Feature feature
= element
.getFeature();
192 Assert
.isNotNull(feature
, "Element does not have a feature.");
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
);
200 // Create an element composite in the feature group according to its type
201 Composite elementComposite
= null;
202 if (element
.isInstanceOf(CommonTaxonName
.class)) {
204 new CommonNameComposite(editor
, groupComposite
, (CommonTaxonName
) element
);
205 }else if(element
.isInstanceOf(Distribution
.class)){
207 new DistributionComposite(editor
, groupComposite
, (Distribution
) element
);
210 new DescriptionElementComposite(editor
, groupComposite
, element
);
213 return elementComposite
;
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);
224 return groupComposite
;
228 public Composite
createDescriptionFeatureGroup(TaxonDescriptionEditor editor
,
229 TaxonDescription description
, Feature feature
) {
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.");
236 // Create the group composite
237 Composite groupComposite
;
238 if(feature
.equals(Feature
.DISTRIBUTION())){
239 groupComposite
= new DistributionFeatureGroupComposite
240 (editor
, descriptionGroupComposite
, description
, feature
);
242 groupComposite
= new DescriptionFeatureGroupComposite
243 (editor
, descriptionGroupComposite
, description
, feature
);
245 groupComposite
.addFocusListener(new CompositeBorderDecorator(groupComposite
, editor
.getManagedForm()));
247 return groupComposite
;
250 /********************* IMAGES *************************/
253 public Composite
createGalleryLabel(AbstractTaxonEditor editor
, TaxonDescription imageGallery
) {
255 // Create a group composite for the description
256 Composite groupComposite
= createDescriptionGroup(editor
, imageGallery
);
258 // Create label composite
259 Composite labelComposite
=
260 new GalleryLabelComposite(editor
, groupComposite
, imageGallery
);
262 // Return the label composite
263 return labelComposite
;
267 * @see eu.etaxonomy.taxeditor.editor.IFreeTextElementFactory#createImageElement(org.eclipse.ui.forms.ManagedForm, eu.etaxonomy.cdm.model.taxon.Taxon, java.net.URL)
269 public Composite
createImageElement(TaxonImageEditor editor
, ImageFile imageFile
) {
271 // Get the group composite for all images
272 GroupComposite groupComposite
= editor
.getImageGroup();
273 if (groupComposite
== null) {
274 groupComposite
= createImagesGroup(editor
);
277 // Create the image composite
278 GroupedComposite imageComposite
= new ImageComposite(editor
, groupComposite
, imageFile
);
279 imageComposite
.addFocusListener(new CompositeBorderDecorator(imageComposite
, editor
.getManagedForm()));
281 return imageComposite
;
289 private GroupComposite
createImagesGroup(AbstractTaxonEditor editor
) {
291 // Create the group composite
292 GroupComposite groupComposite
= new ImagesGroupComposite(editor
.getTopLevelComposite(), editor
);
294 return groupComposite
;