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 javax.inject.Inject;
|
23
|
|
24
|
import org.apache.commons.collections4.map.LinkedMap;
|
25
|
import org.apache.commons.lang.StringUtils;
|
26
|
import org.eclipse.core.runtime.ICoreRunnable;
|
27
|
import org.eclipse.core.runtime.IProgressMonitor;
|
28
|
import org.eclipse.core.runtime.SubMonitor;
|
29
|
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
|
30
|
import org.eclipse.core.runtime.jobs.Job;
|
31
|
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
|
32
|
import org.eclipse.e4.ui.di.UISynchronize;
|
33
|
import org.eclipse.e4.ui.services.EMenuService;
|
34
|
import org.eclipse.jface.layout.GridDataFactory;
|
35
|
import org.eclipse.jface.viewers.ComboViewer;
|
36
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
37
|
import org.eclipse.jface.viewers.StructuredSelection;
|
38
|
import org.eclipse.nebula.widgets.nattable.NatTable;
|
39
|
import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
|
40
|
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
|
41
|
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
|
42
|
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
|
43
|
import org.eclipse.nebula.widgets.nattable.coordinate.Range;
|
44
|
import org.eclipse.nebula.widgets.nattable.copy.command.InternalCopyDataCommandHandler;
|
45
|
import org.eclipse.nebula.widgets.nattable.copy.command.InternalPasteDataCommandHandler;
|
46
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
47
|
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
|
48
|
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
|
49
|
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
|
50
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
|
51
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
|
52
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeData;
|
53
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeRowModel;
|
54
|
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
|
55
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeHelper;
|
56
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
|
57
|
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
|
58
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
|
59
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
|
60
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
|
61
|
import org.eclipse.nebula.widgets.nattable.grid.data.FixedSummaryRowHeaderLayer;
|
62
|
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
|
63
|
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
|
64
|
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
|
65
|
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
|
66
|
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
|
67
|
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
|
68
|
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
|
69
|
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
|
70
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
|
71
|
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
|
72
|
import org.eclipse.nebula.widgets.nattable.persistence.gui.PersistenceDialog;
|
73
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
74
|
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
|
75
|
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
|
76
|
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
|
77
|
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
|
78
|
import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
|
79
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
|
80
|
import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel;
|
81
|
import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
|
82
|
import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
|
83
|
import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
|
84
|
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
|
85
|
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
|
86
|
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
|
87
|
import org.eclipse.swt.SWT;
|
88
|
import org.eclipse.swt.layout.GridData;
|
89
|
import org.eclipse.swt.layout.GridLayout;
|
90
|
import org.eclipse.swt.widgets.Button;
|
91
|
import org.eclipse.swt.widgets.Composite;
|
92
|
import org.eclipse.swt.widgets.Menu;
|
93
|
|
94
|
import ca.odell.glazedlists.BasicEventList;
|
95
|
import ca.odell.glazedlists.EventList;
|
96
|
import ca.odell.glazedlists.SortedList;
|
97
|
import ca.odell.glazedlists.TreeList;
|
98
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
99
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
100
|
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
|
101
|
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
|
102
|
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
|
103
|
import eu.etaxonomy.cdm.model.description.Character;
|
104
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
105
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
106
|
import eu.etaxonomy.cdm.model.description.Feature;
|
107
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
108
|
import eu.etaxonomy.cdm.model.description.State;
|
109
|
import eu.etaxonomy.cdm.model.term.FeatureNode;
|
110
|
import eu.etaxonomy.cdm.model.term.FeatureTree;
|
111
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
112
|
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
|
113
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
114
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
115
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
116
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
117
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
118
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
119
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
120
|
|
121
|
/**
|
122
|
* Character matrix editor for editing specimen/taxon descriptions in a table
|
123
|
* @author pplitzner
|
124
|
* @since Nov 26, 2017
|
125
|
*
|
126
|
*/
|
127
|
public class CharacterMatrix extends Composite {
|
128
|
|
129
|
private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties"; //$NON-NLS-1$
|
130
|
|
131
|
static final int LEADING_COLUMN_COUNT = 4;
|
132
|
static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
|
133
|
static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
|
134
|
static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
|
135
|
static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
|
136
|
|
137
|
static final String LABEL_TAXON_ROW = "TAXON_ROW"; //$NON-NLS-1$
|
138
|
static final String LABEL_TAXON_AGGREGATED_DESCRIPTION = "TAXON_AGGREGATED_DESCRIPTION"; //$NON-NLS-1$
|
139
|
static final String LABEL_TAXON_AGGREGATED_DESCRIPTION_ICON = "TAXON_AGGREGATED_DESCRIPTION_ICON"; //$NON-NLS-1$
|
140
|
static final String LABEL_TAXON_DEFAULT_DESCRIPTION = "TAXON_DEFAULT_DESCRIPTION"; //$NON-NLS-1$
|
141
|
static final String LABEL_TAXON_DEFAULT_DESCRIPTION_ICON = "TAXON_DEFAULT_DESCRIPTION_ICON"; //$NON-NLS-1$
|
142
|
static final String LABEL_TAXON_LITERATURE_DESCRIPTION = "TAXON_LITERATURE_DESCRIPTION"; //$NON-NLS-1$
|
143
|
static final String LABEL_TAXON_LITERATURE_DESCRIPTION_ICON = "TAXON_LITERATURE_DESCRIPTION_ICON"; //$NON-NLS-1$
|
144
|
static final String LABEL_TAXON_DESCRIPTION = "LABEL_TAXON_DESCRIPTION"; //$NON-NLS-1$
|
145
|
static final String LABEL_DESCRIPTION_HAS_SUPPLEMENTAL_DATA = "LABEL_DESCRIPTION_HAS_SUPPLEMENTAL_DATA"; //$NON-NLS-1$
|
146
|
|
147
|
@Inject
|
148
|
private UISynchronize sync;
|
149
|
|
150
|
@Inject
|
151
|
private EMenuService menuService;
|
152
|
|
153
|
private DescriptiveDataSet descriptiveDataSet;
|
154
|
|
155
|
private NatTable natTable;
|
156
|
|
157
|
private Map<Integer, Character> indexToCharacterMap = new HashMap<>();
|
158
|
|
159
|
private Map<Feature, List<TermDto>> categoricalFeatureToStateMap = new HashMap<>();
|
160
|
|
161
|
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
|
162
|
|
163
|
private EventList<Object> descriptions;
|
164
|
|
165
|
private Collection<SpecimenNodeWrapper> specimenCache = null;
|
166
|
|
167
|
private Map<Feature, CategoricalDataHistogram> featureToHistogramMap = new HashMap<>();
|
168
|
|
169
|
private Map<Feature, QuantitativeDataStatistics> featureToQuantDataStatisticsMap = new HashMap<>();
|
170
|
|
171
|
private ListDataProvider<Object> bodyDataProvider;
|
172
|
|
173
|
private FreezeLayer freezeLayer;
|
174
|
|
175
|
private List<Character> characters;
|
176
|
|
177
|
private CharacterMatrixPart part;
|
178
|
|
179
|
private AbstractLayer topMostLayer;
|
180
|
|
181
|
private FixedSummaryRowLayer summaryRowLayer;
|
182
|
|
183
|
private ConfigRegistry configRegistry;
|
184
|
|
185
|
private DefaultBodyLayerStack bodyLayer;
|
186
|
|
187
|
private boolean isTreeView = true;
|
188
|
|
189
|
private CharacterMatrixToolbar toolbar;
|
190
|
|
191
|
private boolean isShowTooltips = true;
|
192
|
|
193
|
public CharacterMatrix(Composite parent, CharacterMatrixPart part) {
|
194
|
super(parent, SWT.NONE);
|
195
|
this.part = part;
|
196
|
this.setLayout(new GridLayout());
|
197
|
|
198
|
createToolBar();
|
199
|
|
200
|
natTable = new NatTable(this, false);
|
201
|
|
202
|
createBottomToolbar();
|
203
|
|
204
|
}
|
205
|
|
206
|
private void createToolBar(){
|
207
|
toolbar = new CharacterMatrixToolbar(this, SWT.NONE);
|
208
|
}
|
209
|
|
210
|
@SuppressWarnings("unused")
|
211
|
private void createBottomToolbar() {
|
212
|
new CharacterMatrixBottomToolbar(this, SWT.NONE);
|
213
|
}
|
214
|
|
215
|
|
216
|
private void applyStyles(){
|
217
|
ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
|
218
|
configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
|
219
|
// NOTE: Getting the colors and fonts from the GUIHelper ensures that
|
220
|
// they are disposed properly (required by SWT)
|
221
|
configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
222
|
configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
223
|
natTable.addConfiguration(configuration);
|
224
|
|
225
|
}
|
226
|
|
227
|
void toggleTreeFlat(boolean isTree, Button btnToggleFlat, Button btnToggleTree, Button btnCollapseAll, Button btnExpandAll, Button btnFreezeSuppInfo) {
|
228
|
isTreeView = isTree;
|
229
|
createTable(isTree, freezeLayer.isFrozen());
|
230
|
btnToggleFlat.setEnabled(isTree);
|
231
|
btnToggleTree.setEnabled(!isTree);
|
232
|
btnCollapseAll.setEnabled(isTree);
|
233
|
btnExpandAll.setEnabled(isTree);
|
234
|
}
|
235
|
|
236
|
public boolean isTreeView() {
|
237
|
return isTreeView;
|
238
|
}
|
239
|
|
240
|
public void createTable(boolean treeView, boolean freezeSupplementalColumns){
|
241
|
/**
|
242
|
* layers
|
243
|
*/
|
244
|
createLayers(treeView);
|
245
|
|
246
|
/**
|
247
|
* configuration
|
248
|
*/
|
249
|
configureNatTable(treeView, configRegistry, topMostLayer, summaryRowLayer);
|
250
|
|
251
|
/**
|
252
|
* handlers and listeners
|
253
|
*/
|
254
|
registerHandlersAndListeners();
|
255
|
|
256
|
//grab all space
|
257
|
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
|
258
|
|
259
|
//update label to current data set
|
260
|
toolbar.getWsLabel().setText(descriptiveDataSet.getLabel());
|
261
|
toolbar.getWsLabel().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
262
|
toolbar.getWsLabel().getParent().layout();
|
263
|
|
264
|
//initial freeze of supplemental columns
|
265
|
freezeSupplementalColumns(freezeSupplementalColumns);
|
266
|
|
267
|
|
268
|
//add tooltip to table
|
269
|
new CategoricalChartTooltip(this);
|
270
|
new QuantitativeChartTooltip(this);
|
271
|
|
272
|
|
273
|
this.layout();
|
274
|
// natTable.doCommand(new ClientAreaResizeCommand(natTable));
|
275
|
|
276
|
// load active table state
|
277
|
String activeState = getNatTableState().getProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY);
|
278
|
natTable.loadState(activeState!=null?activeState:StringUtils.EMPTY, getNatTableState());
|
279
|
getNatTableState().remove(NatTable.INITIAL_PAINT_COMPLETE_FLAG);
|
280
|
}
|
281
|
|
282
|
private List<Character> initCharacterList(FeatureNode<Character> node){
|
283
|
List<Character> characters = new ArrayList<>();
|
284
|
node.getChildNodes().forEach(childNode->
|
285
|
{
|
286
|
characters.add(childNode.getTerm());
|
287
|
characters.addAll(initCharacterList(childNode));
|
288
|
});
|
289
|
return characters;
|
290
|
}
|
291
|
|
292
|
public void initDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
|
293
|
this.descriptiveDataSet = descriptiveDataSet;
|
294
|
//get features/columns stored in descriptive data set
|
295
|
FeatureTree<Character> tree = descriptiveDataSet.getDescriptiveSystem();
|
296
|
characters = initCharacterList(tree.getRoot());
|
297
|
|
298
|
//init state data for categorical features
|
299
|
characters.forEach(character->fetchSupportedStates(character));
|
300
|
|
301
|
descriptions = new BasicEventList<>();
|
302
|
|
303
|
}
|
304
|
|
305
|
private void fetchSupportedStates(Character character) {
|
306
|
if(character.isSupportsCategoricalData()){
|
307
|
Set<TermVocabulary<State>> supportedCategoricalEnumerations = character.getSupportedCategoricalEnumerations();
|
308
|
List<UUID> vocUuids = new ArrayList<>();
|
309
|
for (TermVocabulary<State> termVocabulary : supportedCategoricalEnumerations) {
|
310
|
vocUuids.add(termVocabulary.getUuid());
|
311
|
}
|
312
|
List<TermDto> supportedStates = new ArrayList<>(CdmStore.getService(IVocabularyService.class).getTerms(vocUuids));
|
313
|
categoricalFeatureToStateMap.put(character, supportedStates);
|
314
|
}
|
315
|
}
|
316
|
|
317
|
private void createLayers(boolean treeView) {
|
318
|
SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
|
319
|
// wrap the SortedList with the TreeList
|
320
|
TreeList<Object> treeList = new TreeList(sortedList, new DescriptionTreeFormat(descriptiveDataSet), TreeList.NODES_START_EXPANDED);
|
321
|
/**
|
322
|
* data provider
|
323
|
*/
|
324
|
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
|
325
|
bodyDataProvider = treeView?new ListDataProvider<>(treeList, columnPropertyAccessor):new ListDataProvider<>(sortedList, columnPropertyAccessor);
|
326
|
|
327
|
configRegistry = new ConfigRegistry();
|
328
|
|
329
|
|
330
|
/**
|
331
|
* BODY layer
|
332
|
*
|
333
|
*
|
334
|
|
335
|
CompositeLayer
|
336
|
- (top) SummaryRowLayer
|
337
|
- (bottom) ViewportLayer
|
338
|
|
339
|
^
|
340
|
ViewportLayer
|
341
|
|
342
|
^
|
343
|
TreeLayer (default visible)
|
344
|
|
345
|
^
|
346
|
CompositeFreezeLayer
|
347
|
- viewportLayer
|
348
|
- selectionLayer
|
349
|
- freezeLayer
|
350
|
|
351
|
^
|
352
|
FreezeLayer
|
353
|
|
354
|
^
|
355
|
SelectionLayer
|
356
|
|
357
|
^
|
358
|
ColumnHideShowLayer
|
359
|
|
360
|
^
|
361
|
ColumnReorderLayer
|
362
|
|
363
|
^
|
364
|
DataLayer
|
365
|
|
366
|
*
|
367
|
|
368
|
*/
|
369
|
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
|
370
|
bodyDataLayer.registerCommandHandler(new CopyPasteUpdateDataCommandHandler(bodyDataLayer));
|
371
|
|
372
|
//register labels
|
373
|
CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this);
|
374
|
bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
|
375
|
|
376
|
|
377
|
propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
|
378
|
propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
|
379
|
propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
|
380
|
propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
|
381
|
for(int i=0;i<characters.size();i++){
|
382
|
Character character = characters.get(i);
|
383
|
initLabels(i, character);
|
384
|
}
|
385
|
|
386
|
// layer for event handling of GlazedLists and PropertyChanges
|
387
|
GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, (EventList)bodyDataProvider.getList());
|
388
|
|
389
|
GlazedListTreeData treeData = new GlazedListTreeData<>(treeList);
|
390
|
ITreeRowModel treeRowModel = new GlazedListTreeRowModel<>(treeData);
|
391
|
|
392
|
bodyLayer = new DefaultBodyLayerStack(eventLayer);
|
393
|
final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
|
394
|
freezeLayer = new FreezeLayer(selectionLayer);
|
395
|
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
|
396
|
freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
|
397
|
TreeLayer treeLayer = new TreeLayer(compositeFreezeLayer, treeRowModel);
|
398
|
|
399
|
topMostLayer = treeView?treeLayer:compositeFreezeLayer;
|
400
|
|
401
|
summaryRowLayer = new FixedSummaryRowLayer(bodyDataLayer, topMostLayer, configRegistry, false);
|
402
|
//regoster labels with summary prefix for summary layer
|
403
|
ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
|
404
|
summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
|
405
|
for(int i=0;i<characters.size();i++){
|
406
|
Character character = characters.get(i);
|
407
|
summaryColumnLabelAccumulator.registerColumnOverrides(
|
408
|
i+LEADING_COLUMN_COUNT,
|
409
|
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(character));
|
410
|
}
|
411
|
// because the horizontal dependency is the ViewportLayer
|
412
|
// we need to set the composite dependency to false
|
413
|
summaryRowLayer.setHorizontalCompositeDependency(false);
|
414
|
|
415
|
CompositeLayer composite = new CompositeLayer(1, 2);
|
416
|
composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0); //$NON-NLS-1$
|
417
|
composite.setChildLayer(GridRegion.BODY, topMostLayer, 0, 1);
|
418
|
|
419
|
|
420
|
/**
|
421
|
* column header layer
|
422
|
*/
|
423
|
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
|
424
|
propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
|
425
|
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
|
426
|
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, topMostLayer, selectionLayer);
|
427
|
|
428
|
// add the SortHeaderLayer to the column header layer stack
|
429
|
// as we use GlazedLists, we use the GlazedListsSortModel which
|
430
|
// delegates the sorting to the SortedList
|
431
|
final SortHeaderLayer<DescriptionBase> sortHeaderLayer = new SortHeaderLayer<>(
|
432
|
columnHeaderLayer,
|
433
|
new GlazedListsSortModel<>(
|
434
|
sortedList,
|
435
|
columnPropertyAccessor,
|
436
|
configRegistry,
|
437
|
columnHeaderDataLayer));
|
438
|
|
439
|
|
440
|
/**
|
441
|
* row header layer
|
442
|
*/
|
443
|
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
|
444
|
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
|
445
|
FixedSummaryRowHeaderLayer fixedSummaryRowHeaderLayer = new FixedSummaryRowHeaderLayer(rowHeaderDataLayer,
|
446
|
composite, selectionLayer);
|
447
|
fixedSummaryRowHeaderLayer.setSummaryRowLabel("\u2211"); //$NON-NLS-1$
|
448
|
|
449
|
|
450
|
/**
|
451
|
* corner layer
|
452
|
*/
|
453
|
ILayer cornerLayer = new CornerLayer(
|
454
|
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
|
455
|
fixedSummaryRowHeaderLayer, sortHeaderLayer);
|
456
|
|
457
|
|
458
|
/**
|
459
|
* GRID layer (composition of all other layers)
|
460
|
*/
|
461
|
GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, fixedSummaryRowHeaderLayer, cornerLayer);
|
462
|
|
463
|
natTable.setLayer(gridLayer);
|
464
|
|
465
|
}
|
466
|
|
467
|
private void registerHandlersAndListeners() {
|
468
|
natTable.registerCommandHandler(new ExportCommandHandler(natTable));
|
469
|
|
470
|
//selection listener
|
471
|
E4SelectionListener selectionListener = new CellSelectionListener(part.getSelectionService(),
|
472
|
bodyLayer.getSelectionLayer(), bodyDataProvider, part);
|
473
|
bodyLayer.getSelectionLayer().addLayerListener(selectionListener);
|
474
|
selectionListener.setFullySelectedRowsOnly(false);
|
475
|
|
476
|
//register handler for view configuration menu
|
477
|
natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
|
478
|
|
479
|
//register handlers for copy&paste
|
480
|
natTable.registerCommandHandler(
|
481
|
new InternalPasteDataCommandHandler(bodyLayer.getSelectionLayer(), natTable.getInternalCellClipboard()));
|
482
|
natTable.registerCommandHandler(
|
483
|
new InternalCopyDataCommandHandler(bodyLayer.getSelectionLayer(), natTable.getInternalCellClipboard()));
|
484
|
}
|
485
|
|
486
|
private void configureNatTable(boolean treeView,
|
487
|
ConfigRegistry configRegistry,
|
488
|
AbstractLayer topMostLayer,
|
489
|
FixedSummaryRowLayer summaryRowLayer) {
|
490
|
/**
|
491
|
* CONFIGURATION
|
492
|
*/
|
493
|
natTable.setConfigRegistry(configRegistry);
|
494
|
|
495
|
applyStyles();
|
496
|
|
497
|
//add default configuration because autoconfigure is set to false in constructor
|
498
|
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
|
499
|
|
500
|
// this is for DEBUG ONLY
|
501
|
// natTable.addConfiguration(new DebugMenuConfiguration(natTable));
|
502
|
|
503
|
// override the default sort configuration and change the mouse bindings
|
504
|
// to sort on a single click
|
505
|
if(!treeView){
|
506
|
natTable.addConfiguration(new SingleClickSortConfiguration());
|
507
|
}
|
508
|
|
509
|
natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
|
510
|
|
511
|
// add the header menu configuration for adding the column header menu
|
512
|
// with hide/show actions
|
513
|
natTable.addConfiguration(new CharacterMatrixHeaderMenuConfiguration(natTable));
|
514
|
|
515
|
// add custom configuration for data conversion and add column labels to viewport layer
|
516
|
topMostLayer.addConfiguration(new CellEditorDataConversionConfiguration(this));
|
517
|
|
518
|
//register aggregation configuration
|
519
|
summaryRowLayer.addConfiguration(new AggregationConfiguration(this));
|
520
|
|
521
|
//copy&paste configuration
|
522
|
natTable.addConfiguration(new CopyPasteEditBindings(bodyLayer.getSelectionLayer(), natTable.getInternalCellClipboard()));
|
523
|
|
524
|
//+++CONTEXT MENU+++
|
525
|
menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$
|
526
|
// get the menu registered by EMenuService
|
527
|
final Menu e4Menu = natTable.getMenu();
|
528
|
// remove the menu reference from NatTable instance
|
529
|
natTable.setMenu(null);
|
530
|
natTable.addConfiguration(
|
531
|
new AbstractUiBindingConfiguration() {
|
532
|
@Override
|
533
|
public void configureUiBindings(
|
534
|
UiBindingRegistry uiBindingRegistry) {
|
535
|
// add e4 menu to NatTable
|
536
|
new PopupMenuBuilder(natTable, e4Menu)
|
537
|
.build();
|
538
|
|
539
|
// register the UI binding for header, corner and body region
|
540
|
uiBindingRegistry.registerMouseDownBinding(
|
541
|
new MouseEventMatcher(
|
542
|
SWT.NONE,
|
543
|
null,
|
544
|
MouseEventMatcher.RIGHT_BUTTON),
|
545
|
new PopupMenuAction(e4Menu));
|
546
|
}
|
547
|
});
|
548
|
|
549
|
natTable.configure();
|
550
|
}
|
551
|
|
552
|
void freezeSupplementalColumns(boolean freeze){
|
553
|
if(freeze){
|
554
|
FreezeHelper.freeze(freezeLayer, bodyLayer.getViewportLayer(),
|
555
|
new PositionCoordinate(bodyLayer.getViewportLayer(), 0, 0),
|
556
|
new PositionCoordinate(bodyLayer.getViewportLayer(), LEADING_COLUMN_COUNT-1, -1));
|
557
|
}
|
558
|
else{
|
559
|
FreezeHelper.unfreeze(freezeLayer, bodyLayer.getViewportLayer());
|
560
|
}
|
561
|
}
|
562
|
|
563
|
void selectStateItem(ComboViewer comboStates, String stateName){
|
564
|
String[] items = comboStates.getCombo().getItems();
|
565
|
for(int i=0;i<items.length;i++){
|
566
|
if(items[i].equals(stateName)){
|
567
|
comboStates.getCombo().select(i);
|
568
|
break;
|
569
|
}
|
570
|
}
|
571
|
}
|
572
|
|
573
|
private void initLabels(int index, Character character) {
|
574
|
indexToCharacterMap.put(index+LEADING_COLUMN_COUNT, character);
|
575
|
|
576
|
String label = character.getLabel();
|
577
|
String property = character.getUuid().toString();
|
578
|
//show unit for quantitative data
|
579
|
if(character.isSupportsQuantitativeData()){
|
580
|
Set<MeasurementUnit> recommendedMeasurementUnits = character.getRecommendedMeasurementUnits();
|
581
|
if(recommendedMeasurementUnits.size()>1){
|
582
|
MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
|
583
|
String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, character.getLabel()));
|
584
|
}
|
585
|
if(recommendedMeasurementUnits.size()==1){
|
586
|
MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
|
587
|
label += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
|
588
|
}
|
589
|
}
|
590
|
propertyToLabelMap.put(property, label);
|
591
|
}
|
592
|
|
593
|
public void loadDescriptions(DescriptiveDataSet descriptiveDataSet) {
|
594
|
UUID monitorUuid = CdmApplicationState.getLongRunningTasksService().monitGetRowWrapper(descriptiveDataSet);
|
595
|
|
596
|
final Collection<RowWrapperDTO> wrappers = new ArrayList<>();
|
597
|
String jobLabel = Messages.CharacterMatrix_LOAD_CHARACTER_DATA;
|
598
|
Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
|
599
|
SubMonitor subMonitor = SubMonitor.convert(monitor);
|
600
|
subMonitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
|
601
|
IRemotingProgressMonitor remotingMonitor;
|
602
|
try {
|
603
|
remotingMonitor = CdmStore.getProgressMonitorClientManager()
|
604
|
.pollMonitor(jobLabel,
|
605
|
monitorUuid,
|
606
|
50,
|
607
|
null,
|
608
|
(List)null,
|
609
|
subMonitor);
|
610
|
} catch (InterruptedException e) {
|
611
|
MessagingUtils.informationDialog(Messages.CharacterMatrix_LOADING_FAILED_TITLE,
|
612
|
Messages.CharacterMatrix_LOADING_FAILED_MESSAGE);
|
613
|
return;
|
614
|
}
|
615
|
Object result = remotingMonitor.getResult();
|
616
|
if(result instanceof Collection){
|
617
|
wrappers.addAll((Collection<RowWrapperDTO>) result);
|
618
|
}
|
619
|
if(result instanceof Exception){
|
620
|
MessagingUtils.errorDialog("Exception during description loading", this.getClass(), "An exception occured during loading", TaxeditorEditorPlugin.PLUGIN_ID, (Throwable) result, true);
|
621
|
}
|
622
|
else if(wrappers.isEmpty()){
|
623
|
MessagingUtils.informationDialog(Messages.CharacterMatrix_NO_DESCRIPTION_TITLE,
|
624
|
Messages.CharacterMatrix_NO_DESCRIPTION_MESSAGE);
|
625
|
}
|
626
|
monitor.done();
|
627
|
});
|
628
|
job.addJobChangeListener(new JobChangeAdapter(){
|
629
|
@Override
|
630
|
public void done(IJobChangeEvent event) {
|
631
|
sync.syncExec(()->{
|
632
|
List<RowWrapperDTO> rowsWithoutTaxonNode = wrappers.stream().filter(row->row.getTaxonNode()==null).collect(Collectors.toList());
|
633
|
if(!rowsWithoutTaxonNode.isEmpty()){
|
634
|
String collect = rowsWithoutTaxonNode.stream().
|
635
|
map(row->row.getDescription().toString())
|
636
|
.collect(Collectors.joining("\n\n - ")); //$NON-NLS-1$
|
637
|
MessagingUtils.warningDialog(
|
638
|
Messages.CharacterMatrix_NO_NODE_FOUND_TITLE,
|
639
|
this.getClass(),
|
640
|
String.format(Messages.CharacterMatrix_NO_NODE_FOUND_MESSAGE, collect)
|
641
|
);
|
642
|
}
|
643
|
wrappers.stream().filter(row->row.getTaxonNode()!=null).forEach(wrapper->CharacterMatrix.this.descriptions.add(wrapper));
|
644
|
loadingDone();
|
645
|
});
|
646
|
}
|
647
|
});
|
648
|
job.schedule();
|
649
|
}
|
650
|
|
651
|
public IStructuredSelection getSelection(){
|
652
|
Set<Range> selectedRowPositions = bodyLayer.getSelectionLayer().getSelectedRowPositions();
|
653
|
List<Object> selectedObjects = new ArrayList<>();
|
654
|
for (Range range : selectedRowPositions) {
|
655
|
for(int i=range.start;i<range.end;i++){
|
656
|
selectedObjects.add(bodyDataProvider.getRowObject(i));
|
657
|
}
|
658
|
}
|
659
|
return new StructuredSelection(selectedObjects);
|
660
|
}
|
661
|
|
662
|
private void loadingDone() {
|
663
|
this.part.loadingDone();
|
664
|
createTable(isTreeView, freezeLayer.isFrozen());
|
665
|
}
|
666
|
|
667
|
public List<TermDto> getSupportedStatesForCategoricalFeature(Feature feature){
|
668
|
return categoricalFeatureToStateMap.get(feature);
|
669
|
}
|
670
|
|
671
|
public Map<Integer, Character> getIndexToCharacterMap() {
|
672
|
return indexToCharacterMap;
|
673
|
}
|
674
|
|
675
|
public LinkedMap<String, String> getPropertyToLabelMap() {
|
676
|
return propertyToLabelMap;
|
677
|
}
|
678
|
|
679
|
public void setDirty() {
|
680
|
part.setDirty();
|
681
|
}
|
682
|
|
683
|
public CharacterMatrixPart getPart() {
|
684
|
return part;
|
685
|
}
|
686
|
|
687
|
public NatTable getNatTable() {
|
688
|
return natTable;
|
689
|
}
|
690
|
|
691
|
public EventList<Object> getDescriptions() {
|
692
|
return descriptions;
|
693
|
}
|
694
|
|
695
|
public DescriptiveDataSet getDescriptiveDataSet() {
|
696
|
return descriptiveDataSet;
|
697
|
}
|
698
|
|
699
|
public Collection<SpecimenNodeWrapper> getSpecimenCache() {
|
700
|
return specimenCache;
|
701
|
}
|
702
|
|
703
|
public void setSpecimenCache(Collection<SpecimenNodeWrapper> specimenCache) {
|
704
|
this.specimenCache = specimenCache.stream()
|
705
|
.filter(wrapper ->
|
706
|
//map descriptions on a list of uuids of the described specimen
|
707
|
!this.descriptions.stream()
|
708
|
.filter(rowWrapper->rowWrapper instanceof SpecimenRowWrapperDTO)
|
709
|
.map(specimenRowWrapper->((SpecimenRowWrapperDTO) specimenRowWrapper).getSpecimen().getUuid())
|
710
|
.collect(Collectors.toList())
|
711
|
//an check if the specimen to add is already contained
|
712
|
.contains(wrapper.getUuidAndTitleCache().getUuid())
|
713
|
)
|
714
|
.collect(Collectors.toList());
|
715
|
}
|
716
|
|
717
|
public Properties getNatTableState() {
|
718
|
return toolbar.getNatTableState();
|
719
|
}
|
720
|
|
721
|
public ListDataProvider<Object> getBodyDataProvider() {
|
722
|
return bodyDataProvider;
|
723
|
}
|
724
|
|
725
|
DefaultBodyLayerStack getBodyLayer() {
|
726
|
return bodyLayer;
|
727
|
}
|
728
|
|
729
|
File getStatePropertiesFile() {
|
730
|
return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
|
731
|
}
|
732
|
|
733
|
public List<Character> getFeatures() {
|
734
|
return characters;
|
735
|
}
|
736
|
|
737
|
public Map<Feature, CategoricalDataHistogram> getFeatureToHistogramMap() {
|
738
|
return featureToHistogramMap;
|
739
|
}
|
740
|
|
741
|
public Map<Feature, QuantitativeDataStatistics> getFeatureToQuantDataStatisticsMap() {
|
742
|
return featureToQuantDataStatisticsMap;
|
743
|
}
|
744
|
|
745
|
public void toogleIsShowTooltips() {
|
746
|
this.isShowTooltips = !this.isShowTooltips;
|
747
|
}
|
748
|
|
749
|
public boolean isShowTooltips() {
|
750
|
return isShowTooltips;
|
751
|
}
|
752
|
|
753
|
public ICdmEntitySession getCdmEntitiySession(){
|
754
|
return part.getCdmEntitySession();
|
755
|
}
|
756
|
|
757
|
}
|