ref #8810: check for taxonnode permission and whether the user has taxon node granted...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / AbstractEntityCollectionSection.java
index 81ece03c26b0f8c3b54ec18729b0a5fe18e92daf..9dc51edac3ae8fb3e13fa723ad668dbecafd0e9d 100644 (file)
@@ -3,8 +3,12 @@
  */
 package eu.etaxonomy.taxeditor.ui.section;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.EnumSet;
+import java.util.List;
 import java.util.Observable;
 import java.util.Observer;
 
@@ -29,7 +33,7 @@ import org.eclipse.ui.forms.widgets.ExpandableComposite;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
+import eu.etaxonomy.cdm.model.permission.CRUD;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.ImageResources;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
@@ -63,7 +67,7 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
 
        private String title;
 
-    private AbstractEntityCollectionElement entityCollectionElement;
+    private AbstractEntityCollectionElement<ENTITY> entityCollectionElement;
 
        public AbstractEntityCollectionSection(CdmFormFactory formFactory, ConversationHolder conversation, ICdmFormElement parentElement, String title, int style) {
                super(formFactory, parentElement, ExpandableComposite.CLIENT_INDENT | style);
@@ -137,10 +141,16 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
                    toolBarManager.add(browseAction);
                }
 
+               addAction(toolBarManager);
+
                return toolBarManager.createControl(this);
        }
 
-       /**
+    protected void addAction(ToolBarManager toolBarManager) {
+        // default implementation empty
+    }
+
+    /**
         * using this method is discouraged, use updateToolBar() instead
         */
        public void showToolbar(){
@@ -212,11 +222,13 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
         */
        private void renderContent(boolean forceExpansion)
        {
-               Collection<ELEMENT> elements = getCollection(getEntity());
+               Collection<ELEMENT> collection = getCollection(getEntity());
 
-               if(elements == null || elements.isEmpty()){
+               if(collection == null || collection.isEmpty()){
                        createEmptyContent();
                }else{
+                   List<ELEMENT> elements = new ArrayList<>(collection);
+                   Collections.sort(elements, getComparator());
                        createDynamicContents(elements);
                        forceExpansion = true;
                }
@@ -309,7 +321,7 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
        }
 
        private boolean expandSectionWhenContentAvailable(){
-               return PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOULD_EXPAND_SECTION_WHEN_DATA_AVAILABLE);
+               return PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOULD_EXPAND_SECTION_WHEN_DATA_AVAILABLE);
        }
 
        /**
@@ -329,7 +341,7 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
            }
        }
 
-    private void updateToolbar() {
+    protected void updateToolbar() {
         if(getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), UPDATE)){
             showToolbar();
         } else {
@@ -337,10 +349,16 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
         }
     }
 
-    public AbstractEntityCollectionElement getEntityCollectionElement() {
+    public AbstractEntityCollectionElement<ENTITY> getEntityCollectionElement() {
         return entityCollectionElement;
     }
 
+    /**
+     * Returns the {@link Comparator} specific for the ELEMENTs
+     * which is used to sort the elements
+     * @return the comparator for ELEMENT
+     */
+    public abstract Comparator<ELEMENT> getComparator();
 
        /**
         * Get the specific collection of this entity
@@ -350,6 +368,7 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT> extends A
         */
        public abstract Collection<ELEMENT> getCollection(ENTITY entity);
 
+
        /**
         * Create a new Element for this collection
         *