Merge branch 'release/4.0.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / DescriptionElementSourceSection.java
index 69ffb03cb04f8b97e2fa22eb54e9b5606b25f0f0..6c74da87009652102f6c3a523691da51f28c8569 100644 (file)
@@ -1,9 +1,12 @@
 /**
- * 
+ *
  */
 package eu.etaxonomy.taxeditor.ui.section.description;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.common.OriginalSourceType;
@@ -14,60 +17,74 @@ import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
 
 /**
- * <p>DescriptionElementSourceSection class.</p>
+ * <p>
+ * DescriptionElementSourceSection class.
+ * </p>
  *
  * @author n.hoffmann
  * @created Nov 17, 2009
  * @version 1.0
  */
-public class DescriptionElementSourceSection extends AbstractEntityCollectionSection<DescriptionElementBase, DescriptionElementSource>{
+public class DescriptionElementSourceSection extends
+        AbstractEntityCollectionSection<DescriptionElementBase, DescriptionElementSource> {
 
-       /**
-        * <p>Constructor for DescriptionElementSourceSection.</p>
-        *
-        * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
-        * @param style a int.
-        * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
-        * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
-        */
-       public DescriptionElementSourceSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style){
-               super(cdmFormFactory, conversation, parentElement, "References", style);
-       }
+    /**
+     * <p>
+     * Constructor for DescriptionElementSourceSection.
+     * </p>
+     *
+     * @param parentElement
+     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
+     *            object.
+     * @param style
+     *            a int.
+     * @param cdmFormFactory
+     *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
+     *            object.
+     * @param conversation
+     *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
+     *            object.
+     */
+    public DescriptionElementSourceSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
+            ICdmFormElement parentElement, int style) {
+        super(cdmFormFactory, conversation, parentElement, "References", style);
+    }
 
-       /** {@inheritDoc} */
-       @Override
-       public DescriptionElementSource createNewElement() {
-               return DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
-       }
+    /** {@inheritDoc} */
+    @Override
+    public DescriptionElementSource createNewElement() {
+        return DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
+    }
 
-       /** {@inheritDoc} */
-       @Override
-       public Collection<DescriptionElementSource> getCollection(
-                       DescriptionElementBase entity) {
-               return entity.getSources();
-       }
+    /** {@inheritDoc} */
+    @Override
+    public Collection<DescriptionElementSource> getCollection(DescriptionElementBase entity) {
+        List<DescriptionElementSource> sources = new ArrayList<DescriptionElementSource>(entity.getSources());
+        Collections.sort(sources, new SourceComparator());
+        return sources;
+    }
 
-       /** {@inheritDoc} */
-       @Override
-       public String getEmptyString() {
-               return "No references yet.";
-       }
+    /** {@inheritDoc} */
+    @Override
+    public String getEmptyString() {
+        return "No references yet.";
+    }
 
-       /** {@inheritDoc} */
-       @Override
-       protected String getTooltipString() {
-               return "Create a new reference";
-       }
+    /** {@inheritDoc} */
+    @Override
+    protected String getTooltipString() {
+        return "Create a new reference";
+    }
 
-       /** {@inheritDoc} */
-       @Override
-       public void addElement(DescriptionElementSource element) {
-               getEntity().addSource(element);
-       }
+    /** {@inheritDoc} */
+    @Override
+    public void addElement(DescriptionElementSource element) {
+        getEntity().addSource(element);
+    }
 
-       /** {@inheritDoc} */
-       @Override
-       public void removeElement(DescriptionElementSource element) {
-               getEntity().removeSource(element);
-       }
+    /** {@inheritDoc} */
+    @Override
+    public void removeElement(DescriptionElementSource element) {
+        getEntity().removeSource(element);
+    }
 }