Project

General

Profile

Download (22.7 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2017 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.descriptiveDataSet.matrix;
10

    
11
import java.io.File;
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.HashMap;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Properties;
18
import java.util.Set;
19
import java.util.UUID;
20
import java.util.stream.Collectors;
21

    
22
import org.apache.commons.collections4.map.LinkedMap;
23
import org.eclipse.core.runtime.ICoreRunnable;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.jobs.Job;
26
import org.eclipse.jface.layout.GridDataFactory;
27
import org.eclipse.jface.viewers.ComboViewer;
28
import org.eclipse.nebula.widgets.nattable.NatTable;
29
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
30
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
31
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
32
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
33
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
34
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
35
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
36
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
37
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeData;
38
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeRowModel;
39
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
40
import org.eclipse.nebula.widgets.nattable.freeze.FreezeHelper;
41
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
42
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
43
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
44
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
45
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
46
import org.eclipse.nebula.widgets.nattable.grid.data.FixedSummaryRowHeaderLayer;
47
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
48
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
49
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
50
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
51
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
52
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
53
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
54
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
55
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
56
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
57
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
58
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
59
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
60
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
61
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
62
import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
63
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
64
import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel;
65
import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
66
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
67
import org.eclipse.swt.SWT;
68
import org.eclipse.swt.layout.GridData;
69
import org.eclipse.swt.layout.GridLayout;
70
import org.eclipse.swt.widgets.Button;
71
import org.eclipse.swt.widgets.Composite;
72

    
73
import ca.odell.glazedlists.BasicEventList;
74
import ca.odell.glazedlists.EventList;
75
import ca.odell.glazedlists.SortedList;
76
import ca.odell.glazedlists.TreeList;
77
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
78
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
79
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
80
import eu.etaxonomy.cdm.api.service.UpdateResult;
81
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
82
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
83
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
84
import eu.etaxonomy.cdm.model.description.Feature;
85
import eu.etaxonomy.cdm.model.description.FeatureNode;
86
import eu.etaxonomy.cdm.model.description.FeatureTree;
87
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
88
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
89
import eu.etaxonomy.cdm.model.description.State;
90
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
91
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
92
import eu.etaxonomy.taxeditor.model.MessagingUtils;
93
import eu.etaxonomy.taxeditor.store.CdmStore;
94
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
95

    
96
/**
97
 * Character matrix editor for editing specimen/taxon descriptions in a table
98
 * @author pplitzner
99
 * @since Nov 26, 2017
100
 *
101
 */
102
public class CharacterMatrix extends Composite {
103

    
104
    private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties"; //$NON-NLS-1$
105

    
106
    static final int LEADING_COLUMN_COUNT = 4;
107
    static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
108
    static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
109
    static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
110
    static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
111

    
112
    static final String LABEL_TAXON_ROW = "TAXON_ROW"; //$NON-NLS-1$
113

    
114
    private DescriptiveDataSet descriptiveDataSet;
115

    
116
    private NatTable natTable;
117

    
118
    private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
119

    
120
    private Map<Feature, List<State>> categoricalFeatureToStateMap = new HashMap<>();
121

    
122
    private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
123

    
124
    private EventList<Object> descriptions;
125

    
126
    private Collection<SpecimenNodeWrapper> specimenCache = null;
127

    
128
    private ListDataProvider<Object> bodyDataProvider;
129

    
130
    private FreezeLayer freezeLayer;
131

    
132
    private List<Feature> features;
133

    
134
    private CharacterMatrixPart part;
135

    
136
    private AbstractLayer topMostLayer;
137

    
138
    private FixedSummaryRowLayer summaryRowLayer;
139

    
140
    private ConfigRegistry configRegistry;
141

    
142
    private DefaultBodyLayerStack bodyLayer;
143

    
144
    private boolean isTreeView = true;
145

    
146
    private CharacterMatrixToolbar toolbar;
147

    
148

    
149
    public CharacterMatrix(Composite parent, CharacterMatrixPart part) {
150
        super(parent, SWT.NONE);
151
        this.part = part;
152
        this.setLayout(new GridLayout());
153

    
154
        createToolBar();
155

    
156
        natTable = new NatTable(this, false);
157

    
158
        createBottomToolbar();
159

    
160
    }
161

    
162
    private void createToolBar(){
163
        toolbar = new CharacterMatrixToolbar(this, SWT.NONE);
164
    }
165

    
166
    @SuppressWarnings("unused")
167
    private void createBottomToolbar() {
168
        new CharacterMatrixBottomToolbar(this, SWT.NONE);
169
    }
170

    
171

    
172
    private void applyStyles(){
173
        ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
174
        configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
175
        // NOTE: Getting the colors and fonts from the GUIHelper ensures that
176
        // they are disposed properly (required by SWT)
177
        configuration.summaryRowBgColor = GUIHelper.getColor(255, 255, 153);
178
        configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
179
        configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
180
        natTable.addConfiguration(configuration);
181

    
182
    }
183

    
184
    void toggleTreeFlat(boolean isTree, Button btnToggleFlat, Button btnToggleTree, Button btnCollapseAll, Button btnExpandAll, Button btnFreezeSuppInfo) {
185
        isTreeView = isTree;
186
        createTable(isTree);
187
        btnToggleFlat.setEnabled(isTree);
188
        btnToggleTree.setEnabled(!isTree);
189
        btnCollapseAll.setEnabled(isTree);
190
        btnExpandAll.setEnabled(isTree);
191
    }
192

    
193
    public boolean isTreeView() {
194
        return isTreeView;
195
    }
196

    
197
    public void createTable(boolean treeView){
198
        /**
199
         * layers
200
         */
201
        createLayers(treeView);
202

    
203
        /**
204
         * configuration
205
         */
206
        configureNatTable(treeView, configRegistry, topMostLayer, summaryRowLayer);
207

    
208
        /**
209
         * handlers and listeners
210
         */
211
        registerHandlersAndListeners(topMostLayer);
212

    
213
        //grab all space
214
        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
215

    
216
        //update label to current data set
217
        toolbar.getWsLabel().setText(descriptiveDataSet.getLabel());
218
        toolbar.getWsLabel().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
219
        toolbar.getWsLabel().getParent().layout();
220

    
221
        //initial freeze of supplemental columns
222
        freezeSupplementalColumns(true);
223

    
224
        this.layout();
225
    }
226

    
227
    private List<Feature> initFeatureList(FeatureNode node){
228
        List<Feature> features = new ArrayList<>();
229
        node.getChildNodes().forEach(childNode->
230
                {
231
                    features.add(childNode.getFeature());
232
                    features.addAll(initFeatureList(childNode));
233
                });
234
        return features;
235
    }
236

    
237
    public void initDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
238
        this.descriptiveDataSet = descriptiveDataSet;
239
        //get features/columns stored in descriptive data set
240
        FeatureTree tree = descriptiveDataSet.getDescriptiveSystem();
241
        features = initFeatureList(tree.getRoot());
242

    
243
        //init state data for categorical features
244
        features.forEach(feature->
245
        {
246
            if(feature.isSupportsCategoricalData()){
247
                List<State> supportedStates = new ArrayList<>();
248
                feature.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
249
                categoricalFeatureToStateMap.put(feature, supportedStates);
250
            }
251
        });
252
        descriptions = new BasicEventList<>();
253

    
254
    }
255

    
256
    private void createLayers(boolean treeView) {
257
        // use the SortedList constructor with 'null' for the Comparator
258
        // because the Comparator will be set by configuration
259
        SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
260
        // wrap the SortedList with the TreeList
261
        TreeList<Object> treeList = new TreeList(sortedList, new DescriptionTreeFormat(descriptiveDataSet), TreeList.NODES_START_EXPANDED);
262
        /**
263
         * data provider
264
         */
265
        SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
266
        bodyDataProvider = treeView?new ListDataProvider<>(treeList, columnPropertyAccessor):new ListDataProvider<>(sortedList, columnPropertyAccessor);
267

    
268
        configRegistry = new ConfigRegistry();
269

    
270

    
271
        /**
272
         * BODY layer
273
         *
274
         *
275

    
276
        CompositeLayer
277
         - (top) SummaryRowLayer
278
         - (bottom) ViewportLayer
279

    
280
             ^
281
        ViewportLayer
282

    
283
             ^
284
        TreeLayer (default visible)
285

    
286
             ^
287
        CompositeFreezeLayer
288
         - viewportLayer
289
         - selectionLayer
290
         - freezeLayer
291

    
292
             ^
293
        FreezeLayer
294

    
295
             ^
296
        SelectionLayer
297

    
298
             ^
299
        ColumnHideShowLayer
300

    
301
             ^
302
        ColumnReorderLayer
303

    
304
             ^
305
        DataLayer
306

    
307
         *
308

    
309
         */
310
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
311

    
312
        //register labels
313
        CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this);
314
        bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
315

    
316

    
317
        propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
318
        propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
319
        propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
320
        propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
321
        for(int i=0;i<features.size();i++){
322
            Feature feature = features.get(i);
323
            initLabels(i, feature);
324
        }
325

    
326
        // layer for event handling of GlazedLists and PropertyChanges
327
        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, treeList);
328
        GlazedListTreeData treeData = new GlazedListTreeData<>(treeList);
329
        ITreeRowModel treeRowModel = new GlazedListTreeRowModel<>(treeData);
330

    
331
        bodyLayer = new DefaultBodyLayerStack(eventLayer);
332
        final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
333
        freezeLayer = new FreezeLayer(selectionLayer);
334
        final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
335
                freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
336
        TreeLayer treeLayer = new TreeLayer(compositeFreezeLayer, treeRowModel);
337

    
338
        topMostLayer = treeView?treeLayer:compositeFreezeLayer;
339

    
340
        summaryRowLayer = new FixedSummaryRowLayer(bodyDataLayer, topMostLayer, configRegistry, false);
341
        //regoster labels with summary prefix for summary layer
342
        ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
343
        summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
344
        for(int i=0;i<features.size();i++){
345
            Feature feature = features.get(i);
346
            summaryColumnLabelAccumulator.registerColumnOverrides(
347
                    i+LEADING_COLUMN_COUNT,
348
                    SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
349
        }
350
        // because the horizontal dependency is the ViewportLayer
351
        // we need to set the composite dependency to false
352
        summaryRowLayer.setHorizontalCompositeDependency(false);
353

    
354
        CompositeLayer composite = new CompositeLayer(1, 2);
355
        composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0); //$NON-NLS-1$
356
        composite.setChildLayer(GridRegion.BODY, topMostLayer, 0, 1);
357

    
358

    
359
        /**
360
         * column header layer
361
         */
362
        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
363
                propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
364
        DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
365
        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, topMostLayer, selectionLayer);
366

    
367
        // add the SortHeaderLayer to the column header layer stack
368
        // as we use GlazedLists, we use the GlazedListsSortModel which
369
        // delegates the sorting to the SortedList
370
        final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
371
                columnHeaderLayer,
372
                new GlazedListsSortModel<>(
373
                        sortedList,
374
                        columnPropertyAccessor,
375
                        configRegistry,
376
                        columnHeaderDataLayer));
377

    
378

    
379
        /**
380
         * row header layer
381
         */
382
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
383
        DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
384
        FixedSummaryRowHeaderLayer fixedSummaryRowHeaderLayer = new FixedSummaryRowHeaderLayer(rowHeaderDataLayer,
385
                composite, selectionLayer);
386
        fixedSummaryRowHeaderLayer.setSummaryRowLabel("\u2211"); //$NON-NLS-1$
387

    
388

    
389
        /**
390
         * corner layer
391
         */
392
        ILayer cornerLayer = new CornerLayer(
393
                new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
394
                fixedSummaryRowHeaderLayer, sortHeaderLayer);
395

    
396

    
397
        /**
398
         * GRID layer (composition of all other layers)
399
         */
400
        GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, fixedSummaryRowHeaderLayer, cornerLayer);
401

    
402
        natTable.setLayer(gridLayer);
403

    
404
    }
405

    
406
    private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
407
        // add the ExportCommandHandler to the ViewportLayer in order to make
408
        // exporting work
409
        topMostLayer.registerCommandHandler(new ExportCommandHandler(topMostLayer));
410

    
411
        //propagate single cell selection
412
        natTable.addLayerListener(new CellSelectionListener(part));
413

    
414
        //register handler for view configuration menu
415
        natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
416
    }
417

    
418
    private void configureNatTable(boolean treeView,
419
            ConfigRegistry configRegistry,
420
            AbstractLayer topMostLayer,
421
            FixedSummaryRowLayer summaryRowLayer) {
422
        /**
423
         * CONFIGURATION
424
         */
425
        natTable.setConfigRegistry(configRegistry);
426

    
427
        applyStyles();
428

    
429
        //add default configuration because autoconfigure is set to false in constructor
430
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
431

    
432
        //FIXME: this is for DEBUG ONLY
433
        //        natTable.addConfiguration(new DebugMenuConfiguration(natTable));
434

    
435
        // override the default sort configuration and change the mouse bindings
436
        // to sort on a single click
437
        if(!treeView){
438
            natTable.addConfiguration(new SingleClickSortConfiguration());
439
        }
440

    
441
        natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
442

    
443
        // add the header menu configuration for adding the column header menu
444
        // with hide/show actions
445
        natTable.addConfiguration(new CharacterMatrixHeaderMenuConfiguration(natTable));
446

    
447
        // add custom configuration for data conversion and add column labels to viewport layer
448
        topMostLayer.addConfiguration(new DataConversionConfiguration(this));
449

    
450
        //register aggregation configuration
451
        summaryRowLayer.addConfiguration(new AggregationConfiguration(this));
452

    
453
        natTable.configure();
454
    }
455

    
456
    void freezeSupplementalColumns(boolean freeze){
457
        if(freeze){
458
            FreezeHelper.freeze(freezeLayer, bodyLayer.getViewportLayer(),
459
                    new PositionCoordinate(bodyLayer.getViewportLayer(), 0, 0),
460
                    new PositionCoordinate(bodyLayer.getViewportLayer(), LEADING_COLUMN_COUNT-1, -1));
461
        }
462
        else{
463
            FreezeHelper.unfreeze(freezeLayer, bodyLayer.getViewportLayer());
464
        }
465
    }
466

    
467
    void selectStateItem(ComboViewer comboStates, String stateName){
468
        String[] items = comboStates.getCombo().getItems();
469
        for(int i=0;i<items.length;i++){
470
            if(items[i].equals(stateName)){
471
                comboStates.getCombo().select(i);
472
                break;
473
            }
474
        }
475
    }
476

    
477
    private void initLabels(int index, Feature feature) {
478
        indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
479

    
480
        String featureLabel = feature.getLabel();
481
        String property = featureLabel;
482
        //show unit for quantitative data
483
        if(feature.isSupportsQuantitativeData()){
484
            Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
485
            if(recommendedMeasurementUnits.size()>1){
486
                MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
487
                        String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel()));
488
            }
489
            if(recommendedMeasurementUnits.size()==1){
490
                MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
491
                featureLabel += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
492
            }
493
        }
494
        propertyToLabelMap.put(property, featureLabel);
495
    }
496

    
497
    public void loadDescriptions(DescriptiveDataSet descriptiveDataSet) {
498
        UUID monitorUuid = CdmStore.getService(IDescriptiveDataSetService.class).monitGetRowWrapper(descriptiveDataSet);
499
        IProgressMonitorService progressMonitorService = CdmApplicationState.getCurrentAppConfig().getProgressMonitorService();
500

    
501

    
502
        String jobLabel = "Load character data";
503
        Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
504
            monitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
505
            while(progressMonitorService.isMonitorThreadRunning(monitorUuid)){
506
                if(monitor.isCanceled()){
507
                    progressMonitorService.interrupt(monitorUuid);
508
                }
509
            }
510
            IRemotingProgressMonitor remotingMonitor = progressMonitorService.getRemotingMonitor(monitorUuid);
511
            Collection<RowWrapperDTO> wrappers = (Collection<RowWrapperDTO>) remotingMonitor.getResult();
512
            if(wrappers!=null){
513
                wrappers.forEach(wrapper->CharacterMatrix.this.descriptions.add(wrapper));
514
            }
515
            monitor.done();
516
        });
517
        job.schedule(1000);
518
    }
519

    
520
    public List<State> getSupportedStatesForCategoricalFeature(Feature feature){
521
        return categoricalFeatureToStateMap.get(feature);
522
    }
523

    
524
    public Map<Integer, Feature> getIndexToFeatureMap() {
525
        return indexToFeatureMap;
526
    }
527

    
528
    public LinkedMap<String, String> getPropertyToLabelMap() {
529
        return propertyToLabelMap;
530
    }
531

    
532
    public void setDirty() {
533
        part.setDirty();
534
    }
535

    
536
    public NatTable getNatTable() {
537
        return natTable;
538
    }
539

    
540
    public EventList<Object> getDescriptions() {
541
        return descriptions;
542
    }
543

    
544
    public DescriptiveDataSet getDescriptiveDataSet() {
545
        return descriptiveDataSet;
546
    }
547

    
548
    public Collection<SpecimenNodeWrapper> getSpecimenCache() {
549
        return specimenCache;
550
    }
551

    
552
    public void setSpecimenCache(Collection<SpecimenNodeWrapper> specimenCache) {
553
        this.specimenCache = specimenCache.stream()
554
                .filter(wrapper ->
555
        //map descriptions on a list of uuids of the described specimen
556
        !this.descriptions.stream()
557
        .map(o->((RowWrapperDTO)o).getSpecimen().getUuid())
558
        .collect(Collectors.toList())
559
        //an check if the specimen to add is already contained
560
        .contains(wrapper.getUuidAndTitleCache().getUuid())
561
        )
562
        .collect(Collectors.toList());
563
    }
564

    
565
    public Properties getNatTableState() {
566
        return toolbar.getNatTableState();
567
    }
568

    
569
    public ListDataProvider<Object> getBodyDataProvider() {
570
        return bodyDataProvider;
571
    }
572

    
573
    DefaultBodyLayerStack getBodyLayer() {
574
        return bodyLayer;
575
    }
576

    
577
    File getStatePropertiesFile() {
578
        return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
579
    }
580

    
581
    public List<Feature> getFeatures() {
582
        return features;
583
    }
584

    
585
    public void addUpdateResult(UpdateResult result){
586
        part.addUpdateResult(result);
587
    }
588

    
589
}
(3-3/16)