1
|
/**
|
2
|
* Copyright (C) 2018 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.view.checklist.e4;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.Iterator;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
import java.util.Set;
|
19
|
import java.util.SortedSet;
|
20
|
import java.util.TreeSet;
|
21
|
import java.util.UUID;
|
22
|
|
23
|
import javax.inject.Inject;
|
24
|
|
25
|
import org.apache.commons.collections4.map.LinkedMap;
|
26
|
import org.apache.log4j.Logger;
|
27
|
import org.eclipse.e4.ui.services.EMenuService;
|
28
|
import org.eclipse.jface.layout.GridDataFactory;
|
29
|
import org.eclipse.jface.layout.GridLayoutFactory;
|
30
|
import org.eclipse.jface.wizard.WizardDialog;
|
31
|
import org.eclipse.nebula.widgets.nattable.NatTable;
|
32
|
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
|
33
|
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
|
34
|
import org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate;
|
35
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
36
|
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
|
37
|
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
|
38
|
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
|
39
|
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.filterrow.DefaultGlazedListsFilterStrategy;
|
40
|
import org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite;
|
41
|
import org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer;
|
42
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeHelper;
|
43
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
|
44
|
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
|
45
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
|
46
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
|
47
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
|
48
|
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
|
49
|
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
|
50
|
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer;
|
51
|
import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
|
52
|
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
|
53
|
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
|
54
|
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
|
55
|
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
|
56
|
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
|
57
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
58
|
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
|
59
|
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
|
60
|
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
|
61
|
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
|
62
|
import org.eclipse.swt.SWT;
|
63
|
import org.eclipse.swt.events.SelectionAdapter;
|
64
|
import org.eclipse.swt.events.SelectionEvent;
|
65
|
import org.eclipse.swt.layout.GridData;
|
66
|
import org.eclipse.swt.layout.GridLayout;
|
67
|
import org.eclipse.swt.widgets.Button;
|
68
|
import org.eclipse.swt.widgets.Composite;
|
69
|
import org.eclipse.swt.widgets.Label;
|
70
|
import org.eclipse.swt.widgets.Text;
|
71
|
|
72
|
import ca.odell.glazedlists.BasicEventList;
|
73
|
import ca.odell.glazedlists.EventList;
|
74
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
75
|
import eu.etaxonomy.cdm.api.service.dto.TaxonDescriptionDTO;
|
76
|
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
|
77
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
78
|
import eu.etaxonomy.cdm.model.common.Language;
|
79
|
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
|
80
|
import eu.etaxonomy.cdm.model.common.OrderedTermComparator;
|
81
|
import eu.etaxonomy.cdm.model.common.Representation;
|
82
|
import eu.etaxonomy.cdm.model.common.TermIdInVocabularyComparator;
|
83
|
import eu.etaxonomy.cdm.model.common.TermLanguageComparator;
|
84
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
85
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
86
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
87
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
88
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
89
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
90
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
91
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
92
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
93
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
94
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
95
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
96
|
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
|
97
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
98
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
99
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog;
|
100
|
|
101
|
/**
|
102
|
* @author k.luther
|
103
|
* @since 27.11.2018
|
104
|
*
|
105
|
*/
|
106
|
public class DistributionEditor extends Composite {
|
107
|
|
108
|
|
109
|
private static final String DISTRIBUTION_EDITOR = "Distribution Editor";
|
110
|
private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
|
111
|
private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
|
112
|
private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
|
113
|
public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$
|
114
|
|
115
|
static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
|
116
|
static final String RANK_COLUMN = "collector_column"; //$NON-NLS-1$
|
117
|
|
118
|
private static final Logger logger = Logger.getLogger(DistributionEditor.class);
|
119
|
@Inject
|
120
|
private EMenuService menuService;
|
121
|
private NatTable natTable;
|
122
|
private Label statusLabel;
|
123
|
private Label statusLabelSourceReference;
|
124
|
private Reference defaultSource;
|
125
|
|
126
|
private Map<Integer, NamedArea> areaToColumnIndexMap= new HashMap();
|
127
|
private int firstDataColumnIndex;
|
128
|
|
129
|
private ListDataProvider<TaxonDistributionDTO> bodyDataProvider;
|
130
|
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
|
131
|
|
132
|
private boolean isShowRank;
|
133
|
private Integer countNodes;
|
134
|
private Text searchText;
|
135
|
|
136
|
EventList<TaxonDistributionDTO> taxonList;
|
137
|
Map<UUID,Map<NamedArea,Set<DescriptionElementBase>>> taxonDistributionMap = new HashMap();
|
138
|
|
139
|
List<TaxonDistributionDTO> descriptionsToSave = new ArrayList();
|
140
|
|
141
|
|
142
|
SortedSet<DefinedTermBase> areas;
|
143
|
DistributionEditorPart part;
|
144
|
BodyLayerStack<TaxonDistributionDTO> bodyLayerStack;
|
145
|
private FreezeLayer freezeLayer;
|
146
|
private ConfigRegistry configRegistry;
|
147
|
private AbstractLayer topMostLayer;
|
148
|
|
149
|
private SelectionLayer selectionLayer;
|
150
|
|
151
|
|
152
|
|
153
|
// private FixedSummaryRowLayer summaryRowLayer;
|
154
|
|
155
|
|
156
|
/**
|
157
|
* @param parent
|
158
|
* @param style
|
159
|
*/
|
160
|
public DistributionEditor(Composite parent, DistributionEditorPart part) {
|
161
|
super(parent, SWT.NULL);
|
162
|
this.part = part;
|
163
|
this.setLayout(new GridLayout());
|
164
|
GridLayoutFactory.fillDefaults().applyTo(parent);
|
165
|
|
166
|
Composite topComposite = new Composite(parent, SWT.NONE);
|
167
|
createTopComposite(topComposite);
|
168
|
|
169
|
Composite bottomComposite = new Composite(parent, SWT.NONE);
|
170
|
GridLayoutFactory.fillDefaults().applyTo(bottomComposite);
|
171
|
|
172
|
natTable = new NatTable(parent, false);
|
173
|
parent.pack();
|
174
|
|
175
|
|
176
|
// // natTable = new NatTable(parent, viewportLayer);
|
177
|
// natTable = new NatTable(parent, false);
|
178
|
|
179
|
createStatusBar(parent);
|
180
|
}
|
181
|
|
182
|
public boolean isShowRank() {
|
183
|
return isShowRank;
|
184
|
}
|
185
|
|
186
|
public void setShowRank(boolean isShowRank) {
|
187
|
this.isShowRank = isShowRank;
|
188
|
}
|
189
|
|
190
|
public int getFirstDataColumnIndex() {
|
191
|
return firstDataColumnIndex;
|
192
|
}
|
193
|
|
194
|
public void setFirstDataColumnIndex(int firstDataColumnIndex) {
|
195
|
this.firstDataColumnIndex = firstDataColumnIndex;
|
196
|
}
|
197
|
|
198
|
public LinkedMap<String, String> getPropertyToLabelMap() {
|
199
|
return propertyToLabelMap;
|
200
|
}
|
201
|
|
202
|
public void setPropertyToLabelMap(LinkedMap<String, String> propertyToLabelMap) {
|
203
|
this.propertyToLabelMap = propertyToLabelMap;
|
204
|
}
|
205
|
|
206
|
public Map<Integer, NamedArea> getAreaToColumnIndexMap() {
|
207
|
return areaToColumnIndexMap;
|
208
|
}
|
209
|
|
210
|
|
211
|
public void setAreaToColumnIndexMap(Map<Integer, NamedArea> areaToColumnIndexMap) {
|
212
|
this.areaToColumnIndexMap = areaToColumnIndexMap;
|
213
|
}
|
214
|
|
215
|
|
216
|
public List<TaxonDistributionDTO> getDescriptionsToSave() {
|
217
|
return descriptionsToSave;
|
218
|
}
|
219
|
|
220
|
public void setDescriptionsToSave(List<TaxonDistributionDTO> descriptionsToSave) {
|
221
|
this.descriptionsToSave = descriptionsToSave;
|
222
|
}
|
223
|
|
224
|
|
225
|
|
226
|
private void createStatusBar(Composite composite) {
|
227
|
GridData gridData = new GridData();
|
228
|
gridData.horizontalSpan = 1;
|
229
|
gridData.grabExcessHorizontalSpace = true;
|
230
|
gridData.horizontalAlignment = GridData.FILL;
|
231
|
|
232
|
statusLabel = new Label(composite, SWT.LEFT);
|
233
|
statusLabel.setText(ELEMENT_COUNT + (taxonList != null ? taxonList.size() : UNKNOWN));
|
234
|
statusLabel.setLayoutData(gridData);
|
235
|
|
236
|
statusLabelSourceReference = new Label(composite, SWT.RIGHT);
|
237
|
|
238
|
statusLabelSourceReference.setLayoutData(gridData);
|
239
|
|
240
|
if (defaultSource != null){
|
241
|
statusLabelSourceReference.setText("Default Source Reference: " + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache());
|
242
|
|
243
|
}
|
244
|
}
|
245
|
|
246
|
private void applyStyles(){
|
247
|
ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
|
248
|
configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
|
249
|
// NOTE: Getting the colors and fonts from the GUIHelper ensures that
|
250
|
// they are disposed properly (required by SWT)
|
251
|
configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
252
|
configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
253
|
natTable.addConfiguration(configuration);
|
254
|
|
255
|
}
|
256
|
|
257
|
private void configureNatTable(ConfigRegistry configRegistry,
|
258
|
AbstractLayer topMostLayer) {
|
259
|
/**
|
260
|
* CONFIGURATION
|
261
|
*/
|
262
|
natTable.setConfigRegistry(configRegistry);
|
263
|
|
264
|
applyStyles();
|
265
|
|
266
|
//add default configuration because autoconfigure is set to false in constructor
|
267
|
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
|
268
|
|
269
|
// override the default sort configuration and change the mouse bindings
|
270
|
// to sort on a single click
|
271
|
|
272
|
natTable.addConfiguration(new SingleClickSortConfiguration());
|
273
|
natTable.addConfiguration(new FilterRowConfiguration(this));
|
274
|
|
275
|
// add the header menu configuration for adding the column header menu
|
276
|
// with hide/show actions
|
277
|
natTable.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable));
|
278
|
|
279
|
// add custom configuration for data conversion and add column labels to viewport layer
|
280
|
topMostLayer.addConfiguration(new DistributionCellEditorDataConversionConfiguration(this));
|
281
|
|
282
|
natTable.configure();
|
283
|
}
|
284
|
|
285
|
public void createTable(){
|
286
|
/**
|
287
|
* layers
|
288
|
*/
|
289
|
|
290
|
createLayers();
|
291
|
|
292
|
/**
|
293
|
* configuration
|
294
|
*/
|
295
|
configureNatTable( configRegistry, topMostLayer);
|
296
|
|
297
|
/**
|
298
|
* handlers and listeners
|
299
|
*/
|
300
|
registerHandlersAndListeners(topMostLayer);
|
301
|
FreezeHelper.freeze(freezeLayer, bodyLayerStack.getViewPortLayer(),
|
302
|
new PositionCoordinate(bodyLayerStack.getViewPortLayer(), 0, 0),
|
303
|
new PositionCoordinate(bodyLayerStack.getViewPortLayer(), 0, -1));
|
304
|
//grab all space
|
305
|
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
|
306
|
|
307
|
this.layout();
|
308
|
// boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
|
309
|
// System.out.println(ok);
|
310
|
}
|
311
|
|
312
|
|
313
|
private void createLayers() {
|
314
|
|
315
|
DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this);
|
316
|
|
317
|
DistributionEditorConfigLabelAccumulator labelAccumulator = new DistributionEditorConfigLabelAccumulator(this);
|
318
|
bodyLayerStack = new BodyLayerStack<>(taxonList, columnPropertyAccessor, new TaxonDistributionDtoComparator(), labelAccumulator);
|
319
|
|
320
|
bodyDataProvider = bodyLayerStack.getBodyDataProvider();
|
321
|
|
322
|
|
323
|
|
324
|
propertyToLabelMap.put(TAXON_COLUMN, Messages.ChecklistEditor_TAXON);
|
325
|
if (isShowRank){
|
326
|
propertyToLabelMap.put(RANK_COLUMN, Messages.ChecklistEditor_RANK);
|
327
|
}
|
328
|
configRegistry = new ConfigRegistry();
|
329
|
|
330
|
initLabels();
|
331
|
this.selectionLayer = bodyLayerStack.getSelectionLayer();
|
332
|
|
333
|
|
334
|
|
335
|
freezeLayer = new FreezeLayer(selectionLayer);
|
336
|
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
|
337
|
freezeLayer, bodyLayerStack.getViewPortLayer(), selectionLayer);
|
338
|
|
339
|
// as the selection mouse bindings are registered for the region label
|
340
|
// GridRegion.BODY
|
341
|
// we need to set that region label to the viewport so the selection via mouse
|
342
|
// is working correctly
|
343
|
compositeFreezeLayer.setRegionName(GridRegion.BODY);
|
344
|
|
345
|
|
346
|
IDataProvider columnHeaderDataProvider =
|
347
|
new DefaultColumnHeaderDataProvider(propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
|
348
|
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
|
349
|
ILayer columnHeaderLayer = new ColumnHeaderLayer(
|
350
|
columnHeaderDataLayer,
|
351
|
compositeFreezeLayer,
|
352
|
selectionLayer);
|
353
|
|
354
|
FilterRowHeaderComposite<TaxonDistributionDTO> filterRowHeaderLayer =
|
355
|
new FilterRowHeaderComposite<>(
|
356
|
new DefaultGlazedListsFilterStrategy<>(
|
357
|
bodyLayerStack.getFilterList(),
|
358
|
columnPropertyAccessor,
|
359
|
configRegistry),
|
360
|
columnHeaderLayer,
|
361
|
columnHeaderDataLayer.getDataProvider(),
|
362
|
configRegistry);
|
363
|
|
364
|
|
365
|
|
366
|
// build the row header layer stack
|
367
|
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
|
368
|
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
|
369
|
ILayer rowHeaderLayer = new RowHeaderLayer(
|
370
|
rowHeaderDataLayer,
|
371
|
compositeFreezeLayer,
|
372
|
selectionLayer);
|
373
|
|
374
|
|
375
|
|
376
|
IDataProvider cornerDataProvider =
|
377
|
new DefaultCornerDataProvider(
|
378
|
columnHeaderDataProvider,
|
379
|
rowHeaderDataProvider);
|
380
|
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
|
381
|
ILayer cornerLayer = new CornerLayer(
|
382
|
cornerDataLayer,
|
383
|
rowHeaderLayer,
|
384
|
filterRowHeaderLayer);
|
385
|
|
386
|
GridLayer gridLayer = new GridLayer(
|
387
|
compositeFreezeLayer,
|
388
|
filterRowHeaderLayer,
|
389
|
rowHeaderLayer,
|
390
|
cornerLayer);
|
391
|
|
392
|
natTable.setLayer(gridLayer);
|
393
|
|
394
|
topMostLayer = compositeFreezeLayer;
|
395
|
|
396
|
|
397
|
}
|
398
|
|
399
|
/**
|
400
|
* @param parent
|
401
|
* @return
|
402
|
*/
|
403
|
private Text createSearchBar(Composite parent) {
|
404
|
|
405
|
Button button1 = new Button(parent, SWT.PUSH );
|
406
|
GridData gridData2 = new GridData();
|
407
|
gridData2.horizontalSpan = 1;
|
408
|
gridData2.horizontalAlignment = SWT.RIGHT;
|
409
|
button1.setLayoutData(gridData2);
|
410
|
|
411
|
|
412
|
button1.setText(Messages.ChecklistEditor_DIST_STATUS);
|
413
|
button1.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
|
414
|
button1.addSelectionListener(new SelectionAdapter() {
|
415
|
@Override
|
416
|
public void widgetSelected(SelectionEvent event) {
|
417
|
AvailableDistributionWizard availableDistributionWizard = new AvailableDistributionWizard();
|
418
|
WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
|
419
|
availableDistributionWizard);
|
420
|
|
421
|
int open = dialog.open();
|
422
|
if(open == 0){
|
423
|
reload();
|
424
|
}
|
425
|
}
|
426
|
});
|
427
|
|
428
|
Button button2 = new Button(parent, SWT.PUSH );
|
429
|
GridData gridData3 = new GridData();
|
430
|
gridData2.horizontalSpan = 1;
|
431
|
button2.setLayoutData(gridData3);
|
432
|
|
433
|
|
434
|
button2.setText(Messages.ChecklistEditor_DEFAULT_SOURCE);
|
435
|
button2.setToolTipText(Messages.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP);
|
436
|
button2.addSelectionListener(new SelectionAdapter() {
|
437
|
|
438
|
@Override
|
439
|
public void widgetSelected(SelectionEvent event) {
|
440
|
defaultSource = part.getCdmEntitySession().load(ReferenceSelectionDialog.select(AbstractUtility.getShell(), null), true);
|
441
|
|
442
|
String defaultSourceStr = (defaultSource == null) ? "" : "Default Source Reference: " + defaultSource.getTitleCache();
|
443
|
if (defaultSourceStr.length()> 100){
|
444
|
defaultSourceStr = defaultSourceStr.substring(0, 98) + "...";
|
445
|
}
|
446
|
statusLabelSourceReference.setText(defaultSourceStr);
|
447
|
|
448
|
button2.setBackground(EditorUtil.getColor(Resources.COLOR_CONTROL_SELECTED));
|
449
|
}
|
450
|
|
451
|
});
|
452
|
|
453
|
parent.pack();
|
454
|
return searchText;
|
455
|
}
|
456
|
/**
|
457
|
* This method should only be called for adding new Distribution columns and reloading the table.<br>
|
458
|
* It will hide the old distribution column and load the newly added columns.<br>
|
459
|
* <p>
|
460
|
* <b>Notice:</b> for data update please use <b>refresh()</b>
|
461
|
*
|
462
|
*/
|
463
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
464
|
public void reload(){
|
465
|
this.areaToColumnIndexMap.clear();
|
466
|
this.areas.clear();
|
467
|
this.propertyToLabelMap.clear();
|
468
|
createTable();
|
469
|
natTable.redraw();
|
470
|
}
|
471
|
|
472
|
/**
|
473
|
* @param parent
|
474
|
*/
|
475
|
private void createTopComposite(Composite parent) {
|
476
|
GridLayout gridLayout = new GridLayout(3, false);
|
477
|
gridLayout.marginWidth = 0;
|
478
|
gridLayout.marginHeight = 0;
|
479
|
parent.setLayout(gridLayout);
|
480
|
searchText = createSearchBar(parent);
|
481
|
|
482
|
|
483
|
}
|
484
|
public void loadDistributions(List<TaxonDistributionDTO> taxonList) {
|
485
|
if (this.taxonList == null){
|
486
|
this.taxonList = new BasicEventList<>();
|
487
|
}
|
488
|
taxonList.stream().forEach(wrapper->DistributionEditor.this.taxonList.add(wrapper));
|
489
|
statusLabel.setText(ELEMENT_COUNT + (taxonList != null ? taxonList.size() : UNKNOWN));
|
490
|
createTaxonDistributionMap();
|
491
|
}
|
492
|
|
493
|
protected void createTaxonDistributionMap() {
|
494
|
Iterator<TaxonDistributionDTO> iterator = this.taxonList.iterator();
|
495
|
while (iterator.hasNext()){
|
496
|
TaxonDistributionDTO dto = iterator.next();
|
497
|
TaxonDescriptionDTO descriptionDto = dto.getDescriptionsWrapper();
|
498
|
for (TaxonDescription desc: descriptionDto.getDescriptions()){
|
499
|
if(this.part.getCdmEntitySession()!=null){
|
500
|
this.part.getCdmEntitySession().load(desc, true);
|
501
|
}
|
502
|
for (DescriptionElementBase descElement: desc.getElements()){
|
503
|
if (descElement instanceof Distribution){
|
504
|
Map<NamedArea, Set<DescriptionElementBase>> distributionsMap = taxonDistributionMap.get(dto.getTaxonUuid());
|
505
|
|
506
|
if (distributionsMap == null){
|
507
|
distributionsMap = new HashMap();
|
508
|
taxonDistributionMap.put(dto.getTaxonUuid(), distributionsMap);
|
509
|
}
|
510
|
Set<DescriptionElementBase> distributions = distributionsMap.get(((Distribution) descElement).getArea());
|
511
|
if (distributions == null){
|
512
|
distributions = new HashSet();
|
513
|
distributionsMap.put(((Distribution)descElement).getArea(), distributions);
|
514
|
}
|
515
|
distributions.add(descElement);
|
516
|
|
517
|
}
|
518
|
}
|
519
|
}
|
520
|
}
|
521
|
}
|
522
|
|
523
|
|
524
|
|
525
|
|
526
|
|
527
|
private void initLabels() {
|
528
|
|
529
|
int index = 1;
|
530
|
if (isShowRank){
|
531
|
index++;
|
532
|
}
|
533
|
|
534
|
loadNamedAreas();
|
535
|
for (DefinedTermBase area: areas) {
|
536
|
this.areaToColumnIndexMap.put(index++, (NamedArea)area);
|
537
|
String areaLabel;
|
538
|
//TODO: adapt to preference
|
539
|
Representation rep = area.getPreferredRepresentation(CdmStore.getDefaultLanguage());
|
540
|
String label = rep.getLabel();
|
541
|
if (label == null){
|
542
|
label = area.getTitleCache();
|
543
|
}
|
544
|
if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
|
545
|
if (area.getIdInVocabulary() != null){
|
546
|
areaLabel = area.getIdInVocabulary();
|
547
|
} else{
|
548
|
areaLabel = label;
|
549
|
}
|
550
|
}else if (PreferencesUtil.isShowSymbol1InChecklistEditor()){
|
551
|
if (area.getSymbol() != null){
|
552
|
areaLabel = area.getSymbol();
|
553
|
} else{
|
554
|
areaLabel = label;
|
555
|
}
|
556
|
}else if (PreferencesUtil.isShowSymbol2InChecklistEditor()){
|
557
|
if (area.getSymbol2() != null){
|
558
|
areaLabel = area.getSymbol2();
|
559
|
} else{
|
560
|
areaLabel = label;
|
561
|
}
|
562
|
}else{
|
563
|
areaLabel = label;
|
564
|
}
|
565
|
|
566
|
|
567
|
//String areaLabel = area.getLabel();
|
568
|
String property = areaLabel;
|
569
|
propertyToLabelMap.put(property, areaLabel);
|
570
|
}
|
571
|
}
|
572
|
|
573
|
private SortedSet<DefinedTermBase> loadNamedAreas() {
|
574
|
//IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
|
575
|
|
576
|
String valuesAreas = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey());
|
577
|
String values = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
|
578
|
if (values != null && values != "") { //$NON-NLS-1$
|
579
|
String[] split = values.split(";"); //$NON-NLS-1$
|
580
|
List<String> listValue = Arrays.asList(split);
|
581
|
List<DefinedTermBase> termlist = new ArrayList<DefinedTermBase>();
|
582
|
Set<UUID> uuidList = new HashSet<UUID>();
|
583
|
UUID uuid;
|
584
|
for(String s : listValue){
|
585
|
uuid = UUID.fromString(s);
|
586
|
uuidList.add(uuid);
|
587
|
|
588
|
}
|
589
|
IVocabularyService service = CdmStore.getService(IVocabularyService.class);
|
590
|
List<TermVocabulary> vocs = service.find(uuidList);
|
591
|
split = valuesAreas.split(";");
|
592
|
listValue = Arrays.asList(split);
|
593
|
for (TermVocabulary voc: vocs){
|
594
|
termlist.addAll(service.getTerms(voc, null, null, null, null).getRecords());
|
595
|
}
|
596
|
List<DefinedTermBase> filteredList = new ArrayList();
|
597
|
for (DefinedTermBase area: termlist){
|
598
|
if (listValue.contains(area.getUuid().toString())) {
|
599
|
filteredList.add(area);
|
600
|
}
|
601
|
|
602
|
}
|
603
|
|
604
|
if (PreferencesUtil.isSortNamedAreaByOrderInVocabulary()){
|
605
|
areas = getTermsOrderedByVocabularyOrder(filteredList);
|
606
|
} else if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
|
607
|
areas = getTermsOrderedByIdInVocabulary(filteredList);
|
608
|
}else{
|
609
|
areas = getTermsOrderedByLabels(filteredList, CdmStore.getDefaultLanguage());
|
610
|
}
|
611
|
}
|
612
|
return null;
|
613
|
}
|
614
|
|
615
|
public SortedSet<DefinedTermBase> getTermsOrderedByLabels(List<DefinedTermBase> listTerm,Language language){
|
616
|
TermLanguageComparator<?> comp = new TermLanguageComparator<>();
|
617
|
comp.setCompareLanguage(language);
|
618
|
SortedSet<DefinedTermBase> result = new TreeSet(comp);
|
619
|
if(listTerm != null){
|
620
|
result.addAll(listTerm);
|
621
|
}
|
622
|
return result;
|
623
|
}
|
624
|
|
625
|
public SortedSet<DefinedTermBase> getTermsOrderedByIdInVocabulary(List<DefinedTermBase> namedAreas) {
|
626
|
TermIdInVocabularyComparator<?> comp = new TermIdInVocabularyComparator<>();
|
627
|
|
628
|
SortedSet<DefinedTermBase> result = new TreeSet(comp);
|
629
|
if(namedAreas != null){
|
630
|
result.addAll(namedAreas);
|
631
|
}
|
632
|
return result;
|
633
|
}
|
634
|
|
635
|
public SortedSet<DefinedTermBase> getTermsOrderedByVocabularyOrder(List<DefinedTermBase> listAreas){
|
636
|
HashMap<TermVocabulary<DefinedTermBase>, List<DefinedTermBase>> vocs = new HashMap<>();
|
637
|
OrderedTermComparator<?> comp = new OrderedTermComparator<>();
|
638
|
boolean allOrderedTerms = true;
|
639
|
List<TermVocabulary> alreadyOrderIndexNull = new ArrayList<>();
|
640
|
for (DefinedTermBase term: listAreas){
|
641
|
if (!(term instanceof OrderedTermBase)){
|
642
|
allOrderedTerms = false;
|
643
|
break;
|
644
|
}else if (((OrderedTermBase)term).getOrderIndex() == 0){
|
645
|
if(alreadyOrderIndexNull.contains(term.getVocabulary())) {
|
646
|
allOrderedTerms = false;
|
647
|
break;
|
648
|
}else{
|
649
|
alreadyOrderIndexNull.add(term.getVocabulary());
|
650
|
}
|
651
|
|
652
|
|
653
|
}
|
654
|
}
|
655
|
if (allOrderedTerms){
|
656
|
SortedSet<DefinedTermBase> result = new TreeSet(comp.reversed());
|
657
|
result.addAll(listAreas);
|
658
|
return result;
|
659
|
}else{
|
660
|
return getTermsOrderedByLabels(listAreas, PreferencesUtil.getGlobalLanguage());
|
661
|
}
|
662
|
|
663
|
|
664
|
}
|
665
|
|
666
|
private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
|
667
|
//selection listener
|
668
|
E4SelectionListener selectionListener = new DistributionCellSelectionListener(part.getSelectionService(),
|
669
|
selectionLayer, bodyDataProvider, part);
|
670
|
selectionLayer.addLayerListener(selectionListener);
|
671
|
selectionListener.setFullySelectedRowsOnly(false);
|
672
|
|
673
|
//register handler for view configuration menu
|
674
|
// natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
|
675
|
}
|
676
|
|
677
|
/**
|
678
|
* @return
|
679
|
*/
|
680
|
public IRowDataProvider<TaxonDistributionDTO> getBodyDataProvider() {
|
681
|
return bodyDataProvider;
|
682
|
}
|
683
|
|
684
|
public void setDirty() {
|
685
|
part.setDirty();
|
686
|
}
|
687
|
|
688
|
public Reference getDefaultSource(){
|
689
|
return defaultSource;
|
690
|
}
|
691
|
|
692
|
/**
|
693
|
* @param result
|
694
|
*/
|
695
|
public void reloadDistributions() {
|
696
|
loadDistributions(taxonList);
|
697
|
|
698
|
}
|
699
|
|
700
|
|
701
|
|
702
|
}
|