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
.description
;
12 import java
.util
.HashSet
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.ui
.IEditorInput
;
19 import org
.eclipse
.ui
.IEditorSite
;
20 import org
.eclipse
.ui
.PartInitException
;
21 import org
.eclipse
.ui
.Saveable
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
24 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
25 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
26 import eu
.etaxonomy
.taxeditor
.editor
.AbstractTaxonEditor
;
27 import eu
.etaxonomy
.taxeditor
.editor
.FreeTextElementFactory
;
28 import eu
.etaxonomy
.taxeditor
.editor
.GroupedComposite
;
29 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
32 * Displays the <code>TaxonDescription</code>s attached to a <code>Taxon</code>.
34 * For each <code>TaxonDescription</code>:
36 * <li>Displays a <code>DescriptionLabelComposite</code> with <code>TaxonDescription#getTextCache()</code></li>
37 * <li>Displays a <code>DescriptionFeatureGroupComposite</code> for each <code>Feature</code> for which there are descriptive elements</li>
38 * <li>Displays a <code>DescriptionElementComposite</code> for each <code>TaxonDescription#getElements()</code></li>
42 * If the <Taxon> has no descriptions, creates a <code>TaxonDescription</code> that is saved when
43 * <code>firePropertyChange()</code> is called with <code>PROP_DIRTY</code>.
50 public class TaxonDescriptionEditor
extends AbstractTaxonEditor
51 implements IDescriptionEditorCompositeRepository
{
52 private static final Logger logger
= Logger
53 .getLogger(TaxonDescriptionEditor
.class);
55 private static final String ID
= "eu.etaxonomy.taxeditor.taxonDescriptionEditor";
57 public TaxonDescriptionEditor(MultiPageTaxonEditor editor
){
62 * If this view is opened and the <code>Taxon</code> has no <code>Description</code>,
63 * a <code>Description</code> element is created and saved to <code>emptyDescription</code>.
64 * It should not be added to the <code>Taxon</code> until it has been changed.
66 * @see firePropertyChange(int)
68 private TaxonDescription emptyDescription
;
70 private boolean pageInitialized
= false;
73 public void doSave(IProgressMonitor monitor
) {}
76 public void doSaveAs() {}
79 public void init(IEditorSite site
, IEditorInput input
)
80 throws PartInitException
{
82 super.init(site
, input
);
86 public boolean isDirty() {
91 public boolean isSaveAsAllowed() {
96 protected void createManagedForm(Composite composite
) {
98 super.createManagedForm(composite
);
100 // FIXME image description makes this all very clumsy rethink immediately
101 Set
<TaxonDescription
> descriptions
= taxon
.getDescriptions();
103 Set
<TaxonDescription
> nonGalleryDescriptions
= new HashSet
<TaxonDescription
>();
105 for (TaxonDescription description
: descriptions
){
106 if( ! description
.isImageGallery()){
107 nonGalleryDescriptions
.add(description
);
112 // If the taxon has no descriptions, give it an empty one to display
113 if (nonGalleryDescriptions
== null || nonGalleryDescriptions
.size() == 0) {
114 emptyDescription
= TaxonDescription
.NewInstance();
115 TaxonDescription description
= emptyDescription
;
116 description
.setTitleCache("");
117 descriptions
.add(description
);
122 firstGroupedComposite
= null;
124 // FIXME image gallery stuff makes this all very clumsy
126 // Iterate through taxon's descriptions
127 for (TaxonDescription description
: descriptions
) {
128 if(description
.isImageGallery()){
129 // image galleries will be handled in image editor
131 // Draw description label
132 Composite labelComposite
=
133 FreeTextElementFactory
.getDefault().createDescriptionLabel(this, description
);
135 // Note whether this is the first label drawn
136 if (firstGroupedComposite
== null) {
137 firstGroupedComposite
= (GroupedComposite
) labelComposite
;
140 // Draw each element in description
141 for (DescriptionElementBase element
: description
.getElements()) {
142 FreeTextElementFactory
.getDefault().createDescriptionElement(this, description
, element
);
150 pageInitialized
= true;
154 * @see org.eclipse.ui.part.WorkbenchPart#firePropertyChange(int)
156 protected void firePropertyChange(final int propertyId
) {
157 if (pageInitialized
&& propertyId
== PROP_DIRTY
&& emptyDescription
!= null) {
158 getTaxon().addDescription(emptyDescription
);
159 emptyDescription
= null;
161 super.firePropertyChange(propertyId
);
165 public Composite
getDescriptionElement(DescriptionElementBase element
) {
166 for(Composite c
: getAllComposites()){
167 if(c
instanceof DescriptionElementComposite
){
169 (((DescriptionElementComposite
) c
).getElement())) {
178 public Composite
getDescriptionFeatureGroup(TaxonDescription description
,
180 for(Composite c
: getAllComposites()){
181 if(c
instanceof DescriptionFeatureGroupComposite
){
182 if (description
.equals(((DescriptionFeatureGroupComposite
) c
).getDescription()) &&
183 feature
.equals(((DescriptionFeatureGroupComposite
) c
).getFeature())) {
192 public Composite
getDescriptionGroup(TaxonDescription description
) {
193 for(Composite c
: getAllComposites()){
194 if(c
instanceof DescriptionGroupComposite
){
195 if (description
.equals
196 (((DescriptionGroupComposite
) c
).getDescription())) {
205 public Composite
getDescriptionLabel(TaxonDescription description
) {
206 for(Composite c
: getAllComposites()){
207 if(c
instanceof DescriptionLabelComposite
){
208 if (description
.equals
209 (((DescriptionLabelComposite
) c
).getDescription())) {
217 public Saveable
[] getActiveSaveables() {
221 public Saveable
[] getSaveables() {
226 * @see eu.etaxonomy.taxeditor.editor.AbstractTaxonEditor#getID()
229 public String
getID() {
230 return TaxonDescriptionEditor
.ID
;