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.Collections;
|
15
|
import java.util.HashMap;
|
16
|
import java.util.HashSet;
|
17
|
import java.util.LinkedList;
|
18
|
import java.util.List;
|
19
|
import java.util.Map;
|
20
|
import java.util.Map.Entry;
|
21
|
import java.util.Properties;
|
22
|
import java.util.Set;
|
23
|
import java.util.TreeSet;
|
24
|
import java.util.UUID;
|
25
|
import java.util.stream.Collectors;
|
26
|
|
27
|
import javax.inject.Inject;
|
28
|
|
29
|
import org.apache.commons.collections4.map.LinkedMap;
|
30
|
import org.eclipse.core.runtime.ICoreRunnable;
|
31
|
import org.eclipse.core.runtime.IProgressMonitor;
|
32
|
import org.eclipse.core.runtime.SubMonitor;
|
33
|
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
|
34
|
import org.eclipse.core.runtime.jobs.Job;
|
35
|
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
|
36
|
import org.eclipse.e4.core.di.annotations.Optional;
|
37
|
import org.eclipse.e4.ui.di.UIEventTopic;
|
38
|
import org.eclipse.e4.ui.di.UISynchronize;
|
39
|
import org.eclipse.e4.ui.services.EMenuService;
|
40
|
import org.eclipse.jface.layout.GridDataFactory;
|
41
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
42
|
import org.eclipse.jface.viewers.StructuredSelection;
|
43
|
import org.eclipse.nebula.widgets.nattable.NatTable;
|
44
|
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
|
45
|
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
|
46
|
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
|
47
|
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
|
48
|
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
|
49
|
import org.eclipse.nebula.widgets.nattable.copy.command.InternalCopyDataCommandHandler;
|
50
|
import org.eclipse.nebula.widgets.nattable.copy.command.InternalPasteDataCommandHandler;
|
51
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
52
|
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
|
53
|
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
|
54
|
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
|
55
|
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
|
56
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
|
57
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
|
58
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeData;
|
59
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeRowModel;
|
60
|
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
|
61
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeHelper;
|
62
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
|
63
|
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
|
64
|
import org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand;
|
65
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
|
66
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
|
67
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
|
68
|
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
|
69
|
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
|
70
|
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
|
71
|
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
|
72
|
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
|
73
|
import org.eclipse.nebula.widgets.nattable.group.ColumnGroupGroupHeaderLayer;
|
74
|
import org.eclipse.nebula.widgets.nattable.group.ColumnGroupHeaderLayer;
|
75
|
import org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel;
|
76
|
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
|
77
|
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
|
78
|
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
|
79
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
|
80
|
import org.eclipse.nebula.widgets.nattable.persistence.gui.PersistenceDialog;
|
81
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
82
|
import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand;
|
83
|
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
|
84
|
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
|
85
|
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
|
86
|
import org.eclipse.nebula.widgets.nattable.tooltip.NatTableContentTooltip;
|
87
|
import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel;
|
88
|
import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
|
89
|
import org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand;
|
90
|
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
|
91
|
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
|
92
|
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
|
93
|
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
|
94
|
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
|
95
|
import org.eclipse.swt.SWT;
|
96
|
import org.eclipse.swt.layout.GridData;
|
97
|
import org.eclipse.swt.layout.GridLayout;
|
98
|
import org.eclipse.swt.widgets.Button;
|
99
|
import org.eclipse.swt.widgets.Composite;
|
100
|
import org.eclipse.swt.widgets.Event;
|
101
|
import org.eclipse.swt.widgets.Menu;
|
102
|
|
103
|
import ca.odell.glazedlists.BasicEventList;
|
104
|
import ca.odell.glazedlists.EventList;
|
105
|
import ca.odell.glazedlists.SortedList;
|
106
|
import ca.odell.glazedlists.TreeList;
|
107
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
108
|
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
|
109
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
110
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
111
|
import eu.etaxonomy.cdm.api.service.config.RemoveDescriptionsFromDescriptiveDataSetConfigurator;
|
112
|
import eu.etaxonomy.cdm.api.service.dto.FieldUnitDTO;
|
113
|
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
|
114
|
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
|
115
|
import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
|
116
|
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
|
117
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
118
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
119
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
120
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
121
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
122
|
import eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto;
|
123
|
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
|
124
|
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
|
125
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
126
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
127
|
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
|
128
|
import eu.etaxonomy.cdm.persistence.dto.TermTreeDto;
|
129
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
130
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
131
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
132
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
133
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
134
|
import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
|
135
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
136
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
137
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
138
|
|
139
|
/**
|
140
|
* Character matrix editor for editing specimen/taxon descriptions in a table
|
141
|
* @author pplitzner
|
142
|
* @since Nov 26, 2017
|
143
|
*/
|
144
|
public class CharacterMatrix extends Composite {
|
145
|
|
146
|
private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties"; //$NON-NLS-1$
|
147
|
|
148
|
static final int LEADING_COLUMN_COUNT = 4;
|
149
|
static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
|
150
|
static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
|
151
|
static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
|
152
|
static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
|
153
|
|
154
|
static final String LABEL_TAXON_ROW = "TAXON_ROW"; //$NON-NLS-1$
|
155
|
static final String LABEL_TAXON_AGGREGATED_DESCRIPTION = "TAXON_AGGREGATED_DESCRIPTION"; //$NON-NLS-1$
|
156
|
static final String LABEL_TAXON_AGGREGATED_DESCRIPTION_ICON = "TAXON_AGGREGATED_DESCRIPTION_ICON"; //$NON-NLS-1$
|
157
|
static final String LABEL_TAXON_DEFAULT_DESCRIPTION = "TAXON_DEFAULT_DESCRIPTION"; //$NON-NLS-1$
|
158
|
static final String LABEL_TAXON_DEFAULT_DESCRIPTION_ICON = "TAXON_DEFAULT_DESCRIPTION_ICON"; //$NON-NLS-1$
|
159
|
static final String LABEL_TAXON_LITERATURE_DESCRIPTION = "TAXON_LITERATURE_DESCRIPTION"; //$NON-NLS-1$
|
160
|
static final String LABEL_TAXON_LITERATURE_DESCRIPTION_ICON = "TAXON_LITERATURE_DESCRIPTION_ICON"; //$NON-NLS-1$
|
161
|
static final String LABEL_TAXON_DESCRIPTION = "LABEL_TAXON_DESCRIPTION"; //$NON-NLS-1$
|
162
|
static final String LABEL_DESCRIPTION_HAS_SUPPLEMENTAL_DATA = "LABEL_DESCRIPTION_HAS_SUPPLEMENTAL_DATA"; //$NON-NLS-1$
|
163
|
|
164
|
boolean isFirstCall = true;
|
165
|
@Inject
|
166
|
private UISynchronize sync;
|
167
|
|
168
|
@Inject
|
169
|
private EMenuService menuService;
|
170
|
|
171
|
private NatTable natTable;
|
172
|
|
173
|
private HashMap<UUID, RowWrapperDTO<?>> rowsToMerge = new HashMap<>();
|
174
|
|
175
|
private Map<Integer, FeatureDto> indexToFeatureMap = new HashMap<>();
|
176
|
private Map<UUID, Integer> featureToIndexMap = new HashMap<>();
|
177
|
|
178
|
private Map<UUID, List<TermDto>> categoricalFeatureToStateMap = new HashMap<>();
|
179
|
|
180
|
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
|
181
|
|
182
|
private EventList<Object> descriptions;
|
183
|
|
184
|
private Collection<SpecimenNodeWrapper> specimenCache = null;
|
185
|
|
186
|
private Map<FeatureDto, CategoricalDataHistogram> featureToHistogramMap = new HashMap<>();
|
187
|
|
188
|
private ListDataProvider<Object> bodyDataProvider;
|
189
|
|
190
|
private FreezeLayer freezeLayer;
|
191
|
|
192
|
private List<FeatureDto> features;
|
193
|
|
194
|
private CharacterMatrixPart part;
|
195
|
|
196
|
private AbstractLayer topMostLayer;
|
197
|
|
198
|
private ConfigRegistry configRegistry;
|
199
|
|
200
|
private MatrixBodyLayerStack bodyLayer;
|
201
|
|
202
|
private SelectionLayer selectionLayer;
|
203
|
|
204
|
private boolean isTreeView = true;
|
205
|
|
206
|
private CharacterMatrixToolbar toolbar;
|
207
|
|
208
|
private DescriptionTreeFormat treeFormat;
|
209
|
|
210
|
private Map<RemoveDescriptionsFromDescriptiveDataSetConfigurator, List<UUID>> descriptionUuidsToDelete;
|
211
|
|
212
|
private List<SpecimenRowWrapperDTO> specimenToAdd;
|
213
|
|
214
|
private MouseEventMatcher mouseEventMatcher = null;
|
215
|
|
216
|
private Set<DescriptionBase<?>> descriptionsToSave = new HashSet<>();
|
217
|
|
218
|
public CharacterMatrix(Composite parent, CharacterMatrixPart part) {
|
219
|
super(parent, SWT.NONE);
|
220
|
this.part = part;
|
221
|
this.setLayout(new GridLayout());
|
222
|
|
223
|
createToolBar();
|
224
|
|
225
|
natTable = new NatTable(this, false);
|
226
|
}
|
227
|
|
228
|
private void createToolBar(){
|
229
|
toolbar = new CharacterMatrixToolbar(this, SWT.NONE);
|
230
|
}
|
231
|
|
232
|
private void applyStyles(){
|
233
|
ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
|
234
|
// NOTE: Getting the colors and fonts from the GUIHelper ensures that
|
235
|
// they are disposed properly (required by SWT)
|
236
|
configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
237
|
configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
238
|
natTable.addConfiguration(configuration);
|
239
|
}
|
240
|
|
241
|
void toggleTreeFlat(boolean isTree, Button btnToggleFlat, Button btnToggleTree, Button btnCollapseAll, Button btnExpandAll, Button btnFreezeSuppInfo) {
|
242
|
isTreeView = isTree;
|
243
|
createTable(isTree, freezeLayer.isFrozen(), true);
|
244
|
btnToggleFlat.setEnabled(isTree);
|
245
|
btnToggleTree.setEnabled(!isTree);
|
246
|
btnCollapseAll.setEnabled(isTree);
|
247
|
btnExpandAll.setEnabled(isTree);
|
248
|
}
|
249
|
|
250
|
public boolean isTreeView() {
|
251
|
return isTreeView;
|
252
|
}
|
253
|
|
254
|
public void createTable(boolean treeView, boolean freezeSupplementalColumns, boolean isInitialExpandToDeepestTaxonLevel){
|
255
|
/**
|
256
|
* layers
|
257
|
*/
|
258
|
createLayers(treeView);
|
259
|
|
260
|
/**
|
261
|
* configuration
|
262
|
*/
|
263
|
|
264
|
configureNatTable(treeView, configRegistry, topMostLayer);
|
265
|
|
266
|
/**
|
267
|
* handlers and listeners
|
268
|
*/
|
269
|
registerHandlersAndListeners();
|
270
|
|
271
|
//grab all space
|
272
|
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
|
273
|
|
274
|
//update label to current dataset
|
275
|
toolbar.getWsLabel().setText(getDescriptiveDataSet().getTitleCache());
|
276
|
toolbar.getWsLabel().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
277
|
toolbar.getWsLabel().getParent().layout();
|
278
|
|
279
|
//initial freeze of supplemental columns
|
280
|
freezeSupplementalColumns(freezeSupplementalColumns);
|
281
|
|
282
|
|
283
|
//add tooltip to table
|
284
|
// new CategoricalChartTooltip(this);
|
285
|
// new QuantitativeChartTooltip(this);
|
286
|
|
287
|
|
288
|
this.layout();
|
289
|
natTable.doCommand(new ClientAreaResizeCommand(natTable));
|
290
|
|
291
|
// expand all taxa
|
292
|
if(isInitialExpandToDeepestTaxonLevel){
|
293
|
Integer deepestTaxonLevel = treeFormat.getDeepestTaxonLevel();
|
294
|
if(deepestTaxonLevel!=null){
|
295
|
natTable.doCommand(new TreeExpandToLevelCommand(deepestTaxonLevel-2));
|
296
|
}
|
297
|
}
|
298
|
new NatTableContentTooltip(natTable, GridRegion.BODY) {
|
299
|
protected String getText(Event event) {
|
300
|
int col = this.natTable.getColumnPositionByX(event.x);
|
301
|
int row = this.natTable.getRowPositionByY(event.y);
|
302
|
|
303
|
ILayerCell cell = this.natTable.getCellByPosition(col, row);
|
304
|
if (cell.getConfigLabels().getLabels().contains(CharacterMatrixConfigLabelAccumulator.NOT_EDITABLE)){
|
305
|
Object o = bodyDataProvider.getRowObject(row);
|
306
|
String object = "";
|
307
|
if (o instanceof TaxonNodeDto || o instanceof TaxonRowWrapperDTO){
|
308
|
object = "taxon";
|
309
|
}else {
|
310
|
object = "specimen";
|
311
|
}
|
312
|
|
313
|
return "Multiple data exist. Editing only possible in factual data view of " + object;
|
314
|
}
|
315
|
if (cell.getConfigLabels().getLabels().contains(CharacterMatrixConfigLabelAccumulator.NOT_APPLICABLE)){
|
316
|
return "This character is not applicable because of the state of a parent feature." ;
|
317
|
}
|
318
|
return null;
|
319
|
}
|
320
|
};
|
321
|
|
322
|
|
323
|
// clean up table state
|
324
|
getNatTableState().remove(NatTable.INITIAL_PAINT_COMPLETE_FLAG);
|
325
|
getNatTableState().remove(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY);
|
326
|
}
|
327
|
|
328
|
private List<FeatureDto> initFeatureList(TermNodeDto node){
|
329
|
List<FeatureDto> features = new ArrayList<>();
|
330
|
List<TermNodeDto> childNodes = node.getChildren();
|
331
|
for (TermNodeDto childNode : childNodes) {
|
332
|
if (childNode != null){
|
333
|
features.add((FeatureDto) childNode.getTerm());
|
334
|
features.addAll(initFeatureList(childNode));
|
335
|
}
|
336
|
}
|
337
|
return features;
|
338
|
}
|
339
|
|
340
|
public void initDescriptiveDataSet(){
|
341
|
//get features/columns stored in descriptive dataset
|
342
|
TermTreeDto tree = getDescriptiveDataSet().getDescriptiveSystem();
|
343
|
features = initFeatureList(tree.getRoot());
|
344
|
|
345
|
Set<FeatureDto> duplicateFeatures = features.stream().filter(i -> Collections.frequency(features, i) >1)
|
346
|
.collect(Collectors.toSet());
|
347
|
|
348
|
if (!duplicateFeatures.isEmpty()) {
|
349
|
throw new IllegalArgumentException("Duplicate features found: "
|
350
|
+ duplicateFeatures.stream().map(feature -> feature.getRepresentation_L10n()).collect(Collectors.joining(",")));
|
351
|
}
|
352
|
|
353
|
//init state data for categorical features
|
354
|
// features.forEach(feature->fetchSupportedStates(feature));
|
355
|
fetchSupportedStates(features);
|
356
|
|
357
|
descriptions = new BasicEventList<>();
|
358
|
|
359
|
}
|
360
|
|
361
|
private void fetchSupportedStates(List<FeatureDto> features) {
|
362
|
Set<UUID> featureUuids = new HashSet<>();
|
363
|
features.forEach(i->featureUuids.add(i.getUuid()));
|
364
|
categoricalFeatureToStateMap = CdmStore.getService(IDescriptiveDataSetService.class).getSupportedStatesForFeature(featureUuids);
|
365
|
|
366
|
}
|
367
|
|
368
|
|
369
|
|
370
|
private void createLayers(boolean treeView) {
|
371
|
|
372
|
SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
|
373
|
// wrap the SortedList with the TreeList
|
374
|
treeFormat = new DescriptionTreeFormat(getDescriptiveDataSet());
|
375
|
@SuppressWarnings("unchecked")
|
376
|
TreeList<Object> treeList = new TreeList<Object>(sortedList, treeFormat, TreeList.NODES_START_COLLAPSED);
|
377
|
// wrap the SortedList with the TreeList
|
378
|
// treeFormat = new DescriptionTreeFormat(getDescriptiveDataSet());
|
379
|
|
380
|
/**
|
381
|
* data provider
|
382
|
*/
|
383
|
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
|
384
|
bodyDataProvider = treeView?new ListDataProvider<>(treeList, columnPropertyAccessor):new ListDataProvider<>(sortedList, columnPropertyAccessor);
|
385
|
|
386
|
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
|
387
|
bodyDataLayer.registerCommandHandler(new CopyPasteUpdateDataCommandHandler(bodyDataLayer));
|
388
|
|
389
|
|
390
|
/**
|
391
|
* BODY layer
|
392
|
*
|
393
|
*
|
394
|
|
395
|
ViewportLayer
|
396
|
|
397
|
^
|
398
|
TreeLayer (default visible)
|
399
|
|
400
|
^
|
401
|
CompositeFreezeLayer
|
402
|
- viewportLayer
|
403
|
- selectionLayer
|
404
|
- freezeLayer
|
405
|
|
406
|
^
|
407
|
FreezeLayer
|
408
|
|
409
|
^
|
410
|
SelectionLayer
|
411
|
|
412
|
^
|
413
|
ColumnHideShowLayer
|
414
|
|
415
|
^
|
416
|
DataLayer
|
417
|
|
418
|
*
|
419
|
|
420
|
*/
|
421
|
|
422
|
configRegistry = new ConfigRegistry();
|
423
|
//register labels
|
424
|
CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this);
|
425
|
bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
|
426
|
|
427
|
|
428
|
propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
|
429
|
propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
|
430
|
propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
|
431
|
propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
|
432
|
for(int i=0;i<features.size();i++){
|
433
|
FeatureDto feature = features.get(i);
|
434
|
initLabels(i, feature);
|
435
|
}
|
436
|
|
437
|
// layer for event handling of GlazedLists and PropertyChanges
|
438
|
GlazedListsEventLayer<Object> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, (EventList<Object>)bodyDataProvider.getList());
|
439
|
|
440
|
GlazedListTreeData<?> treeData = new GlazedListTreeData<>(treeList);
|
441
|
ITreeRowModel<?> treeRowModel = new GlazedListTreeRowModel<>(treeData);
|
442
|
|
443
|
// assemble the column groups
|
444
|
LinkedList<ColumnGroupWrapper> columnGroups = new LinkedList<>();
|
445
|
List<TermNodeDto> rootChildren = getDescriptiveDataSet().getDescriptiveSystem().getRoot().getChildren();
|
446
|
buildHeader(rootChildren, columnGroups);
|
447
|
|
448
|
bodyLayer = new MatrixBodyLayerStack(eventLayer, columnGroups);
|
449
|
selectionLayer = bodyLayer.getSelectionLayer();
|
450
|
freezeLayer = new FreezeLayer(selectionLayer);
|
451
|
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
|
452
|
freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
|
453
|
TreeLayer treeLayer = null;
|
454
|
if (treeView){
|
455
|
treeLayer = new TreeLayer(compositeFreezeLayer, treeRowModel);
|
456
|
}
|
457
|
|
458
|
topMostLayer = treeView?treeLayer:compositeFreezeLayer;
|
459
|
|
460
|
|
461
|
/**
|
462
|
* column header layer
|
463
|
*/
|
464
|
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
|
465
|
propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
|
466
|
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
|
467
|
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, topMostLayer, selectionLayer);
|
468
|
|
469
|
ILayer topHeaderLayer = columnHeaderLayer;
|
470
|
|
471
|
if(!columnGroups.isEmpty()){
|
472
|
// first group level
|
473
|
ColumnGroupWrapper groupLevel1 = columnGroups.get(0);
|
474
|
ColumnGroupHeaderLayer groupLayerLevel1 = null;
|
475
|
ColumnGroupGroupHeaderLayer groupLayerLevel2 = null;
|
476
|
groupLayerLevel1 = new ColumnGroupHeaderLayer(columnHeaderLayer, selectionLayer, groupLevel1.getModel());
|
477
|
for (Entry<TermNodeDto, TreeSet<Integer>> entry: groupLevel1.getColumnGroupToIndexMap().entrySet()) {
|
478
|
TermNodeDto group = entry.getKey();
|
479
|
TreeSet<Integer> indexList = entry.getValue();
|
480
|
int[] intArray = indexList.stream().mapToInt(Integer::intValue).toArray();
|
481
|
groupLayerLevel1.addColumnsIndexesToGroup(group.getTerm().getTitleCache(), intArray);
|
482
|
groupLayerLevel1.setGroupUnbreakable(indexList.iterator().next());
|
483
|
}
|
484
|
topHeaderLayer = groupLayerLevel1;
|
485
|
|
486
|
// second group level
|
487
|
if(columnGroups.size()>1){
|
488
|
ColumnGroupWrapper groupLevel2 = columnGroups.get(1);
|
489
|
groupLayerLevel2 = new ColumnGroupGroupHeaderLayer(groupLayerLevel1, selectionLayer, groupLevel2.getModel());
|
490
|
for (Entry<TermNodeDto, TreeSet<Integer>> entry: groupLevel2.getColumnGroupToIndexMap().entrySet()) {
|
491
|
TermNodeDto group = entry.getKey();
|
492
|
TreeSet<Integer> indexList = entry.getValue();
|
493
|
int[] intArray = indexList.stream().mapToInt(Integer::intValue).toArray();
|
494
|
groupLayerLevel2.addColumnsIndexesToGroup(group.getTerm().getTitleCache(), intArray);
|
495
|
groupLayerLevel2.setGroupUnbreakable(indexList.iterator().next());
|
496
|
}
|
497
|
topHeaderLayer = groupLayerLevel2;
|
498
|
}
|
499
|
}
|
500
|
|
501
|
// add the SortHeaderLayer to the column header layer stack
|
502
|
// as we use GlazedLists, we use the GlazedListsSortModel which
|
503
|
// delegates the sorting to the SortedList
|
504
|
final SortHeaderLayer<DescriptionBase<?>> sortHeaderLayer = new SortHeaderLayer<>(
|
505
|
topHeaderLayer,
|
506
|
new GlazedListsSortModel<>(
|
507
|
sortedList,
|
508
|
columnPropertyAccessor,
|
509
|
configRegistry,
|
510
|
columnHeaderDataLayer));
|
511
|
|
512
|
/**
|
513
|
* row header layer
|
514
|
*/
|
515
|
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
|
516
|
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
|
517
|
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
|
518
|
topMostLayer, selectionLayer);
|
519
|
|
520
|
/**
|
521
|
* corner layer
|
522
|
*/
|
523
|
ILayer cornerLayer = new CornerLayer(
|
524
|
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
|
525
|
rowHeaderLayer, sortHeaderLayer);
|
526
|
|
527
|
/**
|
528
|
* GRID layer (composition of all other layers)
|
529
|
*/
|
530
|
GridLayer gridLayer = new GridLayer(topMostLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
|
531
|
natTable.setLayer(gridLayer);
|
532
|
}
|
533
|
|
534
|
private TreeSet<Integer> recurseChildIndexes(TermNodeDto node){
|
535
|
TreeSet<Integer> childIndexes = new TreeSet<>();
|
536
|
if(node.getChildren().size() >0){
|
537
|
List<TermNodeDto> childNodes = node.getChildren();
|
538
|
for (TermNodeDto childNode: childNodes) {
|
539
|
if (childNode != null){
|
540
|
childIndexes.addAll(recurseChildIndexes(childNode));
|
541
|
}
|
542
|
}
|
543
|
}
|
544
|
childIndexes.add(features.indexOf(node.getTerm())+LEADING_COLUMN_COUNT);
|
545
|
return childIndexes;
|
546
|
}
|
547
|
|
548
|
private void buildHeader(List<TermNodeDto> nodes, LinkedList<ColumnGroupWrapper> columnGroups){
|
549
|
Map<TermNodeDto, TreeSet<Integer>> columnGroupToIndexMap = new HashMap<>();
|
550
|
List<TermNodeDto> childNodes = new ArrayList<>();
|
551
|
for (TermNodeDto node : nodes) {
|
552
|
if (node != null){
|
553
|
TreeSet<Integer> childIndexes = recurseChildIndexes(node);
|
554
|
if(childIndexes.size()>1){
|
555
|
// filter out groups that only have one member
|
556
|
columnGroupToIndexMap.put(node, childIndexes);
|
557
|
}
|
558
|
childNodes.addAll(node.getChildren());
|
559
|
}
|
560
|
}
|
561
|
if(!columnGroupToIndexMap.isEmpty()){
|
562
|
columnGroups.addFirst(new ColumnGroupWrapper(new ColumnGroupModel(), columnGroupToIndexMap));
|
563
|
}
|
564
|
if(!childNodes.isEmpty()){
|
565
|
buildHeader(childNodes, columnGroups);
|
566
|
}
|
567
|
}
|
568
|
|
569
|
private void registerHandlersAndListeners() {
|
570
|
natTable.registerCommandHandler(new ExportCommandHandler(natTable));
|
571
|
|
572
|
//selection listener
|
573
|
E4SelectionListener<Object> selectionListener = new CellSelectionListener(part.getSelectionService(),
|
574
|
bodyLayer.getSelectionLayer(), bodyDataProvider, part);
|
575
|
bodyLayer.getSelectionLayer().addLayerListener(selectionListener);
|
576
|
selectionListener.setFullySelectedRowsOnly(false);
|
577
|
|
578
|
//register handler for view configuration menu
|
579
|
natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
|
580
|
|
581
|
//register handlers for copy&paste
|
582
|
natTable.registerCommandHandler(
|
583
|
new InternalPasteDataCommandHandler(bodyLayer.getSelectionLayer(), natTable.getInternalCellClipboard()));
|
584
|
natTable.registerCommandHandler(
|
585
|
new InternalCopyDataCommandHandler(bodyLayer.getSelectionLayer(), natTable.getInternalCellClipboard()));
|
586
|
}
|
587
|
|
588
|
private void configureNatTable(boolean treeView,
|
589
|
ConfigRegistry configRegistry,
|
590
|
AbstractLayer topMostLayer) {
|
591
|
/**
|
592
|
* CONFIGURATION
|
593
|
*/
|
594
|
//+++CONTEXT MENU+++
|
595
|
menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$
|
596
|
// get the menu registered by EMenuService
|
597
|
final Menu e4Menu = natTable.getMenu();
|
598
|
|
599
|
natTable.setConfigRegistry(configRegistry);
|
600
|
|
601
|
applyStyles();
|
602
|
|
603
|
//add default configuration because autoconfigure is set to false in constructor
|
604
|
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
|
605
|
|
606
|
// this is for DEBUG ONLY
|
607
|
// natTable.addConfiguration(new DebugMenuConfiguration(natTable));
|
608
|
|
609
|
// override the default sort configuration and change the mouse bindings
|
610
|
// to sort on a single click
|
611
|
if(!treeView){
|
612
|
natTable.addConfiguration(new SingleClickSortConfiguration());
|
613
|
}
|
614
|
|
615
|
natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
|
616
|
|
617
|
// add the header menu configuration for adding the column header menu
|
618
|
// with hide/show actions
|
619
|
// natTable.addConfiguration(new CharacterMatrixHeaderMenuConfiguration(natTable));
|
620
|
|
621
|
// add custom configuration for data conversion and add column labels to viewport layer
|
622
|
topMostLayer.addConfiguration(new CellEditorDataConversionConfiguration(this));
|
623
|
|
624
|
//copy&paste configuration
|
625
|
natTable.addConfiguration(new CopyPasteEditBindings(bodyLayer.getSelectionLayer(), natTable.getInternalCellClipboard()));
|
626
|
|
627
|
|
628
|
// remove the menu reference from NatTable instance
|
629
|
natTable.setMenu(null);
|
630
|
|
631
|
|
632
|
// natTable.addConfiguration(new CharacterMatrixHeaderMenuConfiguration(natTable));
|
633
|
|
634
|
|
635
|
natTable.configure();
|
636
|
|
637
|
|
638
|
natTable.addConfiguration(
|
639
|
new AbstractUiBindingConfiguration() {
|
640
|
@Override
|
641
|
public void configureUiBindings(
|
642
|
UiBindingRegistry uiBindingRegistry) {
|
643
|
// add e4 menu to NatTable
|
644
|
uiBindingRegistry.unregisterMouseDownBinding(mouseEventMatcher);
|
645
|
if (isFirstCall){
|
646
|
new PopupMenuBuilder(natTable, e4Menu)
|
647
|
.withHideColumnMenuItem()
|
648
|
.withShowAllColumnsMenuItem()
|
649
|
.build();
|
650
|
isFirstCall = false;
|
651
|
}else{
|
652
|
new PopupMenuBuilder(natTable, e4Menu)
|
653
|
.build();
|
654
|
}
|
655
|
// register the UI binding for header, corner and body region
|
656
|
mouseEventMatcher = new MouseEventMatcher(
|
657
|
SWT.NONE,
|
658
|
null,
|
659
|
MouseEventMatcher.RIGHT_BUTTON);
|
660
|
uiBindingRegistry.registerMouseDownBinding(mouseEventMatcher,
|
661
|
new PopupMenuAction(e4Menu));
|
662
|
}
|
663
|
});
|
664
|
|
665
|
}
|
666
|
|
667
|
void freezeSupplementalColumns(boolean freeze){
|
668
|
int rightMostFreezeColumIndex = LEADING_COLUMN_COUNT-1;
|
669
|
Collection<Integer> hiddenColumnIndexes = bodyLayer.getColumnHideShowLayer().getHiddenColumnIndexes();
|
670
|
for (Integer integer : hiddenColumnIndexes) {
|
671
|
if(integer<LEADING_COLUMN_COUNT){
|
672
|
rightMostFreezeColumIndex--;
|
673
|
}
|
674
|
}
|
675
|
if(freeze){
|
676
|
FreezeHelper.freeze(freezeLayer, bodyLayer.getViewportLayer(),
|
677
|
new PositionCoordinate(bodyLayer.getViewportLayer(), 0, 0),
|
678
|
new PositionCoordinate(bodyLayer.getViewportLayer(), rightMostFreezeColumIndex, -1));
|
679
|
}
|
680
|
else{
|
681
|
FreezeHelper.unfreeze(freezeLayer, bodyLayer.getViewportLayer());
|
682
|
}
|
683
|
}
|
684
|
|
685
|
private void initLabels(int index, FeatureDto feature) {
|
686
|
indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
|
687
|
featureToIndexMap.put(feature.getUuid(), index+LEADING_COLUMN_COUNT);
|
688
|
String label = feature.getTitleCache();
|
689
|
String property = feature.getUuid().toString();
|
690
|
//show unit for quantitative data
|
691
|
if(feature.isSupportsQuantitativeData()){
|
692
|
Set<TermDto> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
|
693
|
// if(recommendedMeasurementUnits.size()>1){
|
694
|
// MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
|
695
|
// String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel()));
|
696
|
// }
|
697
|
if(recommendedMeasurementUnits.size()==1){
|
698
|
TermDto unit = recommendedMeasurementUnits.iterator().next();
|
699
|
label += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
|
700
|
}
|
701
|
}
|
702
|
propertyToLabelMap.put(property, label);
|
703
|
}
|
704
|
|
705
|
public void loadDescriptions(boolean isInitialExpandToDeepestTaxonLevel, boolean initialLoading) {
|
706
|
|
707
|
UUID monitorUuid = CdmApplicationState.getLongRunningTasksService().monitGetRowWrapper(this.getDescriptiveDataSet().getUuid());
|
708
|
|
709
|
final Collection<RowWrapperDTO<?>> wrappers = new ArrayList<>();
|
710
|
String jobLabel = Messages.CharacterMatrix_LOAD_CHARACTER_DATA;
|
711
|
Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
|
712
|
SubMonitor subMonitor = SubMonitor.convert(monitor);
|
713
|
subMonitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
|
714
|
IRemotingProgressMonitor remotingMonitor;
|
715
|
try {
|
716
|
remotingMonitor = CdmStore.getProgressMonitorClientManager()
|
717
|
.pollMonitor(jobLabel,
|
718
|
monitorUuid,
|
719
|
50,
|
720
|
null,
|
721
|
(List<IFeedbackGenerator>)null,
|
722
|
subMonitor);
|
723
|
} catch (InterruptedException e) {
|
724
|
MessagingUtils.informationDialog(Messages.CharacterMatrix_LOADING_FAILED_TITLE,
|
725
|
Messages.CharacterMatrix_LOADING_FAILED_MESSAGE);
|
726
|
return;
|
727
|
}
|
728
|
Object result = remotingMonitor.getResult();
|
729
|
if(result instanceof Collection){
|
730
|
wrappers.addAll((Collection<RowWrapperDTO<?>>) result);
|
731
|
}
|
732
|
if(result instanceof Exception){
|
733
|
MessagingUtils.errorDialog("Exception during description loading", this.getClass(), "An exception occured during loading", TaxeditorEditorPlugin.PLUGIN_ID, (Throwable) result, true);
|
734
|
}
|
735
|
else if(wrappers.isEmpty()){
|
736
|
MessagingUtils.informationDialog(Messages.CharacterMatrix_NO_DESCRIPTION_TITLE,
|
737
|
Messages.CharacterMatrix_NO_DESCRIPTION_MESSAGE);
|
738
|
}
|
739
|
monitor.done();
|
740
|
});
|
741
|
job.addJobChangeListener(new JobChangeAdapter(){
|
742
|
@Override
|
743
|
public void done(IJobChangeEvent event) {
|
744
|
sync.syncExec(()->{
|
745
|
List<RowWrapperDTO> rowsWithoutTaxonNode = wrappers.stream().filter(row->row.getTaxonNode()==null).collect(Collectors.toList());
|
746
|
if(!rowsWithoutTaxonNode.isEmpty()){
|
747
|
String collect = rowsWithoutTaxonNode.stream().
|
748
|
map(row->row.getDescription().toString())
|
749
|
.collect(Collectors.joining("\n\n - ")); //$NON-NLS-1$
|
750
|
MessagingUtils.warningDialog(
|
751
|
Messages.CharacterMatrix_NO_NODE_FOUND_TITLE,
|
752
|
this.getClass(),
|
753
|
String.format(Messages.CharacterMatrix_NO_NODE_FOUND_MESSAGE, collect)
|
754
|
);
|
755
|
}
|
756
|
descriptions.clear();
|
757
|
// part.setDescriptiveDataSet(CdmStore.getService(IDescriptiveDataSetService.class).getDescriptiveDataSetDtoByUuid(part.getDescriptiveDataSet().getUuid()));
|
758
|
wrappers.stream().filter(row->row.getTaxonNode()!=null).forEach(wrapper->CharacterMatrix.this.descriptions.add(wrapper));
|
759
|
if(initialLoading){
|
760
|
loadingDone(isInitialExpandToDeepestTaxonLevel);
|
761
|
}
|
762
|
});
|
763
|
}
|
764
|
});
|
765
|
job.schedule();
|
766
|
}
|
767
|
|
768
|
public IStructuredSelection getSelection(){
|
769
|
Set<Range> selectedRowPositions = bodyLayer.getSelectionLayer().getSelectedRowPositions();
|
770
|
List<Object> selectedObjects = new ArrayList<>();
|
771
|
for (Range range : selectedRowPositions) {
|
772
|
for(int i=range.start;i<range.end;i++){
|
773
|
selectedObjects.add(bodyDataProvider.getRowObject(i));
|
774
|
}
|
775
|
}
|
776
|
return new StructuredSelection(selectedObjects);
|
777
|
}
|
778
|
|
779
|
private void loadingDone(boolean isInitialExpandToDeepestTaxonLevel) {
|
780
|
this.part.loadingDone();
|
781
|
createTable(isTreeView, freezeLayer.isFrozen(), isInitialExpandToDeepestTaxonLevel);
|
782
|
|
783
|
}
|
784
|
|
785
|
public List<TermDto> getSupportedStatesForCategoricalFeature(UUID featureUuid){
|
786
|
return categoricalFeatureToStateMap.get(featureUuid);
|
787
|
}
|
788
|
|
789
|
public Set<DescriptionBase<?>> getDescriptionsToSave() {
|
790
|
return descriptionsToSave;
|
791
|
}
|
792
|
|
793
|
public void addDescriptionToSave(DescriptionBase<?> descriptionToSave) {
|
794
|
this.descriptionsToSave.add(descriptionToSave);
|
795
|
}
|
796
|
|
797
|
public Map<Integer, FeatureDto> getIndexToFeatureMap() {
|
798
|
return indexToFeatureMap;
|
799
|
}
|
800
|
|
801
|
public Map<UUID, Integer> getFeatureToIndexMap() {
|
802
|
return featureToIndexMap;
|
803
|
}
|
804
|
|
805
|
public void setFeatureToIndexMap(Map<UUID, Integer> featureToIndexMap) {
|
806
|
this.featureToIndexMap = featureToIndexMap;
|
807
|
}
|
808
|
|
809
|
public LinkedMap<String, String> getPropertyToLabelMap() {
|
810
|
return propertyToLabelMap;
|
811
|
}
|
812
|
|
813
|
public void setDirty() {
|
814
|
part.setDirty();
|
815
|
}
|
816
|
|
817
|
public Map<RemoveDescriptionsFromDescriptiveDataSetConfigurator, List<UUID>> getDescriptionsToDelete() {
|
818
|
return descriptionUuidsToDelete;
|
819
|
}
|
820
|
|
821
|
public void addDescriptionToDelete(UUID descriptionToDelete, RemoveDescriptionsFromDescriptiveDataSetConfigurator config) {
|
822
|
if (descriptionUuidsToDelete == null){
|
823
|
descriptionUuidsToDelete = new HashMap<>();
|
824
|
}
|
825
|
if (descriptionUuidsToDelete.get(config) != null){
|
826
|
descriptionUuidsToDelete.get(config).add(descriptionToDelete);
|
827
|
}else{
|
828
|
List<UUID> uuidList = new ArrayList<>();
|
829
|
uuidList.add(descriptionToDelete);
|
830
|
this.descriptionUuidsToDelete.put(config, uuidList);
|
831
|
}
|
832
|
|
833
|
|
834
|
}
|
835
|
|
836
|
public List<SpecimenRowWrapperDTO> getSpecimenToAdd() {
|
837
|
return specimenToAdd;
|
838
|
}
|
839
|
|
840
|
public void addSpecimenToAdd(Collection<SpecimenRowWrapperDTO> specimenToAdd) {
|
841
|
if (this.specimenToAdd == null){
|
842
|
this.specimenToAdd = new ArrayList<>();
|
843
|
}
|
844
|
|
845
|
this.specimenToAdd.addAll(specimenToAdd);
|
846
|
this.specimenCache.removeAll(specimenToAdd);
|
847
|
}
|
848
|
public void addSpecimenToAdd(SpecimenRowWrapperDTO specimenToAdd) {
|
849
|
if (this.specimenToAdd == null){
|
850
|
this.specimenToAdd = new ArrayList<>();
|
851
|
}
|
852
|
|
853
|
this.specimenToAdd.add(specimenToAdd);
|
854
|
this.specimenCache.remove(specimenToAdd);
|
855
|
}
|
856
|
|
857
|
public CharacterMatrixPart getPart() {
|
858
|
return part;
|
859
|
}
|
860
|
|
861
|
public NatTable getNatTable() {
|
862
|
return natTable;
|
863
|
}
|
864
|
|
865
|
public EventList<Object> getDescriptions() {
|
866
|
return descriptions;
|
867
|
}
|
868
|
|
869
|
public DescriptiveDataSetBaseDto getDescriptiveDataSet() {
|
870
|
return part.getDescriptiveDataSet();
|
871
|
}
|
872
|
|
873
|
public void setDescriptiveDataSet(DescriptiveDataSetBaseDto dataSet) {
|
874
|
part.setDescriptiveDataSet(dataSet);
|
875
|
}
|
876
|
|
877
|
public Collection<SpecimenNodeWrapper> getSpecimenCache() {
|
878
|
return specimenCache;
|
879
|
}
|
880
|
|
881
|
public void setSpecimenCache(Collection<SpecimenNodeWrapper> specimenCache) {
|
882
|
this.specimenCache = specimenCache.stream()
|
883
|
.filter(wrapper ->
|
884
|
//map descriptions on a list of uuids of the described specimen
|
885
|
!this.descriptions.stream()
|
886
|
.filter(rowWrapper->rowWrapper instanceof SpecimenRowWrapperDTO)
|
887
|
.map(specimenRowWrapper->((SpecimenRowWrapperDTO) specimenRowWrapper).getSpecimenDto().getUuid())
|
888
|
.collect(Collectors.toList())
|
889
|
//and check if the specimen to add is already contained
|
890
|
.contains(wrapper.getUuidAndTitleCache().getUuid())
|
891
|
)
|
892
|
.collect(Collectors.toList());
|
893
|
}
|
894
|
|
895
|
// public void addRowToSave(RowWrapperDTO<?> row){
|
896
|
// rowsToMerge.put(row.getDescription().getDescription().getUuid(), row);
|
897
|
// }
|
898
|
//
|
899
|
// public HashMap<UUID,RowWrapperDTO<?>> getRowsToSave() {
|
900
|
// return rowsToMerge;
|
901
|
// }
|
902
|
|
903
|
public HashMap<UUID, RowWrapperDTO<?>> getRowsToMerge() {
|
904
|
return rowsToMerge;
|
905
|
}
|
906
|
|
907
|
public void putRowToMerge(RowWrapperDTO<?> rowToMerge) {
|
908
|
if (this.rowsToMerge == null){
|
909
|
this.rowsToMerge = new HashMap<>();
|
910
|
}
|
911
|
this.rowsToMerge.put(rowToMerge.getDescription().getDescriptionUuid(), rowToMerge);
|
912
|
}
|
913
|
|
914
|
public Properties getNatTableState() {
|
915
|
return toolbar.getNatTableState();
|
916
|
}
|
917
|
|
918
|
public ListDataProvider<Object> getBodyDataProvider() {
|
919
|
return bodyDataProvider;
|
920
|
}
|
921
|
|
922
|
MatrixBodyLayerStack getBodyLayer() {
|
923
|
return bodyLayer;
|
924
|
}
|
925
|
|
926
|
File getStatePropertiesFile() {
|
927
|
return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
|
928
|
}
|
929
|
|
930
|
public List<FeatureDto> getFeatures() {
|
931
|
return features;
|
932
|
}
|
933
|
|
934
|
public Map<FeatureDto, CategoricalDataHistogram> getFeatureToHistogramMap() {
|
935
|
return featureToHistogramMap;
|
936
|
}
|
937
|
|
938
|
|
939
|
|
940
|
public ICdmEntitySession getCdmEntitySession(){
|
941
|
return part.getCdmEntitySession();
|
942
|
}
|
943
|
|
944
|
@Inject
|
945
|
@Optional
|
946
|
private void updateSpecimenList(@UIEventTopic(WorkbenchEventConstants.REFRESH_DESCRIPTIVE_DATASET)UUID uuid){
|
947
|
if(uuid!= null && uuid.equals(part.getDescriptiveDataSet().getUuid())){
|
948
|
this.specimenCache = null;
|
949
|
|
950
|
}
|
951
|
}
|
952
|
|
953
|
@Inject
|
954
|
@Optional
|
955
|
private void updateMatrix(@UIEventTopic(WorkbenchEventConstants.REFRESH_MATRIX)UUID uuid){
|
956
|
if(uuid!= null && uuid.equals(part.getDescriptiveDataSet().getUuid())){
|
957
|
this.specimenCache = null;
|
958
|
|
959
|
}
|
960
|
}
|
961
|
|
962
|
public void addRowsToMatrix(Collection<SpecimenNodeWrapper> wrappers){
|
963
|
|
964
|
List<UUID> specimenUuids = new ArrayList<>();
|
965
|
wrappers.forEach(wrapper -> specimenUuids.add(wrapper.getUuidAndTitleCache().getUuid()));
|
966
|
// List<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).load(specimenUuids, null);
|
967
|
Map<UUID, UuidAndTitleCache<FieldUnit>> specimenMap = new HashMap<>();
|
968
|
|
969
|
for (UUID specimenUuid: specimenUuids ){
|
970
|
try{
|
971
|
FieldUnitDTO fieldUnitDto = CdmStore.getService(IOccurrenceService.class).loadFieldUnitDTO(specimenUuid);
|
972
|
if (fieldUnitDto != null){
|
973
|
UuidAndTitleCache<FieldUnit> fieldUnit = new UuidAndTitleCache<>(FieldUnit.class, fieldUnitDto.getUuid(), null, fieldUnitDto.getLabel());
|
974
|
specimenMap.put(specimenUuid, fieldUnit);
|
975
|
}
|
976
|
}catch(Exception e){
|
977
|
e.printStackTrace();
|
978
|
}
|
979
|
|
980
|
}
|
981
|
for (SpecimenNodeWrapper wrapper: wrappers){
|
982
|
SpecimenRowWrapperDTO rowWrapper = CdmStore.getService(IDescriptiveDataSetService.class).createSpecimenRowWrapper(wrapper.getUuidAndTitleCache().getUuid(), wrapper.getTaxonNode().getUuid(), getDescriptiveDataSet().getUuid());
|
983
|
addSpecimenToAdd(rowWrapper);
|
984
|
// SpecimenRowWrapperDTO rowWrapper = new SpecimenRowWrapperDTO(wrapper.getUuidAndTitleCache(), wrapper.getType(), wrapper.getTaxonNode(), specimenMap.get(wrapper.getUuidAndTitleCache().getUuid()), null, null);
|
985
|
descriptions.add(rowWrapper);
|
986
|
}
|
987
|
|
988
|
|
989
|
setDirty();
|
990
|
}
|
991
|
|
992
|
public HashMap<UUID, DescriptionBase<?>> addSpecimensToDescriptiveDataSet(){
|
993
|
if (specimenToAdd == null || specimenToAdd.isEmpty()){
|
994
|
return new HashMap<>();
|
995
|
}
|
996
|
UpdateResult result = CdmStore.getService(IDescriptiveDataSetService.class).addRowWrapperToDataset(specimenToAdd, getDescriptiveDataSet().getUuid(), true);
|
997
|
if(!result.getExceptions().isEmpty()){
|
998
|
MessagingUtils.warningDialog(Messages.CharacterMatrixBottomToolbar_ERROR_ROW_CREATION_TITLE, this,
|
999
|
String.format(Messages.CharacterMatrixBottomToolbar_ERROR_ROW_CREATION_MESSAGE, result.getExceptions()
|
1000
|
.stream().map(ex->ex.toString())
|
1001
|
.collect(Collectors.joining("\n"))));
|
1002
|
}
|
1003
|
DescriptiveDataSet dataSet = (DescriptiveDataSet) result.getCdmEntity();
|
1004
|
HashMap<UUID, DescriptionBase<?>> resultMap = new HashMap<>();
|
1005
|
for (CdmBase updated: result.getUpdatedObjects()){
|
1006
|
if (updated instanceof SpecimenDescription){
|
1007
|
resultMap.put(updated.getUuid(), (DescriptionBase<?>)updated);
|
1008
|
}
|
1009
|
|
1010
|
|
1011
|
}
|
1012
|
dataSet = this.getCdmEntitySession().load(dataSet, true);
|
1013
|
// update local dataset
|
1014
|
DescriptiveDataSetBaseDto dto = DescriptiveDataSetBaseDto.fromDescriptiveDataSet(dataSet);
|
1015
|
this.setDescriptiveDataSet(dto);
|
1016
|
|
1017
|
//these descriptions are already updated
|
1018
|
for (SpecimenRowWrapperDTO row: specimenToAdd){
|
1019
|
this.rowsToMerge.remove(row.getDescription().getDescriptionUuid());
|
1020
|
}
|
1021
|
specimenToAdd.clear();
|
1022
|
return resultMap;
|
1023
|
|
1024
|
}
|
1025
|
public void setSelectedObject(Object selectedObject){
|
1026
|
|
1027
|
int rowIndex = ((IRowDataProvider<Object>)bodyDataProvider).indexOfRowObject(selectedObject);
|
1028
|
int rowPosition = selectionLayer.getRowPositionByIndex(rowIndex);
|
1029
|
natTable.doCommand( new SelectRowsCommand(natTable, 1, rowPosition, false, false));
|
1030
|
}
|
1031
|
|
1032
|
public TreeList<Object> updateDescriptions(boolean treeView){
|
1033
|
SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
|
1034
|
// wrap the SortedList with the TreeList
|
1035
|
treeFormat = new DescriptionTreeFormat(getDescriptiveDataSet());
|
1036
|
TreeList<Object> treeList = new TreeList<Object>(sortedList, treeFormat, TreeList.NODES_START_COLLAPSED);
|
1037
|
// wrap the SortedList with the TreeList
|
1038
|
// treeFormat = new DescriptionTreeFormat(getDescriptiveDataSet());
|
1039
|
|
1040
|
/**
|
1041
|
* data provider
|
1042
|
*/
|
1043
|
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
|
1044
|
bodyDataProvider = treeView?new ListDataProvider<>(treeList, columnPropertyAccessor):new ListDataProvider<>(sortedList, columnPropertyAccessor);
|
1045
|
return treeList;
|
1046
|
|
1047
|
}
|
1048
|
|
1049
|
@Override
|
1050
|
public void dispose () {
|
1051
|
super.dispose();
|
1052
|
if (descriptions != null){
|
1053
|
descriptions.dispose();
|
1054
|
}
|
1055
|
descriptions = null;
|
1056
|
this.natTable.dispose();
|
1057
|
this.natTable = null;
|
1058
|
categoricalFeatureToStateMap = null;
|
1059
|
rowsToMerge.clear();
|
1060
|
rowsToMerge = null;
|
1061
|
indexToFeatureMap = null;
|
1062
|
propertyToLabelMap = null;
|
1063
|
specimenCache = null;
|
1064
|
featureToHistogramMap = null;
|
1065
|
bodyDataProvider = null;
|
1066
|
freezeLayer = null;
|
1067
|
features = null;
|
1068
|
topMostLayer.dispose();
|
1069
|
topMostLayer = null;
|
1070
|
configRegistry = null;
|
1071
|
bodyLayer.dispose();
|
1072
|
bodyLayer = null;
|
1073
|
toolbar.dispose();
|
1074
|
toolbar = null;
|
1075
|
treeFormat = null;
|
1076
|
descriptionUuidsToDelete = null;
|
1077
|
specimenToAdd = null;
|
1078
|
mouseEventMatcher = null;
|
1079
|
descriptionsToSave = null;
|
1080
|
menuService = null;
|
1081
|
sync = null;
|
1082
|
part = null;
|
1083
|
|
1084
|
}
|
1085
|
|
1086
|
}
|