1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
|
10
|
|
11
|
import java.io.File;
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Collection;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Properties;
|
18
|
import java.util.Set;
|
19
|
import java.util.UUID;
|
20
|
import java.util.stream.Collectors;
|
21
|
|
22
|
import org.apache.commons.collections4.map.LinkedMap;
|
23
|
import org.eclipse.core.runtime.ICoreRunnable;
|
24
|
import org.eclipse.core.runtime.IProgressMonitor;
|
25
|
import org.eclipse.core.runtime.jobs.Job;
|
26
|
import org.eclipse.jface.layout.GridDataFactory;
|
27
|
import org.eclipse.jface.viewers.ComboViewer;
|
28
|
import org.eclipse.jface.viewers.StructuredSelection;
|
29
|
import org.eclipse.nebula.widgets.nattable.NatTable;
|
30
|
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
|
31
|
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
|
32
|
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
|
33
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
34
|
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
|
35
|
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
|
36
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
|
37
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
|
38
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeData;
|
39
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeRowModel;
|
40
|
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
|
41
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeHelper;
|
42
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
|
43
|
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
|
44
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
|
45
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
|
46
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
|
47
|
import org.eclipse.nebula.widgets.nattable.grid.data.FixedSummaryRowHeaderLayer;
|
48
|
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
|
49
|
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
|
50
|
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
|
51
|
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
|
52
|
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
|
53
|
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
|
54
|
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
|
55
|
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
|
56
|
import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
|
57
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
|
58
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
|
59
|
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
|
60
|
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
|
61
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
62
|
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
|
63
|
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
|
64
|
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
|
65
|
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
|
66
|
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
|
67
|
import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
|
68
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
|
69
|
import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel;
|
70
|
import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
|
71
|
import org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration;
|
72
|
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
|
73
|
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
|
74
|
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
|
75
|
import org.eclipse.swt.SWT;
|
76
|
import org.eclipse.swt.layout.GridData;
|
77
|
import org.eclipse.swt.layout.GridLayout;
|
78
|
import org.eclipse.swt.widgets.Button;
|
79
|
import org.eclipse.swt.widgets.Composite;
|
80
|
|
81
|
import ca.odell.glazedlists.BasicEventList;
|
82
|
import ca.odell.glazedlists.EventList;
|
83
|
import ca.odell.glazedlists.SortedList;
|
84
|
import ca.odell.glazedlists.TreeList;
|
85
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
86
|
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
|
87
|
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
|
88
|
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
|
89
|
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
|
90
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
91
|
import eu.etaxonomy.cdm.model.description.Feature;
|
92
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
93
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
94
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
95
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
96
|
import eu.etaxonomy.cdm.model.description.State;
|
97
|
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
|
98
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
99
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
100
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
101
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
102
|
|
103
|
/**
|
104
|
* Character matrix editor for editing specimen/taxon descriptions in a table
|
105
|
* @author pplitzner
|
106
|
* @since Nov 26, 2017
|
107
|
*
|
108
|
*/
|
109
|
public class CharacterMatrix extends Composite {
|
110
|
|
111
|
private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties"; //$NON-NLS-1$
|
112
|
|
113
|
static final int LEADING_COLUMN_COUNT = 4;
|
114
|
static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
|
115
|
static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
|
116
|
static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
|
117
|
static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
|
118
|
|
119
|
static final String LABEL_TAXON_ROW = "TAXON_ROW"; //$NON-NLS-1$
|
120
|
|
121
|
private DescriptiveDataSet descriptiveDataSet;
|
122
|
|
123
|
private NatTable natTable;
|
124
|
|
125
|
private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
|
126
|
|
127
|
private Map<Feature, List<State>> categoricalFeatureToStateMap = new HashMap<>();
|
128
|
|
129
|
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
|
130
|
|
131
|
private EventList<Object> descriptions;
|
132
|
|
133
|
private Collection<SpecimenNodeWrapper> specimenCache = null;
|
134
|
|
135
|
private ListDataProvider<Object> bodyDataProvider;
|
136
|
|
137
|
private FreezeLayer freezeLayer;
|
138
|
|
139
|
private ViewportLayer viewportLayer;
|
140
|
|
141
|
private List<Feature> features;
|
142
|
|
143
|
private CharacterMatrixPart part;
|
144
|
|
145
|
private AbstractLayer topMostLayer;
|
146
|
|
147
|
private FixedSummaryRowLayer summaryRowLayer;
|
148
|
|
149
|
private ConfigRegistry configRegistry;
|
150
|
|
151
|
private DefaultBodyLayerStack bodyLayer;
|
152
|
|
153
|
private boolean isTreeView = true;
|
154
|
|
155
|
private CharacterMatrixToolbar toolbar;
|
156
|
|
157
|
|
158
|
public CharacterMatrix(Composite parent, CharacterMatrixPart part) {
|
159
|
super(parent, SWT.NONE);
|
160
|
this.part = part;
|
161
|
this.setLayout(new GridLayout());
|
162
|
|
163
|
createToolBar();
|
164
|
|
165
|
natTable = new NatTable(this, false);
|
166
|
|
167
|
createBottomToolbar();
|
168
|
|
169
|
}
|
170
|
|
171
|
private void createToolBar(){
|
172
|
toolbar = new CharacterMatrixToolbar(this, SWT.NONE);
|
173
|
}
|
174
|
|
175
|
@SuppressWarnings("unused")
|
176
|
private void createBottomToolbar() {
|
177
|
new CharacterMatrixBottomToolbar(this, SWT.NONE);
|
178
|
}
|
179
|
|
180
|
|
181
|
private void applyStyles(){
|
182
|
ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
|
183
|
configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
|
184
|
configuration.summaryRowBgColor = GUIHelper.getColor(255, 255, 153);
|
185
|
configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
186
|
configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
187
|
natTable.addConfiguration(configuration);
|
188
|
// // NOTE: Getting the colors and fonts from the GUIHelper ensures that
|
189
|
// // they are disposed properly (required by SWT)
|
190
|
// DefaultNatTableStyleConfiguration natTableConfiguration = new DefaultNatTableStyleConfiguration();
|
191
|
// natTableConfiguration.bgColor = GUIHelper.getColor(249, 172, 7);
|
192
|
// natTableConfiguration.fgColor = GUIHelper.getColor(30, 76, 19);
|
193
|
// natTableConfiguration.hAlign = HorizontalAlignmentEnum.LEFT;
|
194
|
// natTableConfiguration.vAlign = VerticalAlignmentEnum.TOP;
|
195
|
//// natTableConfiguration.borderStyle = new BorderStyle(1, GUIHelper.getColor(249, 172, 7), LineStyleEnum.SOLID);
|
196
|
//
|
197
|
// // Setup even odd row colors - row colors override the NatTable default
|
198
|
// // colors
|
199
|
// DefaultRowStyleConfiguration rowStyleConfiguration = new DefaultRowStyleConfiguration();
|
200
|
// rowStyleConfiguration.oddRowBgColor = ColorResources.getColor(Resources.COLOR_LIST_ODD);
|
201
|
// rowStyleConfiguration.evenRowBgColor = ColorResources.getColor(Resources.COLOR_LIST_EVEN);
|
202
|
//
|
203
|
// // Setup selection styling
|
204
|
// DefaultSelectionStyleConfiguration selectionStyle = new DefaultSelectionStyleConfiguration();
|
205
|
//// selectionStyle.selectionFont = GUIHelper.getFont(new FontData("Verdana", 8, SWT.NORMAL));
|
206
|
//// selectionStyle.selectionBgColor = GUIHelper.getColor(217, 232, 251);
|
207
|
//// selectionStyle.selectionFgColor = GUIHelper.COLOR_BLACK;
|
208
|
//// selectionStyle.anchorBorderStyle = new BorderStyle(1, GUIHelper.COLOR_DARK_GRAY, LineStyleEnum.SOLID);
|
209
|
//// selectionStyle.anchorBgColor = GUIHelper.getColor(65, 113, 43);
|
210
|
// selectionStyle.selectedHeaderBgColor = GUIHelper.getColor(156, 209, 103);
|
211
|
//
|
212
|
// // Add all style configurations to NatTable
|
213
|
// natTable.addConfiguration(natTableConfiguration);
|
214
|
// natTable.addConfiguration(rowStyleConfiguration);
|
215
|
// natTable.addConfiguration(selectionStyle);
|
216
|
//
|
217
|
// // Column/Row header style and custom painters
|
218
|
// DefaultRowHeaderStyleConfiguration rowHeaderConfig = new DefaultRowHeaderStyleConfiguration();
|
219
|
// Color rowColumnColor = GUIHelper.getColor(230, 255, 255);
|
220
|
// rowHeaderConfig.bgColor = rowColumnColor;
|
221
|
// natTable.addConfiguration(rowHeaderConfig);
|
222
|
// DefaultColumnHeaderStyleConfiguration columnHeaderStyle = new DefaultColumnHeaderStyleConfiguration();
|
223
|
// columnHeaderStyle.bgColor = rowColumnColor;
|
224
|
// columnHeaderStyle.font = GUIHelper.getFont(new FontData("Verdana", 9, SWT.BOLD)); //$NON-NLS-1$
|
225
|
// natTable.addConfiguration(columnHeaderStyle);
|
226
|
|
227
|
}
|
228
|
|
229
|
void toggleTreeFlat(boolean isTree, Button btnToggleFlat, Button btnToggleTree, Button btnCollapseAll, Button btnExpandAll, Button btnFreezeSuppInfo) {
|
230
|
isTreeView = isTree;
|
231
|
createTable(isTree);
|
232
|
btnToggleFlat.setEnabled(isTree);
|
233
|
btnToggleTree.setEnabled(!isTree);
|
234
|
btnCollapseAll.setEnabled(isTree);
|
235
|
btnExpandAll.setEnabled(isTree);
|
236
|
}
|
237
|
|
238
|
public boolean isTreeView() {
|
239
|
return isTreeView;
|
240
|
}
|
241
|
|
242
|
public void createTable(boolean treeView){
|
243
|
/**
|
244
|
* layers
|
245
|
*/
|
246
|
createLayers(treeView);
|
247
|
|
248
|
/**
|
249
|
* configuration
|
250
|
*/
|
251
|
configureNatTable(treeView, configRegistry, topMostLayer, summaryRowLayer);
|
252
|
|
253
|
/**
|
254
|
* handlers and listeners
|
255
|
*/
|
256
|
registerHandlersAndListeners(topMostLayer);
|
257
|
|
258
|
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
|
259
|
|
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
|
freezeSupplementalColumns(true);
|
265
|
|
266
|
this.layout();
|
267
|
}
|
268
|
|
269
|
private List<Feature> initFeatureList(FeatureNode node){
|
270
|
List<Feature> features = new ArrayList<>();
|
271
|
node.getChildNodes().forEach(childNode->
|
272
|
{
|
273
|
features.add(childNode.getFeature());
|
274
|
features.addAll(initFeatureList(childNode));
|
275
|
});
|
276
|
return features;
|
277
|
}
|
278
|
|
279
|
public void initDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
|
280
|
this.descriptiveDataSet = descriptiveDataSet;
|
281
|
//get features/columns stored in descriptive data set
|
282
|
FeatureTree tree = descriptiveDataSet.getDescriptiveSystem();
|
283
|
features = initFeatureList(tree.getRoot());
|
284
|
|
285
|
//init state data for categorical features
|
286
|
features.forEach(feature->
|
287
|
{
|
288
|
if(feature.isSupportsCategoricalData()){
|
289
|
List<State> supportedStates = new ArrayList<>();
|
290
|
feature.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
|
291
|
categoricalFeatureToStateMap.put(feature, supportedStates);
|
292
|
}
|
293
|
});
|
294
|
descriptions = new BasicEventList<>();
|
295
|
|
296
|
}
|
297
|
|
298
|
private void createLayers(boolean treeView) {
|
299
|
// use the SortedList constructor with 'null' for the Comparator
|
300
|
// because the Comparator will be set by configuration
|
301
|
SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
|
302
|
// wrap the SortedList with the TreeList
|
303
|
TreeList<Object> treeList = new TreeList(sortedList, new DescriptionTreeFormat(descriptiveDataSet), TreeList.NODES_START_EXPANDED);
|
304
|
/**
|
305
|
* data provider
|
306
|
*/
|
307
|
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
|
308
|
bodyDataProvider = treeView?new ListDataProvider<>(treeList, columnPropertyAccessor):new ListDataProvider<>(sortedList, columnPropertyAccessor);
|
309
|
|
310
|
configRegistry = new ConfigRegistry();
|
311
|
|
312
|
|
313
|
/**
|
314
|
* BODY layer
|
315
|
*
|
316
|
*
|
317
|
|
318
|
CompositeLayer
|
319
|
- (top) SummaryRowLayer
|
320
|
- (bottom) ViewportLayer
|
321
|
|
322
|
^
|
323
|
ViewportLayer
|
324
|
|
325
|
^
|
326
|
TreeLayer (default visible)
|
327
|
|
328
|
^
|
329
|
CompositeFreezeLayer
|
330
|
- viewportLayer
|
331
|
- selectionLayer
|
332
|
- freezeLayer
|
333
|
|
334
|
^
|
335
|
FreezeLayer
|
336
|
|
337
|
^
|
338
|
SelectionLayer
|
339
|
|
340
|
^
|
341
|
ColumnHideShowLayer
|
342
|
|
343
|
^
|
344
|
ColumnReorderLayer
|
345
|
|
346
|
^
|
347
|
DataLayer
|
348
|
|
349
|
*
|
350
|
|
351
|
*/
|
352
|
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
|
353
|
|
354
|
//register labels
|
355
|
CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this);
|
356
|
bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
|
357
|
|
358
|
|
359
|
propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
|
360
|
propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
|
361
|
propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
|
362
|
propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
|
363
|
for(int i=0;i<features.size();i++){
|
364
|
Feature feature = features.get(i);
|
365
|
initLabels(i, feature);
|
366
|
}
|
367
|
|
368
|
// layer for event handling of GlazedLists and PropertyChanges
|
369
|
GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, treeList);
|
370
|
GlazedListTreeData treeData = new GlazedListTreeData<>(treeList);
|
371
|
ITreeRowModel treeRowModel = new GlazedListTreeRowModel<>(treeData);
|
372
|
|
373
|
bodyLayer = new DefaultBodyLayerStack(
|
374
|
eventLayer);
|
375
|
viewportLayer = bodyLayer.getViewportLayer();
|
376
|
final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
|
377
|
freezeLayer = new FreezeLayer(selectionLayer);
|
378
|
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
|
379
|
freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
|
380
|
TreeLayer treeLayer = new TreeLayer(compositeFreezeLayer, treeRowModel);
|
381
|
|
382
|
topMostLayer = treeView?treeLayer:compositeFreezeLayer;
|
383
|
|
384
|
summaryRowLayer = new FixedSummaryRowLayer(bodyDataLayer, topMostLayer, configRegistry, false);
|
385
|
//regoster labels with summary prefix for summary layer
|
386
|
ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
|
387
|
summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
|
388
|
for(int i=0;i<features.size();i++){
|
389
|
Feature feature = features.get(i);
|
390
|
summaryColumnLabelAccumulator.registerColumnOverrides(
|
391
|
i+LEADING_COLUMN_COUNT,
|
392
|
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
|
393
|
}
|
394
|
// because the horizontal dependency is the ViewportLayer
|
395
|
// we need to set the composite dependency to false
|
396
|
summaryRowLayer.setHorizontalCompositeDependency(false);
|
397
|
|
398
|
CompositeLayer composite = new CompositeLayer(1, 2);
|
399
|
composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0); //$NON-NLS-1$
|
400
|
composite.setChildLayer(GridRegion.BODY, topMostLayer, 0, 1);
|
401
|
|
402
|
|
403
|
/**
|
404
|
* column header layer
|
405
|
*/
|
406
|
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
|
407
|
propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
|
408
|
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
|
409
|
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, topMostLayer, selectionLayer);
|
410
|
|
411
|
// add the SortHeaderLayer to the column header layer stack
|
412
|
// as we use GlazedLists, we use the GlazedListsSortModel which
|
413
|
// delegates the sorting to the SortedList
|
414
|
final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
|
415
|
columnHeaderLayer,
|
416
|
new GlazedListsSortModel<>(
|
417
|
sortedList,
|
418
|
columnPropertyAccessor,
|
419
|
configRegistry,
|
420
|
columnHeaderDataLayer));
|
421
|
|
422
|
|
423
|
/**
|
424
|
* row header layer
|
425
|
*/
|
426
|
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
|
427
|
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
|
428
|
FixedSummaryRowHeaderLayer fixedSummaryRowHeaderLayer = new FixedSummaryRowHeaderLayer(rowHeaderDataLayer,
|
429
|
composite, selectionLayer);
|
430
|
fixedSummaryRowHeaderLayer.setSummaryRowLabel("\u2211"); //$NON-NLS-1$
|
431
|
|
432
|
|
433
|
/**
|
434
|
* corner layer
|
435
|
*/
|
436
|
ILayer cornerLayer = new CornerLayer(
|
437
|
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
|
438
|
fixedSummaryRowHeaderLayer, sortHeaderLayer);
|
439
|
|
440
|
|
441
|
/**
|
442
|
* GRID layer (composition of all other layers)
|
443
|
*/
|
444
|
GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, fixedSummaryRowHeaderLayer, cornerLayer);
|
445
|
|
446
|
natTable.setLayer(gridLayer);
|
447
|
|
448
|
}
|
449
|
|
450
|
private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
|
451
|
// add the ExportCommandHandler to the ViewportLayer in order to make
|
452
|
// exporting work
|
453
|
topMostLayer.registerCommandHandler(new ExportCommandHandler(topMostLayer));
|
454
|
|
455
|
//propagate single cell selection
|
456
|
natTable.addLayerListener(new ILayerListener() {
|
457
|
@Override
|
458
|
public void handleLayerEvent(ILayerEvent event) {
|
459
|
if(event instanceof CellSelectionEvent){
|
460
|
CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
|
461
|
int columnPosition = cellSelectionEvent.getColumnPosition();
|
462
|
if(columnPosition>LEADING_COLUMN_COUNT){
|
463
|
Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
|
464
|
StructuredSelection selection = new StructuredSelection();
|
465
|
if(selectedCells.size()==1){
|
466
|
ILayerCell cell = selectedCells.iterator().next();
|
467
|
Object dataValue = cell.getDataValue();
|
468
|
if(dataValue!=null){
|
469
|
selection = new StructuredSelection(dataValue);
|
470
|
}
|
471
|
}
|
472
|
part.getSelectionService().setSelection(selection);
|
473
|
}
|
474
|
}
|
475
|
}
|
476
|
});
|
477
|
|
478
|
//register handler for view configuration menu
|
479
|
natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
|
480
|
}
|
481
|
|
482
|
private void configureNatTable(boolean treeView,
|
483
|
ConfigRegistry configRegistry,
|
484
|
AbstractLayer topMostLayer,
|
485
|
FixedSummaryRowLayer summaryRowLayer) {
|
486
|
/**
|
487
|
* CONFIGURATION
|
488
|
*/
|
489
|
natTable.setConfigRegistry(configRegistry);
|
490
|
|
491
|
applyStyles();
|
492
|
|
493
|
//add default configuration because autoconfigure is set to false in constructor
|
494
|
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
|
495
|
|
496
|
//FIXME: this is for DEBUG ONLY
|
497
|
// natTable.addConfiguration(new DebugMenuConfiguration(natTable));
|
498
|
|
499
|
// override the default sort configuration and change the mouse bindings
|
500
|
// to sort on a single click
|
501
|
if(!treeView){
|
502
|
natTable.addConfiguration(new SingleClickSortConfiguration());
|
503
|
}
|
504
|
|
505
|
natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
|
506
|
|
507
|
// add the header menu configuration for adding the column header menu
|
508
|
// with hide/show actions
|
509
|
natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {
|
510
|
|
511
|
@Override
|
512
|
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
|
513
|
return super.createColumnHeaderMenu(natTable)
|
514
|
.withHideColumnMenuItem()
|
515
|
.withShowAllColumnsMenuItem();
|
516
|
}
|
517
|
|
518
|
});
|
519
|
|
520
|
// add custom configuration for data conversion and add column labels to viewport layer
|
521
|
topMostLayer.addConfiguration(new DataConversionConfiguration(this));
|
522
|
|
523
|
//no summary for the supplemental columns
|
524
|
summaryRowLayer.addConfiguration(new SummaryRowConfiguration());
|
525
|
|
526
|
//register aggregation configuration for each feature
|
527
|
features.forEach(feature->summaryRowLayer.addConfiguration(new AggregationConfiguration(bodyDataProvider, feature)));
|
528
|
|
529
|
natTable.configure();
|
530
|
}
|
531
|
|
532
|
void freezeSupplementalColumns(boolean freeze){
|
533
|
if(freeze){
|
534
|
FreezeHelper.freeze(freezeLayer, viewportLayer,
|
535
|
new PositionCoordinate(viewportLayer, 0, 0),
|
536
|
new PositionCoordinate(viewportLayer, LEADING_COLUMN_COUNT-1, -1));
|
537
|
}
|
538
|
else{
|
539
|
FreezeHelper.unfreeze(freezeLayer, viewportLayer);
|
540
|
}
|
541
|
}
|
542
|
|
543
|
void selectStateItem(ComboViewer comboStates, String stateName){
|
544
|
String[] items = comboStates.getCombo().getItems();
|
545
|
for(int i=0;i<items.length;i++){
|
546
|
if(items[i].equals(stateName)){
|
547
|
comboStates.getCombo().select(i);
|
548
|
break;
|
549
|
}
|
550
|
}
|
551
|
}
|
552
|
|
553
|
private void initLabels(int index, Feature feature) {
|
554
|
indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
|
555
|
|
556
|
String featureLabel = feature.getLabel();
|
557
|
String property = featureLabel;
|
558
|
//show unit for quantitative data
|
559
|
if(feature.isSupportsQuantitativeData()){
|
560
|
Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
|
561
|
if(recommendedMeasurementUnits.size()>1){
|
562
|
MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
|
563
|
String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel()));
|
564
|
}
|
565
|
if(recommendedMeasurementUnits.size()==1){
|
566
|
MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
|
567
|
featureLabel += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
|
568
|
}
|
569
|
}
|
570
|
propertyToLabelMap.put(property, featureLabel);
|
571
|
}
|
572
|
|
573
|
public void loadDescriptions(DescriptiveDataSet descriptiveDataSet) {
|
574
|
UUID monitorUuid = CdmStore.getService(IDescriptiveDataSetService.class).monitGetRowWrapper(descriptiveDataSet);
|
575
|
IProgressMonitorService progressMonitorService = CdmApplicationState.getCurrentAppConfig().getProgressMonitorService();
|
576
|
|
577
|
|
578
|
String jobLabel = "Load character data";
|
579
|
Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
|
580
|
monitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
|
581
|
while(progressMonitorService.isMonitorThreadRunning(monitorUuid)){
|
582
|
if(monitor.isCanceled()){
|
583
|
progressMonitorService.interrupt(monitorUuid);
|
584
|
}
|
585
|
}
|
586
|
IRemotingProgressMonitor remotingMonitor = progressMonitorService.getRemotingMonitor(monitorUuid);
|
587
|
Collection<RowWrapperDTO> wrappers = (Collection<RowWrapperDTO>) remotingMonitor.getResult();
|
588
|
if(wrappers!=null){
|
589
|
wrappers.forEach(wrapper->CharacterMatrix.this.descriptions.add(wrapper));
|
590
|
}
|
591
|
monitor.done();
|
592
|
});
|
593
|
job.schedule();
|
594
|
}
|
595
|
|
596
|
public List<State> getSupportedStatesForCategoricalFeature(Feature feature){
|
597
|
return categoricalFeatureToStateMap.get(feature);
|
598
|
}
|
599
|
|
600
|
public Map<Integer, Feature> getIndexToFeatureMap() {
|
601
|
return indexToFeatureMap;
|
602
|
}
|
603
|
|
604
|
public LinkedMap<String, String> getPropertyToLabelMap() {
|
605
|
return propertyToLabelMap;
|
606
|
}
|
607
|
|
608
|
public void setDirty() {
|
609
|
part.setDirty();
|
610
|
}
|
611
|
|
612
|
public NatTable getNatTable() {
|
613
|
return natTable;
|
614
|
}
|
615
|
|
616
|
public EventList<Object> getDescriptions() {
|
617
|
return descriptions;
|
618
|
}
|
619
|
|
620
|
public DescriptiveDataSet getDescriptiveDataSet() {
|
621
|
return descriptiveDataSet;
|
622
|
}
|
623
|
|
624
|
public Collection<SpecimenNodeWrapper> getSpecimenCache() {
|
625
|
return specimenCache;
|
626
|
}
|
627
|
|
628
|
public void setSpecimenCache(Collection<SpecimenNodeWrapper> specimenCache) {
|
629
|
this.specimenCache = specimenCache.stream()
|
630
|
.filter(wrapper ->
|
631
|
//map descriptions on a list of uuids of the described specimen
|
632
|
!this.descriptions.stream()
|
633
|
.map(o->((RowWrapperDTO)o).getSpecimen().getUuid())
|
634
|
.collect(Collectors.toList())
|
635
|
//an check if the specimen to add is already contained
|
636
|
.contains(wrapper.getUuidAndTitleCache().getUuid())
|
637
|
)
|
638
|
.collect(Collectors.toList());
|
639
|
}
|
640
|
|
641
|
public Properties getNatTableState() {
|
642
|
return toolbar.getNatTableState();
|
643
|
}
|
644
|
|
645
|
public ListDataProvider<Object> getBodyDataProvider() {
|
646
|
return bodyDataProvider;
|
647
|
}
|
648
|
|
649
|
DefaultBodyLayerStack getBodyLayer() {
|
650
|
return bodyLayer;
|
651
|
}
|
652
|
|
653
|
File getStatePropertiesFile() {
|
654
|
return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
|
655
|
}
|
656
|
|
657
|
public List<Feature> getFeatures() {
|
658
|
return features;
|
659
|
}
|
660
|
|
661
|
}
|