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