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 java
.util
.HashMap
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.runtime
.Assert
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.ui
.forms
.IManagedForm
;
20 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.UiUtil
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.AcceptedNameComposite
;
25 import eu
.etaxonomy
.taxeditor
.editor
.name
.HomotypicalGroupComposite
;
26 import eu
.etaxonomy
.taxeditor
.editor
.name
.MisappliedGroupComposite
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.MisappliedNameComposite
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.SynonymComposite
;
35 public class FreeTextElementFactory
implements IFreeTextElementFactory
{
36 private static final Logger logger
= Logger
37 .getLogger(FreeTextElementFactory
.class);
39 private static IFreeTextElementFactory factory
;
41 private Map
<Taxon
, IManagedForm
> nameForms
;
45 * Returns a taxon's composite which holds all misapplied names.
47 private Map
<Taxon
, Composite
> misappliedComposites
;
49 public static IFreeTextElementFactory
getDefault() {
50 if (factory
== null) {
51 factory
= new FreeTextElementFactory();
56 public Composite
createAcceptedTaxon(IManagedForm form
, Taxon taxon
) {
58 // Put the taxon's form in the form map
59 Assert
.isNotNull(form
, "A non-null IManagedForm must be provided.");
60 getTaxonForms().put(taxon
, form
);
62 // Create a homotypic group composite for the accepted taxon
63 HomotypicalGroup group
= taxon
.getHomotypicGroup();
64 Assert
.isNotNull(group
, "Taxon does not have a homotypic group");
65 Composite groupComposite
= createHomotypicalGroup(taxon
, group
);
67 // Create a name composite for the accepted taxon
68 Composite acceptedNameComposite
=
69 new AcceptedNameComposite(groupComposite
, form
, taxon
);
72 // Return the name composite
73 return acceptedNameComposite
;
76 public Composite
createSynonym(Synonym synonym
, Taxon taxon
) {
78 // Get the taxon's form
79 IManagedForm form
= getForm(taxon
);
80 Assert
.isNotNull(form
, "No IManagedForm has been provided for the synonym's accepted taxon.");
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
=
88 UiUtil
.getTaxonNameEditor(taxon
).getHomotypicGroup(group
);
89 if (groupComposite
== null) {
90 groupComposite
= createHomotypicalGroup(taxon
, group
);
93 // Create a synonym composite in the homotypic group
94 Composite synonymComposite
=
95 new SynonymComposite(groupComposite
, form
, taxon
, synonym
);
97 return synonymComposite
;
101 public Composite
createMisappliedName(Taxon misappliedName
, Taxon taxon
) {
103 // Get the taxon's form
104 IManagedForm form
= getForm(taxon
);
105 Assert
.isNotNull(form
, "No IManagedForm has been provided for the synonym's accepted taxon.");
107 // If there is no composite for misapplied names,
108 // create one and add it to the repository
109 Composite groupComposite
=
110 UiUtil
.getTaxonNameEditor(taxon
).getMisappliedGroup();
111 if (groupComposite
== null) {
112 groupComposite
= createMisappliedGroup(taxon
);
115 // Create the name's composite
116 Composite composite
= new MisappliedNameComposite
117 (groupComposite
, form
, taxon
, misappliedName
);
123 public Composite
createMisappliedGroup(Taxon taxon
) {
125 // Get the taxon's form
126 IManagedForm form
= getForm(taxon
);
128 // Create the group composite
129 Composite groupComposite
= new MisappliedGroupComposite(getTopLevelComposite(form
), taxon
);
130 new CompositeBorderDecorator(groupComposite
, form
);
132 return groupComposite
;
135 public Composite
createHomotypicalGroup(Taxon taxon
, HomotypicalGroup group
) {
137 // Get the taxon's form
138 IManagedForm form
= getForm(taxon
);
140 // Create the group composite
141 Composite groupComposite
= new HomotypicalGroupComposite(getTopLevelComposite(form
), taxon
, group
);
142 new CompositeBorderDecorator(groupComposite
, form
);
144 return groupComposite
;
147 private Map
<Taxon
, IManagedForm
> getTaxonForms() {
148 if (nameForms
== null) {
149 nameForms
= new HashMap
<Taxon
, IManagedForm
>();
154 private IManagedForm
getForm(Taxon taxon
) {
155 return getTaxonForms().get(taxon
);
158 private Composite
getTopLevelComposite(IManagedForm form
) {
159 return form
.getForm().getBody();