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.IOException;
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.Collection;
|
16
|
import java.util.HashMap;
|
17
|
import java.util.HashSet;
|
18
|
import java.util.List;
|
19
|
import java.util.Map;
|
20
|
import java.util.Properties;
|
21
|
import java.util.Set;
|
22
|
import java.util.stream.Collectors;
|
23
|
|
24
|
import org.apache.commons.collections4.map.LinkedMap;
|
25
|
import org.eclipse.core.runtime.ICoreRunnable;
|
26
|
import org.eclipse.core.runtime.IProgressMonitor;
|
27
|
import org.eclipse.core.runtime.jobs.Job;
|
28
|
import org.eclipse.jface.layout.GridDataFactory;
|
29
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
30
|
import org.eclipse.jface.viewers.ComboViewer;
|
31
|
import org.eclipse.jface.viewers.LabelProvider;
|
32
|
import org.eclipse.jface.viewers.StructuredSelection;
|
33
|
import org.eclipse.jface.window.Window;
|
34
|
import org.eclipse.nebula.widgets.nattable.NatTable;
|
35
|
import org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand;
|
36
|
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
|
37
|
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
|
38
|
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
|
39
|
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
|
40
|
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
|
41
|
import org.eclipse.nebula.widgets.nattable.config.IEditableRule;
|
42
|
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
|
43
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
44
|
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
|
45
|
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
|
46
|
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand;
|
47
|
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
|
48
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
|
49
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
|
50
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeData;
|
51
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeRowModel;
|
52
|
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
|
53
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeHelper;
|
54
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
|
55
|
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
|
56
|
import org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand;
|
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.grid.layer.config.DefaultRowStyleConfiguration;
|
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.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.config.DefaultColumnHeaderStyleConfiguration;
|
74
|
import org.eclipse.nebula.widgets.nattable.layer.config.DefaultRowHeaderStyleConfiguration;
|
75
|
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
|
76
|
import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
|
77
|
import org.eclipse.nebula.widgets.nattable.persistence.PersistenceHelper;
|
78
|
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommand;
|
79
|
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler;
|
80
|
import org.eclipse.nebula.widgets.nattable.persistence.command.IStateChangedListener;
|
81
|
import org.eclipse.nebula.widgets.nattable.persistence.command.StateChangeEvent;
|
82
|
import org.eclipse.nebula.widgets.nattable.persistence.gui.PersistenceDialog;
|
83
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
84
|
import org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionStyleConfiguration;
|
85
|
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
|
86
|
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
|
87
|
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
|
88
|
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
|
89
|
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
|
90
|
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
|
91
|
import org.eclipse.nebula.widgets.nattable.style.Style;
|
92
|
import org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum;
|
93
|
import org.eclipse.nebula.widgets.nattable.summaryrow.DefaultSummaryRowConfiguration;
|
94
|
import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
|
95
|
import org.eclipse.nebula.widgets.nattable.summaryrow.ISummaryProvider;
|
96
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowConfigAttributes;
|
97
|
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
|
98
|
import org.eclipse.nebula.widgets.nattable.tree.ITreeRowModel;
|
99
|
import org.eclipse.nebula.widgets.nattable.tree.TreeLayer;
|
100
|
import org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand;
|
101
|
import org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandAllCommand;
|
102
|
import org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration;
|
103
|
import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
|
104
|
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
|
105
|
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
|
106
|
import org.eclipse.swt.SWT;
|
107
|
import org.eclipse.swt.events.SelectionAdapter;
|
108
|
import org.eclipse.swt.events.SelectionEvent;
|
109
|
import org.eclipse.swt.graphics.Color;
|
110
|
import org.eclipse.swt.graphics.FontData;
|
111
|
import org.eclipse.swt.layout.GridData;
|
112
|
import org.eclipse.swt.layout.GridLayout;
|
113
|
import org.eclipse.swt.layout.RowLayout;
|
114
|
import org.eclipse.swt.widgets.Button;
|
115
|
import org.eclipse.swt.widgets.Composite;
|
116
|
import org.eclipse.swt.widgets.Label;
|
117
|
|
118
|
import ca.odell.glazedlists.BasicEventList;
|
119
|
import ca.odell.glazedlists.EventList;
|
120
|
import ca.odell.glazedlists.SortedList;
|
121
|
import ca.odell.glazedlists.TreeList;
|
122
|
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
123
|
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
|
124
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
125
|
import eu.etaxonomy.cdm.model.description.Feature;
|
126
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
127
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
128
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
129
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
130
|
import eu.etaxonomy.cdm.model.description.State;
|
131
|
import eu.etaxonomy.cdm.model.description.WorkingSet;
|
132
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
133
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataCellEditor;
|
134
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataDisplayConverter;
|
135
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataCellEditor;
|
136
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataDisplayConverter;
|
137
|
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
|
138
|
import eu.etaxonomy.taxeditor.model.ColorResources;
|
139
|
import eu.etaxonomy.taxeditor.model.DescriptionHelper;
|
140
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
141
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
142
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
143
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
144
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
145
|
|
146
|
/**
|
147
|
* Character matrix editor for editing specimen/taxon descriptions in a table
|
148
|
* @author pplitzner
|
149
|
* @since Nov 26, 2017
|
150
|
*
|
151
|
*/
|
152
|
public class CharacterMatrix extends Composite {
|
153
|
|
154
|
private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties"; //$NON-NLS-1$
|
155
|
|
156
|
private static final int LEADING_COLUMN_COUNT = 4;
|
157
|
private static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
|
158
|
private static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
|
159
|
private static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
|
160
|
private static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
|
161
|
|
162
|
private WorkingSet workingSet;
|
163
|
|
164
|
private NatTable natTable;
|
165
|
|
166
|
private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
|
167
|
|
168
|
private Map<Feature, List<State>> categoricalFeatureToStateMap = new HashMap<>();
|
169
|
|
170
|
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
|
171
|
|
172
|
private Properties natTableState;
|
173
|
|
174
|
private EventList<Object> descriptions;
|
175
|
|
176
|
private List<RowWrapperDTO> specimenCache = null;
|
177
|
|
178
|
private ListDataProvider<Object> bodyDataProvider;
|
179
|
|
180
|
private FreezeLayer freezeLayer;
|
181
|
|
182
|
private ViewportLayer viewportLayer;
|
183
|
|
184
|
private Label wsLabel;
|
185
|
|
186
|
private List<Feature> features;
|
187
|
|
188
|
private DisplayPersistenceDialogCommandHandler displayPersistenceDialogCommandHandler;
|
189
|
|
190
|
private CharacterMatrixPart part;
|
191
|
|
192
|
private AbstractLayer topMostLayer;
|
193
|
|
194
|
private FixedSummaryRowLayer summaryRowLayer;
|
195
|
|
196
|
private ConfigRegistry configRegistry;
|
197
|
|
198
|
private DefaultBodyLayerStack bodyLayer;
|
199
|
|
200
|
private boolean isTreeView = true;
|
201
|
|
202
|
|
203
|
public CharacterMatrix(Composite parent, CharacterMatrixPart part) {
|
204
|
super(parent, SWT.NONE);
|
205
|
this.part = part;
|
206
|
this.setLayout(new GridLayout());
|
207
|
|
208
|
createToolBar();
|
209
|
|
210
|
natTable = new NatTable(this, false);
|
211
|
|
212
|
applyStyles();
|
213
|
|
214
|
createBottomToolbar();
|
215
|
|
216
|
}
|
217
|
|
218
|
private void createToolBar(){
|
219
|
Composite toolbarComposite = new Composite(this, SWT.NONE);
|
220
|
toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
221
|
toolbarComposite.setLayout(new GridLayout(9, false));
|
222
|
|
223
|
wsLabel = new Label(toolbarComposite, SWT.NONE);
|
224
|
|
225
|
Button btnToggleTree = new Button(toolbarComposite, SWT.PUSH);
|
226
|
Button btnToggleFlat = new Button(toolbarComposite, SWT.PUSH);
|
227
|
Button btnCollapseAll = new Button(toolbarComposite, SWT.PUSH);
|
228
|
Button btnExpandAll = new Button(toolbarComposite, SWT.PUSH);
|
229
|
Button btnFreezeSuppInfo = new Button(toolbarComposite, SWT.TOGGLE);
|
230
|
ComboViewer comboStates = new ComboViewer(toolbarComposite, SWT.DROP_DOWN);
|
231
|
Button btnManageState = new Button(toolbarComposite, SWT.PUSH);
|
232
|
Button btnExcelExport = new Button(toolbarComposite, SWT.PUSH);
|
233
|
|
234
|
/**
|
235
|
* Toogle tree button
|
236
|
*/
|
237
|
btnToggleTree.setImage(ImageResources.getImage(ImageResources.HIERARCHICAL));
|
238
|
btnToggleTree.setToolTipText(Messages.CharacterMatrix_SHOW_HIERARCHY);
|
239
|
btnToggleTree.setSelection(true);
|
240
|
btnToggleTree.setEnabled(false);
|
241
|
btnToggleTree.addSelectionListener(new SelectionAdapter() {
|
242
|
@Override
|
243
|
public void widgetSelected(SelectionEvent e) {
|
244
|
toggleTreeFlat(true, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo);
|
245
|
}
|
246
|
});
|
247
|
|
248
|
/**
|
249
|
* Toogle flat button
|
250
|
*/
|
251
|
btnToggleFlat.setImage(ImageResources.getImage(ImageResources.FLAT));
|
252
|
btnToggleFlat.setToolTipText(Messages.CharacterMatrix_SHOW_FLAT_LIST);
|
253
|
btnToggleFlat.addSelectionListener(new SelectionAdapter() {
|
254
|
@Override
|
255
|
public void widgetSelected(SelectionEvent e) {
|
256
|
toggleTreeFlat(false, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo);
|
257
|
}
|
258
|
});
|
259
|
|
260
|
/**
|
261
|
*
|
262
|
* Collapse button
|
263
|
*/
|
264
|
btnCollapseAll.setImage(ImageResources.getImage(ImageResources.COLLAPSE_ALL));
|
265
|
btnCollapseAll.setToolTipText(Messages.CharacterMatrix_COLLAPSE);
|
266
|
btnCollapseAll.addSelectionListener(new SelectionAdapter() {
|
267
|
@Override
|
268
|
public void widgetSelected(SelectionEvent e) {
|
269
|
natTable.doCommand(new TreeCollapseAllCommand());
|
270
|
}
|
271
|
});
|
272
|
|
273
|
/**
|
274
|
* Expand button
|
275
|
*/
|
276
|
btnExpandAll.setImage(ImageResources.getImage(ImageResources.EXPAND_ALL));
|
277
|
btnExpandAll.setToolTipText(Messages.CharacterMatrix_EXPAND);
|
278
|
btnExpandAll.addSelectionListener(new SelectionAdapter() {
|
279
|
@Override
|
280
|
public void widgetSelected(SelectionEvent e) {
|
281
|
natTable.doCommand(new TreeExpandAllCommand());
|
282
|
}
|
283
|
});
|
284
|
|
285
|
/**
|
286
|
* Freeze supplemental info button
|
287
|
*/
|
288
|
btnFreezeSuppInfo.setImage(ImageResources.getImage(ImageResources.LOCK_ICON));
|
289
|
btnFreezeSuppInfo.setToolTipText(Messages.CharacterMatrix_LOCK_COLUMNS);
|
290
|
btnFreezeSuppInfo.setSelection(true);
|
291
|
btnFreezeSuppInfo.addSelectionListener(new SelectionAdapter() {
|
292
|
@Override
|
293
|
public void widgetSelected(SelectionEvent e) {
|
294
|
boolean isSelected = btnFreezeSuppInfo.getSelection();
|
295
|
freezeSupplementalColumns(isSelected);
|
296
|
btnFreezeSuppInfo.setImage(isSelected?
|
297
|
ImageResources.getImage(ImageResources.LOCK_ICON):
|
298
|
ImageResources.getImage(ImageResources.LOCK_OPEN_ICON));
|
299
|
}
|
300
|
});
|
301
|
|
302
|
/**
|
303
|
* Table state persistence
|
304
|
*/
|
305
|
natTableState = new Properties();
|
306
|
//load persisted state
|
307
|
File statePropertiesFile = getStatePropertiesFile();
|
308
|
FileInputStream inputStream;
|
309
|
try {
|
310
|
inputStream = new FileInputStream(statePropertiesFile);
|
311
|
natTableState.load(inputStream);
|
312
|
} catch (IOException e) {
|
313
|
MessagingUtils.info("No initial state properties file found for character matrix"); //$NON-NLS-1$
|
314
|
}
|
315
|
|
316
|
// create a combobox for showing the available view states
|
317
|
Collection<String> availableStates = PersistenceHelper.getAvailableStates(natTableState);
|
318
|
comboStates.setLabelProvider(new LabelProvider(){
|
319
|
@Override
|
320
|
public String getText(Object element) {
|
321
|
if(element instanceof String && ((String) element).isEmpty()){
|
322
|
return Messages.CharacterMatrix_DEFAULT;
|
323
|
}
|
324
|
return super.getText(element);
|
325
|
}
|
326
|
});
|
327
|
comboStates.setContentProvider(new ArrayContentProvider());
|
328
|
comboStates.addSelectionChangedListener(e->
|
329
|
{
|
330
|
int index = comboStates.getCombo().getSelectionIndex();
|
331
|
if (index >= 0) {
|
332
|
String selected = comboStates.getCombo().getItem(index);
|
333
|
// load the state
|
334
|
natTable.loadState(selected, natTableState);
|
335
|
natTableState.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, selected);
|
336
|
}
|
337
|
});
|
338
|
comboStates.setInput(availableStates);
|
339
|
if(comboStates.getCombo().getItemCount()>0){
|
340
|
comboStates.getCombo().select(0);
|
341
|
}
|
342
|
|
343
|
displayPersistenceDialogCommandHandler = new DisplayPersistenceDialogCommandHandler(natTableState, natTable);
|
344
|
// add listener to update the combo on view state management changes
|
345
|
displayPersistenceDialogCommandHandler.addStateChangeListener(new IStateChangedListener() {
|
346
|
@Override
|
347
|
public void handleStateChange(StateChangeEvent event) {
|
348
|
comboStates.setInput(PersistenceHelper.getAvailableStates(natTableState));
|
349
|
selectStateItem(comboStates, event.getViewConfigName());
|
350
|
}
|
351
|
});
|
352
|
|
353
|
// add button to show dialog
|
354
|
btnManageState.setImage(ImageResources.getImage(ImageResources.SETTINGS));
|
355
|
btnManageState.setToolTipText(Messages.CharacterMatrix_VIEW_CONFIG);
|
356
|
btnManageState.addSelectionListener(new SelectionAdapter() {
|
357
|
@Override
|
358
|
public void widgetSelected(SelectionEvent e) {
|
359
|
natTable.doCommand(new DisplayPersistenceDialogCommand(natTable));
|
360
|
selectStateItem(comboStates, natTableState.get(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY).toString());
|
361
|
}
|
362
|
});
|
363
|
|
364
|
/**
|
365
|
* excel export
|
366
|
*/
|
367
|
btnExcelExport.setToolTipText(Messages.CharacterMatrix_EXPORT);
|
368
|
btnExcelExport.setImage(ImageResources.getImage(ImageResources.EXPORT));
|
369
|
btnExcelExport.addSelectionListener(new SelectionAdapter() {
|
370
|
@Override
|
371
|
public void widgetSelected(SelectionEvent e) {
|
372
|
natTable.doCommand(
|
373
|
new ExportCommand(
|
374
|
natTable.getConfigRegistry(),
|
375
|
natTable.getShell()));
|
376
|
}
|
377
|
});
|
378
|
}
|
379
|
|
380
|
private void createBottomToolbar() {
|
381
|
Composite buttonPanel = new Composite(this, SWT.NONE);
|
382
|
|
383
|
buttonPanel.setLayout(new RowLayout());
|
384
|
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
|
385
|
|
386
|
/**
|
387
|
* Add description button
|
388
|
*/
|
389
|
Button btnAddDescription = new Button(buttonPanel, SWT.PUSH);
|
390
|
btnAddDescription.setImage(ImageResources.getImage(ImageResources.ADD_ICON_GREEN));
|
391
|
btnAddDescription.addSelectionListener(new SelectionAdapter() {
|
392
|
@Override
|
393
|
public void widgetSelected(SelectionEvent e) {
|
394
|
SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(natTable.getShell(), CharacterMatrix.this);
|
395
|
if(dialog.open()==Window.OK){
|
396
|
Collection<RowWrapperDTO> wrappers = dialog.getSpecimen();
|
397
|
for (RowWrapperDTO wrapper : wrappers) {
|
398
|
SpecimenDescription description = getDescriptionForWorkingSet(wrapper);
|
399
|
//description elements
|
400
|
Map<Feature, DescriptionElementBase> featureToElementMap = new HashMap<>();
|
401
|
Set<DescriptionElementBase> elements = description.getElements();
|
402
|
for (DescriptionElementBase descriptionElementBase : elements) {
|
403
|
Feature feature = descriptionElementBase.getFeature();
|
404
|
featureToElementMap.put(feature, descriptionElementBase);
|
405
|
}
|
406
|
wrapper.setDescription(description);
|
407
|
CharacterMatrix.this.descriptions.add(wrapper);
|
408
|
workingSet.addDescription(description);
|
409
|
setDirty();
|
410
|
}
|
411
|
}
|
412
|
}
|
413
|
});
|
414
|
/**
|
415
|
* Remove description button
|
416
|
*/
|
417
|
Button btnRemoveDescription = new Button(buttonPanel, SWT.PUSH);
|
418
|
btnRemoveDescription.setImage(ImageResources.getImage(ImageResources.ACTIVE_DELETE_ICON));
|
419
|
btnRemoveDescription.addSelectionListener(new SelectionAdapter() {
|
420
|
@Override
|
421
|
public void widgetSelected(SelectionEvent e) {
|
422
|
int[] fullySelectedRowPositions = bodyLayer.getSelectionLayer().getFullySelectedRowPositions();
|
423
|
for (int i : fullySelectedRowPositions) {
|
424
|
Object rowObject = bodyDataProvider.getRowObject(i);
|
425
|
if(rowObject instanceof RowWrapperDTO){
|
426
|
CharacterMatrix.this.descriptions.remove(rowObject);
|
427
|
workingSet.removeDescription(((RowWrapperDTO) rowObject).getSpecimenDescription());
|
428
|
setDirty();
|
429
|
}
|
430
|
}
|
431
|
}
|
432
|
});
|
433
|
}
|
434
|
|
435
|
private void applyStyles(){
|
436
|
// NOTE: Getting the colors and fonts from the GUIHelper ensures that
|
437
|
// they are disposed properly (required by SWT)
|
438
|
DefaultNatTableStyleConfiguration natTableConfiguration = new DefaultNatTableStyleConfiguration();
|
439
|
natTableConfiguration.bgColor = GUIHelper.getColor(249, 172, 7);
|
440
|
natTableConfiguration.fgColor = GUIHelper.getColor(30, 76, 19);
|
441
|
natTableConfiguration.hAlign = HorizontalAlignmentEnum.LEFT;
|
442
|
natTableConfiguration.vAlign = VerticalAlignmentEnum.TOP;
|
443
|
// natTableConfiguration.borderStyle = new BorderStyle(1, GUIHelper.getColor(249, 172, 7), LineStyleEnum.SOLID);
|
444
|
|
445
|
// Setup even odd row colors - row colors override the NatTable default
|
446
|
// colors
|
447
|
DefaultRowStyleConfiguration rowStyleConfiguration = new DefaultRowStyleConfiguration();
|
448
|
rowStyleConfiguration.oddRowBgColor = ColorResources.getColor(Resources.COLOR_LIST_ODD);
|
449
|
rowStyleConfiguration.evenRowBgColor = ColorResources.getColor(Resources.COLOR_LIST_EVEN);
|
450
|
|
451
|
// Setup selection styling
|
452
|
DefaultSelectionStyleConfiguration selectionStyle = new DefaultSelectionStyleConfiguration();
|
453
|
// selectionStyle.selectionFont = GUIHelper.getFont(new FontData("Verdana", 8, SWT.NORMAL));
|
454
|
// selectionStyle.selectionBgColor = GUIHelper.getColor(217, 232, 251);
|
455
|
// selectionStyle.selectionFgColor = GUIHelper.COLOR_BLACK;
|
456
|
// selectionStyle.anchorBorderStyle = new BorderStyle(1, GUIHelper.COLOR_DARK_GRAY, LineStyleEnum.SOLID);
|
457
|
// selectionStyle.anchorBgColor = GUIHelper.getColor(65, 113, 43);
|
458
|
selectionStyle.selectedHeaderBgColor = GUIHelper.getColor(156, 209, 103);
|
459
|
|
460
|
// Add all style configurations to NatTable
|
461
|
natTable.addConfiguration(natTableConfiguration);
|
462
|
natTable.addConfiguration(rowStyleConfiguration);
|
463
|
natTable.addConfiguration(selectionStyle);
|
464
|
|
465
|
// Column/Row header style and custom painters
|
466
|
DefaultRowHeaderStyleConfiguration rowHeaderConfig = new DefaultRowHeaderStyleConfiguration();
|
467
|
Color rowColumnColor = GUIHelper.getColor(230, 255, 255);
|
468
|
rowHeaderConfig.bgColor = rowColumnColor;
|
469
|
natTable.addConfiguration(rowHeaderConfig);
|
470
|
DefaultColumnHeaderStyleConfiguration columnHeaderStyle = new DefaultColumnHeaderStyleConfiguration();
|
471
|
columnHeaderStyle.bgColor = rowColumnColor;
|
472
|
columnHeaderStyle.font = GUIHelper.getFont(new FontData("Verdana", 9, SWT.BOLD)); //$NON-NLS-1$
|
473
|
natTable.addConfiguration(columnHeaderStyle);
|
474
|
|
475
|
}
|
476
|
|
477
|
private void toggleTreeFlat(boolean isTree, Button btnToggleFlat, Button btnToggleTree, Button btnCollapseAll, Button btnExpandAll, Button btnFreezeSuppInfo) {
|
478
|
isTreeView = isTree;
|
479
|
createLayers(isTree);
|
480
|
btnToggleFlat.setEnabled(isTree);
|
481
|
btnToggleTree.setEnabled(!isTree);
|
482
|
btnCollapseAll.setEnabled(isTree);
|
483
|
btnExpandAll.setEnabled(isTree);
|
484
|
natTable.doCommand(new ClientAreaResizeCommand(natTable));
|
485
|
natTable.doCommand(new VisualRefreshCommand());
|
486
|
freezeSupplementalColumns(btnFreezeSuppInfo.getSelection());
|
487
|
}
|
488
|
|
489
|
public boolean isTreeView() {
|
490
|
return isTreeView;
|
491
|
}
|
492
|
|
493
|
public void createTable(boolean treeView){
|
494
|
/**
|
495
|
* layers
|
496
|
*/
|
497
|
createLayers(treeView);
|
498
|
|
499
|
/**
|
500
|
* configuration
|
501
|
*/
|
502
|
configureNatTable(treeView, configRegistry, topMostLayer, summaryRowLayer);
|
503
|
|
504
|
/**
|
505
|
* handlers and listeners
|
506
|
*/
|
507
|
registerHandlersAndListeners(topMostLayer);
|
508
|
|
509
|
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
|
510
|
|
511
|
wsLabel.setText(workingSet.getLabel());
|
512
|
wsLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
513
|
wsLabel.getParent().layout();
|
514
|
|
515
|
freezeSupplementalColumns(true);
|
516
|
|
517
|
this.layout();
|
518
|
}
|
519
|
|
520
|
private List<Feature> initFeatureList(FeatureNode node){
|
521
|
List<Feature> features = new ArrayList<>();
|
522
|
node.getChildNodes().forEach(childNode->
|
523
|
{
|
524
|
features.add(childNode.getFeature());
|
525
|
features.addAll(initFeatureList(childNode));
|
526
|
});
|
527
|
return features;
|
528
|
}
|
529
|
|
530
|
public void initWorkingSet(WorkingSet workingSet){
|
531
|
this.workingSet = workingSet;
|
532
|
//get features/columns stored in working set
|
533
|
FeatureTree tree = workingSet.getDescriptiveSystem();
|
534
|
features = initFeatureList(tree.getRoot());
|
535
|
|
536
|
//init state data for categorical features
|
537
|
features.forEach(feature->
|
538
|
{
|
539
|
if(feature.isSupportsCategoricalData()){
|
540
|
List<State> supportedStates = new ArrayList<>();
|
541
|
feature.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
|
542
|
categoricalFeatureToStateMap.put(feature, supportedStates);
|
543
|
}
|
544
|
});
|
545
|
descriptions = new BasicEventList<>();
|
546
|
|
547
|
}
|
548
|
|
549
|
private void createLayers(boolean treeView) {
|
550
|
// use the SortedList constructor with 'null' for the Comparator
|
551
|
// because the Comparator will be set by configuration
|
552
|
SortedList<Object> sortedList = new SortedList<>(descriptions, new MatrixRowComparator());
|
553
|
// wrap the SortedList with the TreeList
|
554
|
TreeList<Object> treeList = new TreeList(sortedList, new DescriptionTreeFormat(workingSet), TreeList.NODES_START_EXPANDED);
|
555
|
/**
|
556
|
* data provider
|
557
|
*/
|
558
|
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
|
559
|
bodyDataProvider = treeView?new ListDataProvider<>(treeList, columnPropertyAccessor):new ListDataProvider<>(sortedList, columnPropertyAccessor);
|
560
|
|
561
|
configRegistry = new ConfigRegistry();
|
562
|
|
563
|
|
564
|
/**
|
565
|
* BODY layer
|
566
|
*
|
567
|
*
|
568
|
|
569
|
CompositeLayer
|
570
|
- (top) SummaryRowLayer
|
571
|
- (bottom) ViewportLayer
|
572
|
|
573
|
^
|
574
|
ViewportLayer
|
575
|
|
576
|
^
|
577
|
TreeLayer (default visible)
|
578
|
|
579
|
^
|
580
|
CompositeFreezeLayer
|
581
|
- viewportLayer
|
582
|
- selectionLayer
|
583
|
- freezeLayer
|
584
|
|
585
|
^
|
586
|
FreezeLayer
|
587
|
|
588
|
^
|
589
|
SelectionLayer
|
590
|
|
591
|
^
|
592
|
ColumnHideShowLayer
|
593
|
|
594
|
^
|
595
|
ColumnReorderLayer
|
596
|
|
597
|
^
|
598
|
DataLayer
|
599
|
|
600
|
*
|
601
|
|
602
|
*/
|
603
|
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
|
604
|
|
605
|
//register labels for columns
|
606
|
ColumnOverrideLabelAccumulator bodyColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
|
607
|
bodyDataLayer.setConfigLabelAccumulator(bodyColumnLabelAccumulator);
|
608
|
propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
|
609
|
bodyColumnLabelAccumulator.registerColumnOverrides(0, TAXON_COLUMN);
|
610
|
propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
|
611
|
bodyColumnLabelAccumulator.registerColumnOverrides(1, COLLECTOR_COLUMN);
|
612
|
propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
|
613
|
bodyColumnLabelAccumulator.registerColumnOverrides(2, IDENTIFIER_COLUMN);
|
614
|
propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
|
615
|
bodyColumnLabelAccumulator.registerColumnOverrides(3, COUNTRY_COLUMN);
|
616
|
for(int i=0;i<features.size();i++){
|
617
|
Feature feature = features.get(i);
|
618
|
initLabels(bodyColumnLabelAccumulator, i, feature);
|
619
|
}
|
620
|
|
621
|
// layer for event handling of GlazedLists and PropertyChanges
|
622
|
GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, treeList);
|
623
|
GlazedListTreeData treeData = new GlazedListTreeData<>(treeList);
|
624
|
ITreeRowModel treeRowModel = new GlazedListTreeRowModel<>(treeData);
|
625
|
|
626
|
bodyLayer = new DefaultBodyLayerStack(
|
627
|
eventLayer);
|
628
|
viewportLayer = bodyLayer.getViewportLayer();
|
629
|
final SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
|
630
|
freezeLayer = new FreezeLayer(selectionLayer);
|
631
|
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
|
632
|
freezeLayer, bodyLayer.getViewportLayer(), selectionLayer);
|
633
|
TreeLayer treeLayer = new TreeLayer(compositeFreezeLayer, treeRowModel);
|
634
|
|
635
|
topMostLayer = treeView?treeLayer:compositeFreezeLayer;
|
636
|
|
637
|
summaryRowLayer = new FixedSummaryRowLayer(bodyDataLayer, topMostLayer, configRegistry, false);
|
638
|
//regoster labels with summary prefix for summary layer
|
639
|
ColumnOverrideLabelAccumulator summaryColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
|
640
|
summaryRowLayer.setConfigLabelAccumulator(summaryColumnLabelAccumulator);
|
641
|
for(int i=0;i<features.size();i++){
|
642
|
Feature feature = features.get(i);
|
643
|
summaryColumnLabelAccumulator.registerColumnOverrides(
|
644
|
i+LEADING_COLUMN_COUNT,
|
645
|
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+MatrixUtility.getProperty(feature));
|
646
|
}
|
647
|
// because the horizontal dependency is the ViewportLayer
|
648
|
// we need to set the composite dependency to false
|
649
|
summaryRowLayer.setHorizontalCompositeDependency(false);
|
650
|
|
651
|
CompositeLayer composite = new CompositeLayer(1, 2);
|
652
|
composite.setChildLayer("SUMMARY", summaryRowLayer, 0, 0); //$NON-NLS-1$
|
653
|
composite.setChildLayer(GridRegion.BODY, topMostLayer, 0, 1);
|
654
|
|
655
|
|
656
|
/**
|
657
|
* column header layer
|
658
|
*/
|
659
|
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
|
660
|
propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
|
661
|
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
|
662
|
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, topMostLayer, selectionLayer);
|
663
|
|
664
|
// add the SortHeaderLayer to the column header layer stack
|
665
|
// as we use GlazedLists, we use the GlazedListsSortModel which
|
666
|
// delegates the sorting to the SortedList
|
667
|
final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
|
668
|
columnHeaderLayer,
|
669
|
new GlazedListsSortModel<>(
|
670
|
sortedList,
|
671
|
columnPropertyAccessor,
|
672
|
configRegistry,
|
673
|
columnHeaderDataLayer));
|
674
|
|
675
|
|
676
|
/**
|
677
|
* row header layer
|
678
|
*/
|
679
|
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
|
680
|
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
|
681
|
FixedSummaryRowHeaderLayer fixedSummaryRowHeaderLayer = new FixedSummaryRowHeaderLayer(rowHeaderDataLayer,
|
682
|
composite, selectionLayer);
|
683
|
fixedSummaryRowHeaderLayer.setSummaryRowLabel("\u2211"); //$NON-NLS-1$
|
684
|
|
685
|
|
686
|
/**
|
687
|
* corner layer
|
688
|
*/
|
689
|
ILayer cornerLayer = new CornerLayer(
|
690
|
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
|
691
|
fixedSummaryRowHeaderLayer, sortHeaderLayer);
|
692
|
|
693
|
|
694
|
/**
|
695
|
* GRID layer (composition of all other layers)
|
696
|
*/
|
697
|
GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, fixedSummaryRowHeaderLayer, cornerLayer);
|
698
|
|
699
|
natTable.setLayer(gridLayer);
|
700
|
|
701
|
}
|
702
|
|
703
|
private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
|
704
|
// add the ExportCommandHandler to the ViewportLayer in order to make
|
705
|
// exporting work
|
706
|
topMostLayer.registerCommandHandler(new ExportCommandHandler(topMostLayer));
|
707
|
|
708
|
//propagate single cell selection
|
709
|
natTable.addLayerListener(new ILayerListener() {
|
710
|
@Override
|
711
|
public void handleLayerEvent(ILayerEvent event) {
|
712
|
if(event instanceof CellSelectionEvent){
|
713
|
CellSelectionEvent cellSelectionEvent = (CellSelectionEvent)event;
|
714
|
int columnPosition = cellSelectionEvent.getColumnPosition();
|
715
|
if(columnPosition>LEADING_COLUMN_COUNT){
|
716
|
Collection<ILayerCell> selectedCells = cellSelectionEvent.getSelectionLayer().getSelectedCells();
|
717
|
StructuredSelection selection = new StructuredSelection();
|
718
|
if(selectedCells.size()==1){
|
719
|
ILayerCell cell = selectedCells.iterator().next();
|
720
|
Object dataValue = cell.getDataValue();
|
721
|
if(dataValue!=null){
|
722
|
selection = new StructuredSelection(dataValue);
|
723
|
}
|
724
|
}
|
725
|
part.getSelectionService().setSelection(selection);
|
726
|
}
|
727
|
}
|
728
|
}
|
729
|
});
|
730
|
|
731
|
//register handler for view configuration menu
|
732
|
natTable.registerCommandHandler(displayPersistenceDialogCommandHandler);
|
733
|
}
|
734
|
|
735
|
private void configureNatTable(boolean treeView, ConfigRegistry configRegistry, AbstractLayer topMostLayer,
|
736
|
FixedSummaryRowLayer summaryRowLayer) {
|
737
|
/**
|
738
|
* CONFIGURATION
|
739
|
*/
|
740
|
natTable.setConfigRegistry(configRegistry);
|
741
|
|
742
|
//add default configuration because autoconfigure is set to false in constructor
|
743
|
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
|
744
|
|
745
|
//FIXME: this is for DEBUG ONLY
|
746
|
// natTable.addConfiguration(new DebugMenuConfiguration(natTable));
|
747
|
|
748
|
// override the default sort configuration and change the mouse bindings
|
749
|
// to sort on a single click
|
750
|
if(!treeView){
|
751
|
natTable.addConfiguration(new SingleClickSortConfiguration());
|
752
|
}
|
753
|
|
754
|
// add the header menu configuration for adding the column header menu
|
755
|
// with hide/show actions
|
756
|
natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {
|
757
|
|
758
|
@Override
|
759
|
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
|
760
|
return super.createColumnHeaderMenu(natTable)
|
761
|
.withHideColumnMenuItem()
|
762
|
.withShowAllColumnsMenuItem();
|
763
|
}
|
764
|
|
765
|
});
|
766
|
|
767
|
Style cellStyle = new Style();
|
768
|
cellStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
|
769
|
|
770
|
// add custom configuration for data conversion and add column labels to viewport layer
|
771
|
topMostLayer.addConfiguration(new AbstractRegistryConfiguration() {
|
772
|
@Override
|
773
|
public void configureRegistry(IConfigRegistry configRegistry) {
|
774
|
//add display converter for string representation
|
775
|
configRegistry.registerConfigAttribute(
|
776
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
777
|
new SupplementalInfoDisplayConverter(CharacterMatrix.this),
|
778
|
DisplayMode.NORMAL,
|
779
|
TAXON_COLUMN);
|
780
|
configRegistry.registerConfigAttribute(
|
781
|
CellConfigAttributes.CELL_STYLE,
|
782
|
cellStyle,
|
783
|
DisplayMode.NORMAL,
|
784
|
TAXON_COLUMN);
|
785
|
configRegistry.registerConfigAttribute(
|
786
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
787
|
new SupplementalInfoDisplayConverter(CharacterMatrix.this),
|
788
|
DisplayMode.NORMAL,
|
789
|
COLLECTOR_COLUMN);
|
790
|
configRegistry.registerConfigAttribute(
|
791
|
CellConfigAttributes.CELL_STYLE,
|
792
|
cellStyle,
|
793
|
DisplayMode.NORMAL,
|
794
|
COLLECTOR_COLUMN);
|
795
|
configRegistry.registerConfigAttribute(
|
796
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
797
|
new SupplementalInfoDisplayConverter(CharacterMatrix.this),
|
798
|
DisplayMode.NORMAL,
|
799
|
IDENTIFIER_COLUMN);
|
800
|
configRegistry.registerConfigAttribute(
|
801
|
CellConfigAttributes.CELL_STYLE,
|
802
|
cellStyle,
|
803
|
DisplayMode.NORMAL,
|
804
|
IDENTIFIER_COLUMN);
|
805
|
configRegistry.registerConfigAttribute(
|
806
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
807
|
new SupplementalInfoDisplayConverter(CharacterMatrix.this),
|
808
|
DisplayMode.NORMAL,
|
809
|
COUNTRY_COLUMN);
|
810
|
configRegistry.registerConfigAttribute(
|
811
|
CellConfigAttributes.CELL_STYLE,
|
812
|
cellStyle,
|
813
|
DisplayMode.NORMAL,
|
814
|
COUNTRY_COLUMN);
|
815
|
features.forEach(feature->registerColumnConfiguration(feature, configRegistry));
|
816
|
}
|
817
|
|
818
|
});
|
819
|
|
820
|
//no summary for the supplemental columns
|
821
|
for(int i=0;i<LEADING_COLUMN_COUNT;i++){
|
822
|
int index = i;
|
823
|
summaryRowLayer.addConfiguration(new DefaultSummaryRowConfiguration() {
|
824
|
@Override
|
825
|
public void addSummaryProviderConfig(IConfigRegistry configRegistry) {
|
826
|
configRegistry.registerConfigAttribute(
|
827
|
SummaryRowConfigAttributes.SUMMARY_PROVIDER,
|
828
|
new ISummaryProvider() {
|
829
|
|
830
|
@Override
|
831
|
public Object summarize(int columnIndex) {
|
832
|
return "";
|
833
|
}
|
834
|
},
|
835
|
DisplayMode.NORMAL,
|
836
|
SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX+index);
|
837
|
}
|
838
|
});
|
839
|
}
|
840
|
//register aggregation configuration for each feature
|
841
|
features.forEach(feature->summaryRowLayer.addConfiguration(new AggregationConfiguration(bodyDataProvider, feature)));
|
842
|
|
843
|
natTable.configure();
|
844
|
}
|
845
|
|
846
|
private void freezeSupplementalColumns(boolean freeze){
|
847
|
if(freeze){
|
848
|
FreezeHelper.freeze(freezeLayer, viewportLayer,
|
849
|
new PositionCoordinate(viewportLayer, 0, 0),
|
850
|
new PositionCoordinate(viewportLayer, LEADING_COLUMN_COUNT-1, -1));
|
851
|
}
|
852
|
else{
|
853
|
FreezeHelper.unfreeze(freezeLayer, viewportLayer);
|
854
|
}
|
855
|
}
|
856
|
|
857
|
private void selectStateItem(ComboViewer comboStates, String stateName){
|
858
|
String[] items = comboStates.getCombo().getItems();
|
859
|
for(int i=0;i<items.length;i++){
|
860
|
if(items[i].equals(stateName)){
|
861
|
comboStates.getCombo().select(i);
|
862
|
break;
|
863
|
}
|
864
|
}
|
865
|
}
|
866
|
|
867
|
private SpecimenDescription getDescriptionForWorkingSet(RowWrapperDTO wrapper){
|
868
|
Set<Feature> wsFeatures = workingSet.getDescriptiveSystem().getDistinctFeatures();
|
869
|
List<DescriptionElementBase> matchingDescriptionElements = new ArrayList<>();
|
870
|
|
871
|
for (SpecimenDescription specimenDescription : (Set<SpecimenDescription>) wrapper.getSpecimen().getDescriptions()) {
|
872
|
Set<Feature> specimenDescriptionFeatures = new HashSet<>();
|
873
|
//gather specimen description features and check for match with WS features
|
874
|
for (DescriptionElementBase specimenDescriptionElement : specimenDescription.getElements()) {
|
875
|
Feature feature = specimenDescriptionElement.getFeature();
|
876
|
specimenDescriptionFeatures.add(feature);
|
877
|
if(wsFeatures.contains(feature)){
|
878
|
matchingDescriptionElements.add(specimenDescriptionElement);
|
879
|
}
|
880
|
}
|
881
|
//if description with the exact same features is found return the description
|
882
|
if(specimenDescriptionFeatures.equals(wsFeatures)){
|
883
|
return specimenDescription;
|
884
|
}
|
885
|
}
|
886
|
//Create new specimen description if no match was found
|
887
|
setDirty();
|
888
|
SpecimenDescription newDesription = SpecimenDescription.NewInstance(wrapper.getSpecimen());
|
889
|
newDesription.setTitleCache(Messages.CharacterMatrix_WORKING_SET+workingSet.getLabel()+": "+newDesription.generateTitle(), true); //$NON-NLS-2$
|
890
|
|
891
|
//check for equals description element (same feature and same values)
|
892
|
Map<Feature, List<DescriptionElementBase>> featureToElementMap = new HashMap<>();
|
893
|
for(DescriptionElementBase element:matchingDescriptionElements){
|
894
|
List<DescriptionElementBase> list = featureToElementMap.get(element.getFeature());
|
895
|
if(list==null){
|
896
|
list = new ArrayList<>();
|
897
|
}
|
898
|
list.add(element);
|
899
|
featureToElementMap.put(element.getFeature(), list);
|
900
|
}
|
901
|
Set<DescriptionElementBase> descriptionElementsToClone = new HashSet<>();
|
902
|
for(Feature feature:featureToElementMap.keySet()){
|
903
|
List<DescriptionElementBase> elements = featureToElementMap.get(feature);
|
904
|
//no duplicate description elements found for this feature
|
905
|
if(elements.size()==1){
|
906
|
descriptionElementsToClone.add(elements.get(0));
|
907
|
}
|
908
|
//duplicates found -> check if all are equal
|
909
|
else{
|
910
|
DescriptionElementBase match = null;
|
911
|
for (DescriptionElementBase descriptionElementBase : elements) {
|
912
|
if(match==null){
|
913
|
match = descriptionElementBase;
|
914
|
}
|
915
|
else if(!new DescriptionElementCompareWrapper(match).equals(new DescriptionElementCompareWrapper(descriptionElementBase))){
|
916
|
match = null;
|
917
|
MessagingUtils.informationDialog(Messages.CharacterMatrix_MULTIPLE_DATA,
|
918
|
String.format(Messages.CharacterMatrix_MULTIPLE_DATA_MESSAGE, feature.getLabel()));
|
919
|
break;
|
920
|
}
|
921
|
}
|
922
|
if(match!=null){
|
923
|
descriptionElementsToClone.add(match);
|
924
|
}
|
925
|
}
|
926
|
}
|
927
|
//clone matching descriptionElements
|
928
|
for (DescriptionElementBase descriptionElementBase : descriptionElementsToClone) {
|
929
|
DescriptionElementBase clone;
|
930
|
try {
|
931
|
clone = descriptionElementBase.clone(newDesription);
|
932
|
clone.getSources().forEach(source -> source.setOriginalNameString(DescriptionHelper.getLabel(descriptionElementBase)));
|
933
|
} catch (CloneNotSupportedException e) {
|
934
|
MessagingUtils.error(CharacterMatrix.class, e);
|
935
|
}
|
936
|
}
|
937
|
return newDesription;
|
938
|
|
939
|
}
|
940
|
|
941
|
private void initLabels(final ColumnOverrideLabelAccumulator columnLabelAccumulator,
|
942
|
int index, Feature feature) {
|
943
|
|
944
|
columnLabelAccumulator.registerColumnOverrides(index+LEADING_COLUMN_COUNT, MatrixUtility.getProperty(feature));
|
945
|
indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
|
946
|
|
947
|
String featureLabel = feature.getLabel();
|
948
|
String property = featureLabel;
|
949
|
//show unit for quantitative data
|
950
|
if(feature.isSupportsQuantitativeData()){
|
951
|
Set<MeasurementUnit> recommendedMeasurementUnits = feature.getRecommendedMeasurementUnits();
|
952
|
if(recommendedMeasurementUnits.size()>1){
|
953
|
MessagingUtils.warningDialog(Messages.CharacterMatrix_INIT_PROBLEM, CharacterMatrix.class,
|
954
|
String.format(Messages.CharacterMatrix_INIT_PROBLEM_MESSAGE, feature.getLabel()));
|
955
|
}
|
956
|
if(recommendedMeasurementUnits.size()==1){
|
957
|
MeasurementUnit unit = recommendedMeasurementUnits.iterator().next();
|
958
|
featureLabel += " ["+unit.getIdInVocabulary()+"]"; //$NON-NLS-1$ //$NON-NLS-2$
|
959
|
}
|
960
|
}
|
961
|
propertyToLabelMap.put(property, featureLabel);
|
962
|
}
|
963
|
|
964
|
private void registerColumnConfiguration(Feature feature, IConfigRegistry configRegistry) {
|
965
|
//make cell editable
|
966
|
configRegistry.registerConfigAttribute(
|
967
|
EditConfigAttributes.CELL_EDITABLE_RULE,
|
968
|
IEditableRule.ALWAYS_EDITABLE,
|
969
|
DisplayMode.EDIT,
|
970
|
MatrixUtility.getProperty(feature)
|
971
|
);
|
972
|
if(feature.isSupportsQuantitativeData()){
|
973
|
//add display converter for string representation
|
974
|
configRegistry.registerConfigAttribute(
|
975
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
976
|
new QuantitativeDataDisplayConverter(),
|
977
|
DisplayMode.NORMAL,
|
978
|
MatrixUtility.getProperty(feature));
|
979
|
//register quantitative editor
|
980
|
configRegistry.registerConfigAttribute(
|
981
|
EditConfigAttributes.CELL_EDITOR,
|
982
|
new QuantitativeDataCellEditor(feature, this),
|
983
|
DisplayMode.EDIT,
|
984
|
MatrixUtility.getProperty(feature));
|
985
|
}
|
986
|
else if(feature.isSupportsCategoricalData()){
|
987
|
//add display converter for string representation
|
988
|
configRegistry.registerConfigAttribute(
|
989
|
CellConfigAttributes.DISPLAY_CONVERTER,
|
990
|
new CategoricalDataDisplayConverter(),
|
991
|
DisplayMode.NORMAL,
|
992
|
MatrixUtility.getProperty(feature));
|
993
|
|
994
|
//add combo box cell editor
|
995
|
//register editor
|
996
|
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
|
997
|
new CategoricalDataCellEditor(getSupportedStatesForCategoricalFeature(feature), this, feature),
|
998
|
DisplayMode.EDIT,
|
999
|
MatrixUtility.getProperty(feature));
|
1000
|
|
1001
|
}
|
1002
|
|
1003
|
}
|
1004
|
|
1005
|
|
1006
|
public void loadDescriptions(WorkingSet workingSet) {
|
1007
|
String jobLabel = "Load character data";
|
1008
|
Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
|
1009
|
monitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
|
1010
|
Collection<RowWrapperDTO> wrappers = CdmStore.getService(IWorkingSetService.class).getRowWrapper(workingSet);
|
1011
|
wrappers.forEach(wrapper->{
|
1012
|
CharacterMatrix.this.descriptions.add(wrapper);
|
1013
|
});
|
1014
|
monitor.done();
|
1015
|
});
|
1016
|
job.schedule();
|
1017
|
}
|
1018
|
|
1019
|
public List<State> getSupportedStatesForCategoricalFeature(Feature feature){
|
1020
|
return categoricalFeatureToStateMap.get(feature);
|
1021
|
}
|
1022
|
|
1023
|
public Map<Integer, Feature> getIndexToFeatureMap() {
|
1024
|
return indexToFeatureMap;
|
1025
|
}
|
1026
|
|
1027
|
public LinkedMap<String, String> getPropertyToLabelMap() {
|
1028
|
return propertyToLabelMap;
|
1029
|
}
|
1030
|
|
1031
|
public void setDirty() {
|
1032
|
part.setDirty();
|
1033
|
}
|
1034
|
|
1035
|
public NatTable getNatTable() {
|
1036
|
return natTable;
|
1037
|
}
|
1038
|
|
1039
|
public WorkingSet getWorkingSet() {
|
1040
|
return workingSet;
|
1041
|
}
|
1042
|
|
1043
|
public List<RowWrapperDTO> getSpecimenCache() {
|
1044
|
return specimenCache;
|
1045
|
}
|
1046
|
|
1047
|
public void setSpecimenCache(Collection<RowWrapperDTO> specimenCache) {
|
1048
|
this.specimenCache =
|
1049
|
specimenCache.stream().filter(wrapper ->
|
1050
|
wrapper.getSpecimen().getDescriptions().stream().noneMatch(description ->
|
1051
|
workingSet.getDescriptions().contains(description)))
|
1052
|
.collect(Collectors.toList());
|
1053
|
}
|
1054
|
|
1055
|
public Properties getNatTableState() {
|
1056
|
return natTableState;
|
1057
|
}
|
1058
|
|
1059
|
public ListDataProvider<Object> getBodyDataProvider() {
|
1060
|
return bodyDataProvider;
|
1061
|
}
|
1062
|
|
1063
|
private File getStatePropertiesFile() {
|
1064
|
return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
|
1065
|
}
|
1066
|
|
1067
|
}
|