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
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
17 import org
.eclipse
.ui
.IEditorInput
;
18 import org
.eclipse
.ui
.IEditorSite
;
19 import org
.eclipse
.ui
.PartInitException
;
20 import org
.eclipse
.ui
.Saveable
;
22 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
23 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
24 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
25 import eu
.etaxonomy
.taxeditor
.editor
.AbstractTaxonEditor
;
26 import eu
.etaxonomy
.taxeditor
.editor
.FreeTextElementFactory
;
27 import eu
.etaxonomy
.taxeditor
.editor
.GroupedComposite
;
28 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
31 * Displays the <code>TaxonDescription</code>s attached to a <code>Taxon</code>.
33 * For each <code>TaxonDescription</code>:
35 * <li>Displays a <code>DescriptionLabelComposite</code> with <code>TaxonDescription#getTextCache()</code></li>
36 * <li>Displays a <code>DescriptionFeatureGroupComposite</code> for each <code>Feature</code> for which there are descriptive elements</li>
37 * <li>Displays a <code>DescriptionElementComposite</code> for each <code>TaxonDescription#getElements()</code></li>
41 * If the <Taxon> has no descriptions, creates a <code>TaxonDescription</code> that is saved when
42 * <code>firePropertyChange()</code> is called with <code>PROP_DIRTY</code>.
49 public class TaxonDescriptionEditor
extends AbstractTaxonEditor
50 implements IDescriptionEditorCompositeRepository
{
52 private static final String ID
= "eu.etaxonomy.taxeditor.taxonDescriptionEditor";
54 public TaxonDescriptionEditor(MultiPageTaxonEditor editor
){
59 * If this view is opened and the <code>Taxon</code> has no <code>Description</code>,
60 * a <code>Description</code> element is created and saved to <code>emptyDescription</code>.
61 * It should not be added to the <code>Taxon</code> until it has been changed.
63 * @see firePropertyChange(int)
65 private TaxonDescription emptyDescription
;
67 private boolean pageInitialized
= false;
70 public void doSave(IProgressMonitor monitor
) {}
73 public void doSaveAs() {}
76 public void init(IEditorSite site
, IEditorInput input
)
77 throws PartInitException
{
79 super.init(site
, input
);
83 public boolean isDirty() {
88 public boolean isSaveAsAllowed() {
93 protected void createManagedForm(Composite composite
) {
95 super.createManagedForm(composite
);
97 // FIXME image description makes this all very clumsy rethink immediately
98 Set
<TaxonDescription
> descriptions
= taxon
.getDescriptions();
100 Set
<TaxonDescription
> nonGalleryDescriptions
= new HashSet
<TaxonDescription
>();
102 for (TaxonDescription description
: descriptions
){
103 if( ! description
.isImageGallery()){
104 nonGalleryDescriptions
.add(description
);
109 // If the taxon has no descriptions, give it an empty one to display
110 if (nonGalleryDescriptions
== null || nonGalleryDescriptions
.size() == 0) {
111 emptyDescription
= TaxonDescription
.NewInstance();
112 TaxonDescription description
= emptyDescription
;
113 description
.setTitleCache("");
114 descriptions
.add(description
);
119 firstGroupedComposite
= null;
121 // FIXME image gallery stuff makes this all very clumsy
123 // Iterate through taxon's descriptions
124 for (TaxonDescription description
: descriptions
) {
125 if(description
.isImageGallery()){
126 // image galleries will be handled in image editor
128 // Draw description label
129 Composite labelComposite
=
130 FreeTextElementFactory
.getDefault().createDescriptionLabel(this, description
);
132 // Note whether this is the first label drawn
133 if (firstGroupedComposite
== null) {
134 firstGroupedComposite
= (GroupedComposite
) labelComposite
;
137 // Draw each element in description
138 for (DescriptionElementBase element
: description
.getElements()) {
139 FreeTextElementFactory
.getDefault().createDescriptionElement(this, description
, element
);
147 pageInitialized
= true;
151 * @see org.eclipse.ui.part.WorkbenchPart#firePropertyChange(int)
153 protected void firePropertyChange(final int propertyId
) {
154 if (pageInitialized
&& propertyId
== PROP_DIRTY
&& emptyDescription
!= null) {
155 getTaxon().addDescription(emptyDescription
);
156 emptyDescription
= null;
158 super.firePropertyChange(propertyId
);
162 public Composite
getDescriptionElement(DescriptionElementBase element
) {
163 for(Composite c
: getGroupedComposites()){
164 if(c
instanceof DescriptionElementComposite
){
166 (((DescriptionElementComposite
) c
).getElement())) {
175 public Composite
getDescriptionFeatureGroup(TaxonDescription description
,
177 for(Composite c
: getGroupComposites()){
178 if(c
instanceof DescriptionFeatureGroupComposite
){
179 if (description
.equals(((DescriptionFeatureGroupComposite
) c
).getDescription()) &&
180 feature
.equals(((DescriptionFeatureGroupComposite
) c
).getFeature())) {
189 public Composite
getDescriptionGroup(TaxonDescription description
) {
190 for(Composite c
: getGroupComposites()){
191 if(c
instanceof DescriptionGroupComposite
){
192 if (description
.equals
193 (((DescriptionGroupComposite
) c
).getDescription())) {
201 public Composite
getDescriptionLabel(TaxonDescription description
) {
202 for(Composite c
: getGroupedComposites()){
203 if(c
instanceof DescriptionLabelComposite
){
204 if (description
.equals
205 (((DescriptionLabelComposite
) c
).getDescription())) {
213 public Saveable
[] getActiveSaveables() {
217 public Saveable
[] getSaveables() {
222 * @see eu.etaxonomy.taxeditor.editor.AbstractTaxonEditor#getID()
225 public String
getID() {
226 return TaxonDescriptionEditor
.ID
;
230 * @see eu.etaxonomy.taxeditor.editor.AbstractTaxonEditor#resetGroupComposites()
233 protected void resetGroupComposites() {
234 // TODO Auto-generated method stub