ref #9821: sources of description should not be editable
authorKatja Luther <k.luther@bgbm.org>
Wed, 20 Oct 2021 13:09:59 +0000 (15:09 +0200)
committerKatja Luther <k.luther@bgbm.org>
Wed, 20 Oct 2021 13:09:59 +0000 (15:09 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionSection.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceSection.java

index 70add212d2b8711a50e02fb06ae8fe49eb26e3f1..21492d2b87600782a1a02bd84bff1382e9fb943d 100644 (file)
@@ -201,7 +201,7 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT>
        /**
         * Removes all content from the container
         */
-       private void destroyDynamicContent(){
+       protected void destroyDynamicContent(){
                if(label_empty != null){
                        label_empty.dispose();
                        label_empty = null;
@@ -321,7 +321,7 @@ public abstract class AbstractEntityCollectionSection<ENTITY, ELEMENT>
                }
        }
 
-       private boolean expandSectionWhenContentAvailable(){
+       protected boolean expandSectionWhenContentAvailable(){
                return PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOULD_EXPAND_SECTION_WHEN_DATA_AVAILABLE, true);
        }
 
index 843bfd8a37b214033923da3e68cee9e5ae867d6f..d3a7f0863765ba27d4a2345c23f0f17c87587aa0 100644 (file)
@@ -8,9 +8,12 @@
 */
 package eu.etaxonomy.taxeditor.ui.section.description;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
+import java.util.List;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
@@ -52,15 +55,66 @@ public class DescriptionElementSourceSection extends
         }
         return source;
     }
-
     @Override
-    public Collection<OriginalSourceBase> getCollection(DescriptionElementBase entity) {
+    protected void internalUpdateSection(boolean changed){
+           setSectionTitle();
+               destroyDynamicContent();
+               if(isExpanded() || expandSectionWhenContentAvailable()) {
+            renderContent(isExpanded());
+        }
+               if(changed) {
+            firePropertyChangeEvent(this);
+        }
+       }
+    
+    private void renderContent(boolean forceExpansion){
+               Collection<OriginalSourceBase> collectionElement = getCollectionElement(getEntity());
+               Collection<OriginalSourceBase> collectionDescription = getCollectionDescription(getEntity());
+
+               if(collectionElement == null || collectionElement.isEmpty()){
+                       createEmptyContent();
+               }else{
+                   List<OriginalSourceBase> elements = new ArrayList<>(collectionElement);
+                   Collections.sort(elements, getComparator());
+                       createDynamicContents(elements);
+                       forceExpansion = true;
+               }
+
+               this.setExpanded(forceExpansion);
+
+               
+               
+               if(collectionDescription == null || collectionDescription.isEmpty()){
+                       createEmptyContent();
+               }else{
+                   List<OriginalSourceBase> elements = new ArrayList<>(collectionDescription);
+                   Collections.sort(elements, getComparator());
+                       createDynamicContents(elements);
+                       getEntityCollectionElement().setEnabled(false);
+                       forceExpansion = true;
+               }
+
+               this.setExpanded(forceExpansion);
+
+               reflow();
+       }
+
+
+
+       public Collection<OriginalSourceBase> getCollectionDescription(DescriptionElementBase entity) {
         Collection<OriginalSourceBase> sources = new HashSet<>();
-        sources.addAll(entity.getSources());
+//        sources.addAll(entity.getSources());
         sources.addAll(entity.getInDescription().getSources());
 
         return sources;
     }
+    public Collection<OriginalSourceBase> getCollectionElement(DescriptionElementBase entity) {
+        Collection<OriginalSourceBase> sources = new HashSet<>();
+        sources.addAll(entity.getSources());
+//        sources.addAll(entity.getInDescription().getSources());
+
+        return sources;
+    }
 
     @Override
     public Comparator<OriginalSourceBase> getComparator() {
@@ -100,4 +154,13 @@ public class DescriptionElementSourceSection extends
     public boolean allowAddExisting() {
         return false;
     }
+
+       @Override
+       public Collection<OriginalSourceBase> getCollection(DescriptionElementBase entity) {
+               Collection<OriginalSourceBase> sources = new HashSet<>();
+           sources.addAll(entity.getSources());
+           sources.addAll(entity.getInDescription().getSources());
+           return sources;
+           
+       }
 }
\ No newline at end of file