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.Collection;
|
17
|
import java.util.Collections;
|
18
|
import java.util.HashMap;
|
19
|
import java.util.List;
|
20
|
import java.util.Map;
|
21
|
import java.util.Properties;
|
22
|
import java.util.Set;
|
23
|
import java.util.UUID;
|
24
|
|
25
|
import javax.annotation.PostConstruct;
|
26
|
import javax.annotation.PreDestroy;
|
27
|
import javax.inject.Inject;
|
28
|
|
29
|
import org.apache.commons.collections4.map.LinkedMap;
|
30
|
import org.eclipse.core.runtime.IProgressMonitor;
|
31
|
import org.eclipse.e4.ui.di.Focus;
|
32
|
import org.eclipse.e4.ui.di.Persist;
|
33
|
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
34
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
35
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
36
|
import org.eclipse.jface.layout.GridDataFactory;
|
37
|
import org.eclipse.jface.viewers.StructuredSelection;
|
38
|
import org.eclipse.nebula.widgets.nattable.NatTable;
|
39
|
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
|
40
|
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
|
41
|
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
|
42
|
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
|
43
|
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
|
44
|
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
|
45
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
46
|
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
|
47
|
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
|
48
|
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
|
49
|
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
|
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.grid.data.DefaultColumnHeaderDataProvider;
|
53
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
|
54
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
|
55
|
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
|
56
|
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
|
57
|
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
|
58
|
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
|
59
|
import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
|
60
|
import org.eclipse.nebula.widgets.nattable.hideshow.RowHideShowLayer;
|
61
|
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
|
62
|
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
|
63
|
import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
|
64
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator;
|
65
|
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
|
66
|
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
|
67
|
import org.eclipse.nebula.widgets.nattable.persistence.PersistenceHelper;
|
68
|
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommand;
|
69
|
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler;
|
70
|
import org.eclipse.nebula.widgets.nattable.persistence.command.IStateChangedListener;
|
71
|
import org.eclipse.nebula.widgets.nattable.persistence.command.StateChangeEvent;
|
72
|
import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
|
73
|
import org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer;
|
74
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
75
|
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
|
76
|
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
|
77
|
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
|
78
|
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
|
79
|
import org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration;
|
80
|
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
|
81
|
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
|
82
|
import org.eclipse.swt.SWT;
|
83
|
import org.eclipse.swt.events.SelectionAdapter;
|
84
|
import org.eclipse.swt.events.SelectionEvent;
|
85
|
import org.eclipse.swt.layout.GridData;
|
86
|
import org.eclipse.swt.layout.GridLayout;
|
87
|
import org.eclipse.swt.widgets.Button;
|
88
|
import org.eclipse.swt.widgets.Combo;
|
89
|
import org.eclipse.swt.widgets.Composite;
|
90
|
|
91
|
import ca.odell.glazedlists.EventList;
|
92
|
import ca.odell.glazedlists.GlazedLists;
|
93
|
import ca.odell.glazedlists.SortedList;
|
94
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
95
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
96
|
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
97
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
98
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
99
|
import eu.etaxonomy.cdm.model.description.Feature;
|
100
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
101
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
102
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
103
|
import eu.etaxonomy.cdm.model.description.State;
|
104
|
import eu.etaxonomy.cdm.model.description.WorkingSet;
|
105
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
106
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataCellEditor;
|
107
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataDisplayConverter;
|
108
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataCellEditor;
|
109
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataDisplayConverter;
|
110
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
|
111
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
112
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
113
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
114
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
115
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
116
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
117
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
118
|
|
119
|
/**
|
120
|
* @author pplitzner
|
121
|
* @since Nov 26, 2017
|
122
|
*
|
123
|
*/
|
124
|
public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails, IConversationEnabled, IDirtyMarkable{
|
125
|
|
126
|
private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties";
|
127
|
|
128
|
private static final int LEADING_COLUMN_COUNT = 4;
|
129
|
private static final String TAXON_COLUMN = "taxon_column";
|
130
|
private static final String COLLECTOR_COLUMN = "collector_column";
|
131
|
private static final String IDENTIFIER_COLUMN = "identifier_column";
|
132
|
private static final String COUNTRY_COLUMN = "country_column";
|
133
|
|
134
|
private WorkingSet workingSet;
|
135
|
|
136
|
private Composite parent;
|
137
|
|
138
|
private ConversationHolder conversation;
|
139
|
|
140
|
@Inject
|
141
|
private ESelectionService selService;
|
142
|
|
143
|
@Inject
|
144
|
private MDirtyable dirty;
|
145
|
|
146
|
@Inject
|
147
|
private MPart thisPart;
|
148
|
|
149
|
private NatTable natTable;
|
150
|
|
151
|
private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
|
152
|
|
153
|
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
|
154
|
|
155
|
private Properties natTableState;
|
156
|
|
157
|
@PostConstruct
|
158
|
public void create(Composite parent) {
|
159
|
if(CdmStore.isActive() && conversation==null){
|
160
|
conversation = CdmStore.createConversation();
|
161
|
}
|
162
|
else{
|
163
|
return;
|
164
|
}
|
165
|
parent.setLayout(new GridLayout());
|
166
|
this.parent = parent;
|
167
|
}
|
168
|
|
169
|
|
170
|
public void init(UUID workingSetUuid) {
|
171
|
this.workingSet = CdmStore.getService(IWorkingSetService.class).load(workingSetUuid);
|
172
|
thisPart.setLabel(workingSet.getLabel());
|
173
|
|
174
|
Composite toolbarComposite = new Composite(parent, SWT.NONE);
|
175
|
toolbarComposite.setLayout(new GridLayout(2, false));
|
176
|
toolbarComposite.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
|
177
|
|
178
|
//get features/columns stored in working set
|
179
|
FeatureTree tree = workingSet.getDescriptiveSystem();
|
180
|
List<Feature> features = new ArrayList<>(tree.getDistinctFeatures());
|
181
|
Collections.sort(features);
|
182
|
|
183
|
|
184
|
EventList<RowWrapper> descriptions = GlazedLists.eventList(getDescriptions(workingSet));
|
185
|
SortedList<RowWrapper> sortedList = new SortedList<>(descriptions, null);
|
186
|
|
187
|
/**
|
188
|
* data provider
|
189
|
*/
|
190
|
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
|
191
|
IDataProvider bodyDataProvider = new ListDataProvider<RowWrapper>(sortedList, columnPropertyAccessor);
|
192
|
|
193
|
/**
|
194
|
* BODY layer
|
195
|
*/
|
196
|
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
|
197
|
|
198
|
//register labels for columns
|
199
|
final ColumnOverrideLabelAccumulator columnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
|
200
|
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
|
201
|
propertyToLabelMap.put(TAXON_COLUMN, "Taxon");
|
202
|
columnLabelAccumulator.registerColumnOverrides(0, TAXON_COLUMN);
|
203
|
propertyToLabelMap.put(COLLECTOR_COLUMN, "Collector + No");
|
204
|
columnLabelAccumulator.registerColumnOverrides(1, COLLECTOR_COLUMN);
|
205
|
propertyToLabelMap.put(IDENTIFIER_COLUMN, "Identifier");
|
206
|
columnLabelAccumulator.registerColumnOverrides(2, IDENTIFIER_COLUMN);
|
207
|
propertyToLabelMap.put(COUNTRY_COLUMN, "Country");
|
208
|
columnLabelAccumulator.registerColumnOverrides(3, COUNTRY_COLUMN);
|
209
|
for(int i=0;i<features.size();i++){
|
210
|
Feature feature = features.get(i);
|
211
|
initLabels(columnLabelAccumulator, i, feature);
|
212
|
}
|
213
|
|
214
|
GlazedListsEventLayer<RowWrapper> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, sortedList);
|
215
|
|
216
|
RowReorderLayer rowReorderLayer = new RowReorderLayer(eventLayer);
|
217
|
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(rowReorderLayer);
|
218
|
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
|
219
|
RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(columnHideShowLayer);
|
220
|
SelectionLayer selectionLayer = new SelectionLayer(rowHideShowLayer);
|
221
|
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
|
222
|
|
223
|
/**
|
224
|
* column header layer
|
225
|
*/
|
226
|
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
|
227
|
propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
|
228
|
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
|
229
|
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
|
230
|
|
231
|
ConfigRegistry configRegistry = new ConfigRegistry();
|
232
|
|
233
|
// add the SortHeaderLayer to the column header layer stack
|
234
|
// as we use GlazedLists, we use the GlazedListsSortModel which
|
235
|
// delegates the sorting to the SortedList
|
236
|
final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
|
237
|
columnHeaderLayer,
|
238
|
new GlazedListsSortModel<>(
|
239
|
sortedList,
|
240
|
columnPropertyAccessor,
|
241
|
configRegistry,
|
242
|
columnHeaderDataLayer));
|
243
|
|
244
|
|
245
|
/**
|
246
|
* row header layer
|
247
|
*/
|
248
|
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
|
249
|
DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider, 40, 20);
|
250
|
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
|
251
|
|
252
|
|
253
|
/**
|
254
|
* corner layer
|
255
|
*/
|
256
|
ILayer cornerLayer = new CornerLayer(
|
257
|
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
|
258
|
rowHeaderLayer, sortHeaderLayer);
|
259
|
|
260
|
|
261
|
/**
|
262
|
* GRID layer (composition of all other layers)
|
263
|
*/
|
264
|
GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
|
265
|
|
266
|
|
267
|
natTable = new NatTable(parent, gridLayer, false);
|
268
|
|
269
|
|
270
|
/**
|
271
|
* CONFIGURATION
|
272
|
*/
|
273
|
natTable.setConfigRegistry(configRegistry);
|
274
|
|
275
|
|
276
|
//add default configuration because autoconfigure is set to false in constructor
|
277
|
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
|
278
|
|
279
|
// override the default sort configuration and change the mouse bindings
|
280
|
// to sort on a single click
|
281
|
natTable.addConfiguration(new SingleClickSortConfiguration());
|
282
|
|
283
|
// add the header menu configuration for adding the column header menu
|
284
|
// with hide/show actions
|
285
|
natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {
|
286
|
|
287
|
@Override
|
288
|
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
|
289
|
return super.createColumnHeaderMenu(natTable)
|
290
|
.withHideColumnMenuItem()
|
291
|
.withShowAllColumnsMenuItem()
|
292
|
.withStateManagerMenuItemProvider();
|
293
|
}
|
294
|
|
295
|
@Override
|
296
|
protected PopupMenuBuilder createRowHeaderMenu(NatTable natTable) {
|
297
|
return super.createRowHeaderMenu(natTable)
|
298
|
.withHideRowMenuItem()
|
299
|
.withShowAllRowsMenuItem()
|
300
|
.withStateManagerMenuItemProvider();
|
301
|
}
|
302
|
|
303
|
@Override
|
304
|
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
|
305
|
return super.createCornerMenu(natTable)
|
306
|
.withShowAllColumnsMenuItem().withShowAllRowsMenuItem()
|
307
|
.withStateManagerMenuItemProvider();
|
308
|
}
|
309
|
});
|
310
|
|
311
|
// add custom configuration for data conversion and add column labels
|
312
|
viewportLayer.addConfiguration(new AbstractRegistryConfiguration() {
|
313
|
@Override
|
314
|
public void configureRegistry(IConfigRegistry configRegistry) {
|
315
|
//add display converter for string representation
|
316
|
configRegistry.registerConfigAttribute(
|
317
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
318
|
new SupplementalInfoDisplayConverter(),
|
319
|
DisplayMode.NORMAL,
|
320
|
TAXON_COLUMN);
|
321
|
configRegistry.registerConfigAttribute(
|
322
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
323
|
new SupplementalInfoDisplayConverter(),
|
324
|
DisplayMode.NORMAL,
|
325
|
COLLECTOR_COLUMN);
|
326
|
configRegistry.registerConfigAttribute(
|
327
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
328
|
new SupplementalInfoDisplayConverter(),
|
329
|
DisplayMode.NORMAL,
|
330
|
IDENTIFIER_COLUMN);
|
331
|
configRegistry.registerConfigAttribute(
|
332
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
333
|
new SupplementalInfoDisplayConverter(),
|
334
|
DisplayMode.NORMAL,
|
335
|
COUNTRY_COLUMN);
|
336
|
features.forEach(feature->registerColumnConfiguration(feature, configRegistry));
|
337
|
}
|
338
|
|
339
|
});
|
340
|
|
341
|
// add the ExportCommandHandler to the ViewportLayer in order to make
|
342
|
// exporting work
|
343
|
viewportLayer.registerCommandHandler(new ExportCommandHandler(viewportLayer));
|
344
|
|
345
|
//propagate single cell selection
|
346
|
natTable.addLayerListener(new ILayerListener() {
|
347
|
@Override
|
348
|
public void handleLayerEvent(ILayerEvent event) {
|
349
|
if(event instanceof CellSelectionEvent){
|
350
|
CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
|
351
|
Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
|
352
|
StructuredSelection selection = new StructuredSelection();
|
353
|
if(selectedCells.size()==1){
|
354
|
ILayerCell cell = selectedCells.iterator().next();
|
355
|
selection = new StructuredSelection(cell.getDataValue());
|
356
|
}
|
357
|
selService.setSelection(selection);
|
358
|
}
|
359
|
}
|
360
|
});
|
361
|
|
362
|
natTable.configure();
|
363
|
|
364
|
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
|
365
|
|
366
|
/**
|
367
|
* Table state persistence
|
368
|
*/
|
369
|
natTableState = new Properties();
|
370
|
//load persisted state
|
371
|
File statePropertiesFile = getStatePropertiesFile();
|
372
|
FileInputStream inputStream;
|
373
|
try {
|
374
|
inputStream = new FileInputStream(statePropertiesFile);
|
375
|
natTableState.load(inputStream);
|
376
|
} catch (IOException e) {
|
377
|
MessagingUtils.info("No initial state properties file found for character matrix");
|
378
|
}
|
379
|
|
380
|
DisplayPersistenceDialogCommandHandler handler =
|
381
|
new DisplayPersistenceDialogCommandHandler(natTableState, natTable);
|
382
|
gridLayer.registerCommandHandler(handler);
|
383
|
// create a combobox for showing the available view states
|
384
|
Combo comboStates = new Combo(toolbarComposite, SWT.DROP_DOWN);
|
385
|
comboStates.setItems(PersistenceHelper
|
386
|
.getAvailableStates(natTableState)
|
387
|
.toArray(new String[] {}));
|
388
|
comboStates.addSelectionListener(new SelectionAdapter() {
|
389
|
|
390
|
@Override
|
391
|
public void widgetSelected(SelectionEvent e) {
|
392
|
int index = comboStates.getSelectionIndex();
|
393
|
if (index >= 0) {
|
394
|
String selected = comboStates.getItem(index);
|
395
|
// load the state
|
396
|
natTable.loadState(selected, natTableState);
|
397
|
}
|
398
|
}
|
399
|
});
|
400
|
|
401
|
// add listener to update the combo on view state management changes
|
402
|
handler.addStateChangeListener(new IStateChangedListener() {
|
403
|
|
404
|
@Override
|
405
|
public void handleStateChange(StateChangeEvent event) {
|
406
|
comboStates.setItems(PersistenceHelper
|
407
|
.getAvailableStates(natTableState)
|
408
|
.toArray(new String[] {}));
|
409
|
}
|
410
|
});
|
411
|
|
412
|
// add button to show dialog
|
413
|
Button btnManageState = new Button(toolbarComposite, SWT.PUSH);
|
414
|
btnManageState.setImage(ImageResources.getImage(ImageResources.SETTINGS));
|
415
|
btnManageState.addSelectionListener(new SelectionAdapter() {
|
416
|
@Override
|
417
|
public void widgetSelected(SelectionEvent e) {
|
418
|
natTable.doCommand(new DisplayPersistenceDialogCommand(natTable));
|
419
|
}
|
420
|
});
|
421
|
|
422
|
/**
|
423
|
* excel export
|
424
|
*/
|
425
|
// Button addColumnButton = new Button(toolbarComposite, SWT.PUSH);
|
426
|
// addColumnButton.setImage(ImageResources.getImage(ImageResources.EXPORT));
|
427
|
// addColumnButton.addSelectionListener(new SelectionAdapter() {
|
428
|
// @Override
|
429
|
// public void widgetSelected(SelectionEvent e) {
|
430
|
// natTable.doCommand(
|
431
|
// new ExportCommand(
|
432
|
// natTable.getConfigRegistry(),
|
433
|
// natTable.getShell()));
|
434
|
// }
|
435
|
// });
|
436
|
|
437
|
parent.layout();
|
438
|
}
|
439
|
|
440
|
private void initLabels(final ColumnOverrideLabelAccumulator columnLabelAccumulator,
|
441
|
int index, Feature feature) {
|
442
|
|
443
|
columnLabelAccumulator.registerColumnOverrides(index+LEADING_COLUMN_COUNT, getProperty(feature));
|
444
|
indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
|
445
|
|
446
|
String featureLabel = feature.getLabel();
|
447
|
String property = featureLabel;
|
448
|
//show unit for quantitative data
|
449
|
if(feature.isSupportsQuantitativeData()){
|
450
|
Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
|
451
|
if(recommendedMeasurementUnits.size()!=1){
|
452
|
MessagingUtils.warningDialog("Column initialization problem", CharacterMatrix.class,
|
453
|
String.format("Only one unit is allowed for quantitative data: %s", feature.getLabel()));
|
454
|
return;
|
455
|
}
|
456
|
MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
|
457
|
featureLabel += " ["+unit.getLabel()+"]";
|
458
|
}
|
459
|
propertyToLabelMap.put(property, featureLabel);
|
460
|
}
|
461
|
|
462
|
private void registerColumnConfiguration(Feature feature, IConfigRegistry configRegistry) {
|
463
|
//make cell editable
|
464
|
configRegistry.registerConfigAttribute(
|
465
|
EditConfigAttributes.CELL_EDITABLE_RULE,
|
466
|
IEditableRule.ALWAYS_EDITABLE,
|
467
|
DisplayMode.EDIT,
|
468
|
getProperty(feature)
|
469
|
);
|
470
|
if(feature.isSupportsQuantitativeData()){
|
471
|
//add display converter for string representation
|
472
|
configRegistry.registerConfigAttribute(
|
473
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
474
|
new QuantitativeDataDisplayConverter(),
|
475
|
DisplayMode.NORMAL,
|
476
|
getProperty(feature));
|
477
|
//register quantitative editor
|
478
|
configRegistry.registerConfigAttribute(
|
479
|
EditConfigAttributes.CELL_EDITOR,
|
480
|
new QuantitativeDataCellEditor(feature.getRecommendedStatisticalMeasures(), this),
|
481
|
DisplayMode.EDIT,
|
482
|
getProperty(feature));
|
483
|
}
|
484
|
else if(feature.isSupportsCategoricalData()){
|
485
|
//add display converter for string representation
|
486
|
configRegistry.registerConfigAttribute(
|
487
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
488
|
new CategoricalDataDisplayConverter(),
|
489
|
DisplayMode.NORMAL,
|
490
|
getProperty(feature));
|
491
|
|
492
|
//add combo box cell editor
|
493
|
CategoricalDataCellEditor comboBoxCellEditor = new CategoricalDataCellEditor(new IComboBoxDataProvider() {
|
494
|
|
495
|
@Override
|
496
|
public List<?> getValues(int columnIndex, int rowIndex) {
|
497
|
List<State> states = new ArrayList<>();
|
498
|
Feature feature = indexToFeatureMap.get(columnIndex);
|
499
|
if(feature.isSupportsCategoricalData()){
|
500
|
Set<TermVocabulary<State>> stateVocs = feature.getSupportedCategoricalEnumerations();
|
501
|
for (TermVocabulary<State> voc : stateVocs) {
|
502
|
states.addAll(voc.getTerms());
|
503
|
}
|
504
|
}
|
505
|
return states;
|
506
|
}
|
507
|
}, 5, this);
|
508
|
//register editor
|
509
|
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
|
510
|
comboBoxCellEditor,
|
511
|
DisplayMode.EDIT,
|
512
|
getProperty(feature));
|
513
|
|
514
|
}
|
515
|
|
516
|
}
|
517
|
|
518
|
private List<RowWrapper> getDescriptions(WorkingSet workingSet) {
|
519
|
List<RowWrapper> rowWrappers = new ArrayList<>();
|
520
|
Set<DescriptionBase> wsDescriptions = workingSet.getDescriptions();
|
521
|
for (DescriptionBase descriptionBase : wsDescriptions) {
|
522
|
if(descriptionBase instanceof SpecimenDescription){
|
523
|
rowWrappers.add(new RowWrapper((SpecimenDescription) descriptionBase));
|
524
|
}
|
525
|
}
|
526
|
return rowWrappers;
|
527
|
}
|
528
|
|
529
|
private String getProperty(Feature feature){
|
530
|
return feature.getLabel();
|
531
|
}
|
532
|
|
533
|
public Map<Integer, Feature> getIndexToFeatureMap() {
|
534
|
return indexToFeatureMap;
|
535
|
}
|
536
|
|
537
|
public LinkedMap<String, String> getPropertyToLabelMap() {
|
538
|
return propertyToLabelMap;
|
539
|
}
|
540
|
|
541
|
public void setDirty() {
|
542
|
this.dirty.setDirty(true);
|
543
|
}
|
544
|
|
545
|
public NatTable getNatTable() {
|
546
|
return natTable;
|
547
|
}
|
548
|
|
549
|
@Persist
|
550
|
@Override
|
551
|
public void save(IProgressMonitor monitor) {
|
552
|
CdmStore.getService(IWorkingSetService.class).merge(workingSet, true);
|
553
|
conversation.commit();
|
554
|
dirty.setDirty(false);
|
555
|
}
|
556
|
|
557
|
@Focus
|
558
|
public void setFocus(){
|
559
|
if(conversation!=null){
|
560
|
conversation.bind();
|
561
|
}
|
562
|
}
|
563
|
|
564
|
@PreDestroy
|
565
|
public void dispose(){
|
566
|
if(conversation!=null){
|
567
|
conversation.close();
|
568
|
conversation = null;
|
569
|
}
|
570
|
try (FileOutputStream tableStateStream =
|
571
|
new FileOutputStream(getStatePropertiesFile())) {
|
572
|
natTableState.store(tableStateStream, null);
|
573
|
} catch (IOException ioe) {
|
574
|
ioe.printStackTrace();
|
575
|
}
|
576
|
}
|
577
|
|
578
|
|
579
|
private File getStatePropertiesFile() {
|
580
|
return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
|
581
|
}
|
582
|
|
583
|
|
584
|
/**
|
585
|
* {@inheritDoc}
|
586
|
*/
|
587
|
@Override
|
588
|
public void update(CdmDataChangeMap arg0) {
|
589
|
}
|
590
|
|
591
|
|
592
|
/**
|
593
|
* {@inheritDoc}
|
594
|
*/
|
595
|
@Override
|
596
|
public ConversationHolder getConversationHolder() {
|
597
|
return conversation;
|
598
|
}
|
599
|
|
600
|
|
601
|
/**
|
602
|
* {@inheritDoc}
|
603
|
*/
|
604
|
@Override
|
605
|
public void changed(Object element) {
|
606
|
dirty.setDirty(true);
|
607
|
natTable.refresh();
|
608
|
}
|
609
|
|
610
|
|
611
|
/**
|
612
|
* {@inheritDoc}
|
613
|
*/
|
614
|
@Override
|
615
|
public void forceDirty() {
|
616
|
dirty.setDirty(true);
|
617
|
}
|
618
|
|
619
|
}
|