2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.e4
;
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
;
19 import java
.util
.SortedSet
;
20 import java
.util
.TreeSet
;
21 import java
.util
.UUID
;
23 import javax
.inject
.Inject
;
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
.command
.ClientAreaResizeCommand
;
46 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.data
.DefaultColumnHeaderDataProvider
;
47 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.data
.DefaultCornerDataProvider
;
48 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.data
.DefaultRowHeaderDataProvider
;
49 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.ColumnHeaderLayer
;
50 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.CornerLayer
;
51 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.DefaultColumnHeaderDataLayer
;
52 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.DefaultRowHeaderDataLayer
;
53 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.GridLayer
;
54 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.RowHeaderLayer
;
55 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.AbstractLayer
;
56 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.DataLayer
;
57 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.ILayer
;
58 import org
.eclipse
.nebula
.widgets
.nattable
.selection
.SelectionLayer
;
59 import org
.eclipse
.nebula
.widgets
.nattable
.sort
.config
.SingleClickSortConfiguration
;
60 import org
.eclipse
.nebula
.widgets
.nattable
.style
.HorizontalAlignmentEnum
;
61 import org
.eclipse
.nebula
.widgets
.nattable
.style
.theme
.ModernNatTableThemeConfiguration
;
62 import org
.eclipse
.nebula
.widgets
.nattable
.util
.GUIHelper
;
63 import org
.eclipse
.swt
.SWT
;
64 import org
.eclipse
.swt
.events
.SelectionAdapter
;
65 import org
.eclipse
.swt
.events
.SelectionEvent
;
66 import org
.eclipse
.swt
.layout
.GridData
;
67 import org
.eclipse
.swt
.layout
.GridLayout
;
68 import org
.eclipse
.swt
.widgets
.Button
;
69 import org
.eclipse
.swt
.widgets
.Composite
;
70 import org
.eclipse
.swt
.widgets
.Label
;
71 import org
.eclipse
.swt
.widgets
.Text
;
73 import ca
.odell
.glazedlists
.BasicEventList
;
74 import ca
.odell
.glazedlists
.EventList
;
75 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
76 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonDescriptionDTO
;
77 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonDistributionDTO
;
78 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
79 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
80 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermBase
;
81 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermComparator
;
82 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
83 import eu
.etaxonomy
.cdm
.model
.term
.TermIdInVocabularyComparator
;
84 import eu
.etaxonomy
.cdm
.model
.term
.TermLanguageComparator
;
85 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
86 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
87 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
88 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
89 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
90 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
91 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
92 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
93 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
94 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
95 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
96 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
97 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
98 import eu
.etaxonomy
.taxeditor
.preference
.TermOrder
;
99 import eu
.etaxonomy
.taxeditor
.preference
.wizard
.AvailableDistributionWizard
;
100 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
101 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
102 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.ReferenceSelectionDialog
;
109 public class DistributionEditor
extends Composite
{
112 private static final String DISTRIBUTION_EDITOR
= "Distribution Editor"; //$NON-NLS-1$
113 private static final String LOADING_TAXA
= Messages
.ChecklistEditor_LOAD_TAXA
;
114 private static final String UNKNOWN
= Messages
.ChecklistEditor_UNKNOWN
;
115 private static final String ELEMENT_COUNT
= Messages
.ChecklistEditor_ELEMENT_COUNT
;
116 public static final String TYPE_FILTER_TEXT
= "type filter text"; //$NON-NLS-1$
118 static final String TAXON_COLUMN
= "taxon_column"; //$NON-NLS-1$
119 static final String RANK_COLUMN
= "collector_column"; //$NON-NLS-1$
121 private static final Logger logger
= Logger
.getLogger(DistributionEditor
.class);
123 private EMenuService menuService
;
124 private NatTable natTable
;
125 private Label statusLabel
;
126 private Label statusLabelSourceReference
;
127 private Reference defaultSource
;
129 private Map
<Integer
, NamedArea
> areaToColumnIndexMap
= new HashMap();
130 private int firstDataColumnIndex
;
132 private ListDataProvider
<TaxonDistributionDTO
> bodyDataProvider
;
133 private LinkedMap
<String
, String
> propertyToLabelMap
= new LinkedMap
<>();
135 private boolean isShowRank
= false;
136 private Integer countNodes
;
137 private Text searchText
;
139 EventList
<TaxonDistributionDTO
> taxonList
;
140 Map
<UUID
,Map
<NamedArea
,Set
<DescriptionElementBase
>>> taxonDistributionMap
= new HashMap
<>();
142 List
<TaxonDistributionDTO
> descriptionsToSave
= new ArrayList
<>();
145 SortedSet
<DefinedTermBase
> areas
;
146 DistributionEditorPart part
;
147 BodyLayerStack
<TaxonDistributionDTO
> bodyLayerStack
;
148 private FreezeLayer freezeLayer
;
149 private ConfigRegistry configRegistry
;
150 private AbstractLayer topMostLayer
;
152 private SelectionLayer selectionLayer
;
156 // private FixedSummaryRowLayer summaryRowLayer;
163 public DistributionEditor(Composite parent
, DistributionEditorPart part
) {
164 super(parent
, SWT
.NULL
);
165 isShowRank
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowRankInDistributionEditor
.getKey());
167 this.setLayout(new GridLayout());
168 GridLayoutFactory
.fillDefaults().applyTo(parent
);
170 Composite topComposite
= new Composite(parent
, SWT
.NONE
);
171 createTopComposite(topComposite
);
175 natTable
= new NatTable(parent
, false);
178 Composite bottomComposite
= new Composite(parent
, SWT
.NONE
);
179 GridLayoutFactory
.fillDefaults().applyTo(bottomComposite
);
180 createStatusBar(bottomComposite
);
183 public boolean isShowRank() {
187 public void setShowRank(boolean isShowRank
) {
188 this.isShowRank
= isShowRank
;
191 public int getFirstDataColumnIndex() {
192 return firstDataColumnIndex
;
195 public void setFirstDataColumnIndex(int firstDataColumnIndex
) {
196 this.firstDataColumnIndex
= firstDataColumnIndex
;
199 public LinkedMap
<String
, String
> getPropertyToLabelMap() {
200 return propertyToLabelMap
;
203 public void setPropertyToLabelMap(LinkedMap
<String
, String
> propertyToLabelMap
) {
204 this.propertyToLabelMap
= propertyToLabelMap
;
207 public Map
<Integer
, NamedArea
> getAreaToColumnIndexMap() {
208 return areaToColumnIndexMap
;
212 public void setAreaToColumnIndexMap(Map
<Integer
, NamedArea
> areaToColumnIndexMap
) {
213 this.areaToColumnIndexMap
= areaToColumnIndexMap
;
217 public List
<TaxonDistributionDTO
> getDescriptionsToSave() {
218 return descriptionsToSave
;
221 public void setDescriptionsToSave(List
<TaxonDistributionDTO
> descriptionsToSave
) {
222 this.descriptionsToSave
= descriptionsToSave
;
227 private void createStatusBar(Composite composite
) {
228 GridData gridData
= new GridData();
229 gridData
.horizontalSpan
= 2;
230 gridData
.grabExcessHorizontalSpace
= true;
231 gridData
.horizontalAlignment
= GridData
.FILL
;
232 GridLayout gridLayout
= new GridLayout();
233 gridLayout
.numColumns
= 2;
234 composite
.setLayoutData(gridData
);
235 composite
.setLayout(gridLayout
);
238 gridData
= new GridData();
239 gridData
.horizontalSpan
= 1;
240 gridData
.grabExcessHorizontalSpace
= true;
241 gridData
.horizontalAlignment
= GridData
.FILL
;
243 statusLabel
= new Label(composite
, SWT
.LEFT
);
244 statusLabel
.setText(ELEMENT_COUNT
+ (taxonList
!= null ? taxonList
.size() : UNKNOWN
));
245 statusLabel
.setLayoutData(gridData
);
247 statusLabelSourceReference
= new Label(composite
, SWT
.RIGHT
);
249 statusLabelSourceReference
.setLayoutData(gridData
);
251 if (defaultSource
!= null){
252 statusLabelSourceReference
.setText(Messages
.DistributionEditor_defaultSource
+ defaultSource
.getAbbrevTitle() != null? defaultSource
.getAbbrevTitle() : defaultSource
.getAbbrevTitleCache());
257 private void applyStyles(){
258 ModernNatTableThemeConfiguration configuration
= new ModernNatTableThemeConfiguration();
259 configuration
.summaryRowHAlign
= HorizontalAlignmentEnum
.CENTER
;
260 // NOTE: Getting the colors and fonts from the GUIHelper ensures that
261 // they are disposed properly (required by SWT)
262 configuration
.cHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
263 configuration
.rHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
264 natTable
.addConfiguration(configuration
);
268 private void configureNatTable(ConfigRegistry configRegistry
,
269 AbstractLayer topMostLayer
) {
273 natTable
.setConfigRegistry(configRegistry
);
277 //add default configuration because autoconfigure is set to false in constructor
278 natTable
.addConfiguration(new DefaultNatTableStyleConfiguration());
282 // override the default sort configuration and change the mouse bindings
283 // to sort on a single click
285 natTable
.addConfiguration(new SingleClickSortConfiguration());
286 natTable
.addConfiguration(new FilterRowConfiguration(this));
288 // add the header menu configuration for adding the column header menu
289 // with hide/show actions
290 natTable
.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable
));
292 // add custom configuration for data conversion and add column labels to viewport layer
293 topMostLayer
.addConfiguration(new DistributionCellEditorDataConversionConfiguration(this));
295 natTable
.configure();
298 public void createTable(){
308 configureNatTable( configRegistry
, topMostLayer
);
311 * handlers and listeners
313 registerHandlersAndListeners(topMostLayer
);
314 FreezeHelper
.freeze(freezeLayer
, bodyLayerStack
.getViewPortLayer(),
315 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, 0),
316 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, -1));
318 GridDataFactory
.fillDefaults().grab(true, true).applyTo(natTable
);
321 natTable
.doCommand(new ClientAreaResizeCommand(natTable
));
322 // boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
327 private void createLayers() {
329 DistributionColumnAccessor columnPropertyAccessor
= new DistributionColumnAccessor(this);
331 DistributionEditorConfigLabelAccumulator labelAccumulator
= new DistributionEditorConfigLabelAccumulator(this);
332 bodyLayerStack
= new BodyLayerStack
<>(taxonList
, columnPropertyAccessor
, new TaxonDistributionDtoComparator(), labelAccumulator
);
334 bodyDataProvider
= bodyLayerStack
.getBodyDataProvider();
338 propertyToLabelMap
.put(TAXON_COLUMN
, Messages
.ChecklistEditor_TAXON
);
340 propertyToLabelMap
.put(RANK_COLUMN
, Messages
.ChecklistEditor_RANK
);
342 configRegistry
= new ConfigRegistry();
345 this.selectionLayer
= bodyLayerStack
.getSelectionLayer();
349 freezeLayer
= new FreezeLayer(selectionLayer
);
350 final CompositeFreezeLayer compositeFreezeLayer
= new CompositeFreezeLayer(
351 freezeLayer
, bodyLayerStack
.getViewPortLayer(), selectionLayer
);
353 // as the selection mouse bindings are registered for the region label
355 // we need to set that region label to the viewport so the selection via mouse
356 // is working correctly
357 compositeFreezeLayer
.setRegionName(GridRegion
.BODY
);
360 IDataProvider columnHeaderDataProvider
=
361 new DefaultColumnHeaderDataProvider(propertyToLabelMap
.values().toArray(new String
[] {}), propertyToLabelMap
);
362 DataLayer columnHeaderDataLayer
= new DefaultColumnHeaderDataLayer(columnHeaderDataProvider
);
363 ILayer columnHeaderLayer
= new ColumnHeaderLayer(
364 columnHeaderDataLayer
,
365 compositeFreezeLayer
,
368 FilterRowHeaderComposite
<TaxonDistributionDTO
> filterRowHeaderLayer
=
369 new FilterRowHeaderComposite
<>(
370 new DefaultGlazedListsFilterStrategy
<>(
371 bodyLayerStack
.getFilterList(),
372 columnPropertyAccessor
,
375 columnHeaderDataLayer
.getDataProvider(),
380 // build the row header layer stack
381 IDataProvider rowHeaderDataProvider
= new DefaultRowHeaderDataProvider(bodyDataProvider
);
382 DataLayer rowHeaderDataLayer
= new DefaultRowHeaderDataLayer(rowHeaderDataProvider
);
383 ILayer rowHeaderLayer
= new RowHeaderLayer(
385 compositeFreezeLayer
,
390 IDataProvider cornerDataProvider
=
391 new DefaultCornerDataProvider(
392 columnHeaderDataProvider
,
393 rowHeaderDataProvider
);
394 DataLayer cornerDataLayer
= new DataLayer(cornerDataProvider
);
395 ILayer cornerLayer
= new CornerLayer(
398 filterRowHeaderLayer
);
400 GridLayer gridLayer
= new GridLayer(
401 compositeFreezeLayer
,
402 filterRowHeaderLayer
,
406 natTable
.setLayer(gridLayer
);
408 topMostLayer
= compositeFreezeLayer
;
417 private Text
createSearchBar(Composite parent
) {
419 Button button1
= new Button(parent
, SWT
.PUSH
);
420 GridData gridData2
= new GridData();
421 gridData2
.horizontalSpan
= 1;
422 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
424 button1
.setLayoutData(gridData2
);
427 button1
.setText(Messages
.ChecklistEditor_DIST_STATUS
);
428 button1
.setToolTipText(Messages
.ChecklistEditor_DIST_STATUS_TOOLTIP
);
429 button1
.addSelectionListener(new SelectionAdapter() {
431 public void widgetSelected(SelectionEvent event
) {
432 AvailableDistributionWizard availableDistributionWizard
= new AvailableDistributionWizard();
433 WizardDialog dialog
= new WizardDialog(StoreUtil
.getShell(),
434 availableDistributionWizard
);
436 int open
= dialog
.open();
443 Button button2
= new Button(parent
, SWT
.PUSH
);
444 GridData gridData3
= new GridData();
445 gridData2
.horizontalSpan
= 1;
446 button2
.setLayoutData(gridData3
);
449 button2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
450 button2
.setToolTipText(Messages
.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP
);
451 button2
.addSelectionListener(new SelectionAdapter() {
454 public void widgetSelected(SelectionEvent event
) {
455 defaultSource
= ReferenceSelectionDialog
.select(AbstractUtility
.getShell(), null);
457 String defaultSourceStr
= (defaultSource
== null) ?
"" : Messages
.DistributionEditor_defaultSource
+ defaultSource
.getTitleCache(); //$NON-NLS-1$
458 if (defaultSourceStr
.length()> 100){
459 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "..."; //$NON-NLS-1$
461 statusLabelSourceReference
.setText(defaultSourceStr
);
463 button2
.setBackground(EditorUtil
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
468 Button button3
= new Button(parent
, SWT
.PUSH
);
470 button3
.setLayoutData(gridData3
);
471 button3
.setText(Messages
.ChecklistEditor_REMOVE_DEFAULT_SOURCE
);
472 button2
.setToolTipText(Messages
.ChecklistEditor_REMOVE_DEFAULT_SOURCE_TOOLTIP
);
473 button3
.addSelectionListener(new SelectionAdapter() {
476 public void widgetSelected(SelectionEvent event
) {
477 defaultSource
= null;
479 String defaultSourceStr
= (defaultSource
== null) ?
"" : Messages
.DistributionEditor_defaultSource
+ defaultSource
.getTitleCache(); //$NON-NLS-1$
480 if (defaultSourceStr
.length()> 100){
481 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "..."; //$NON-NLS-1$
483 statusLabelSourceReference
.setText(defaultSourceStr
);
485 button3
.setBackground(EditorUtil
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
494 * This method should only be called for adding new Distribution columns and reloading the table.<br>
495 * It will hide the old distribution column and load the newly added columns.<br>
497 * <b>Notice:</b> for data update please use <b>refresh()</b>
500 @SuppressWarnings({ "unchecked", "rawtypes" })
501 public void reload(){
502 this.areaToColumnIndexMap
.clear();
504 this.propertyToLabelMap
.clear();
512 private void createTopComposite(Composite parent
) {
513 GridLayout gridLayout
= new GridLayout(3, false);
514 gridLayout
.marginWidth
= 0;
515 gridLayout
.marginHeight
= 0;
516 GridData gridData2
= new GridData();
517 gridData2
.horizontalSpan
= 1;
518 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
519 gridData2
.horizontalIndent
= 3;
520 parent
.setLayoutData(gridData2
);
521 parent
.setLayout(gridLayout
);
522 searchText
= createSearchBar(parent
);
526 public void loadDistributions(List
<TaxonDistributionDTO
> taxonList
) {
527 if (this.taxonList
== null){
528 this.taxonList
= new BasicEventList
<>();
530 taxonList
.stream().forEach(wrapper
->DistributionEditor
.this.taxonList
.add(wrapper
));
531 statusLabel
.setText(ELEMENT_COUNT
+ (taxonList
!= null ? taxonList
.size() : UNKNOWN
));
532 createTaxonDistributionMap();
535 protected void createTaxonDistributionMap() {
536 Iterator
<TaxonDistributionDTO
> iterator
= this.taxonList
.iterator();
537 while (iterator
.hasNext()){
538 TaxonDistributionDTO dto
= iterator
.next();
539 TaxonDescriptionDTO descriptionDto
= dto
.getDescriptionsWrapper();
540 for (TaxonDescription desc
: descriptionDto
.getDescriptions()){
541 if(this.part
.getCdmEntitySession()!=null){
542 this.part
.getCdmEntitySession().load(desc
, true);
544 for (DescriptionElementBase descElement
: desc
.getElements()){
545 if (descElement
instanceof Distribution
){
546 Map
<NamedArea
, Set
<DescriptionElementBase
>> distributionsMap
= taxonDistributionMap
.get(dto
.getTaxonUuid());
548 if (distributionsMap
== null){
549 distributionsMap
= new HashMap();
550 taxonDistributionMap
.put(dto
.getTaxonUuid(), distributionsMap
);
552 Set
<DescriptionElementBase
> distributions
= distributionsMap
.get(((Distribution
) descElement
).getArea());
553 if (distributions
== null){
554 distributions
= new HashSet();
555 distributionsMap
.put(((Distribution
)descElement
).getArea(), distributions
);
557 distributions
.add(descElement
);
569 private void initLabels() {
578 areas
= new TreeSet
<>();
580 for (DefinedTermBase area
: areas
) {
581 this.areaToColumnIndexMap
.put(index
++, (NamedArea
)area
);
583 //TODO: adapt to preference
584 Representation rep
= area
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
585 String label
= rep
.getLabel();
587 label
= area
.getTitleCache();
589 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
590 if (area
.getIdInVocabulary() != null){
591 areaLabel
= area
.getIdInVocabulary();
595 }else if (PreferencesUtil
.isShowSymbol1InChecklistEditor()){
596 if (area
.getSymbol() != null){
597 areaLabel
= area
.getSymbol();
601 }else if (PreferencesUtil
.isShowSymbol2InChecklistEditor()){
602 if (area
.getSymbol2() != null){
603 areaLabel
= area
.getSymbol2();
612 //String areaLabel = area.getLabel();
613 String property
= areaLabel
;
614 propertyToLabelMap
.put(property
, areaLabel
);
619 private SortedSet
<DefinedTermBase
> loadNamedAreas() {
620 //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
622 String valuesAreas
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey());
623 String values
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey());
624 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
626 List
<String
> listValue
;
627 List
<DefinedTermBase
> termlist
= new ArrayList
<DefinedTermBase
>();
628 if (values
!= null && values
!= "") { //$NON-NLS-1$
629 split
= values
.split(";"); //$NON-NLS-1$
630 listValue
= Arrays
.asList(split
);
634 for(String s
: listValue
){
635 uuid
= UUID
.fromString(s
);
641 List
<TermVocabulary
> vocs
= new ArrayList
<>();
642 IVocabularyService service
= CdmStore
.getService(IVocabularyService
.class);
643 if (uuidList
.isEmpty()){
644 List
<TermVocabulary
<DefinedTermBase
>> vocList
= CdmStore
.getService(IVocabularyService
.class).findByTermType(TermType
.NamedArea
, null);
645 vocs
.addAll(vocList
);
647 vocs
= service
.find(uuidList
);
649 split
= valuesAreas
.split(";"); //$NON-NLS-1$
650 listValue
= Arrays
.asList(split
);
651 for (TermVocabulary voc
: vocs
){
652 termlist
.addAll(service
.getTerms(voc
, null, null, null, null).getRecords());
654 List
<DefinedTermBase
> filteredList
= new ArrayList();
655 for (DefinedTermBase area
: termlist
){
656 if (listValue
.contains(area
.getUuid().toString())) {
657 filteredList
.add(area
);
661 String sortOrder
= PreferencesUtil
.getSortNamedAreasInDistributionEditor();
662 if (sortOrder
.equals(TermOrder
.Natural
.getKey())){
663 areas
= getTermsOrderedByVocabularyOrder(filteredList
);
664 } else if (sortOrder
.equals(TermOrder
.IdInVoc
.getKey())){
665 areas
= getTermsOrderedByIdInVocabulary(filteredList
);
667 areas
= getTermsOrderedByLabels(filteredList
, CdmStore
.getDefaultLanguage());
673 public SortedSet
<DefinedTermBase
> getTermsOrderedByLabels(List
<DefinedTermBase
> listTerm
,Language language
){
674 TermLanguageComparator
<?
> comp
= new TermLanguageComparator
<>();
675 comp
.setCompareLanguage(language
);
676 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
);
677 if(listTerm
!= null){
678 result
.addAll(listTerm
);
684 public SortedSet
<DefinedTermBase
> getTermsOrderedByIdInVocabulary(List
<DefinedTermBase
> namedAreas
) {
685 TermIdInVocabularyComparator
<?
> comp
= new TermIdInVocabularyComparator
<>();
687 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
);
688 if(namedAreas
!= null){
689 result
.addAll(namedAreas
);
694 public SortedSet
<DefinedTermBase
> getTermsOrderedByVocabularyOrder(List
<DefinedTermBase
> listAreas
){
695 HashMap
<TermVocabulary
<DefinedTermBase
>, List
<DefinedTermBase
>> vocs
= new HashMap
<>();
696 OrderedTermComparator
<?
> comp
= new OrderedTermComparator
<>();
697 boolean allOrderedTerms
= true;
698 List
<TermVocabulary
> alreadyOrderIndexNull
= new ArrayList
<>();
699 for (DefinedTermBase term
: listAreas
){
700 if (!(term
instanceof OrderedTermBase
)){
701 allOrderedTerms
= false;
703 }else if (((OrderedTermBase
)term
).getOrderIndex() == 0){
704 if(alreadyOrderIndexNull
.contains(term
.getVocabulary())) {
705 allOrderedTerms
= false;
708 alreadyOrderIndexNull
.add(term
.getVocabulary());
714 if (allOrderedTerms
){
715 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
.reversed());
716 result
.addAll(listAreas
);
719 return getTermsOrderedByLabels(listAreas
, PreferencesUtil
.getGlobalLanguage());
725 private void registerHandlersAndListeners(AbstractLayer topMostLayer
) {
727 E4SelectionListener selectionListener
= new DistributionCellSelectionListener(part
.getSelectionService(),
728 selectionLayer
, bodyDataProvider
, part
);
729 selectionLayer
.addLayerListener(selectionListener
);
730 selectionListener
.setFullySelectedRowsOnly(false);
732 //register handler for view configuration menu
733 // natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
739 public IRowDataProvider
<TaxonDistributionDTO
> getBodyDataProvider() {
740 return bodyDataProvider
;
743 public void setDirty() {
747 public Reference
getDefaultSource(){
748 return defaultSource
;
754 // public void reloadDistributions() {
755 // loadDistributions(taxonList);