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
.hibernate
.HibernateProxyHelper
;
18 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
21 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
22 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
23 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
24 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
28 import eu
.etaxonomy
.taxeditor
.editor
.description
.CommonNameComposite
;
29 import eu
.etaxonomy
.taxeditor
.editor
.description
.DescriptionElementComposite
;
30 import eu
.etaxonomy
.taxeditor
.editor
.description
.DescriptionFeatureGroupComposite
;
31 import eu
.etaxonomy
.taxeditor
.editor
.description
.DescriptionGroupComposite
;
32 import eu
.etaxonomy
.taxeditor
.editor
.description
.DescriptionLabelComposite
;
33 import eu
.etaxonomy
.taxeditor
.editor
.description
.DistributionComposite
;
34 import eu
.etaxonomy
.taxeditor
.editor
.description
.DistributionFeatureGroupComposite
;
35 import eu
.etaxonomy
.taxeditor
.editor
.description
.TaxonDescriptionEditor
;
36 import eu
.etaxonomy
.taxeditor
.editor
.images
.GalleryLabelComposite
;
37 import eu
.etaxonomy
.taxeditor
.editor
.images
.ImageComposite
;
38 import eu
.etaxonomy
.taxeditor
.editor
.images
.ImagesGroupComposite
;
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();
64 logger
.trace("Created a new FreeTextElementFactory instance.");
68 public Composite
createAcceptedTaxon(AbstractTaxonEditor editor
) {
69 // Create a homotypic group composite for the accepted taxon
70 HomotypicalGroup group
= editor
.getTaxon().getHomotypicGroup();
71 Assert
.isNotNull(group
, "Taxon does not have a homotypic group");
72 Composite groupComposite
= createHomotypicalGroup(editor
, group
);
74 // Create a name composite for the accepted taxon
75 Composite acceptedNameComposite
= new AcceptedNameComposite(editor
, groupComposite
);
77 // Return the name composite
78 return acceptedNameComposite
;
81 public Composite
createSynonym(TaxonNameEditor editor
, Synonym synonym
) {
82 // Get the synonym's homotypic group
83 HomotypicalGroup group
= synonym
.getHomotypicGroup();
84 Assert
.isNotNull(group
, "Synonym does not have a homotypic group");
86 // If the group doesn't yet have a composite, create one and add it to the repository
87 Composite groupComposite
= editor
.getHomotypicGroup(group
);
88 if (groupComposite
== null) {
89 groupComposite
= createHomotypicalGroup(editor
, group
);
92 // Create a synonym composite in the homotypical group
93 Composite synonymComposite
= new SynonymComposite(editor
, groupComposite
, synonym
);
95 return synonymComposite
;
99 public Composite
createMisappliedName(TaxonNameEditor editor
, Taxon misappliedName
) {
101 // If there is no composite for misapplied names,
102 // create one and add it to the repository
103 Composite groupComposite
= editor
.getMisappliedGroup();
104 if (groupComposite
== null) {
105 groupComposite
= createMisappliedGroup(editor
);
108 // Create the name's composite
109 Composite composite
= new MisappliedNameComposite(editor
, groupComposite
, misappliedName
);
115 public Composite
createMisappliedGroup(TaxonNameEditor editor
) {
116 // Create the group composite
117 Composite groupComposite
= new MisappliedGroupComposite(editor
, editor
.getTopLevelComposite());
118 groupComposite
.addFocusListener(new CompositeBorderDecorator(groupComposite
, editor
.getManagedForm()));
120 // Put the group composite before concept group composite, if any
121 Composite conceptGroupComposite
= editor
.getConceptGroup();
122 if (conceptGroupComposite
!= null) {
123 groupComposite
.moveAbove(conceptGroupComposite
);
126 return groupComposite
;
129 public Composite
createHomotypicalGroup(AbstractTaxonEditor editor
, HomotypicalGroup group
) {
131 // Create the group composite
132 Composite groupComposite
= new HomotypicalGroupComposite(editor
, editor
.getTopLevelComposite(), group
);
133 // groupComposite.addFocusListener(new CompositeBorderDecorator(groupComposite, editor.getManagedForm()));
135 groupComposite
.setData(FormToolkit
.KEY_DRAW_BORDER
, FormToolkit
.TEXT_BORDER
);
136 editor
.getManagedForm().getToolkit().paintBordersFor(groupComposite
.getParent());
138 return groupComposite
;
141 public Composite
createConcept(TaxonNameEditor editor
, TaxonRelationship relationship
) {
142 // If there is no composite for misapplied names,
143 // create one and add it to the repository
144 Composite groupComposite
= editor
.getConceptGroup();
145 if (groupComposite
== null) {
146 groupComposite
= createConceptGroup(editor
);
149 // Create the name's composite
150 Composite composite
= ConceptComposite
.getNewInstance(editor
, groupComposite
, relationship
);
156 public Composite
createConceptGroup(TaxonNameEditor editor
) {
157 // Create the group composite
158 Composite groupComposite
= new ConceptGroupComposite(editor
, editor
.getTopLevelComposite());
159 groupComposite
.addFocusListener(new CompositeBorderDecorator(groupComposite
, editor
.getManagedForm()));
161 // Put the group composite after misapplied group composite, if any
162 Composite misappliedGroupComposite
= editor
.getMisappliedGroup();
163 if (misappliedGroupComposite
!= null) {
164 groupComposite
.moveBelow(misappliedGroupComposite
);
167 return groupComposite
;
172 /*********************** DESCRIPTION **********************************/
174 public Composite
createDescriptionLabel(AbstractTaxonEditor editor
, TaxonDescription description
) {
176 // Create a group composite for the description
177 Composite groupComposite
= createDescriptionGroup(editor
, description
);
179 // Create label composite
180 Composite labelComposite
=
181 new DescriptionLabelComposite(editor
, groupComposite
, description
);
183 // Return the label composite
184 return labelComposite
;
188 public Composite
createDescriptionElement(TaxonDescriptionEditor editor
, TaxonDescription description
,
189 DescriptionElementBase element
) {
191 // Get the element's feature
192 Feature feature
= HibernateProxyHelper
.deproxy(element
.getFeature(), Feature
.class);
193 Assert
.isNotNull(feature
, "Element does not have a feature.");
195 // If the feature doesn't yet have a composite, create one
196 Composite groupComposite
= editor
.getDescriptionFeatureGroup(description
, feature
);
197 if (groupComposite
== null) {
198 groupComposite
= createDescriptionFeatureGroup(editor
, description
, feature
);
201 // Create an element composite in the feature group according to its type
202 Composite elementComposite
= null;
203 if (element
.isInstanceOf(CommonTaxonName
.class)) {
205 new CommonNameComposite(editor
, groupComposite
, (CommonTaxonName
) element
);
206 }else if(element
.isInstanceOf(Distribution
.class)){
208 new DistributionComposite(editor
, groupComposite
, (Distribution
) element
);
211 new DescriptionElementComposite(editor
, groupComposite
, element
);
214 return elementComposite
;
218 public Composite
createDescriptionGroup(AbstractTaxonEditor editor
,
219 TaxonDescription description
) {
220 // Create the group composite
221 GroupComposite groupComposite
= new DescriptionGroupComposite(editor
.getTopLevelComposite(), editor
, description
);
222 groupComposite
.addFocusListener(new CompositeBorderDecorator(groupComposite
, editor
.getManagedForm()));
223 // groupComposite.setDroppable(false);
225 return groupComposite
;
229 public Composite
createDescriptionFeatureGroup(TaxonDescriptionEditor editor
,
230 TaxonDescription description
, Feature feature
) {
232 // Description label should be created before adding features
233 Composite descriptionGroupComposite
= editor
.getDescriptionGroup(description
);
234 Assert
.isNotNull(descriptionGroupComposite
,
235 "Description group must be created - usually by creating its label - before adding features.");
237 // Create the group composite
238 Composite groupComposite
;
239 if(feature
.equals(Feature
.DISTRIBUTION())){
240 groupComposite
= new DistributionFeatureGroupComposite
241 (editor
, descriptionGroupComposite
, description
, feature
);
243 groupComposite
= new DescriptionFeatureGroupComposite
244 (editor
, descriptionGroupComposite
, description
, feature
);
246 groupComposite
.addFocusListener(new CompositeBorderDecorator(groupComposite
, editor
.getManagedForm()));
248 return groupComposite
;
251 /********************* IMAGES *************************/
254 public Composite
createGalleryLabel(AbstractTaxonEditor editor
, TaxonDescription imageGallery
) {
256 // Create a group composite for the description
257 Composite groupComposite
= createDescriptionGroup(editor
, imageGallery
);
259 // Create label composite
260 Composite labelComposite
=
261 new GalleryLabelComposite(editor
, groupComposite
, imageGallery
);
263 // Return the label composite
264 return labelComposite
;
268 * @see eu.etaxonomy.taxeditor.editor.IFreeTextElementFactory#createImageElement(org.eclipse.ui.forms.ManagedForm, eu.etaxonomy.cdm.model.taxon.Taxon, java.net.URL)
270 public Composite
createImageElement(TaxonImageEditor editor
, ImageFile imageFile
) {
272 // Get the group composite for all images
273 GroupComposite groupComposite
= editor
.getImageGroup();
274 if (groupComposite
== null) {
275 groupComposite
= createImagesGroup(editor
);
278 // Create the image composite
279 GroupedComposite imageComposite
= new ImageComposite(editor
, groupComposite
, imageFile
);
280 imageComposite
.addFocusListener(new CompositeBorderDecorator(imageComposite
, editor
.getManagedForm()));
282 return imageComposite
;
290 private GroupComposite
createImagesGroup(AbstractTaxonEditor editor
) {
292 // Create the group composite
293 GroupComposite groupComposite
= new ImagesGroupComposite(editor
.getTopLevelComposite(), editor
);
295 return groupComposite
;