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
.common
.Language
;
79 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
80 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
81 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
82 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
83 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
84 import eu
.etaxonomy
.cdm
.model
.metadata
.TermOrder
;
85 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
86 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
87 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermBase
;
88 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermComparator
;
89 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
90 import eu
.etaxonomy
.cdm
.model
.term
.TermIdInVocabularyComparator
;
91 import eu
.etaxonomy
.cdm
.model
.term
.TermLanguageComparator
;
92 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
93 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
94 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
95 import eu
.etaxonomy
.taxeditor
.editor
.IDistributionEditor
;
96 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
97 import eu
.etaxonomy
.taxeditor
.event
.EventUtility
;
98 import eu
.etaxonomy
.taxeditor
.event
.WorkbenchEventConstants
;
99 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
100 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
101 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
102 import eu
.etaxonomy
.taxeditor
.preference
.wizard
.AvailableDistributionWizard
;
103 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
104 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
105 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.ReferenceSelectionDialog
;
112 public class DistributionEditor
extends Composite
implements IDistributionEditor
{
115 private static final String DISTRIBUTION_EDITOR
= "Distribution Editor"; //$NON-NLS-1$
116 private static final String LOADING_TAXA
= Messages
.ChecklistEditor_LOAD_TAXA
;
117 private static final String UNKNOWN
= Messages
.ChecklistEditor_UNKNOWN
;
118 private static final String ELEMENT_COUNT
= Messages
.ChecklistEditor_ELEMENT_COUNT
;
119 public static final String TYPE_FILTER_TEXT
= "type filter text"; //$NON-NLS-1$
121 static final String TAXON_COLUMN
= "taxon_column"; //$NON-NLS-1$
122 static final String RANK_COLUMN
= "collector_column"; //$NON-NLS-1$
124 private static final Logger logger
= Logger
.getLogger(DistributionEditor
.class);
126 private EMenuService menuService
;
127 private NatTable natTable
;
128 private Label statusLabel
;
129 private Label statusLabelSourceReference
;
130 private Reference defaultSource
;
132 private Map
<Integer
, NamedArea
> areaToColumnIndexMap
= new HashMap();
133 private int firstDataColumnIndex
;
135 private ListDataProvider
<TaxonDistributionDTO
> bodyDataProvider
;
136 private LinkedMap
<String
, String
> propertyToLabelMap
= new LinkedMap
<>();
138 private boolean isShowRank
= false;
139 private Integer countNodes
;
140 private Text searchText
;
142 EventList
<TaxonDistributionDTO
> taxonList
;
143 Map
<UUID
,Map
<NamedArea
,Set
<DescriptionElementBase
>>> taxonDistributionMap
= new HashMap
<>();
145 List
<TaxonDistributionDTO
> descriptionsToSave
= new ArrayList
<>();
148 SortedSet
<DefinedTermBase
> areas
;
149 DistributionEditorPart part
;
150 BodyLayerStack
<TaxonDistributionDTO
> bodyLayerStack
;
151 private FreezeLayer freezeLayer
;
152 private ConfigRegistry configRegistry
;
153 private AbstractLayer topMostLayer
;
155 private SelectionLayer selectionLayer
;
159 // private FixedSummaryRowLayer summaryRowLayer;
166 public DistributionEditor(Composite parent
, DistributionEditorPart part
) {
167 super(parent
, SWT
.NULL
);
168 isShowRank
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowRankInDistributionEditor
.getKey());
170 this.setLayout(new GridLayout());
171 GridLayoutFactory
.fillDefaults().applyTo(parent
);
173 Composite topComposite
= new Composite(parent
, SWT
.NONE
);
174 createTopComposite(topComposite
);
178 natTable
= new NatTable(parent
, false);
181 Composite bottomComposite
= new Composite(parent
, SWT
.NONE
);
182 GridLayoutFactory
.fillDefaults().applyTo(bottomComposite
);
183 createStatusBar(bottomComposite
);
186 public boolean isShowRank() {
190 public void setShowRank(boolean isShowRank
) {
191 this.isShowRank
= isShowRank
;
194 public int getFirstDataColumnIndex() {
195 return firstDataColumnIndex
;
198 public void setFirstDataColumnIndex(int firstDataColumnIndex
) {
199 this.firstDataColumnIndex
= firstDataColumnIndex
;
202 public LinkedMap
<String
, String
> getPropertyToLabelMap() {
203 return propertyToLabelMap
;
206 public void setPropertyToLabelMap(LinkedMap
<String
, String
> propertyToLabelMap
) {
207 this.propertyToLabelMap
= propertyToLabelMap
;
210 public Map
<Integer
, NamedArea
> getAreaToColumnIndexMap() {
211 return areaToColumnIndexMap
;
215 public void setAreaToColumnIndexMap(Map
<Integer
, NamedArea
> areaToColumnIndexMap
) {
216 this.areaToColumnIndexMap
= areaToColumnIndexMap
;
220 public List
<TaxonDistributionDTO
> getDescriptionsToSave() {
221 return descriptionsToSave
;
224 public void setDescriptionsToSave(List
<TaxonDistributionDTO
> descriptionsToSave
) {
225 this.descriptionsToSave
= descriptionsToSave
;
230 private void createStatusBar(Composite composite
) {
231 GridData gridData
= new GridData();
232 gridData
.horizontalSpan
= 2;
233 gridData
.grabExcessHorizontalSpace
= true;
234 gridData
.horizontalAlignment
= GridData
.FILL
;
235 GridLayout gridLayout
= new GridLayout();
236 gridLayout
.numColumns
= 2;
237 composite
.setLayoutData(gridData
);
238 composite
.setLayout(gridLayout
);
241 gridData
= new GridData();
242 gridData
.horizontalSpan
= 1;
243 gridData
.grabExcessHorizontalSpace
= true;
244 gridData
.horizontalAlignment
= GridData
.FILL
;
246 statusLabel
= new Label(composite
, SWT
.LEFT
);
247 statusLabel
.setText(ELEMENT_COUNT
+ (taxonList
!= null ? taxonList
.size() : UNKNOWN
));
248 statusLabel
.setLayoutData(gridData
);
250 statusLabelSourceReference
= new Label(composite
, SWT
.RIGHT
);
252 statusLabelSourceReference
.setLayoutData(gridData
);
254 if (defaultSource
!= null){
255 statusLabelSourceReference
.setText(Messages
.DistributionEditor_defaultSource
+ defaultSource
.getAbbrevTitle() != null? defaultSource
.getAbbrevTitle() : defaultSource
.getAbbrevTitleCache());
260 private void applyStyles(){
261 ModernNatTableThemeConfiguration configuration
= new ModernNatTableThemeConfiguration();
262 configuration
.summaryRowHAlign
= HorizontalAlignmentEnum
.CENTER
;
263 // NOTE: Getting the colors and fonts from the GUIHelper ensures that
264 // they are disposed properly (required by SWT)
265 configuration
.cHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
266 configuration
.rHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
267 natTable
.addConfiguration(configuration
);
271 private void configureNatTable(ConfigRegistry configRegistry
,
272 AbstractLayer topMostLayer
) {
276 natTable
.setConfigRegistry(configRegistry
);
280 //add default configuration because autoconfigure is set to false in constructor
281 natTable
.addConfiguration(new DefaultNatTableStyleConfiguration());
285 // override the default sort configuration and change the mouse bindings
286 // to sort on a single click
288 natTable
.addConfiguration(new SingleClickSortConfiguration());
289 natTable
.addConfiguration(new FilterRowConfiguration(this));
291 // add the header menu configuration for adding the column header menu
292 // with hide/show actions
293 natTable
.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable
));
295 // add custom configuration for data conversion and add column labels to viewport layer
296 topMostLayer
.addConfiguration(new DistributionCellEditorDataConversionConfiguration(this));
298 natTable
.configure();
301 public void createTable(){
311 configureNatTable( configRegistry
, topMostLayer
);
314 * handlers and listeners
316 registerHandlersAndListeners(topMostLayer
);
317 FreezeHelper
.freeze(freezeLayer
, bodyLayerStack
.getViewPortLayer(),
318 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, 0),
319 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, -1));
321 GridDataFactory
.fillDefaults().grab(true, true).applyTo(natTable
);
324 natTable
.doCommand(new ClientAreaResizeCommand(natTable
));
325 // boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
330 private void createLayers() {
332 DistributionColumnAccessor columnPropertyAccessor
= new DistributionColumnAccessor(this);
334 DistributionEditorConfigLabelAccumulator labelAccumulator
= new DistributionEditorConfigLabelAccumulator(this);
335 bodyLayerStack
= new BodyLayerStack
<>(taxonList
, columnPropertyAccessor
, new TaxonDistributionDtoComparator(), labelAccumulator
);
337 bodyDataProvider
= bodyLayerStack
.getBodyDataProvider();
341 propertyToLabelMap
.put(TAXON_COLUMN
, Messages
.ChecklistEditor_TAXON
);
343 propertyToLabelMap
.put(RANK_COLUMN
, Messages
.ChecklistEditor_RANK
);
345 configRegistry
= new ConfigRegistry();
348 this.selectionLayer
= bodyLayerStack
.getSelectionLayer();
352 freezeLayer
= new FreezeLayer(selectionLayer
);
353 final CompositeFreezeLayer compositeFreezeLayer
= new CompositeFreezeLayer(
354 freezeLayer
, bodyLayerStack
.getViewPortLayer(), selectionLayer
);
356 // as the selection mouse bindings are registered for the region label
358 // we need to set that region label to the viewport so the selection via mouse
359 // is working correctly
360 compositeFreezeLayer
.setRegionName(GridRegion
.BODY
);
363 IDataProvider columnHeaderDataProvider
=
364 new DefaultColumnHeaderDataProvider(propertyToLabelMap
.values().toArray(new String
[] {}), propertyToLabelMap
);
365 DataLayer columnHeaderDataLayer
= new DefaultColumnHeaderDataLayer(columnHeaderDataProvider
);
366 ILayer columnHeaderLayer
= new ColumnHeaderLayer(
367 columnHeaderDataLayer
,
368 compositeFreezeLayer
,
371 FilterRowHeaderComposite
<TaxonDistributionDTO
> filterRowHeaderLayer
=
372 new FilterRowHeaderComposite
<>(
373 new DefaultGlazedListsFilterStrategy
<>(
374 bodyLayerStack
.getFilterList(),
375 columnPropertyAccessor
,
378 columnHeaderDataLayer
.getDataProvider(),
383 // build the row header layer stack
384 IDataProvider rowHeaderDataProvider
= new DefaultRowHeaderDataProvider(bodyDataProvider
);
385 DataLayer rowHeaderDataLayer
= new DefaultRowHeaderDataLayer(rowHeaderDataProvider
);
386 ILayer rowHeaderLayer
= new RowHeaderLayer(
388 compositeFreezeLayer
,
393 IDataProvider cornerDataProvider
=
394 new DefaultCornerDataProvider(
395 columnHeaderDataProvider
,
396 rowHeaderDataProvider
);
397 DataLayer cornerDataLayer
= new DataLayer(cornerDataProvider
);
398 ILayer cornerLayer
= new CornerLayer(
401 filterRowHeaderLayer
);
403 GridLayer gridLayer
= new GridLayer(
404 compositeFreezeLayer
,
405 filterRowHeaderLayer
,
409 natTable
.setLayer(gridLayer
);
411 topMostLayer
= compositeFreezeLayer
;
420 private Text
createSearchBar(Composite parent
) {
422 Button button1
= new Button(parent
, SWT
.PUSH
);
423 GridData gridData2
= new GridData();
424 gridData2
.horizontalSpan
= 1;
425 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
427 button1
.setLayoutData(gridData2
);
430 button1
.setText(Messages
.ChecklistEditor_DIST_STATUS
);
431 button1
.setToolTipText(Messages
.ChecklistEditor_DIST_STATUS_TOOLTIP
);
432 button1
.addSelectionListener(new SelectionAdapter() {
434 public void widgetSelected(SelectionEvent event
) {
435 AvailableDistributionWizard availableDistributionWizard
= new AvailableDistributionWizard();
436 WizardDialog dialog
= new WizardDialog(StoreUtil
.getShell(),
437 availableDistributionWizard
);
439 int open
= dialog
.open();
446 Button button2
= new Button(parent
, SWT
.PUSH
);
447 GridData gridData3
= new GridData();
448 gridData2
.horizontalSpan
= 1;
449 button2
.setLayoutData(gridData3
);
452 button2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
453 button2
.setToolTipText(Messages
.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP
);
454 button2
.addSelectionListener(new SelectionAdapter() {
457 public void widgetSelected(SelectionEvent event
) {
458 defaultSource
= ReferenceSelectionDialog
.select(AbstractUtility
.getShell(), null);
460 String defaultSourceStr
= (defaultSource
== null) ?
"" : Messages
.DistributionEditor_defaultSource
+ defaultSource
.getTitleCache(); //$NON-NLS-1$
461 if (defaultSourceStr
.length()> 100){
462 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "..."; //$NON-NLS-1$
464 statusLabelSourceReference
.setText(defaultSourceStr
);
466 button2
.setBackground(EditorUtil
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
467 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_DETAILS
, true);
472 Button button3
= new Button(parent
, SWT
.PUSH
);
474 button3
.setLayoutData(gridData3
);
475 button3
.setText(Messages
.ChecklistEditor_REMOVE_DEFAULT_SOURCE
);
476 button2
.setToolTipText(Messages
.ChecklistEditor_REMOVE_DEFAULT_SOURCE_TOOLTIP
);
477 button3
.addSelectionListener(new SelectionAdapter() {
480 public void widgetSelected(SelectionEvent event
) {
481 defaultSource
= null;
483 String defaultSourceStr
= (defaultSource
== null) ?
"" : Messages
.DistributionEditor_defaultSource
+ defaultSource
.getTitleCache(); //$NON-NLS-1$
484 if (defaultSourceStr
.length()> 100){
485 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "..."; //$NON-NLS-1$
487 statusLabelSourceReference
.setText(defaultSourceStr
);
489 button3
.setBackground(EditorUtil
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
498 * This method should only be called for adding new Distribution columns and reloading the table.<br>
499 * It will hide the old distribution column and load the newly added columns.<br>
501 * <b>Notice:</b> for data update please use <b>refresh()</b>
504 @SuppressWarnings({ "unchecked", "rawtypes" })
505 public void reload(){
506 this.areaToColumnIndexMap
.clear();
508 this.propertyToLabelMap
.clear();
516 private void createTopComposite(Composite parent
) {
517 GridLayout gridLayout
= new GridLayout(3, false);
518 gridLayout
.marginWidth
= 0;
519 gridLayout
.marginHeight
= 0;
520 GridData gridData2
= new GridData();
521 gridData2
.horizontalSpan
= 1;
522 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
523 gridData2
.horizontalIndent
= 3;
524 parent
.setLayoutData(gridData2
);
525 parent
.setLayout(gridLayout
);
526 searchText
= createSearchBar(parent
);
530 public void loadDistributions(List
<TaxonDistributionDTO
> taxonList
) {
531 if (this.taxonList
== null){
532 this.taxonList
= new BasicEventList
<>();
534 taxonList
.stream().forEach(wrapper
->DistributionEditor
.this.taxonList
.add(wrapper
));
535 statusLabel
.setText(ELEMENT_COUNT
+ (taxonList
!= null ? taxonList
.size() : UNKNOWN
));
536 createTaxonDistributionMap();
539 protected void createTaxonDistributionMap() {
540 Iterator
<TaxonDistributionDTO
> iterator
= this.taxonList
.iterator();
541 while (iterator
.hasNext()){
542 TaxonDistributionDTO dto
= iterator
.next();
543 TaxonDescriptionDTO descriptionDto
= dto
.getDescriptionsWrapper();
544 for (TaxonDescription desc
: descriptionDto
.getDescriptions()){
545 if(this.part
.getCdmEntitySession()!=null){
546 this.part
.getCdmEntitySession().load(desc
, true);
548 for (DescriptionElementBase descElement
: desc
.getElements()){
549 if (descElement
instanceof Distribution
){
550 Map
<NamedArea
, Set
<DescriptionElementBase
>> distributionsMap
= taxonDistributionMap
.get(dto
.getTaxonUuid());
552 if (distributionsMap
== null){
553 distributionsMap
= new HashMap();
554 taxonDistributionMap
.put(dto
.getTaxonUuid(), distributionsMap
);
556 Set
<DescriptionElementBase
> distributions
= distributionsMap
.get(((Distribution
) descElement
).getArea());
557 if (distributions
== null){
558 distributions
= new HashSet();
559 distributionsMap
.put(((Distribution
)descElement
).getArea(), distributions
);
561 distributions
.add(descElement
);
573 private void initLabels() {
582 areas
= new TreeSet
<>();
584 for (DefinedTermBase area
: areas
) {
585 this.areaToColumnIndexMap
.put(index
++, (NamedArea
)area
);
587 //TODO: adapt to preference
588 Representation rep
= area
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
589 String label
= rep
.getLabel();
591 label
= area
.getTitleCache();
593 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
594 if (area
.getIdInVocabulary() != null){
595 areaLabel
= area
.getIdInVocabulary();
599 }else if (PreferencesUtil
.isShowSymbol1InChecklistEditor()){
600 if (area
.getSymbol() != null){
601 areaLabel
= area
.getSymbol();
605 }else if (PreferencesUtil
.isShowSymbol2InChecklistEditor()){
606 if (area
.getSymbol2() != null){
607 areaLabel
= area
.getSymbol2();
616 //String areaLabel = area.getLabel();
617 String property
= area
.getUuid().toString();
618 propertyToLabelMap
.put(property
, areaLabel
);
623 private SortedSet
<DefinedTermBase
> loadNamedAreas() {
624 //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
626 String valuesAreas
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey(), true);
627 String values
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey());
628 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
630 List
<String
> listValue
;
631 List
<DefinedTermBase
> termlist
= new ArrayList
<DefinedTermBase
>();
632 if (values
!= null && values
!= "") { //$NON-NLS-1$
633 split
= values
.split(";"); //$NON-NLS-1$
634 listValue
= Arrays
.asList(split
);
638 for(String s
: listValue
){
639 uuid
= UUID
.fromString(s
);
645 List
<TermVocabulary
> vocs
= new ArrayList
<>();
646 IVocabularyService service
= CdmStore
.getService(IVocabularyService
.class);
647 if (uuidList
.isEmpty()){
648 List
<TermVocabulary
<DefinedTermBase
>> vocList
= CdmStore
.getService(IVocabularyService
.class).findByTermType(TermType
.NamedArea
, null);
649 vocs
.addAll(vocList
);
651 vocs
= service
.find(uuidList
);
653 for (TermVocabulary voc
: vocs
){
654 termlist
.addAll(service
.getTerms(voc
, null, null, null, null).getRecords());
656 List
<DefinedTermBase
> filteredList
= new ArrayList();
657 if (valuesAreas
!= null && valuesAreas
!= "") {
658 split
= valuesAreas
.split(";"); //$NON-NLS-1$
659 listValue
= Arrays
.asList(split
);
661 for (DefinedTermBase area
: termlist
){
662 if (listValue
.contains(area
.getUuid().toString())) {
663 filteredList
.add(area
);
668 filteredList
.addAll(termlist
);
672 TermOrder sortOrder
= PreferencesUtil
.getSortNamedAreasInDistributionEditor();
673 if (sortOrder
.equals(TermOrder
.Natural
)){
674 areas
= getTermsOrderedByVocabularyOrder(filteredList
);
675 } else if (sortOrder
.equals(TermOrder
.IdInVoc
)){
676 areas
= getTermsOrderedByIdInVocabulary(filteredList
);
678 areas
= getTermsOrderedByLabels(filteredList
, CdmStore
.getDefaultLanguage());
684 public SortedSet
<DefinedTermBase
> getTermsOrderedByLabels(List
<DefinedTermBase
> listTerm
,Language language
){
685 TermLanguageComparator
<?
> comp
= new TermLanguageComparator
<>();
686 comp
.setCompareLanguage(language
);
687 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
);
688 if(listTerm
!= null){
689 result
.addAll(listTerm
);
695 public SortedSet
<DefinedTermBase
> getTermsOrderedByIdInVocabulary(List
<DefinedTermBase
> namedAreas
) {
696 TermIdInVocabularyComparator
<?
> comp
= new TermIdInVocabularyComparator
<>();
698 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
);
699 if(namedAreas
!= null){
700 result
.addAll(namedAreas
);
705 public SortedSet
<DefinedTermBase
> getTermsOrderedByVocabularyOrder(List
<DefinedTermBase
> listAreas
){
706 HashMap
<TermVocabulary
<DefinedTermBase
>, List
<DefinedTermBase
>> vocs
= new HashMap
<>();
707 OrderedTermComparator
<?
> comp
= new OrderedTermComparator
<>();
708 boolean allOrderedTerms
= true;
709 List
<TermVocabulary
> alreadyOrderIndexNull
= new ArrayList
<>();
710 for (DefinedTermBase term
: listAreas
){
711 if (!(term
instanceof OrderedTermBase
)){
712 allOrderedTerms
= false;
714 }else if (((OrderedTermBase
)term
).getOrderIndex() == 0){
715 if(alreadyOrderIndexNull
.contains(term
.getVocabulary())) {
716 allOrderedTerms
= false;
719 alreadyOrderIndexNull
.add(term
.getVocabulary());
725 if (allOrderedTerms
){
726 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
.reversed());
727 result
.addAll(listAreas
);
730 return getTermsOrderedByLabels(listAreas
, PreferencesUtil
.getGlobalLanguage());
736 private void registerHandlersAndListeners(AbstractLayer topMostLayer
) {
738 E4SelectionListener selectionListener
= new DistributionCellSelectionListener(part
.getSelectionService(),
739 selectionLayer
, bodyDataProvider
, part
);
740 selectionLayer
.addLayerListener(selectionListener
);
741 selectionListener
.setFullySelectedRowsOnly(false);
743 //register handler for view configuration menu
744 // natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
750 public IRowDataProvider
<TaxonDistributionDTO
> getBodyDataProvider() {
751 return bodyDataProvider
;
754 public void setDirty() {
759 public Reference
getDefaultSource(){
760 return defaultSource
;
766 // public void reloadDistributions() {
767 // loadDistributions(taxonList);