commit 8e4eddebc332ba1bb47bef4bd76b222d69cddd07
Author: Katja Luther <k.luther@bgbm.org>
Date:   Wed Dec 5 13:20:12 2018 +0100

    build layers for distribution editor

diff --git a/eu.etaxonomy.taxeditor.editor/fragment.e4xmi b/eu.etaxonomy.taxeditor.editor/fragment.e4xmi
index b019cef07..c8d21752e 100644
--- a/eu.etaxonomy.taxeditor.editor/fragment.e4xmi
+++ b/eu.etaxonomy.taxeditor.editor/fragment.e4xmi
@@ -310,6 +310,7 @@
         <children xsi:type="menu:HandledToolItem" xmi:id="_hnZYUPycEeeOqKfc2I-67A" elementId="eu.etaxonomy.taxeditor.editor.handledtoolitem.0" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/refresh.gif" tooltip="%handledtoolitem.tooltip.1" command="_4k-uYPycEeeOqKfc2I-67A"/>
       </toolbar>
     </elements>
+    <elements xsi:type="basic:PartDescriptor" xmi:id="_KnkUEPemEeiZEKOlcMbiPw" elementId="eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart" label="Distribution Editor" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="__mwtMDVpEee_b7RlBzTDRw" featurename="commands" parentElementId="xpath:/">
     <elements xsi:type="commands:Command" xmi:id="_BjF3ADVqEee_b7RlBzTDRw" elementId="eu.etaxonomy.taxeditor.editor.command.specimeneditor.create_field_unit" commandName="%command.commandname.1"/>
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/AppModelId.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/AppModelId.java
index 6784999f7..12df6865f 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/AppModelId.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/AppModelId.java
@@ -278,6 +278,7 @@ public class AppModelId {
 	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_KEY_POLYTOMOUS_E4_POLYTOMOUSKEYLISTEDITORE4 = "eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4";
 	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_NAME_E4_TAXONNAMEEDITORE4 = "eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4";
 	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_CHECKLISTEDITORE4 = "eu.etaxonomy.taxeditor.editor.view.checklist.e4.ChecklistEditorE4";
+	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART = "eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart";
 	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CONCEPT_E4_CONCEPTVIEWPARTE4 = "eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4";
 	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CONCEPT_GRAPH_E4_CONCEPTGRAPHVIEWE4 = "eu.etaxonomy.taxeditor.editor.view.concept.graph.e4.ConceptGraphViewE4";
 	public static final String PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView";
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
index 7e41446f6..c71b36588 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
@@ -45,6 +45,7 @@ import eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4;
 import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
+import eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
@@ -84,6 +85,15 @@ public class EditorUtil extends AbstractUtility {
         editor.init(descriptiveDataSetUuid, true);
     }
 
+    public static void openDistributionEditor(UUID parentTaxonUuid, EModelService modelService, EPartService partService, MApplication application){
+        Collection<MPart> parts = partService.getParts();
+        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
+        MPart part = showPart(partId, modelService, partService, application);
+        DistributionEditorPart editor = (DistributionEditorPart) part.getObject();
+        editor.init(parentTaxonUuid);
+    }
+
+
     public static void openSpecimenEditor(DerivateViewEditorInput input, EModelService modelService, EPartService partService, MApplication application){
         String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW;
         MPart part = showPart(partId, modelService, partService, application);
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
index 2135b176e..5fa42d488 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
@@ -178,7 +178,7 @@ public class CharacterMatrix extends Composite {
 
     private DefaultBodyLayerStack bodyLayer;
 
-    private boolean isTreeView = true;
+    private boolean isTreeView = false;
 
     private CharacterMatrixToolbar toolbar;
 
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.java
index f986e0b45..faaaf84f5 100755
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.java
@@ -9,11 +9,16 @@
 package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.UUID;
 
 import javax.inject.Inject;
 
@@ -23,46 +28,30 @@ import org.eclipse.e4.ui.services.EMenuService;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.nebula.widgets.nattable.NatTable;
-import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
 import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
 import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
 import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
 import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
 import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
-import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
 import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
-import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
-import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
-import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
 import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
 import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
-import org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
-import org.eclipse.nebula.widgets.nattable.grid.data.FixedSummaryRowHeaderLayer;
 import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
 import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
-import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
 import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
+import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
 import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
-import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
 import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
 import org.eclipse.nebula.widgets.nattable.layer.ILayer;
-import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
-import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
 import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
-import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
 import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
 import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
 import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
-import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
-import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
-import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
-import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
-import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
-import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
 import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
+import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -71,21 +60,31 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Text;
 
+import ca.odell.glazedlists.BasicEventList;
 import ca.odell.glazedlists.EventList;
 import ca.odell.glazedlists.SortedList;
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
 import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.OrderedTermBase;
+import eu.etaxonomy.cdm.model.common.OrderedTermComparator;
+import eu.etaxonomy.cdm.model.common.TermIdInVocabularyComparator;
+import eu.etaxonomy.cdm.model.common.TermLanguageComparator;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.location.NamedArea;
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixLabelStyleConfiguration;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.preference.Resources;
 import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog;
 
@@ -125,14 +124,16 @@ public class DistributionEditor extends Composite {
     private Text searchText;
 
     EventList<TaxonDistributionDTO> taxonList;
-    List<NamedArea> areas = new ArrayList();
+    SortedSet<DefinedTermBase> areas;
     DistributionEditorPart part;
-    private DefaultBodyLayerStack bodyLayer;
+    private ViewportLayer bodyLayer;
     private FreezeLayer freezeLayer;
     private ConfigRegistry configRegistry;
     private AbstractLayer topMostLayer;
 
-    private FixedSummaryRowLayer summaryRowLayer;
+    private SelectionLayer selectionLayer;
+
+ //  private FixedSummaryRowLayer summaryRowLayer;
 
 
     /**
@@ -145,9 +146,11 @@ public class DistributionEditor extends Composite {
         this.part = part;
         createTopComposite(parent);
 
+
+       // natTable = new NatTable(parent, viewportLayer);
         natTable = new NatTable(this, false);
 
-        createStatusBar(parent);
+       // createStatusBar(parent);
     }
 
     public boolean isShowRank() {
@@ -196,11 +199,8 @@ public class DistributionEditor extends Composite {
         statusLabel.setLayoutData(gridData);
 
         statusLabelSourceReference = new Label(composite, SWT.RIGHT);
-//        GridData sourceGrid = new GridData();
-//        sourceGrid.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
-//        //sourceGrid.grabExcessHorizontalSpace = false;
-//        sourceGrid.horizontalSpan = 1;
-       statusLabelSourceReference.setLayoutData(gridData);
+
+        statusLabelSourceReference.setLayoutData(gridData);
 
         if (defaultSource != null){
             statusLabelSourceReference.setText("Default Source Reference: " + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache());
@@ -238,7 +238,7 @@ public class DistributionEditor extends Composite {
         // to sort on a single click
 
         natTable.addConfiguration(new SingleClickSortConfiguration());
-        natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
+   //     natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
 
         // add the header menu configuration for adding the column header menu
         // with hide/show actions
@@ -251,37 +251,38 @@ public class DistributionEditor extends Composite {
 //        summaryRowLayer.addConfiguration(new AggregationConfiguration(this));
 
       //+++CONTEXT MENU+++
-        menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$
-        // get the menu registered by EMenuService
-        final Menu e4Menu = natTable.getMenu();
-        // remove the menu reference from NatTable instance
-        natTable.setMenu(null);
-        natTable.addConfiguration(
-                new AbstractUiBindingConfiguration() {
-            @Override
-            public void configureUiBindings(
-                    UiBindingRegistry uiBindingRegistry) {
-                // add e4 menu to NatTable
-                new PopupMenuBuilder(natTable, e4Menu)
-                    .build();
-
-                // register the UI binding for header, corner and body region
-                uiBindingRegistry.registerMouseDownBinding(
-                        new MouseEventMatcher(
-                                SWT.NONE,
-                                null,
-                                MouseEventMatcher.RIGHT_BUTTON),
-                        new PopupMenuAction(e4Menu));
-            }
-        });
+//        menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$
+//        // get the menu registered by EMenuService
+//        final Menu e4Menu = natTable.getMenu();
+//        // remove the menu reference from NatTable instance
+//        natTable.setMenu(null);
+//        natTable.addConfiguration(
+//                new AbstractUiBindingConfiguration() {
+//            @Override
+//            public void configureUiBindings(
+//                    UiBindingRegistry uiBindingRegistry) {
+//                // add e4 menu to NatTable
+//                new PopupMenuBuilder(natTable, e4Menu)
+//                    .build();
+//
+//                // register the UI binding for header, corner and body region
+//                uiBindingRegistry.registerMouseDownBinding(
+//                        new MouseEventMatcher(
+//                                SWT.NONE,
+//                                null,
+//                                MouseEventMatcher.RIGHT_BUTTON),
+//                        new PopupMenuAction(e4Menu));
+//            }
+//        });
 
         natTable.configure();
     }
 
-    public void createTable(boolean freezeSupplementalColumns){
+    public void createTable(){
         /**
          * layers
          */
+
         createLayers();
 
         /**
@@ -307,158 +308,78 @@ public class DistributionEditor extends Composite {
 
 
         this.layout();
-        natTable.doCommand(new ClientAreaResizeCommand(natTable));
+      //  boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
+      //  System.out.println(ok);
     }
 
 
     private void createLayers() {
 
         SortedList sortedList = new SortedList(taxonList, new TaxonDistributionDtoComparator());
+        DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this);
 
 
-        /**
-         * data provider
-         */
-        DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this);
         bodyDataProvider = new ListDataProvider(sortedList, columnPropertyAccessor);
 
-        propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
+        propertyToLabelMap.put(TAXON_COLUMN, Messages.ChecklistEditor_TAXON);
         if (isShowRank){
-            propertyToLabelMap.put(RANK_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
+            propertyToLabelMap.put(RANK_COLUMN, Messages.ChecklistEditor_RANK);
         }
         configRegistry = new ConfigRegistry();
 
-
-        /**
-         * BODY layer
-         *
-         *
-
-        CompositeLayer
-         - (top) SummaryRowLayer
-         - (bottom) ViewportLayer
-
-             ^
-        ViewportLayer
-
-             ^
-        TreeLayer (default visible)
-
-             ^
-        CompositeFreezeLayer
-         - viewportLayer
-         - selectionLayer
-         - freezeLayer
-
-             ^
-        FreezeLayer
-
-             ^
-        SelectionLayer
-
-             ^
-        ColumnHideShowLayer
-
-             ^
-        ColumnReorderLayer
-
-             ^
-        DataLayer
-
-         *
-
-         */
-        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
-
-        //register labels
-//        CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this);
-//        bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
-
-
-        propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
         initLabels();
+        // build up a layer stack consisting of DataLayer, SelectionLayer and
+        // ViewportLayer
+        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
+        selectionLayer = new SelectionLayer(bodyDataLayer);
+        bodyLayer = new ViewportLayer(selectionLayer);
 
-
-   //     layer for event handling of GlazedLists and PropertyChanges
-        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, taxonList);
-
-
-
-        bodyLayer = new DefaultBodyLayerStack(eventLayer);
-        final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
-        freezeLayer = new FreezeLayer(selectionLayer);
-        final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
-                freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
-
-
-        topMostLayer = compositeFreezeLayer;
-
-        summaryRowLayer = new FixedSummaryRowLayer(bodyDataLayer, topMostLayer, configRegistry, false);
-        //register labels with summary prefix for summary layer
-        ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
-        summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
-        int n = 1;
-        if (isShowRank){
-            n++;
-        }
-        for(int i=0;i<areas.size();i++){
-            NamedArea namedArea = areas.get(i);
-            summaryColumnLabelAccumulator.registerColumnOverrides(
-                    i+n,
-                    SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+namedArea.getLabel());
-        }
-        // because the horizontal dependency is the ViewportLayer
-        // we need to set the composite dependency to false
-        summaryRowLayer.setHorizontalCompositeDependency(false);
-
-        CompositeLayer composite = new CompositeLayer(1, 2);
-        composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0); //$NON-NLS-1$
-        composite.setChildLayer(GridRegion.BODY, topMostLayer, 0, 1);
+        // as the selection mouse bindings are registered for the region label
+        // GridRegion.BODY
+        // we need to set that region label to the viewport so the selection via mouse
+        // is working correctly
+        bodyLayer.setRegionName(GridRegion.BODY);
 
 
-        /**
-         * column header layer
-         */
-        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
-                propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
-        DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
-        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, topMostLayer, selectionLayer);
-
-        // add the SortHeaderLayer to the column header layer stack
-        // as we use GlazedLists, we use the GlazedListsSortModel which
-        // delegates the sorting to the SortedList
-        final SortHeaderLayer<TaxonDistributionDTO> sortHeaderLayer = new SortHeaderLayer<>(
-                columnHeaderLayer,
-                new GlazedListsSortModel<>(sortedList,
-                        columnPropertyAccessor,
-                        configRegistry,
-                        columnHeaderDataLayer));
+        IDataProvider columnHeaderDataProvider =
+                new DefaultColumnHeaderDataProvider(propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
+            DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
+            ILayer columnHeaderLayer = new ColumnHeaderLayer(
+                columnHeaderDataLayer,
+                bodyLayer,
+                selectionLayer);
 
 
-        /**
-         * row header layer
-         */
+     // build the row header layer stack
         IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
-        DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
-        FixedSummaryRowHeaderLayer fixedSummaryRowHeaderLayer = new FixedSummaryRowHeaderLayer(rowHeaderDataLayer,
-                composite, selectionLayer);
-        fixedSummaryRowHeaderLayer.setSummaryRowLabel("\u2211"); //$NON-NLS-1$
-
-
-        /**
-         * corner layer
-         */
-        ILayer cornerLayer = new CornerLayer(
-                new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
-                fixedSummaryRowHeaderLayer, sortHeaderLayer);
+        DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider, 40, 20);
+        ILayer rowHeaderLayer = new RowHeaderLayer(
+            rowHeaderDataLayer,
+            bodyLayer,
+            selectionLayer);
+
+
+
+        IDataProvider cornerDataProvider =
+                new DefaultCornerDataProvider(
+                    columnHeaderDataProvider,
+                    rowHeaderDataProvider);
+            DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
+            ILayer cornerLayer = new CornerLayer(
+                cornerDataLayer,
+                rowHeaderLayer,
+                columnHeaderLayer);
+
+            GridLayer gridLayer = new GridLayer(
+                    bodyLayer,
+                    columnHeaderLayer,
+                    rowHeaderLayer,
+                    cornerLayer);
 
+        natTable.setLayer(gridLayer);
 
-        /**
-         * GRID layer (composition of all other layers)
-         */
-        GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, null, cornerLayer);
+        topMostLayer = bodyLayer;
 
-        natTable.setLayer(gridLayer);
 
     }
 
@@ -543,10 +464,14 @@ public class DistributionEditor extends Composite {
 
     }
     public void loadDistributions(List<TaxonDistributionDTO> taxonList) {
-        this.taxonList.addAll(taxonList);
-
+        if (this.taxonList == null){
+            this.taxonList = new BasicEventList<>();
+        }
+       taxonList.stream().forEach(wrapper->DistributionEditor.this.taxonList.add(wrapper));
     }
 
+
+
     public Collection<DescriptionElementBase> getDistributions() {
         Collection<DescriptionElementBase> descElements = new HashSet();
 //TODO: only for edited taxa
@@ -564,8 +489,10 @@ public class DistributionEditor extends Composite {
         if (isShowRank){
             index++;
         }
-        for (NamedArea area: areas) {
-            this.areaToColumnIndexMap.put(index++, area);
+
+        loadNamedAreas();
+        for (DefinedTermBase area: areas) {
+            this.areaToColumnIndexMap.put(index++, (NamedArea)area);
 
             //TODO: adapt to preference
             String areaLabel = area.getLabel();
@@ -574,16 +501,104 @@ public class DistributionEditor extends Composite {
         }
     }
 
+    private SortedSet<DefinedTermBase> loadNamedAreas() {
+        //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
+
+        String valuesAreas = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey());
+        String values = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
+        if (values != null && values != "") { //$NON-NLS-1$
+            String[] split = values.split(";"); //$NON-NLS-1$
+            List<String> listValue = Arrays.asList(split);
+            List<DefinedTermBase> termlist = new ArrayList<DefinedTermBase>();
+            Set<UUID> uuidList = new HashSet<UUID>();
+            UUID uuid;
+            for(String s : listValue){
+                uuid = UUID.fromString(s);
+                uuidList.add(uuid);
 
-    private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
-        // add the ExportCommandHandler to the ViewportLayer in order to make
-        // exporting work
-        topMostLayer.registerCommandHandler(new ExportCommandHandler(topMostLayer));
+            }
+            IVocabularyService service =  CdmStore.getService(IVocabularyService.class);
+            List<TermVocabulary> vocs = service.find(uuidList);
+            split = valuesAreas.split(";");
+            listValue = Arrays.asList(split);
+            for (TermVocabulary voc: vocs){
+                termlist.addAll(service.getTerms(voc, null, null, null, null).getRecords());
+            }
+            List<DefinedTermBase> filteredList = new ArrayList();
+            for (DefinedTermBase area: termlist){
+                if (listValue.contains(area.getUuid().toString())) {
+                    filteredList.add(area);
+                }
 
+            }
+
+            if (PreferencesUtil.isSortNamedAreaByOrderInVocabulary()){
+                areas =  getTermsOrderedByVocabularyOrder(filteredList);
+            } else if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
+                areas = getTermsOrderedByIdInVocabulary(filteredList);
+            }else{
+                areas =  getTermsOrderedByLabels(filteredList, CdmStore.getDefaultLanguage());
+            }
+        }
+        return null;
+    }
+
+    public SortedSet<DefinedTermBase> getTermsOrderedByLabels(List<DefinedTermBase> listTerm,Language language){
+        TermLanguageComparator<?> comp = new TermLanguageComparator<>();
+        comp.setCompareLanguage(language);
+        SortedSet<DefinedTermBase> result = new TreeSet(comp);
+        if(listTerm != null){
+            result.addAll(listTerm);
+        }
+        return result;
+    }
+
+    public SortedSet<DefinedTermBase> getTermsOrderedByIdInVocabulary(List<DefinedTermBase> namedAreas) {
+        TermIdInVocabularyComparator<?> comp = new TermIdInVocabularyComparator<>();
+
+        SortedSet<DefinedTermBase> result = new TreeSet(comp);
+        if(namedAreas != null){
+            result.addAll(namedAreas);
+        }
+        return result;
+    }
+
+    public SortedSet<DefinedTermBase> getTermsOrderedByVocabularyOrder(List<DefinedTermBase> listAreas){
+        HashMap<TermVocabulary<DefinedTermBase>, List<DefinedTermBase>> vocs = new HashMap<>();
+        OrderedTermComparator<?> comp = new OrderedTermComparator<>();
+        boolean allOrderedTerms = true;
+        List<TermVocabulary> alreadyOrderIndexNull = new ArrayList<>();
+        for (DefinedTermBase term: listAreas){
+            if (!(term instanceof OrderedTermBase)){
+                allOrderedTerms = false;
+                break;
+            }else if (((OrderedTermBase)term).getOrderIndex() == 0){
+                if(alreadyOrderIndexNull.contains(term.getVocabulary())) {
+                    allOrderedTerms = false;
+                    break;
+                }else{
+                    alreadyOrderIndexNull.add(term.getVocabulary());
+                }
+
+
+            }
+        }
+        if (allOrderedTerms){
+            SortedSet<DefinedTermBase> result = new TreeSet(comp.reversed());
+            result.addAll(listAreas);
+            return result;
+        }else{
+            return getTermsOrderedByLabels(listAreas, PreferencesUtil.getGlobalLanguage());
+        }
+
+
+    }
+
+    private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
         //selection listener
         E4SelectionListener selectionListener = new DistributionCellSelectionListener(part.getSelectionService(),
-                bodyLayer.getSelectionLayer(), bodyDataProvider, part);
-        bodyLayer.getSelectionLayer().addLayerListener(selectionListener);
+                selectionLayer, bodyDataProvider, part);
+        selectionLayer.addLayerListener(selectionListener);
         selectionListener.setFullySelectedRowsOnly(false);
 
         //register handler for view configuration menu
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorPart.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorPart.java
index 781bc30cd..6f2e0d667 100755
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorPart.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorPart.java
@@ -24,10 +24,8 @@ import org.eclipse.e4.ui.di.Persist;
 import org.eclipse.e4.ui.model.application.ui.MDirtyable;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
-import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StackLayout;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
@@ -37,7 +35,6 @@ import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-import eu.etaxonomy.taxeditor.editor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
@@ -99,17 +96,21 @@ ICdmEntitySessionEnabled, IPartContentHasSupplementalData, IPartContentHasDetail
         stackLayout = new StackLayout();
         parent.setLayout(stackLayout);
         editor = new DistributionEditor(parent, this);
-        Label label = new Label(parent, SWT.NONE);
-        label.setText(Messages.CharacterMatrixPart_LOADING_MATRIX);
-        stackLayout.topControl = label;
+//        Label label = new Label(parent, SWT.NONE);
+//        label.setText(Messages.CharacterMatrixPart_LOADING_MATRIX);
+   //     stackLayout.topControl = label;
         ContextInjectionFactory.inject(editor, context);
     }
 
     public void init(UUID parentTaxonUuid) {
         this.taxonList = CdmStore.getService(ITaxonNodeService.class).getTaxonDistributionDTOForSubtree(parentTaxonUuid, TAXONNODE_PROPERTY_PATH);
+
         if(taxonList!=null){
-            editor.createTable( true);
             editor.loadDistributions(taxonList);
+            editor.createTable();
+            editor.pack();
+            stackLayout.topControl = editor;
+            editor.getParent().layout();
         }
     }
     public ESelectionService getSelectionService() {
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/handler/OpenChecklistEditorHandlerE4.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/handler/OpenChecklistEditorHandlerE4.java
index 033675d04..485526b72 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/handler/OpenChecklistEditorHandlerE4.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/handler/OpenChecklistEditorHandlerE4.java
@@ -4,30 +4,20 @@ import java.util.UUID;
 
 import javax.inject.Inject;
 
-import org.apache.commons.lang.StringUtils;
 import org.eclipse.e4.core.services.log.Logger;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
 import org.eclipse.e4.ui.workbench.modeling.EPartService;
-import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
-import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
-import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.AppModelId;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
-import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
-import eu.etaxonomy.taxeditor.editor.view.checklist.e4.ChecklistEditorE4;
 import eu.etaxonomy.taxeditor.handler.defaultHandler.e4.DefaultOpenHandlerBaseE4;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.EditorPreferencePredicate;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 public class OpenChecklistEditorHandlerE4 extends DefaultOpenHandlerBaseE4<ITaxonTreeNode> {
     @Inject
@@ -47,47 +37,49 @@ public class OpenChecklistEditorHandlerE4 extends DefaultOpenHandlerBaseE4<ITaxo
 	@Override
 	protected void open(ITaxonTreeNode entity, Shell shell, EPartService partService) {
 
-		if (PreferencesUtil.getBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey())) {
-			if (StringUtils.isBlank(PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()) )){
+//		if (PreferencesUtil.getBooleanValue(EditorPreferencePredicate.DistributionEditorActivated.getKey())) {
+//			if (StringUtils.isBlank(PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()) )){
+//
+//				MessagingUtils.informationDialog(Messages.OpenChecklistEditorHandler_NO_AREAS, Messages.OpenChecklistEditorHandler_CHOOSE_AREA
+//						+ Messages.OpenChecklistEditorHandler_GOTO_PREFERENCES);
+//				return;
+//			}
+//			if (entity instanceof Classification) {
+//				ChecklistEditorInput input = new ChecklistEditorInput(((Classification) entity));
+//				try {
+//					openChecklistEditor(input, partService);
+//				} catch (NullPointerException npe) {
+//					MessagingUtils.messageDialog(COULD_NOT_OPEN_DISTRIBUTION_EDITOR, OpenChecklistEditorHandlerE4.class,
+//							COULD_NOT_OPEN_DISTRIBUTION_EDITOR_THE_HIERARCHY_IS_CORRUPTED, npe);
+//				}
+//			} else if (entity instanceof TaxonNode) {
+//				ChecklistEditorInput input = new ChecklistEditorInput((TaxonNode) entity);
+//				try {
+//					openChecklistEditor(input, partService);
+//				} catch (NullPointerException npe) {
+//					MessagingUtils.messageDialog(COULD_NOT_OPEN_DISTRIBUTION_EDITOR, OpenChecklistEditorHandlerE4.class,
+//							COULD_NOT_OPEN_DISTRIBUTION_EDITOR_THE_HIERARCHY_IS_CORRUPTED, npe);
+//				}
+//			}
+//		}
 
-				MessagingUtils.informationDialog(Messages.OpenChecklistEditorHandler_NO_AREAS, Messages.OpenChecklistEditorHandler_CHOOSE_AREA
-						+ Messages.OpenChecklistEditorHandler_GOTO_PREFERENCES);
-				return;
-			}
-			if (entity instanceof Classification) {
-				ChecklistEditorInput input = new ChecklistEditorInput(((Classification) entity));
-				try {
-					openChecklistEditor(input, partService);
-				} catch (NullPointerException npe) {
-					MessagingUtils.messageDialog(COULD_NOT_OPEN_DISTRIBUTION_EDITOR, OpenChecklistEditorHandlerE4.class,
-							COULD_NOT_OPEN_DISTRIBUTION_EDITOR_THE_HIERARCHY_IS_CORRUPTED, npe);
-				}
-			} else if (entity instanceof TaxonNode) {
-				ChecklistEditorInput input = new ChecklistEditorInput((TaxonNode) entity);
-				try {
-					openChecklistEditor(input, partService);
-				} catch (NullPointerException npe) {
-					MessagingUtils.messageDialog(COULD_NOT_OPEN_DISTRIBUTION_EDITOR, OpenChecklistEditorHandlerE4.class,
-							COULD_NOT_OPEN_DISTRIBUTION_EDITOR_THE_HIERARCHY_IS_CORRUPTED, npe);
-				}
-			}
-		}
+	    EditorUtil.openDistributionEditor(entity.getUuid(), modelService, partService, application);
 	}
 
-	private void openChecklistEditor(ChecklistEditorInput input, EPartService partService) {
-		MPart part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_CHECKLISTEDITORE4);
-		MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
-		if(editorAreaPartStack!=null){
-		    editorAreaPartStack.getChildren().add(part);
-		}
-		part = partService.showPart(part, PartState.ACTIVATE);
-		ChecklistEditorE4 checklistEditor = (ChecklistEditorE4) part.getObject();
-		if (checklistEditor != null){
-			checklistEditor.init(input);
-		}else{
-			logger.debug("Editor is null");
-		}
-	}
+//	private void openChecklistEditor(ChecklistEditorInput input, EPartService partService) {
+//		MPart part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_CHECKLISTEDITORE4);
+//		MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
+//		if(editorAreaPartStack!=null){
+//		    editorAreaPartStack.getChildren().add(part);
+//		}
+//		part = partService.showPart(part, PartState.ACTIVATE);
+//		ChecklistEditorE4 checklistEditor = (ChecklistEditorE4) part.getObject();
+//		if (checklistEditor != null){
+//			checklistEditor.init(input);
+//		}else{
+//			logger.debug("Editor is null");
+//		}
+//	}
 
     /**
      * {@inheritDoc}
@@ -99,6 +91,6 @@ public class OpenChecklistEditorHandlerE4 extends DefaultOpenHandlerBaseE4<ITaxo
 
     @Override
     protected String getPartId() {
-        return AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_CHECKLISTEDITORE4;
+        return AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
     }
 }
