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.Collection;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.HashSet;
|
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.wizard.WizardDialog;
|
30
|
import org.eclipse.nebula.widgets.nattable.NatTable;
|
31
|
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
|
32
|
import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
|
33
|
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
|
34
|
import org.eclipse.nebula.widgets.nattable.data.IRowDataProvider;
|
35
|
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
|
36
|
import org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener;
|
37
|
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
|
38
|
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
|
39
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
|
40
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
|
41
|
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
|
42
|
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
|
43
|
import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
|
44
|
import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
|
45
|
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
|
46
|
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
|
47
|
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
|
48
|
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
|
49
|
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
|
50
|
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
|
51
|
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
|
52
|
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
|
53
|
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
|
54
|
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
|
55
|
import org.eclipse.swt.SWT;
|
56
|
import org.eclipse.swt.events.SelectionAdapter;
|
57
|
import org.eclipse.swt.events.SelectionEvent;
|
58
|
import org.eclipse.swt.layout.GridData;
|
59
|
import org.eclipse.swt.layout.GridLayout;
|
60
|
import org.eclipse.swt.widgets.Button;
|
61
|
import org.eclipse.swt.widgets.Composite;
|
62
|
import org.eclipse.swt.widgets.Label;
|
63
|
import org.eclipse.swt.widgets.Text;
|
64
|
|
65
|
import ca.odell.glazedlists.BasicEventList;
|
66
|
import ca.odell.glazedlists.EventList;
|
67
|
import ca.odell.glazedlists.SortedList;
|
68
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
69
|
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
|
70
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
71
|
import eu.etaxonomy.cdm.model.common.Language;
|
72
|
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
|
73
|
import eu.etaxonomy.cdm.model.common.OrderedTermComparator;
|
74
|
import eu.etaxonomy.cdm.model.common.TermIdInVocabularyComparator;
|
75
|
import eu.etaxonomy.cdm.model.common.TermLanguageComparator;
|
76
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
77
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
78
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
79
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
80
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
81
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
82
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
83
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
84
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
85
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
86
|
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
|
87
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
88
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
89
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog;
|
90
|
|
91
|
/**
|
92
|
* @author k.luther
|
93
|
* @since 27.11.2018
|
94
|
*
|
95
|
*/
|
96
|
public class DistributionEditor extends Composite {
|
97
|
|
98
|
|
99
|
private static final String DISTRIBUTION_EDITOR = "Distribution Editor";
|
100
|
private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
|
101
|
private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
|
102
|
private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
|
103
|
public static final String TYPE_FILTER_TEXT = "type filter text"; //$NON-NLS-1$
|
104
|
|
105
|
static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
|
106
|
static final String RANK_COLUMN = "collector_column"; //$NON-NLS-1$
|
107
|
|
108
|
private static final Logger logger = Logger.getLogger(DistributionEditor.class);
|
109
|
@Inject
|
110
|
private EMenuService menuService;
|
111
|
private NatTable natTable;
|
112
|
private Label statusLabel;
|
113
|
private Label statusLabelSourceReference;
|
114
|
private Reference defaultSource;
|
115
|
|
116
|
private Map<Integer, NamedArea> areaToColumnIndexMap= new HashMap();
|
117
|
private int firstDataColumnIndex;
|
118
|
|
119
|
private ListDataProvider<TaxonDistributionDTO> bodyDataProvider;
|
120
|
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
|
121
|
|
122
|
private boolean isShowRank;
|
123
|
private Integer countNodes;
|
124
|
private Text searchText;
|
125
|
|
126
|
EventList<TaxonDistributionDTO> taxonList;
|
127
|
SortedSet<DefinedTermBase> areas;
|
128
|
DistributionEditorPart part;
|
129
|
private ViewportLayer bodyLayer;
|
130
|
private FreezeLayer freezeLayer;
|
131
|
private ConfigRegistry configRegistry;
|
132
|
private AbstractLayer topMostLayer;
|
133
|
|
134
|
private SelectionLayer selectionLayer;
|
135
|
|
136
|
// private FixedSummaryRowLayer summaryRowLayer;
|
137
|
|
138
|
|
139
|
/**
|
140
|
* @param parent
|
141
|
* @param style
|
142
|
*/
|
143
|
public DistributionEditor(Composite parent, DistributionEditorPart part) {
|
144
|
super(parent, SWT.NULL);
|
145
|
this.setLayout(new GridLayout());
|
146
|
this.part = part;
|
147
|
createTopComposite(parent);
|
148
|
|
149
|
|
150
|
// natTable = new NatTable(parent, viewportLayer);
|
151
|
natTable = new NatTable(this, false);
|
152
|
|
153
|
// createStatusBar(parent);
|
154
|
}
|
155
|
|
156
|
public boolean isShowRank() {
|
157
|
return isShowRank;
|
158
|
}
|
159
|
|
160
|
public void setShowRank(boolean isShowRank) {
|
161
|
this.isShowRank = isShowRank;
|
162
|
}
|
163
|
|
164
|
public int getFirstDataColumnIndex() {
|
165
|
return firstDataColumnIndex;
|
166
|
}
|
167
|
|
168
|
public void setFirstDataColumnIndex(int firstDataColumnIndex) {
|
169
|
this.firstDataColumnIndex = firstDataColumnIndex;
|
170
|
}
|
171
|
|
172
|
public LinkedMap<String, String> getPropertyToLabelMap() {
|
173
|
return propertyToLabelMap;
|
174
|
}
|
175
|
|
176
|
public void setPropertyToLabelMap(LinkedMap<String, String> propertyToLabelMap) {
|
177
|
this.propertyToLabelMap = propertyToLabelMap;
|
178
|
}
|
179
|
|
180
|
public Map<Integer, NamedArea> getAreaToColumnIndexMap() {
|
181
|
return areaToColumnIndexMap;
|
182
|
}
|
183
|
|
184
|
|
185
|
public void setAreaToColumnIndexMap(Map<Integer, NamedArea> areaToColumnIndexMap) {
|
186
|
this.areaToColumnIndexMap = areaToColumnIndexMap;
|
187
|
}
|
188
|
|
189
|
|
190
|
|
191
|
private void createStatusBar(Composite composite) {
|
192
|
GridData gridData = new GridData();
|
193
|
gridData.horizontalSpan = 1;
|
194
|
gridData.grabExcessHorizontalSpace = true;
|
195
|
gridData.horizontalAlignment = GridData.FILL;
|
196
|
|
197
|
statusLabel = new Label(composite, SWT.LEFT);
|
198
|
statusLabel.setText(ELEMENT_COUNT + (countNodes != null ? countNodes : UNKNOWN));
|
199
|
statusLabel.setLayoutData(gridData);
|
200
|
|
201
|
statusLabelSourceReference = new Label(composite, SWT.RIGHT);
|
202
|
|
203
|
statusLabelSourceReference.setLayoutData(gridData);
|
204
|
|
205
|
if (defaultSource != null){
|
206
|
statusLabelSourceReference.setText("Default Source Reference: " + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache());
|
207
|
|
208
|
}
|
209
|
}
|
210
|
|
211
|
private void applyStyles(){
|
212
|
ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
|
213
|
configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
|
214
|
// NOTE: Getting the colors and fonts from the GUIHelper ensures that
|
215
|
// they are disposed properly (required by SWT)
|
216
|
configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
217
|
configuration.rHeaderBgColor = GUIHelper.getColor(211, 211, 211);
|
218
|
natTable.addConfiguration(configuration);
|
219
|
|
220
|
}
|
221
|
|
222
|
private void configureNatTable(ConfigRegistry configRegistry,
|
223
|
AbstractLayer topMostLayer) {
|
224
|
/**
|
225
|
* CONFIGURATION
|
226
|
*/
|
227
|
natTable.setConfigRegistry(configRegistry);
|
228
|
|
229
|
applyStyles();
|
230
|
|
231
|
//add default configuration because autoconfigure is set to false in constructor
|
232
|
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
|
233
|
|
234
|
//FIXME: this is for DEBUG ONLY
|
235
|
// natTable.addConfiguration(new DebugMenuConfiguration(natTable));
|
236
|
|
237
|
// override the default sort configuration and change the mouse bindings
|
238
|
// to sort on a single click
|
239
|
|
240
|
natTable.addConfiguration(new SingleClickSortConfiguration());
|
241
|
// natTable.addConfiguration(new CharacterMatrixLabelStyleConfiguration());
|
242
|
|
243
|
// add the header menu configuration for adding the column header menu
|
244
|
// with hide/show actions
|
245
|
natTable.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable));
|
246
|
|
247
|
// add custom configuration for data conversion and add column labels to viewport layer
|
248
|
// topMostLayer.addConfiguration(new CellEditorDataConversionConfiguration(this));
|
249
|
|
250
|
// //register aggregation configuration
|
251
|
// summaryRowLayer.addConfiguration(new AggregationConfiguration(this));
|
252
|
|
253
|
//+++CONTEXT MENU+++
|
254
|
// menuService.registerContextMenu(natTable, "eu.etaxonomy.taxeditor.editor.popupmenu.charactermatrix"); //$NON-NLS-1$
|
255
|
// // get the menu registered by EMenuService
|
256
|
// final Menu e4Menu = natTable.getMenu();
|
257
|
// // remove the menu reference from NatTable instance
|
258
|
// natTable.setMenu(null);
|
259
|
// natTable.addConfiguration(
|
260
|
// new AbstractUiBindingConfiguration() {
|
261
|
// @Override
|
262
|
// public void configureUiBindings(
|
263
|
// UiBindingRegistry uiBindingRegistry) {
|
264
|
// // add e4 menu to NatTable
|
265
|
// new PopupMenuBuilder(natTable, e4Menu)
|
266
|
// .build();
|
267
|
//
|
268
|
// // register the UI binding for header, corner and body region
|
269
|
// uiBindingRegistry.registerMouseDownBinding(
|
270
|
// new MouseEventMatcher(
|
271
|
// SWT.NONE,
|
272
|
// null,
|
273
|
// MouseEventMatcher.RIGHT_BUTTON),
|
274
|
// new PopupMenuAction(e4Menu));
|
275
|
// }
|
276
|
// });
|
277
|
|
278
|
natTable.configure();
|
279
|
}
|
280
|
|
281
|
public void createTable(){
|
282
|
/**
|
283
|
* layers
|
284
|
*/
|
285
|
|
286
|
createLayers();
|
287
|
|
288
|
/**
|
289
|
* configuration
|
290
|
*/
|
291
|
configureNatTable( configRegistry, topMostLayer);
|
292
|
|
293
|
/**
|
294
|
* handlers and listeners
|
295
|
*/
|
296
|
registerHandlersAndListeners(topMostLayer);
|
297
|
|
298
|
//grab all space
|
299
|
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
|
300
|
|
301
|
//update label to current data set
|
302
|
// toolbar.getWsLabel().setText(descriptiveDataSet.getLabel());
|
303
|
// toolbar.getWsLabel().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
304
|
// toolbar.getWsLabel().getParent().layout();
|
305
|
|
306
|
//initial freeze of supplemental columns
|
307
|
// freezeSupplementalColumns(freezeSupplementalColumns);
|
308
|
|
309
|
|
310
|
this.layout();
|
311
|
// boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
|
312
|
// System.out.println(ok);
|
313
|
}
|
314
|
|
315
|
|
316
|
private void createLayers() {
|
317
|
|
318
|
SortedList sortedList = new SortedList(taxonList, new TaxonDistributionDtoComparator());
|
319
|
DistributionColumnAccessor columnPropertyAccessor = new DistributionColumnAccessor(this);
|
320
|
|
321
|
|
322
|
bodyDataProvider = new ListDataProvider(sortedList, columnPropertyAccessor);
|
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
|
// build up a layer stack consisting of DataLayer, SelectionLayer and
|
332
|
// ViewportLayer
|
333
|
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
|
334
|
selectionLayer = new SelectionLayer(bodyDataLayer);
|
335
|
bodyLayer = new ViewportLayer(selectionLayer);
|
336
|
|
337
|
// as the selection mouse bindings are registered for the region label
|
338
|
// GridRegion.BODY
|
339
|
// we need to set that region label to the viewport so the selection via mouse
|
340
|
// is working correctly
|
341
|
bodyLayer.setRegionName(GridRegion.BODY);
|
342
|
|
343
|
|
344
|
IDataProvider columnHeaderDataProvider =
|
345
|
new DefaultColumnHeaderDataProvider(propertyToLabelMap.values().toArray(new String[] {}), propertyToLabelMap);
|
346
|
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
|
347
|
ILayer columnHeaderLayer = new ColumnHeaderLayer(
|
348
|
columnHeaderDataLayer,
|
349
|
bodyLayer,
|
350
|
selectionLayer);
|
351
|
|
352
|
|
353
|
// build the row header layer stack
|
354
|
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
|
355
|
DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider, 40, 20);
|
356
|
ILayer rowHeaderLayer = new RowHeaderLayer(
|
357
|
rowHeaderDataLayer,
|
358
|
bodyLayer,
|
359
|
selectionLayer);
|
360
|
|
361
|
|
362
|
|
363
|
IDataProvider cornerDataProvider =
|
364
|
new DefaultCornerDataProvider(
|
365
|
columnHeaderDataProvider,
|
366
|
rowHeaderDataProvider);
|
367
|
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
|
368
|
ILayer cornerLayer = new CornerLayer(
|
369
|
cornerDataLayer,
|
370
|
rowHeaderLayer,
|
371
|
columnHeaderLayer);
|
372
|
|
373
|
GridLayer gridLayer = new GridLayer(
|
374
|
bodyLayer,
|
375
|
columnHeaderLayer,
|
376
|
rowHeaderLayer,
|
377
|
cornerLayer);
|
378
|
|
379
|
natTable.setLayer(gridLayer);
|
380
|
|
381
|
topMostLayer = bodyLayer;
|
382
|
|
383
|
|
384
|
}
|
385
|
|
386
|
/**
|
387
|
* @param parent
|
388
|
* @return
|
389
|
*/
|
390
|
private Text createSearchBar(Composite parent) {
|
391
|
|
392
|
final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
|
393
|
GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
|
394
|
|
395
|
searchText.setLayoutData(gridData);
|
396
|
searchText.setForeground(EditorUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
|
397
|
searchText.setText(TYPE_FILTER_TEXT);
|
398
|
searchText.setToolTipText(Messages.ChecklistEditor_SEARCH_TOOLTIP);
|
399
|
|
400
|
Button button1 = new Button(parent, SWT.PUSH );
|
401
|
GridData gridData2 = new GridData();
|
402
|
gridData2.horizontalSpan = 1;
|
403
|
gridData2.horizontalAlignment = SWT.RIGHT;
|
404
|
button1.setLayoutData(gridData2);
|
405
|
|
406
|
|
407
|
button1.setText(Messages.ChecklistEditor_DIST_STATUS);
|
408
|
button1.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
|
409
|
button1.addSelectionListener(new SelectionAdapter() {
|
410
|
@Override
|
411
|
public void widgetSelected(SelectionEvent event) {
|
412
|
AvailableDistributionWizard availableDistributionWizard = new AvailableDistributionWizard();
|
413
|
WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
|
414
|
availableDistributionWizard);
|
415
|
|
416
|
int open = dialog.open();
|
417
|
if(open == 0){
|
418
|
//TODO!!!!
|
419
|
// reload();
|
420
|
}
|
421
|
}
|
422
|
});
|
423
|
|
424
|
Button button2 = new Button(parent, SWT.PUSH );
|
425
|
GridData gridData3 = new GridData();
|
426
|
gridData2.horizontalSpan = 1;
|
427
|
button2.setLayoutData(gridData3);
|
428
|
|
429
|
|
430
|
button2.setText(Messages.ChecklistEditor_DEFAULT_SOURCE);
|
431
|
button2.setToolTipText(Messages.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP);
|
432
|
button2.addSelectionListener(new SelectionAdapter() {
|
433
|
|
434
|
@Override
|
435
|
public void widgetSelected(SelectionEvent event) {
|
436
|
defaultSource = ReferenceSelectionDialog.select(AbstractUtility.getShell(), null);
|
437
|
|
438
|
String defaultSourceStr = (defaultSource == null) ? "" : "Default Source Reference: " + defaultSource.getTitleCache();
|
439
|
if (defaultSourceStr.length()> 100){
|
440
|
defaultSourceStr = defaultSourceStr.substring(0, 98) + "...";
|
441
|
}
|
442
|
statusLabelSourceReference.setText(defaultSourceStr);
|
443
|
|
444
|
button2.setBackground(EditorUtil.getColor(Resources.COLOR_CONTROL_SELECTED));
|
445
|
}
|
446
|
|
447
|
});
|
448
|
|
449
|
parent.pack();
|
450
|
return searchText;
|
451
|
}
|
452
|
|
453
|
/**
|
454
|
* @param parent
|
455
|
*/
|
456
|
private void createTopComposite(Composite parent) {
|
457
|
GridLayout gridLayout = new GridLayout(3, false);
|
458
|
gridLayout.marginWidth = 0;
|
459
|
gridLayout.marginHeight = 0;
|
460
|
parent.setLayout(gridLayout);
|
461
|
|
462
|
searchText = createSearchBar(parent);
|
463
|
|
464
|
|
465
|
}
|
466
|
public void loadDistributions(List<TaxonDistributionDTO> taxonList) {
|
467
|
if (this.taxonList == null){
|
468
|
this.taxonList = new BasicEventList<>();
|
469
|
}
|
470
|
taxonList.stream().forEach(wrapper->DistributionEditor.this.taxonList.add(wrapper));
|
471
|
}
|
472
|
|
473
|
|
474
|
|
475
|
public Collection<DescriptionElementBase> getDistributions() {
|
476
|
Collection<DescriptionElementBase> descElements = new HashSet();
|
477
|
//TODO: only for edited taxa
|
478
|
taxonList.forEach(taxonDto->taxonDto.getDistributionMap()
|
479
|
.forEach((area, descriptionElements)->descElements.addAll(descriptionElements)));
|
480
|
|
481
|
|
482
|
return descElements;
|
483
|
|
484
|
}
|
485
|
|
486
|
private void initLabels() {
|
487
|
|
488
|
int index = 1;
|
489
|
if (isShowRank){
|
490
|
index++;
|
491
|
}
|
492
|
|
493
|
loadNamedAreas();
|
494
|
for (DefinedTermBase area: areas) {
|
495
|
this.areaToColumnIndexMap.put(index++, (NamedArea)area);
|
496
|
|
497
|
//TODO: adapt to preference
|
498
|
String areaLabel = area.getLabel();
|
499
|
String property = areaLabel;
|
500
|
propertyToLabelMap.put(property, areaLabel);
|
501
|
}
|
502
|
}
|
503
|
|
504
|
private SortedSet<DefinedTermBase> loadNamedAreas() {
|
505
|
//IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
|
506
|
|
507
|
String valuesAreas = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey());
|
508
|
String values = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
|
509
|
if (values != null && values != "") { //$NON-NLS-1$
|
510
|
String[] split = values.split(";"); //$NON-NLS-1$
|
511
|
List<String> listValue = Arrays.asList(split);
|
512
|
List<DefinedTermBase> termlist = new ArrayList<DefinedTermBase>();
|
513
|
Set<UUID> uuidList = new HashSet<UUID>();
|
514
|
UUID uuid;
|
515
|
for(String s : listValue){
|
516
|
uuid = UUID.fromString(s);
|
517
|
uuidList.add(uuid);
|
518
|
|
519
|
}
|
520
|
IVocabularyService service = CdmStore.getService(IVocabularyService.class);
|
521
|
List<TermVocabulary> vocs = service.find(uuidList);
|
522
|
split = valuesAreas.split(";");
|
523
|
listValue = Arrays.asList(split);
|
524
|
for (TermVocabulary voc: vocs){
|
525
|
termlist.addAll(service.getTerms(voc, null, null, null, null).getRecords());
|
526
|
}
|
527
|
List<DefinedTermBase> filteredList = new ArrayList();
|
528
|
for (DefinedTermBase area: termlist){
|
529
|
if (listValue.contains(area.getUuid().toString())) {
|
530
|
filteredList.add(area);
|
531
|
}
|
532
|
|
533
|
}
|
534
|
|
535
|
if (PreferencesUtil.isSortNamedAreaByOrderInVocabulary()){
|
536
|
areas = getTermsOrderedByVocabularyOrder(filteredList);
|
537
|
} else if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
|
538
|
areas = getTermsOrderedByIdInVocabulary(filteredList);
|
539
|
}else{
|
540
|
areas = getTermsOrderedByLabels(filteredList, CdmStore.getDefaultLanguage());
|
541
|
}
|
542
|
}
|
543
|
return null;
|
544
|
}
|
545
|
|
546
|
public SortedSet<DefinedTermBase> getTermsOrderedByLabels(List<DefinedTermBase> listTerm,Language language){
|
547
|
TermLanguageComparator<?> comp = new TermLanguageComparator<>();
|
548
|
comp.setCompareLanguage(language);
|
549
|
SortedSet<DefinedTermBase> result = new TreeSet(comp);
|
550
|
if(listTerm != null){
|
551
|
result.addAll(listTerm);
|
552
|
}
|
553
|
return result;
|
554
|
}
|
555
|
|
556
|
public SortedSet<DefinedTermBase> getTermsOrderedByIdInVocabulary(List<DefinedTermBase> namedAreas) {
|
557
|
TermIdInVocabularyComparator<?> comp = new TermIdInVocabularyComparator<>();
|
558
|
|
559
|
SortedSet<DefinedTermBase> result = new TreeSet(comp);
|
560
|
if(namedAreas != null){
|
561
|
result.addAll(namedAreas);
|
562
|
}
|
563
|
return result;
|
564
|
}
|
565
|
|
566
|
public SortedSet<DefinedTermBase> getTermsOrderedByVocabularyOrder(List<DefinedTermBase> listAreas){
|
567
|
HashMap<TermVocabulary<DefinedTermBase>, List<DefinedTermBase>> vocs = new HashMap<>();
|
568
|
OrderedTermComparator<?> comp = new OrderedTermComparator<>();
|
569
|
boolean allOrderedTerms = true;
|
570
|
List<TermVocabulary> alreadyOrderIndexNull = new ArrayList<>();
|
571
|
for (DefinedTermBase term: listAreas){
|
572
|
if (!(term instanceof OrderedTermBase)){
|
573
|
allOrderedTerms = false;
|
574
|
break;
|
575
|
}else if (((OrderedTermBase)term).getOrderIndex() == 0){
|
576
|
if(alreadyOrderIndexNull.contains(term.getVocabulary())) {
|
577
|
allOrderedTerms = false;
|
578
|
break;
|
579
|
}else{
|
580
|
alreadyOrderIndexNull.add(term.getVocabulary());
|
581
|
}
|
582
|
|
583
|
|
584
|
}
|
585
|
}
|
586
|
if (allOrderedTerms){
|
587
|
SortedSet<DefinedTermBase> result = new TreeSet(comp.reversed());
|
588
|
result.addAll(listAreas);
|
589
|
return result;
|
590
|
}else{
|
591
|
return getTermsOrderedByLabels(listAreas, PreferencesUtil.getGlobalLanguage());
|
592
|
}
|
593
|
|
594
|
|
595
|
}
|
596
|
|
597
|
private void registerHandlersAndListeners(AbstractLayer topMostLayer) {
|
598
|
//selection listener
|
599
|
E4SelectionListener selectionListener = new DistributionCellSelectionListener(part.getSelectionService(),
|
600
|
selectionLayer, bodyDataProvider, part);
|
601
|
selectionLayer.addLayerListener(selectionListener);
|
602
|
selectionListener.setFullySelectedRowsOnly(false);
|
603
|
|
604
|
//register handler for view configuration menu
|
605
|
// natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
|
606
|
}
|
607
|
|
608
|
/**
|
609
|
* @return
|
610
|
*/
|
611
|
public IRowDataProvider<TaxonDistributionDTO> getBodyDataProvider() {
|
612
|
return bodyDataProvider;
|
613
|
}
|
614
|
|
615
|
|
616
|
}
|