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
.name
.HomotypicalGroup
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
21 import eu
.etaxonomy
.taxeditor
.editor
.name
.AcceptedNameComposite
;
22 import eu
.etaxonomy
.taxeditor
.editor
.name
.ConceptComposite
;
23 import eu
.etaxonomy
.taxeditor
.editor
.name
.ConceptGroupComposite
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.HomotypicalGroupComposite
;
25 import eu
.etaxonomy
.taxeditor
.editor
.name
.MisappliedGroupComposite
;
26 import eu
.etaxonomy
.taxeditor
.editor
.name
.MisappliedNameComposite
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.SynonymComposite
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
35 public class FreeTextElementFactory
implements IFreeTextElementFactory
{
36 private static final Logger logger
= Logger
37 .getLogger(FreeTextElementFactory
.class);
39 private static IFreeTextElementFactory factory
;
41 public static IFreeTextElementFactory
getDefault() {
42 if (factory
== null) {
43 factory
= new FreeTextElementFactory();
45 logger
.trace("Created a new FreeTextElementFactory instance.");
49 public Composite
createAcceptedTaxon(TaxonNameEditor editor
) {
50 // Create a homotypic group composite for the accepted taxon
51 HomotypicalGroup group
= editor
.getTaxon().getHomotypicGroup();
52 Assert
.isNotNull(group
, "Taxon does not have a homotypic group");
53 Composite groupComposite
= createHomotypicalGroup(editor
, group
);
55 // Create a name composite for the accepted taxon
56 Composite acceptedNameComposite
= new AcceptedNameComposite(editor
, groupComposite
);
58 // Return the name composite
59 return acceptedNameComposite
;
62 public Composite
createSynonym(TaxonNameEditor editor
, Synonym synonym
) {
63 // Get the synonym's homotypic group
64 HomotypicalGroup group
= synonym
.getHomotypicGroup();
65 Assert
.isNotNull(group
, "Synonym does not have a homotypic group");
67 // If the group doesn't yet have a composite, create one and add it to the repository
68 Composite groupComposite
= editor
.getHomotypicGroup(group
);
69 if (groupComposite
== null) {
70 groupComposite
= createHomotypicalGroup(editor
, group
);
73 // Create a synonym composite in the homotypical group
74 Composite synonymComposite
= new SynonymComposite(editor
, groupComposite
, synonym
);
76 return synonymComposite
;
80 public Composite
createMisappliedName(TaxonNameEditor editor
, Taxon misappliedName
) {
82 // If there is no composite for misapplied names,
83 // create one and add it to the repository
84 Composite groupComposite
= editor
.getMisappliedGroup();
85 if (groupComposite
== null) {
86 groupComposite
= createMisappliedGroup(editor
);
89 // Create the name's composite
90 Composite composite
= new MisappliedNameComposite(editor
, groupComposite
, misappliedName
);
96 public Composite
createMisappliedGroup(TaxonNameEditor editor
) {
97 // Create the group composite
98 Composite groupComposite
= new MisappliedGroupComposite(editor
, editor
.getTopLevelComposite());
99 groupComposite
.addFocusListener(new CompositeBorderDecorator(groupComposite
, editor
.getManagedForm()));
101 // Put the group composite before concept group composite, if any
102 Composite conceptGroupComposite
= editor
.getConceptGroup();
103 if (conceptGroupComposite
!= null) {
104 groupComposite
.moveAbove(conceptGroupComposite
);
107 return groupComposite
;
110 public Composite
createHomotypicalGroup(TaxonNameEditor editor
, HomotypicalGroup group
) {
112 // Create the group composite
113 Composite groupComposite
= new HomotypicalGroupComposite(editor
, editor
.getTopLevelComposite(), group
);
114 // groupComposite.addFocusListener(new CompositeBorderDecorator(groupComposite, editor.getManagedForm()));
116 groupComposite
.setData(FormToolkit
.KEY_DRAW_BORDER
, FormToolkit
.TEXT_BORDER
);
117 editor
.getManagedForm().getToolkit().paintBordersFor(groupComposite
.getParent());
119 return groupComposite
;
122 public Composite
createConcept(TaxonNameEditor editor
, TaxonRelationship relationship
) {
123 // If there is no composite for misapplied names,
124 // create one and add it to the repository
125 Composite groupComposite
= editor
.getConceptGroup();
126 if (groupComposite
== null) {
127 groupComposite
= createConceptGroup(editor
);
130 // Create the name's composite
131 Composite composite
= ConceptComposite
.getNewInstance(editor
, groupComposite
, relationship
);
137 public Composite
createConceptGroup(TaxonNameEditor editor
) {
138 // Create the group composite
139 Composite groupComposite
= new ConceptGroupComposite(editor
, editor
.getTopLevelComposite());
140 groupComposite
.addFocusListener(new CompositeBorderDecorator(groupComposite
, editor
.getManagedForm()));
142 // Put the group composite after misapplied group composite, if any
143 Composite misappliedGroupComposite
= editor
.getMisappliedGroup();
144 if (misappliedGroupComposite
!= null) {
145 groupComposite
.moveBelow(misappliedGroupComposite
);
148 return groupComposite
;