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
.HashMap
;
13 import java
.util
.HashSet
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
22 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
25 import eu
.etaxonomy
.taxeditor
.editor
.AbstractTaxonEditorView
;
26 import eu
.etaxonomy
.taxeditor
.editor
.EditorGroupComposite
;
27 import eu
.etaxonomy
.taxeditor
.editor
.EditorGroupedComposite
;
28 import eu
.etaxonomy
.taxeditor
.editor
.IHasPropertySource
;
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>FeatureGroupComposite</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>.
48 public class TaxonDescriptionEditorView
extends AbstractTaxonEditorView
{
49 private static final Logger logger
= Logger
50 .getLogger(TaxonDescriptionEditorView
.class);
53 * If this view is opened and the <code>Taxon</code> has no <code>Description</code>,
54 * a <code>Description</code> element is created and saved to <code>emptyDescription</code>.
55 * It should not be added to the <code>Taxon</code> until it has been changed.
57 * @see firePropertyChange(int)
59 private TaxonDescription emptyDescription
;
61 private boolean pageInitialized
= false;
64 public void doSave(IProgressMonitor monitor
) {
65 // TODO Auto-generated method stub
70 public void doSaveAs() {
71 // TODO Auto-generated method stub
76 public boolean isDirty() {
77 // TODO Auto-generated method stub
82 public boolean isSaveAsAllowed() {
83 // TODO Auto-generated method stub
88 public void createPartControl(Composite composite
) {
90 super.createPartControl(composite
);
92 Taxon taxon
= getTaxon();
94 Set
<TaxonDescription
> descriptions
= taxon
.getDescriptions();
96 EditorGroupedComposite firstEditableComposite
= null;
98 // If the Taxon has no descriptions, give it an empty one to display
99 if (descriptions
== null || descriptions
.size() == 0) {
100 emptyDescription
= TaxonDescription
.NewInstance();
101 TaxonDescription description
= emptyDescription
;
102 description
.setTitleCache("");
103 descriptions
.add(description
);
106 // Iterate through taxon's descriptions
107 for (TaxonDescription description
: descriptions
) {
109 // Create a composite for the description
110 EditorGroupComposite descriptionComposite
= new EditorGroupComposite(
111 parent
, managedForm
, description
);
112 descriptionComposite
.setDroppable(false);
114 // Add a grouped composite for the description's label
115 EditorGroupedComposite descriptionLabelComposite
= new DescriptionLabelComposite(
116 descriptionComposite
, managedForm
, description
);
118 if (firstEditableComposite
== null) {
119 firstEditableComposite
= descriptionLabelComposite
;
122 // Iterate through description's elements, group by feature
123 Map
<Feature
, Set
<DescriptionElementBase
>> features
=
124 new HashMap
<Feature
, Set
<DescriptionElementBase
>>();
125 for (DescriptionElementBase element
: description
.getElements()) {
126 Feature feature
= element
.getFeature();
127 Set
<DescriptionElementBase
> elements
= features
.get(feature
);
128 if (elements
== null) {
129 elements
= new HashSet
<DescriptionElementBase
>();
130 features
.put(feature
, elements
);
132 elements
.add(element
);
135 // Create a composite for each feature, composites for its elements
136 for (Feature feature
: features
.keySet()) {
137 EditorGroupComposite featureComposite
= new FeatureGroupComposite(
138 descriptionComposite
, managedForm
, feature
);
140 for (DescriptionElementBase element
: features
.get(feature
)) {
141 new DescriptionElementComposite(
142 featureComposite
, managedForm
, element
);
147 // We've added elements to the managed form, so redraw it
148 scrolledForm
.reflow(true);
150 // Set focus on the first label composite to give a border and send it
151 // to the property sheet
152 setSelection(firstEditableComposite
);
153 firstEditableComposite
.drawBorder();
155 pageInitialized
= true;
159 * @see org.eclipse.ui.part.WorkbenchPart#firePropertyChange(int)
161 protected void firePropertyChange(final int propertyId
) {
162 if (pageInitialized
&& propertyId
== PROP_DIRTY
&& emptyDescription
!= null) {
163 getTaxon().addDescription(emptyDescription
);
164 emptyDescription
= null;
166 super.firePropertyChange(propertyId
);