fix #6330 Add default sorting for all entity collections
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / CurrentDeterminationDetailSection.java
index d2463cc2a6d146dd18a523b9cf0725e672f4f830..eaf37c443f5e77ecddd1dd3321068bfc1729b1ab 100644 (file)
@@ -1,9 +1,8 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -12,8 +11,10 @@ package eu.etaxonomy.taxeditor.ui.section.occurrence;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Comparator;
 
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.ToolBarManager;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.SWT;
@@ -24,8 +25,9 @@ import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
 import eu.etaxonomy.taxeditor.model.ImageResources;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
 
 /**
  * @author n.hoffmann
@@ -46,43 +48,44 @@ public class CurrentDeterminationDetailSection extends
                        int style) {
                super(formFactory, conversation, parentElement, "Current Determination", style);
        }
-       
+
        @Override
        protected Control createToolbar() {
                ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
-               
-               Action addAction = new Action("add", Action.AS_PUSH_BUTTON){
+
+               Action addAction = new Action("add", IAction.AS_PUSH_BUTTON){
                        /* (non-Javadoc)
                         * @see org.eclipse.jface.action.Action#run()
                         */
                        @Override
                        public void run() {
                                DeterminationEvent element = createNewElement();
-                               
+
                                // set as preferred determination
                                getEntity().setPreferredDetermination(element);
-                               
+
                                if(element != null){
-                                       if(! getSection().isExpanded())
-                                               getSection().setExpanded(true);
-                                       internalUpdateSection(true); 
+                                       if(! getSection().isExpanded()) {
+                        getSection().setExpanded(true);
+                    }
+                                       internalUpdateSection(true);
                                }
                        }
                };
                addAction.setImageDescriptor(new ImageDescriptor() {
-                       
+
                        @Override
                        public ImageData getImageData() {
                                return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
                        }
                });
                addAction.setToolTipText(getTooltipString());
-               
+
                toolBarManager.add(addAction);
-               
+
                return toolBarManager.createControl(this);
        }
-       
+
        @Override
        public void refresh() {
                internalUpdateSection(false);
@@ -96,7 +99,12 @@ public class CurrentDeterminationDetailSection extends
                DeterminationEvent preferredDetermination = entity.getPreferredDetermination();
                return preferredDetermination != null ? Arrays.asList(new DeterminationEvent[]{preferredDetermination}) : null;
        }
-       
+
+       @Override
+       public Comparator<DeterminationEvent> getComparator() {
+        return new DefaultCdmBaseComparator<>();
+       }
+
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.ui.section.occurrence.AbstractDeterminationEventDetailSection#createNewElement()
         */
@@ -106,7 +114,7 @@ public class CurrentDeterminationDetailSection extends
                newElement.setPreferredFlag(true);
                return newElement;
        }
-       
+
 
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString()
@@ -117,4 +125,20 @@ public class CurrentDeterminationDetailSection extends
                return "Create new current determination event";
        }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public DeterminationEvent addExisting() {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean allowAddExisting() {
+        return false;
+    }
+
 }