commit 61cd8ee116ec6c985a18bfe06384f54d1407f2b1
Author: Katja Luther <k.luther@bgbm.org>
Date:   Thu Oct 4 10:34:41 2018 +0200

    ref #7063: optimise setGrayed and check children in distribution selection wizard

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
index cf47cf1a5..cbade01ab 100755
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
@@ -99,7 +99,7 @@ public class AvailableDistributionPage extends AbstractAreaSelectionWizard imple
                 try {
 
                     checkChildren(event.getElement(), event.getChecked());
-                    grayParents(event.getElement());
+                    grayParents(event.getElement(), event.getChecked());
                     ((CheckboxTreeViewer)getViewer()).refresh();
                 }
                 finally {
@@ -199,14 +199,12 @@ public class AvailableDistributionPage extends AbstractAreaSelectionWizard imple
        }
     //   final Object element = path.getLastSegment();
 //       if (element != null) {
-           ((CheckboxTreeViewer)getViewer()).setChecked(element, checked);
-           ((CheckboxTreeViewer)getViewer()).setGrayed(element, false);
-//           int length = tcp.getChildren(element).length;
-//           if(length>1){
-//
-//               ((CheckboxTreeViewer)getViewer()).expandToLevel(element, CheckboxTreeViewer.ALL_LEVELS);
-//               ((CheckboxTreeViewer)getViewer()).setSubtreeChecked(element, checked);
-//           }
+       ((CheckboxTreeViewer)getViewer()).setChecked(element, checked);
+       ((CheckboxTreeViewer)getViewer()).setGrayed(element, false);
+       if (((CheckboxTreeViewer)getViewer()).isExpandable(element)){
+           ((CheckboxTreeViewer)getViewer()).expandToLevel(element, CheckboxTreeViewer.ALL_LEVELS);
+           ((CheckboxTreeViewer)getViewer()).setSubtreeChecked(element, checked);
+       }
 //       }
    }
    /**
@@ -214,7 +212,7 @@ public class AvailableDistributionPage extends AbstractAreaSelectionWizard imple
    * @param path
    * @param checked
    */
-  private void grayParents(final Object element) {
+  private void grayParents(final Object element, boolean checked) {
       TermContentProvider tcp = new TermContentProvider();
 
       if (element == null) {
@@ -223,23 +221,31 @@ public class AvailableDistributionPage extends AbstractAreaSelectionWizard imple
    //   final Object element = path.getLastSegment();
       Object parent = tcp.getParent(element);
       if (parent != null) {
-          boolean allChecked = true;
-          boolean allUnchecked = true;
-          for (final Object fieldElement : tcp.getChildren(parent)) {
-              allChecked = allChecked && ((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
-              allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
-          }
-          if (allUnchecked) {
-              ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
-              ((CheckboxTreeViewer)getViewer()).setGrayed(parent, false);
-          } else {
-             // ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
-              boolean result = ((CheckboxTreeViewer)getViewer()).setGrayed(parent, true);
 
+          boolean allUnchecked = true;
+          //if element is checked then the parent should be grayed if it is unchecked it have to be computed whether the parent should be checked
+          if (checked){
+              if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
+                  ((CheckboxTreeViewer)getViewer()).setGrayChecked(parent, true);
+              }
+
+          }else{
+              for (final Object fieldElement : tcp.getChildren(parent)) {
+                  allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
+                  allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getGrayed(fieldElement);
+              }
+              if (allUnchecked) {
+                  ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
+                  ((CheckboxTreeViewer)getViewer()).setGrayed(parent, false);
+              } else {
+                if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
+                    ((CheckboxTreeViewer)getViewer()).setGrayChecked(parent, true);
+                }
+                checked = true;
 
+              }
           }
-
-        grayParents(tcp.getParent(parent));
+        grayParents(parent, checked);
       }
   }
 
