Project

General

Profile

Download (22.3 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
10

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.HashMap;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Map;
17

    
18
import javax.inject.Inject;
19

    
20
import org.apache.commons.collections4.map.LinkedMap;
21
import org.apache.log4j.Logger;
22
import org.eclipse.e4.ui.services.EMenuService;
23
import org.eclipse.jface.layout.GridDataFactory;
24
import org.eclipse.jface.wizard.WizardDialog;
25
import org.eclipse.nebula.widgets.nattable.NatTable;
26
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
27
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
28
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
29
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
30
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
31
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
32
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
33
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
34
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
35
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
36
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
37
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
38
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
39
import org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand;
40
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
41
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
42
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
43
import org.eclipse.nebula.widgets.nattable.grid.data.FixedSummaryRowHeaderLayer;
44
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
45
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
46
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
47
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
48
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
49
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
50
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
51
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
52
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
53
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
54
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
55
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
56
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
57
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
58
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
59
import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
60
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
61
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
62
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
63
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
64
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
65
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
66
import org.eclipse.swt.SWT;
67
import org.eclipse.swt.events.SelectionAdapter;
68
import org.eclipse.swt.events.SelectionEvent;
69
import org.eclipse.swt.layout.GridData;
70
import org.eclipse.swt.layout.GridLayout;
71
import org.eclipse.swt.widgets.Button;
72
import org.eclipse.swt.widgets.Composite;
73
import org.eclipse.swt.widgets.Label;
74
import org.eclipse.swt.widgets.Menu;
75
import org.eclipse.swt.widgets.Text;
76

    
77
import ca.odell.glazedlists.EventList;
78
import ca.odell.glazedlists.SortedList;
79
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
80
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
81
import eu.etaxonomy.cdm.model.location.NamedArea;
82
import eu.etaxonomy.cdm.model.reference.Reference;
83
import eu.etaxonomy.taxeditor.editor.EditorUtil;
84
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixLabelStyleConfiguration;
85
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
86
import eu.etaxonomy.taxeditor.model.AbstractUtility;
87
import eu.etaxonomy.taxeditor.preference.Resources;
88
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
89
import eu.etaxonomy.taxeditor.store.StoreUtil;
90
import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog;
91

    
92
/**
93
 * @author k.luther
94
 * @since 27.11.2018
95
 *
96
 */
97
public class DistributionEditor extends Composite {
98

    
99

    
100
    private static final String DISTRIBUTION_EDITOR = "Distribution Editor";
101
    private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
102
    private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
103
    private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
104
    public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$
105

    
106
    static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
107
    static final String RANK_COLUMN = "collector_column"; //$NON-NLS-1$
108

    
109
    private static final Logger logger = Logger.getLogger(DistributionEditor.class);
110
    @Inject
111
    private EMenuService menuService;
112
    private NatTable natTable;
113
    private Label statusLabel;
114
    private Label statusLabelSourceReference;
115
    private Reference defaultSource;
116

    
117
    private Map<Integer, NamedArea> areaToColumnIndexMap= new HashMap();
118
    private int firstDataColumnIndex;
119

    
120
    private ListDataProvider<TaxonDistributionDTO> bodyDataProvider;
121
    private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
122

    
123
    private boolean isShowRank;
124
    private Integer countNodes;
125
    private Text searchText;
126

    
127
    EventList<TaxonDistributionDTO> taxonList;
128
    List<NamedArea> areas = new ArrayList();
129
    DistributionEditorPart part;
130
    private DefaultBodyLayerStack bodyLayer;
131
    private FreezeLayer freezeLayer;
132
    private ConfigRegistry configRegistry;
133
    private AbstractLayer topMostLayer;
134

    
135
    private FixedSummaryRowLayer summaryRowLayer;
136

    
137

    
138
    /**
139
     * @param parent
140
     * @param style
141
     */
142
    public DistributionEditor(Composite parent, DistributionEditorPart part) {
143
        super(parent, SWT.NULL);
144
        this.setLayout(new GridLayout());
145
        this.part = part;
146
        createTopComposite(parent);
147

    
148
        natTable = new NatTable(this, false);
149

    
150
        createStatusBar(parent);
151
    }
152

    
153
    public boolean isShowRank() {
154
        return isShowRank;
155
    }
156

    
157
    public void setShowRank(boolean isShowRank) {
158
        this.isShowRank = isShowRank;
159
    }
160

    
161
    public int getFirstDataColumnIndex() {
162
        return firstDataColumnIndex;
163
    }
164

    
165
    public void setFirstDataColumnIndex(int firstDataColumnIndex) {
166
        this.firstDataColumnIndex = firstDataColumnIndex;
167
    }
168

    
169
    public LinkedMap<String, String> getPropertyToLabelMap() {
170
        return propertyToLabelMap;
171
    }
172

    
173
    public void setPropertyToLabelMap(LinkedMap<String, String> propertyToLabelMap) {
174
        this.propertyToLabelMap = propertyToLabelMap;
175
    }
176

    
177
    public Map<Integer, NamedArea> getAreaToColumnIndexMap() {
178
        return areaToColumnIndexMap;
179
    }
180

    
181

    
182
    public void setAreaToColumnIndexMap(Map<Integer, NamedArea> areaToColumnIndexMap) {
183
        this.areaToColumnIndexMap = areaToColumnIndexMap;
184
    }
185

    
186

    
187

    
188
    private void createStatusBar(Composite composite) {
189
        GridData gridData = new GridData();
190
        gridData.horizontalSpan = 1;
191
        gridData.grabExcessHorizontalSpace = true;
192
        gridData.horizontalAlignment = GridData.FILL;
193

    
194
        statusLabel = new Label(composite, SWT.LEFT);
195
        statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
196
        statusLabel.setLayoutData(gridData);
197

    
198
        statusLabelSourceReference = new Label(composite, SWT.RIGHT);
199
//        GridData sourceGrid = new GridData();
200
//        sourceGrid.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
201
//        //sourceGrid.grabExcessHorizontalSpace = false;
202
//        sourceGrid.horizontalSpan = 1;
203
       statusLabelSourceReference.setLayoutData(gridData);
204

    
205
        if (defaultSource != null){
206
            statusLabelSourceReference.setText("Default Source Reference: " + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache());
207

    
208
        }
209
    }
210

    
211
    private void applyStyles(){
212
        ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
213
        configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
214
        // NOTE: Getting the colors and fonts from the GUIHelper ensures that
215
        // they are disposed properly (required by SWT)
216
        configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
217
        configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
218
        natTable.addConfiguration(configuration);
219

    
220
    }
221

    
222
    private void configureNatTable(ConfigRegistry configRegistry,
223
            AbstractLayer topMostLayer) {
224
        /**
225
         * CONFIGURATION
226
         */
227
        natTable.setConfigRegistry(configRegistry);
228

    
229
        applyStyles();
230

    
231
        //add default configuration because autoconfigure is set to false in constructor
232
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
233

    
234
        //FIXME: this is for DEBUG ONLY
235
        //        natTable.addConfiguration(new DebugMenuConfiguration(natTable));
236

    
237
        // override the default sort configuration and change the mouse bindings
238
        // to sort on a single click
239

    
240
        natTable.addConfiguration(new SingleClickSortConfiguration());
241
        natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
242

    
243
        // add the header menu configuration for adding the column header menu
244
        // with hide/show actions
245
        natTable.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable));
246

    
247
        // add custom configuration for data conversion and add column labels to viewport layer
248
     //   topMostLayer.addConfiguration(new CellEditorDataConversionConfiguration(this));
249

    
250
//        //register aggregation configuration
251
//        summaryRowLayer.addConfiguration(new AggregationConfiguration(this));
252

    
253
      //+++CONTEXT MENU+++
254
        menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$
255
        // get the menu registered by EMenuService
256
        final Menu e4Menu = natTable.getMenu();
257
        // remove the menu reference from NatTable instance
258
        natTable.setMenu(null);
259
        natTable.addConfiguration(
260
                new AbstractUiBindingConfiguration() {
261
            @Override
262
            public void configureUiBindings(
263
                    UiBindingRegistry uiBindingRegistry) {
264
                // add e4 menu to NatTable
265
                new PopupMenuBuilder(natTable, e4Menu)
266
                    .build();
267

    
268
                // register the UI binding for header, corner and body region
269
                uiBindingRegistry.registerMouseDownBinding(
270
                        new MouseEventMatcher(
271
                                SWT.NONE,
272
                                null,
273
                                MouseEventMatcher.RIGHT_BUTTON),
274
                        new PopupMenuAction(e4Menu));
275
            }
276
        });
277

    
278
        natTable.configure();
279
    }
280

    
281
    public void createTable(boolean freezeSupplementalColumns){
282
        /**
283
         * layers
284
         */
285
        createLayers();
286

    
287
        /**
288
         * configuration
289
         */
290
        configureNatTable( configRegistry, topMostLayer);
291

    
292
        /**
293
         * handlers and listeners
294
         */
295
        registerHandlersAndListeners(topMostLayer);
296

    
297
        //grab all space
298
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
299

    
300
        //update label to current data set
301
//        toolbar.getWsLabel().setText(descriptiveDataSet.getLabel());
302
//        toolbar.getWsLabel().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
303
//        toolbar.getWsLabel().getParent().layout();
304

    
305
        //initial freeze of supplemental columns
306
//        freezeSupplementalColumns(freezeSupplementalColumns);
307

    
308

    
309
        this.layout();
310
        natTable.doCommand(new ClientAreaResizeCommand(natTable));
311
    }
312

    
313

    
314
    private void createLayers() {
315

    
316
        SortedList sortedList = new SortedList(taxonList, new TaxonDistributionDtoComparator());
317

    
318

    
319
        /**
320
         * data provider
321
         */
322
        DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this);
323
        bodyDataProvider = new ListDataProvider(sortedList, columnPropertyAccessor);
324

    
325
        propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
326
        if (isShowRank){
327
            propertyToLabelMap.put(RANK_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
328
        }
329
        configRegistry = new ConfigRegistry();
330

    
331

    
332
        /**
333
         * BODY layer
334
         *
335
         *
336

    
337
        CompositeLayer
338
         - (top) SummaryRowLayer
339
         - (bottom) ViewportLayer
340

    
341
             ^
342
        ViewportLayer
343

    
344
             ^
345
        TreeLayer (default visible)
346

    
347
             ^
348
        CompositeFreezeLayer
349
         - viewportLayer
350
         - selectionLayer
351
         - freezeLayer
352

    
353
             ^
354
        FreezeLayer
355

    
356
             ^
357
        SelectionLayer
358

    
359
             ^
360
        ColumnHideShowLayer
361

    
362
             ^
363
        ColumnReorderLayer
364

    
365
             ^
366
        DataLayer
367

    
368
         *
369

    
370
         */
371
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
372

    
373
        //register labels
374
//        CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this);
375
//        bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
376

    
377

    
378
        propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
379
        initLabels();
380

    
381

    
382
   //     layer for event handling of GlazedLists and PropertyChanges
383
        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, taxonList);
384

    
385

    
386

    
387
        bodyLayer = new DefaultBodyLayerStack(eventLayer);
388
        final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
389
        freezeLayer = new FreezeLayer(selectionLayer);
390
        final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
391
                freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
392

    
393

    
394
        topMostLayer = compositeFreezeLayer;
395

    
396
        summaryRowLayer = new FixedSummaryRowLayer(bodyDataLayer, topMostLayer, configRegistry, false);
397
        //register labels with summary prefix for summary layer
398
        ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
399
        summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
400
        int n = 1;
401
        if (isShowRank){
402
            n++;
403
        }
404
        for(int i=0;i<areas.size();i++){
405
            NamedArea namedArea = areas.get(i);
406
            summaryColumnLabelAccumulator.registerColumnOverrides(
407
                    i+n,
408
                    SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+namedArea.getLabel());
409
        }
410
        // because the horizontal dependency is the ViewportLayer
411
        // we need to set the composite dependency to false
412
        summaryRowLayer.setHorizontalCompositeDependency(false);
413

    
414
        CompositeLayer composite = new CompositeLayer(1, 2);
415
        composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0); //$NON-NLS-1$
416
        composite.setChildLayer(GridRegion.BODY, topMostLayer, 0, 1);
417

    
418

    
419
        /**
420
         * column header layer
421
         */
422
        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
423
                propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
424
        DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
425
        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, topMostLayer, selectionLayer);
426

    
427
        // add the SortHeaderLayer to the column header layer stack
428
        // as we use GlazedLists, we use the GlazedListsSortModel which
429
        // delegates the sorting to the SortedList
430
        final SortHeaderLayer<TaxonDistributionDTO> sortHeaderLayer = new SortHeaderLayer<>(
431
                columnHeaderLayer,
432
                new GlazedListsSortModel<>(sortedList,
433
                        columnPropertyAccessor,
434
                        configRegistry,
435
                        columnHeaderDataLayer));
436

    
437

    
438
        /**
439
         * row header layer
440
         */
441
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
442
        DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
443
        FixedSummaryRowHeaderLayer fixedSummaryRowHeaderLayer = new FixedSummaryRowHeaderLayer(rowHeaderDataLayer,
444
                composite, selectionLayer);
445
        fixedSummaryRowHeaderLayer.setSummaryRowLabel("\u2211"); //$NON-NLS-1$
446

    
447

    
448
        /**
449
         * corner layer
450
         */
451
        ILayer cornerLayer = new CornerLayer(
452
                new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
453
                fixedSummaryRowHeaderLayer, sortHeaderLayer);
454

    
455

    
456
        /**
457
         * GRID layer (composition of all other layers)
458
         */
459
        GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, null, cornerLayer);
460

    
461
        natTable.setLayer(gridLayer);
462

    
463
    }
464

    
465
    /**
466
     * @param parent
467
     * @return
468
     */
469
    private Text createSearchBar(Composite parent) {
470

    
471
        final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
472
        GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
473

    
474
        searchText.setLayoutData(gridData);
475
        searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
476
        searchText.setText(TYPE_FILTER_TEXT);
477
        searchText.setToolTipText(Messages.ChecklistEditor_SEARCH_TOOLTIP);
478

    
479
        Button button1 = new Button(parent, SWT.PUSH );
480
        GridData gridData2 = new GridData();
481
        gridData2.horizontalSpan = 1;
482
        gridData2.horizontalAlignment = SWT.RIGHT;
483
        button1.setLayoutData(gridData2);
484

    
485

    
486
        button1.setText(Messages.ChecklistEditor_DIST_STATUS);
487
        button1.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
488
        button1.addSelectionListener(new SelectionAdapter() {
489
            @Override
490
            public void widgetSelected(SelectionEvent event) {
491
                AvailableDistributionWizard availableDistributionWizard = new AvailableDistributionWizard();
492
                WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
493
                        availableDistributionWizard);
494

    
495
                int open = dialog.open();
496
                if(open == 0){
497
                    //TODO!!!!
498
                   // reload();
499
                }
500
            }
501
        });
502

    
503
        Button button2 = new Button(parent, SWT.PUSH );
504
        GridData gridData3 = new GridData();
505
        gridData2.horizontalSpan = 1;
506
        button2.setLayoutData(gridData3);
507

    
508

    
509
        button2.setText(Messages.ChecklistEditor_DEFAULT_SOURCE);
510
        button2.setToolTipText(Messages.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP);
511
        button2.addSelectionListener(new SelectionAdapter() {
512

    
513
            @Override
514
            public void widgetSelected(SelectionEvent event) {
515
                defaultSource = ReferenceSelectionDialog.select(AbstractUtility.getShell(), null);
516

    
517
                String defaultSourceStr = (defaultSource == null) ? "" : "Default Source Reference: " + defaultSource.getTitleCache();
518
                if (defaultSourceStr.length()> 100){
519
                    defaultSourceStr = defaultSourceStr.substring(0, 98) + "...";
520
                }
521
                statusLabelSourceReference.setText(defaultSourceStr);
522

    
523
                button2.setBackground(EditorUtil.getColor(Resources.COLOR_CONTROL_SELECTED));
524
            }
525

    
526
        });
527

    
528
        parent.pack();
529
        return searchText;
530
    }
531

    
532
    /**
533
     * @param parent
534
     */
535
    private void createTopComposite(Composite parent) {
536
        GridLayout gridLayout = new GridLayout(3, false);
537
        gridLayout.marginWidth = 0;
538
        gridLayout.marginHeight = 0;
539
        parent.setLayout(gridLayout);
540

    
541
       searchText = createSearchBar(parent);
542

    
543

    
544
    }
545
    public void loadDistributions(List<TaxonDistributionDTO> taxonList) {
546
        this.taxonList.addAll(taxonList);
547

    
548
    }
549

    
550
    public Collection<DescriptionElementBase> getDistributions() {
551
        Collection<DescriptionElementBase> descElements = new HashSet();
552
//TODO: only for edited taxa
553
        taxonList.forEach(taxonDto->taxonDto.getDistributionMap()
554
                .forEach((area, descriptionElements)->descElements.addAll(descriptionElements)));
555

    
556

    
557
        return descElements;
558

    
559
    }
560

    
561
    private void initLabels() {
562

    
563
        int index = 1;
564
        if (isShowRank){
565
            index++;
566
        }
567
        for (NamedArea area: areas) {
568
            this.areaToColumnIndexMap.put(index++, area);
569

    
570
            //TODO: adapt to preference
571
            String areaLabel = area.getLabel();
572
            String property = areaLabel;
573
            propertyToLabelMap.put(property, areaLabel);
574
        }
575
    }
576

    
577

    
578
    private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
579
        // add the ExportCommandHandler to the ViewportLayer in order to make
580
        // exporting work
581
        topMostLayer.registerCommandHandler(new ExportCommandHandler(topMostLayer));
582

    
583
        //selection listener
584
        E4SelectionListener selectionListener = new DistributionCellSelectionListener(part.getSelectionService(),
585
                bodyLayer.getSelectionLayer(), bodyDataProvider, part);
586
        bodyLayer.getSelectionLayer().addLayerListener(selectionListener);
587
        selectionListener.setFullySelectedRowsOnly(false);
588

    
589
        //register handler for view configuration menu
590
      //  natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
591
    }
592

    
593
    /**
594
     * @return
595
     */
596
    public IRowDataProvider<TaxonDistributionDTO> getBodyDataProvider() {
597
        return bodyDataProvider;
598
    }
599

    
600

    
601
}
(6-6/11)