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.workingSet.matrix;
|
10
|
|
11
|
import java.io.File;
|
12
|
import java.io.FileInputStream;
|
13
|
import java.io.FileOutputStream;
|
14
|
import java.io.IOException;
|
15
|
import java.util.ArrayList;
|
16
|
import java.util.Arrays;
|
17
|
import java.util.Collection;
|
18
|
import java.util.Collections;
|
19
|
import java.util.HashMap;
|
20
|
import java.util.HashSet;
|
21
|
import java.util.List;
|
22
|
import java.util.Map;
|
23
|
import java.util.Properties;
|
24
|
import java.util.Set;
|
25
|
import java.util.UUID;
|
26
|
|
27
|
import javax.annotation.PostConstruct;
|
28
|
import javax.annotation.PreDestroy;
|
29
|
import javax.inject.Inject;
|
30
|
|
31
|
import org.apache.commons.collections4.map.LinkedMap;
|
32
|
import org.eclipse.core.runtime.IProgressMonitor;
|
33
|
import org.eclipse.e4.ui.di.Focus;
|
34
|
import org.eclipse.e4.ui.di.Persist;
|
35
|
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
36
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
37
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
38
|
import org.eclipse.jface.layout.GridDataFactory;
|
39
|
import org.eclipse.jface.viewers.StructuredSelection;
|
40
|
import org.eclipse.jface.window.Window;
|
41
|
import org.eclipse.nebula.widgets.nattable.NatTable;
|
42
|
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
|
43
|
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
|
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.config.IConfigRegistry;
|
47
|
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
|
48
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
49
|
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
|
50
|
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
|
51
|
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
|
52
|
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand;
|
53
|
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
|
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.grid.GridRegion;
|
57
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
|
58
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
|
59
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
|
60
|
import org.eclipse.nebula.widgets.nattable.grid.data.FixedSummaryRowHeaderLayer;
|
61
|
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
|
62
|
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
|
63
|
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
|
64
|
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
|
65
|
import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
|
66
|
import org.eclipse.nebula.widgets.nattable.hideshow.RowHideShowLayer;
|
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.ILayerListener;
|
71
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
|
72
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
|
73
|
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
|
74
|
import org.eclipse.nebula.widgets.nattable.persistence.PersistenceHelper;
|
75
|
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommand;
|
76
|
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler;
|
77
|
import org.eclipse.nebula.widgets.nattable.persistence.command.IStateChangedListener;
|
78
|
import org.eclipse.nebula.widgets.nattable.persistence.command.StateChangeEvent;
|
79
|
import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
|
80
|
import org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer;
|
81
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
82
|
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
|
83
|
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
|
84
|
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
|
85
|
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
|
86
|
import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
|
87
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
|
88
|
import org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration;
|
89
|
import org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration;
|
90
|
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
|
91
|
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
|
92
|
import org.eclipse.swt.SWT;
|
93
|
import org.eclipse.swt.events.SelectionAdapter;
|
94
|
import org.eclipse.swt.events.SelectionEvent;
|
95
|
import org.eclipse.swt.layout.GridData;
|
96
|
import org.eclipse.swt.layout.GridLayout;
|
97
|
import org.eclipse.swt.widgets.Button;
|
98
|
import org.eclipse.swt.widgets.Combo;
|
99
|
import org.eclipse.swt.widgets.Composite;
|
100
|
|
101
|
import ca.odell.glazedlists.EventList;
|
102
|
import ca.odell.glazedlists.GlazedLists;
|
103
|
import ca.odell.glazedlists.SortedList;
|
104
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
105
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
106
|
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
107
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
108
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
109
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
110
|
import eu.etaxonomy.cdm.model.description.Feature;
|
111
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
112
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
113
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
114
|
import eu.etaxonomy.cdm.model.description.State;
|
115
|
import eu.etaxonomy.cdm.model.description.WorkingSet;
|
116
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
117
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
118
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataCellEditor;
|
119
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataDisplayConverter;
|
120
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataCellEditor;
|
121
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataDisplayConverter;
|
122
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
|
123
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
124
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
125
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
126
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
127
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
128
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
129
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
130
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
131
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
132
|
|
133
|
/**
|
134
|
* @author pplitzner
|
135
|
* @since Nov 26, 2017
|
136
|
*
|
137
|
*/
|
138
|
public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails, IConversationEnabled, IDirtyMarkable,
|
139
|
ICdmEntitySessionEnabled{
|
140
|
|
141
|
private static final List<String> WS_PROPERTY_PATH = Arrays.asList(new String[] {
|
142
|
"descriptions", //$NON-NLS-1$
|
143
|
"descriptions.descriptionElements", //$NON-NLS-1$
|
144
|
"descriptions.descriptionElements.inDescription", //$NON-NLS-1$
|
145
|
"descriptions.descriptionElements.inDescription.descriptionElements", //$NON-NLS-1$
|
146
|
"descriptions.descriptionElements.feature", //$NON-NLS-1$
|
147
|
});
|
148
|
|
149
|
private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties";
|
150
|
|
151
|
private static final int LEADING_COLUMN_COUNT = 4;
|
152
|
private static final String TAXON_COLUMN = "taxon_column";
|
153
|
private static final String COLLECTOR_COLUMN = "collector_column";
|
154
|
private static final String IDENTIFIER_COLUMN = "identifier_column";
|
155
|
private static final String COUNTRY_COLUMN = "country_column";
|
156
|
|
157
|
private WorkingSet workingSet;
|
158
|
|
159
|
private Composite parent;
|
160
|
|
161
|
private ConversationHolder conversation;
|
162
|
|
163
|
private ICdmEntitySession cdmEntitySession;
|
164
|
|
165
|
@Inject
|
166
|
private ESelectionService selService;
|
167
|
|
168
|
@Inject
|
169
|
private MDirtyable dirty;
|
170
|
|
171
|
@Inject
|
172
|
private MPart thisPart;
|
173
|
|
174
|
private NatTable natTable;
|
175
|
|
176
|
private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
|
177
|
|
178
|
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
|
179
|
|
180
|
private Properties natTableState;
|
181
|
|
182
|
private EventList<RowWrapper> descriptions;
|
183
|
|
184
|
@PostConstruct
|
185
|
public void create(Composite parent) {
|
186
|
if(CdmStore.isActive() && conversation==null){
|
187
|
conversation = CdmStore.createConversation();
|
188
|
}
|
189
|
if(cdmEntitySession == null){
|
190
|
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
191
|
}
|
192
|
else{
|
193
|
return;
|
194
|
}
|
195
|
parent.setLayout(new GridLayout());
|
196
|
this.parent = parent;
|
197
|
}
|
198
|
|
199
|
|
200
|
public void init(UUID workingSetUuid) {
|
201
|
this.workingSet = CdmStore.getService(IWorkingSetService.class).load(workingSetUuid, WS_PROPERTY_PATH);
|
202
|
thisPart.setLabel(workingSet.getLabel());
|
203
|
|
204
|
Composite toolbarComposite = new Composite(parent, SWT.NONE);
|
205
|
toolbarComposite.setLayout(new GridLayout(3, false));
|
206
|
toolbarComposite.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
|
207
|
|
208
|
//get features/columns stored in working set
|
209
|
FeatureTree tree = workingSet.getDescriptiveSystem();
|
210
|
List<Feature> features = new ArrayList<>(tree.getDistinctFeatures());
|
211
|
Collections.sort(features);
|
212
|
|
213
|
descriptions = GlazedLists.eventList(getDescriptions(workingSet));
|
214
|
SortedList<RowWrapper> sortedList = new SortedList<>(descriptions, null);
|
215
|
|
216
|
ConfigRegistry configRegistry = new ConfigRegistry();
|
217
|
|
218
|
/**
|
219
|
* data provider
|
220
|
*/
|
221
|
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
|
222
|
IDataProvider bodyDataProvider = new ListDataProvider<RowWrapper>(sortedList, columnPropertyAccessor);
|
223
|
|
224
|
/**
|
225
|
* BODY layer
|
226
|
*
|
227
|
*
|
228
|
|
229
|
CompositeLayer
|
230
|
- (top) SummaryRowLayer
|
231
|
- (bottom) ViewportLayer
|
232
|
|
233
|
^
|
234
|
ViewportLayer
|
235
|
|
236
|
^
|
237
|
SelectionLayer
|
238
|
|
239
|
^
|
240
|
RowHideShowLayer
|
241
|
|
242
|
^
|
243
|
ColumnHideShowLayer
|
244
|
|
245
|
^
|
246
|
ColumnReorderLayer
|
247
|
|
248
|
^
|
249
|
RowReorderLayer
|
250
|
|
251
|
^
|
252
|
DataLayer
|
253
|
|
254
|
*
|
255
|
|
256
|
*/
|
257
|
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
|
258
|
|
259
|
//register labels for columns
|
260
|
ColumnOverrideLabelAccumulator bodyColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
|
261
|
bodyDataLayer.setConfigLabelAccumulator(bodyColumnLabelAccumulator);
|
262
|
propertyToLabelMap.put(TAXON_COLUMN, "Taxon");
|
263
|
bodyColumnLabelAccumulator.registerColumnOverrides(0, TAXON_COLUMN);
|
264
|
propertyToLabelMap.put(COLLECTOR_COLUMN, "Collector + No");
|
265
|
bodyColumnLabelAccumulator.registerColumnOverrides(1, COLLECTOR_COLUMN);
|
266
|
propertyToLabelMap.put(IDENTIFIER_COLUMN, "Identifier");
|
267
|
bodyColumnLabelAccumulator.registerColumnOverrides(2, IDENTIFIER_COLUMN);
|
268
|
propertyToLabelMap.put(COUNTRY_COLUMN, "Country");
|
269
|
bodyColumnLabelAccumulator.registerColumnOverrides(3, COUNTRY_COLUMN);
|
270
|
for(int i=0;i<features.size();i++){
|
271
|
Feature feature = features.get(i);
|
272
|
initLabels(bodyColumnLabelAccumulator, i, feature);
|
273
|
}
|
274
|
|
275
|
GlazedListsEventLayer<RowWrapper> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, sortedList);
|
276
|
|
277
|
RowReorderLayer rowReorderLayer = new RowReorderLayer(eventLayer);
|
278
|
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(rowReorderLayer);
|
279
|
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
|
280
|
RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(columnHideShowLayer);
|
281
|
SelectionLayer selectionLayer = new SelectionLayer(rowHideShowLayer);
|
282
|
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
|
283
|
|
284
|
|
285
|
// create a standalone FixedSummaryRowLayer
|
286
|
// since the summary row should be fixed at the top of the body
|
287
|
// region the horizontal dependency of the FixedSummaryRowLayer
|
288
|
// is the ViewportLayer
|
289
|
FixedSummaryRowLayer summaryRowLayer =
|
290
|
new FixedSummaryRowLayer(bodyDataLayer, viewportLayer, configRegistry, false);
|
291
|
//regoster labels with summary prefix for summary layer
|
292
|
ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
|
293
|
summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
|
294
|
for(int i=0;i<features.size();i++){
|
295
|
Feature feature = features.get(i);
|
296
|
summaryColumnLabelAccumulator.registerColumnOverrides(
|
297
|
i+LEADING_COLUMN_COUNT,
|
298
|
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
|
299
|
}
|
300
|
// because the horizontal dependency is the ViewportLayer
|
301
|
// we need to set the composite dependency to false
|
302
|
summaryRowLayer.setHorizontalCompositeDependency(false);
|
303
|
|
304
|
CompositeLayer composite = new CompositeLayer(1, 2);
|
305
|
composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0);
|
306
|
composite.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
|
307
|
|
308
|
|
309
|
|
310
|
|
311
|
/**
|
312
|
* column header layer
|
313
|
*/
|
314
|
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
|
315
|
propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
|
316
|
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
|
317
|
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
|
318
|
|
319
|
// add the SortHeaderLayer to the column header layer stack
|
320
|
// as we use GlazedLists, we use the GlazedListsSortModel which
|
321
|
// delegates the sorting to the SortedList
|
322
|
final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
|
323
|
columnHeaderLayer,
|
324
|
new GlazedListsSortModel<>(
|
325
|
sortedList,
|
326
|
columnPropertyAccessor,
|
327
|
configRegistry,
|
328
|
columnHeaderDataLayer));
|
329
|
|
330
|
|
331
|
/**
|
332
|
* row header layer
|
333
|
*/
|
334
|
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
|
335
|
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
|
336
|
FixedSummaryRowHeaderLayer fixedSummaryRowHeaderLayer = new FixedSummaryRowHeaderLayer(rowHeaderDataLayer,
|
337
|
composite, selectionLayer);
|
338
|
fixedSummaryRowHeaderLayer.setSummaryRowLabel("\u2211");
|
339
|
|
340
|
|
341
|
/**
|
342
|
* corner layer
|
343
|
*/
|
344
|
ILayer cornerLayer = new CornerLayer(
|
345
|
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
|
346
|
fixedSummaryRowHeaderLayer, sortHeaderLayer);
|
347
|
|
348
|
|
349
|
/**
|
350
|
* GRID layer (composition of all other layers)
|
351
|
*/
|
352
|
GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, fixedSummaryRowHeaderLayer, cornerLayer);
|
353
|
|
354
|
|
355
|
|
356
|
natTable = new NatTable(parent, gridLayer, false);
|
357
|
|
358
|
|
359
|
/**
|
360
|
* CONFIGURATION
|
361
|
*/
|
362
|
natTable.setConfigRegistry(configRegistry);
|
363
|
|
364
|
|
365
|
//add default configuration because autoconfigure is set to false in constructor
|
366
|
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
|
367
|
|
368
|
// override the default sort configuration and change the mouse bindings
|
369
|
// to sort on a single click
|
370
|
natTable.addConfiguration(new SingleClickSortConfiguration());
|
371
|
|
372
|
//FIXME: this is for DEBUG ONLY
|
373
|
natTable.addConfiguration(new DebugMenuConfiguration(natTable));
|
374
|
|
375
|
// add the header menu configuration for adding the column header menu
|
376
|
// with hide/show actions
|
377
|
natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {
|
378
|
|
379
|
@Override
|
380
|
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
|
381
|
return super.createColumnHeaderMenu(natTable)
|
382
|
.withHideColumnMenuItem()
|
383
|
.withShowAllColumnsMenuItem();
|
384
|
}
|
385
|
|
386
|
@Override
|
387
|
protected PopupMenuBuilder createRowHeaderMenu(NatTable natTable) {
|
388
|
return super.createRowHeaderMenu(natTable)
|
389
|
.withHideRowMenuItem()
|
390
|
.withShowAllRowsMenuItem();
|
391
|
}
|
392
|
|
393
|
@Override
|
394
|
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
|
395
|
return super.createCornerMenu(natTable)
|
396
|
.withShowAllColumnsMenuItem()
|
397
|
.withShowAllRowsMenuItem();
|
398
|
}
|
399
|
});
|
400
|
|
401
|
// add custom configuration for data conversion and add column labels to viewport layer
|
402
|
viewportLayer.addConfiguration(new AbstractRegistryConfiguration() {
|
403
|
@Override
|
404
|
public void configureRegistry(IConfigRegistry configRegistry) {
|
405
|
//add display converter for string representation
|
406
|
configRegistry.registerConfigAttribute(
|
407
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
408
|
new SupplementalInfoDisplayConverter(),
|
409
|
DisplayMode.NORMAL,
|
410
|
TAXON_COLUMN);
|
411
|
configRegistry.registerConfigAttribute(
|
412
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
413
|
new SupplementalInfoDisplayConverter(),
|
414
|
DisplayMode.NORMAL,
|
415
|
COLLECTOR_COLUMN);
|
416
|
configRegistry.registerConfigAttribute(
|
417
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
418
|
new SupplementalInfoDisplayConverter(),
|
419
|
DisplayMode.NORMAL,
|
420
|
IDENTIFIER_COLUMN);
|
421
|
configRegistry.registerConfigAttribute(
|
422
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
423
|
new SupplementalInfoDisplayConverter(),
|
424
|
DisplayMode.NORMAL,
|
425
|
COUNTRY_COLUMN);
|
426
|
features.forEach(feature->registerColumnConfiguration(feature, configRegistry));
|
427
|
}
|
428
|
|
429
|
});
|
430
|
|
431
|
//register aggregation configuration for each feature
|
432
|
features.forEach(feature->summaryRowLayer.addConfiguration(new AggregationConfiguration(bodyDataProvider, feature)));
|
433
|
|
434
|
// add the ExportCommandHandler to the ViewportLayer in order to make
|
435
|
// exporting work
|
436
|
viewportLayer.registerCommandHandler(new ExportCommandHandler(viewportLayer));
|
437
|
|
438
|
//propagate single cell selection
|
439
|
natTable.addLayerListener(new ILayerListener() {
|
440
|
@Override
|
441
|
public void handleLayerEvent(ILayerEvent event) {
|
442
|
if(event instanceof CellSelectionEvent){
|
443
|
CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
|
444
|
Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
|
445
|
StructuredSelection selection = new StructuredSelection();
|
446
|
if(selectedCells.size()==1){
|
447
|
ILayerCell cell = selectedCells.iterator().next();
|
448
|
Object dataValue = cell.getDataValue();
|
449
|
if(dataValue!=null){
|
450
|
selection = new StructuredSelection(dataValue);
|
451
|
}
|
452
|
}
|
453
|
selService.setSelection(selection);
|
454
|
}
|
455
|
}
|
456
|
});
|
457
|
|
458
|
natTable.configure();
|
459
|
|
460
|
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
|
461
|
|
462
|
/**
|
463
|
* Table state persistence
|
464
|
*/
|
465
|
natTableState = new Properties();
|
466
|
//load persisted state
|
467
|
File statePropertiesFile = getStatePropertiesFile();
|
468
|
FileInputStream inputStream;
|
469
|
try {
|
470
|
inputStream = new FileInputStream(statePropertiesFile);
|
471
|
natTableState.load(inputStream);
|
472
|
} catch (IOException e) {
|
473
|
MessagingUtils.info("No initial state properties file found for character matrix");
|
474
|
}
|
475
|
|
476
|
DisplayPersistenceDialogCommandHandler handler =
|
477
|
new DisplayPersistenceDialogCommandHandler(natTableState, natTable);
|
478
|
gridLayer.registerCommandHandler(handler);
|
479
|
// create a combobox for showing the available view states
|
480
|
Combo comboStates = new Combo(toolbarComposite, SWT.DROP_DOWN);
|
481
|
comboStates.setItems(PersistenceHelper
|
482
|
.getAvailableStates(natTableState)
|
483
|
.toArray(new String[] {}));
|
484
|
comboStates.addSelectionListener(new SelectionAdapter() {
|
485
|
|
486
|
@Override
|
487
|
public void widgetSelected(SelectionEvent e) {
|
488
|
int index = comboStates.getSelectionIndex();
|
489
|
if (index >= 0) {
|
490
|
String selected = comboStates.getItem(index);
|
491
|
// load the state
|
492
|
natTable.loadState(selected, natTableState);
|
493
|
}
|
494
|
}
|
495
|
});
|
496
|
|
497
|
// add listener to update the combo on view state management changes
|
498
|
handler.addStateChangeListener(new IStateChangedListener() {
|
499
|
|
500
|
@Override
|
501
|
public void handleStateChange(StateChangeEvent event) {
|
502
|
comboStates.setItems(PersistenceHelper
|
503
|
.getAvailableStates(natTableState)
|
504
|
.toArray(new String[] {}));
|
505
|
}
|
506
|
});
|
507
|
|
508
|
// add button to show dialog
|
509
|
Button btnManageState = new Button(toolbarComposite, SWT.PUSH);
|
510
|
btnManageState.setImage(ImageResources.getImage(ImageResources.SETTINGS));
|
511
|
btnManageState.addSelectionListener(new SelectionAdapter() {
|
512
|
@Override
|
513
|
public void widgetSelected(SelectionEvent e) {
|
514
|
natTable.doCommand(new DisplayPersistenceDialogCommand(natTable));
|
515
|
}
|
516
|
});
|
517
|
|
518
|
/**
|
519
|
* excel export
|
520
|
*/
|
521
|
Button addColumnButton = new Button(toolbarComposite, SWT.PUSH);
|
522
|
addColumnButton.setImage(ImageResources.getImage(ImageResources.EXPORT));
|
523
|
addColumnButton.addSelectionListener(new SelectionAdapter() {
|
524
|
@Override
|
525
|
public void widgetSelected(SelectionEvent e) {
|
526
|
natTable.doCommand(
|
527
|
new ExportCommand(
|
528
|
natTable.getConfigRegistry(),
|
529
|
natTable.getShell()));
|
530
|
}
|
531
|
});
|
532
|
|
533
|
/**
|
534
|
* Add description button
|
535
|
*/
|
536
|
Button btnAddDescription = new Button(parent, SWT.PUSH);
|
537
|
btnAddDescription.setImage(ImageResources.getImage(ImageResources.ADD_ICON));
|
538
|
btnAddDescription.addSelectionListener(new SelectionAdapter() {
|
539
|
@Override
|
540
|
public void widgetSelected(SelectionEvent e) {
|
541
|
SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(natTable.getShell(), workingSet);
|
542
|
if(dialog.open()==Window.OK){
|
543
|
Collection<SpecimenOrObservationBase> specimens = dialog.getSpecimen();
|
544
|
boolean hasAdded = false;
|
545
|
for (SpecimenOrObservationBase specimen : specimens) {
|
546
|
SpecimenDescription description = getDescriptionForWorkingSet(specimen);
|
547
|
if(!workingSet.getDescriptions().contains(description)){
|
548
|
CharacterMatrix.this.descriptions.add(new RowWrapper(description));
|
549
|
workingSet.addDescription(description);
|
550
|
hasAdded = true;
|
551
|
}
|
552
|
}
|
553
|
if(hasAdded){
|
554
|
setDirty();
|
555
|
}
|
556
|
}
|
557
|
}
|
558
|
});
|
559
|
parent.layout();
|
560
|
}
|
561
|
|
562
|
private SpecimenDescription getDescriptionForWorkingSet(SpecimenOrObservationBase specimen){
|
563
|
Set<SpecimenDescription> descriptions = specimen.getDescriptions();
|
564
|
if(descriptions!=null){
|
565
|
Set<Feature> features = workingSet.getDescriptiveSystem().getDistinctFeatures();
|
566
|
for (SpecimenDescription specimenDescription : descriptions) {
|
567
|
Set<Feature> specimenDescriptionFeatures = new HashSet<>();
|
568
|
for (DescriptionElementBase descriptionElementBase : specimenDescription.getElements()) {
|
569
|
specimenDescriptionFeatures.add(descriptionElementBase.getFeature());
|
570
|
}
|
571
|
if(specimenDescriptionFeatures.containsAll(features)){
|
572
|
return specimenDescription;
|
573
|
}
|
574
|
}
|
575
|
}
|
576
|
//Create new specimen description if no match was found
|
577
|
setDirty();
|
578
|
SpecimenDescription newDesription = SpecimenDescription.NewInstance(specimen);
|
579
|
newDesription.setTitleCache("WorkingSet "+workingSet.getLabel()+" "+newDesription.generateTitle(), true);
|
580
|
return newDesription;
|
581
|
|
582
|
}
|
583
|
|
584
|
private void initLabels(final ColumnOverrideLabelAccumulator columnLabelAccumulator,
|
585
|
int index, Feature feature) {
|
586
|
|
587
|
columnLabelAccumulator.registerColumnOverrides(index+LEADING_COLUMN_COUNT, MatrixUtility.getProperty(feature));
|
588
|
indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
|
589
|
|
590
|
String featureLabel = feature.getLabel();
|
591
|
String property = featureLabel;
|
592
|
//show unit for quantitative data
|
593
|
if(feature.isSupportsQuantitativeData()){
|
594
|
Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
|
595
|
if(recommendedMeasurementUnits.size()!=1){
|
596
|
MessagingUtils.warningDialog("Column initialization problem", CharacterMatrix.class,
|
597
|
String.format("Only one unit is allowed for quantitative data: %s", feature.getLabel()));
|
598
|
return;
|
599
|
}
|
600
|
MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
|
601
|
featureLabel += " ["+unit.getLabel()+"]";
|
602
|
}
|
603
|
propertyToLabelMap.put(property, featureLabel);
|
604
|
}
|
605
|
|
606
|
private void registerColumnConfiguration(Feature feature, IConfigRegistry configRegistry) {
|
607
|
//make cell editable
|
608
|
configRegistry.registerConfigAttribute(
|
609
|
EditConfigAttributes.CELL_EDITABLE_RULE,
|
610
|
IEditableRule.ALWAYS_EDITABLE,
|
611
|
DisplayMode.EDIT,
|
612
|
MatrixUtility.getProperty(feature)
|
613
|
);
|
614
|
if(feature.isSupportsQuantitativeData()){
|
615
|
//add display converter for string representation
|
616
|
configRegistry.registerConfigAttribute(
|
617
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
618
|
new QuantitativeDataDisplayConverter(),
|
619
|
DisplayMode.NORMAL,
|
620
|
MatrixUtility.getProperty(feature));
|
621
|
//register quantitative editor
|
622
|
configRegistry.registerConfigAttribute(
|
623
|
EditConfigAttributes.CELL_EDITOR,
|
624
|
new QuantitativeDataCellEditor(feature.getRecommendedStatisticalMeasures(), this),
|
625
|
DisplayMode.EDIT,
|
626
|
MatrixUtility.getProperty(feature));
|
627
|
}
|
628
|
else if(feature.isSupportsCategoricalData()){
|
629
|
//add display converter for string representation
|
630
|
configRegistry.registerConfigAttribute(
|
631
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
632
|
new CategoricalDataDisplayConverter(),
|
633
|
DisplayMode.NORMAL,
|
634
|
MatrixUtility.getProperty(feature));
|
635
|
|
636
|
//add combo box cell editor
|
637
|
CategoricalDataCellEditor comboBoxCellEditor = new CategoricalDataCellEditor(new IComboBoxDataProvider() {
|
638
|
|
639
|
@Override
|
640
|
public List<?> getValues(int columnIndex, int rowIndex) {
|
641
|
List<State> states = new ArrayList<>();
|
642
|
Feature feature = indexToFeatureMap.get(columnIndex);
|
643
|
if(feature.isSupportsCategoricalData()){
|
644
|
Set<TermVocabulary<State>> stateVocs = feature.getSupportedCategoricalEnumerations();
|
645
|
for (TermVocabulary<State> voc : stateVocs) {
|
646
|
states.addAll(voc.getTerms());
|
647
|
}
|
648
|
}
|
649
|
return states;
|
650
|
}
|
651
|
}, 5, this);
|
652
|
//register editor
|
653
|
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
|
654
|
comboBoxCellEditor,
|
655
|
DisplayMode.EDIT,
|
656
|
MatrixUtility.getProperty(feature));
|
657
|
|
658
|
}
|
659
|
|
660
|
}
|
661
|
|
662
|
private List<RowWrapper> getDescriptions(WorkingSet workingSet) {
|
663
|
List<RowWrapper> rowWrappers = new ArrayList<>();
|
664
|
Set<DescriptionBase> wsDescriptions = workingSet.getDescriptions();
|
665
|
for (DescriptionBase descriptionBase : wsDescriptions) {
|
666
|
if(descriptionBase instanceof SpecimenDescription){
|
667
|
rowWrappers.add(new RowWrapper((SpecimenDescription) descriptionBase));
|
668
|
}
|
669
|
}
|
670
|
return rowWrappers;
|
671
|
}
|
672
|
|
673
|
public Map<Integer, Feature> getIndexToFeatureMap() {
|
674
|
return indexToFeatureMap;
|
675
|
}
|
676
|
|
677
|
public LinkedMap<String, String> getPropertyToLabelMap() {
|
678
|
return propertyToLabelMap;
|
679
|
}
|
680
|
|
681
|
public void setDirty() {
|
682
|
this.dirty.setDirty(true);
|
683
|
}
|
684
|
|
685
|
public NatTable getNatTable() {
|
686
|
return natTable;
|
687
|
}
|
688
|
|
689
|
@Persist
|
690
|
@Override
|
691
|
public void save(IProgressMonitor monitor) {
|
692
|
CdmStore.getService(IWorkingSetService.class).merge(workingSet, true);
|
693
|
conversation.commit();
|
694
|
dirty.setDirty(false);
|
695
|
}
|
696
|
|
697
|
@Focus
|
698
|
public void setFocus(){
|
699
|
if(conversation!=null){
|
700
|
conversation.bind();
|
701
|
}
|
702
|
if(cdmEntitySession != null) {
|
703
|
cdmEntitySession.bind();
|
704
|
}
|
705
|
}
|
706
|
|
707
|
@PreDestroy
|
708
|
public void dispose(){
|
709
|
if (conversation != null) {
|
710
|
conversation.close();
|
711
|
conversation = null;
|
712
|
}
|
713
|
if(cdmEntitySession != null) {
|
714
|
cdmEntitySession.dispose();
|
715
|
cdmEntitySession = null;
|
716
|
}
|
717
|
dirty.setDirty(false);
|
718
|
if(natTableState!=null){
|
719
|
try (FileOutputStream tableStateStream =
|
720
|
new FileOutputStream(getStatePropertiesFile())) {
|
721
|
natTableState.store(tableStateStream, null);
|
722
|
} catch (IOException ioe) {
|
723
|
ioe.printStackTrace();
|
724
|
}
|
725
|
}
|
726
|
}
|
727
|
|
728
|
private File getStatePropertiesFile() {
|
729
|
return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
|
730
|
}
|
731
|
|
732
|
/**
|
733
|
* {@inheritDoc}
|
734
|
*/
|
735
|
@Override
|
736
|
public void update(CdmDataChangeMap arg0) {
|
737
|
}
|
738
|
|
739
|
/**
|
740
|
* {@inheritDoc}
|
741
|
*/
|
742
|
@Override
|
743
|
public ConversationHolder getConversationHolder() {
|
744
|
return conversation;
|
745
|
}
|
746
|
|
747
|
/**
|
748
|
* {@inheritDoc}
|
749
|
*/
|
750
|
@Override
|
751
|
public void changed(Object element) {
|
752
|
setDirty();
|
753
|
natTable.refresh();
|
754
|
}
|
755
|
|
756
|
/**
|
757
|
* {@inheritDoc}
|
758
|
*/
|
759
|
@Override
|
760
|
public void forceDirty() {
|
761
|
setDirty();
|
762
|
}
|
763
|
|
764
|
|
765
|
/**
|
766
|
* {@inheritDoc}
|
767
|
*/
|
768
|
@Override
|
769
|
public ICdmEntitySession getCdmEntitySession() {
|
770
|
return cdmEntitySession;
|
771
|
}
|
772
|
|
773
|
|
774
|
/**
|
775
|
* {@inheritDoc}
|
776
|
*/
|
777
|
@Override
|
778
|
public Collection<WorkingSet> getRootEntities() {
|
779
|
return Collections.singleton(this.workingSet);
|
780
|
}
|
781
|
|
782
|
|
783
|
/**
|
784
|
* {@inheritDoc}
|
785
|
*/
|
786
|
@Override
|
787
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
788
|
Map<Object, List<String>> propertyMap = new HashMap<>();
|
789
|
propertyMap.put(SpecimenOrObservationBase.class,WS_PROPERTY_PATH);
|
790
|
return propertyMap;
|
791
|
}
|
792
|
|
793
|
}
|