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 org
.apache
.commons
.collections4
.map
.LinkedMap
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.eclipse
.jface
.layout
.GridDataFactory
;
26 import org
.eclipse
.jface
.layout
.GridLayoutFactory
;
27 import org
.eclipse
.jface
.wizard
.WizardDialog
;
28 import org
.eclipse
.nebula
.widgets
.nattable
.NatTable
;
29 import org
.eclipse
.nebula
.widgets
.nattable
.config
.ConfigRegistry
;
30 import org
.eclipse
.nebula
.widgets
.nattable
.config
.DefaultNatTableStyleConfiguration
;
31 import org
.eclipse
.nebula
.widgets
.nattable
.coordinate
.PositionCoordinate
;
32 import org
.eclipse
.nebula
.widgets
.nattable
.data
.IDataProvider
;
33 import org
.eclipse
.nebula
.widgets
.nattable
.data
.IRowDataProvider
;
34 import org
.eclipse
.nebula
.widgets
.nattable
.data
.ListDataProvider
;
35 import org
.eclipse
.nebula
.widgets
.nattable
.extension
.e4
.selection
.E4SelectionListener
;
36 import org
.eclipse
.nebula
.widgets
.nattable
.extension
.glazedlists
.filterrow
.DefaultGlazedListsFilterStrategy
;
37 import org
.eclipse
.nebula
.widgets
.nattable
.filterrow
.FilterRowHeaderComposite
;
38 import org
.eclipse
.nebula
.widgets
.nattable
.freeze
.CompositeFreezeLayer
;
39 import org
.eclipse
.nebula
.widgets
.nattable
.freeze
.FreezeHelper
;
40 import org
.eclipse
.nebula
.widgets
.nattable
.freeze
.FreezeLayer
;
41 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.GridRegion
;
42 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.command
.ClientAreaResizeCommand
;
43 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.data
.DefaultColumnHeaderDataProvider
;
44 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.data
.DefaultCornerDataProvider
;
45 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.data
.DefaultRowHeaderDataProvider
;
46 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.ColumnHeaderLayer
;
47 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.CornerLayer
;
48 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.DefaultColumnHeaderDataLayer
;
49 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.DefaultRowHeaderDataLayer
;
50 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.GridLayer
;
51 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.RowHeaderLayer
;
52 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.AbstractLayer
;
53 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.DataLayer
;
54 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.ILayer
;
55 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.config
.DefaultColumnHeaderStyleConfiguration
;
56 import org
.eclipse
.nebula
.widgets
.nattable
.painter
.cell
.TextPainter
;
57 import org
.eclipse
.nebula
.widgets
.nattable
.painter
.cell
.decorator
.BeveledBorderDecorator
;
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
.util
.GUIHelper
;
61 import org
.eclipse
.swt
.SWT
;
62 import org
.eclipse
.swt
.events
.SelectionAdapter
;
63 import org
.eclipse
.swt
.events
.SelectionEvent
;
64 import org
.eclipse
.swt
.layout
.GridData
;
65 import org
.eclipse
.swt
.layout
.GridLayout
;
66 import org
.eclipse
.swt
.widgets
.Button
;
67 import org
.eclipse
.swt
.widgets
.Composite
;
68 import org
.eclipse
.swt
.widgets
.Label
;
69 import org
.eclipse
.swt
.widgets
.Text
;
71 import ca
.odell
.glazedlists
.BasicEventList
;
72 import ca
.odell
.glazedlists
.EventList
;
73 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
74 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonDescriptionDTO
;
75 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonDistributionDTO
;
76 import eu
.etaxonomy
.cdm
.compare
.term
.OrderedTermComparator
;
77 import eu
.etaxonomy
.cdm
.compare
.term
.TermIdInVocabularyComparator
;
78 import eu
.etaxonomy
.cdm
.compare
.term
.TermLanguageComparator
;
79 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
80 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
81 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
82 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
83 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
84 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
85 import eu
.etaxonomy
.cdm
.model
.metadata
.TermOrder
;
86 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
87 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
88 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermBase
;
89 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
90 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
91 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
92 import eu
.etaxonomy
.taxeditor
.editor
.IDistributionEditor
;
93 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
94 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
95 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
96 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
97 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
98 import eu
.etaxonomy
.taxeditor
.preference
.wizard
.AvailableDistributionWizard
;
99 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
100 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.ReferenceSelectionDialog
;
106 public class DistributionEditor
extends Composite
implements IDistributionEditor
{
108 @SuppressWarnings("unused")
109 private static final Logger logger
= Logger
.getLogger(DistributionEditor
.class);
111 private static final String DISTRIBUTION_EDITOR
= "Distribution Editor"; //$NON-NLS-1$
112 private static final String LOADING_TAXA
= Messages
.ChecklistEditor_LOAD_TAXA
;
113 private static final String UNKNOWN
= Messages
.ChecklistEditor_UNKNOWN
;
114 private static final String ELEMENT_COUNT
= Messages
.ChecklistEditor_ELEMENT_COUNT
;
115 public static final String TYPE_FILTER_TEXT
= "type filter text"; //$NON-NLS-1$
117 static final String TAXON_COLUMN
= "taxon_column"; //$NON-NLS-1$
118 static final String RANK_COLUMN
= "collector_column";//$NON-NLS-1$
119 static final String SYNONYM_COLUMN
= "synonym_column";//$NON-NLS-1$
122 private NatTable natTable
;
123 private Label statusLabel
;
124 private Label statusLabelSourceReference
;
125 private Reference defaultSource
;
127 private Map
<Integer
, NamedArea
> areaToColumnIndexMap
= new HashMap
<>();
128 private int firstDataColumnIndex
;
130 private ListDataProvider
<TaxonDistributionDTO
> bodyDataProvider
;
131 private LinkedMap
<String
, String
> propertyToLabelMap
= new LinkedMap
<>();
133 private boolean isShowRank
= false;
134 private Text searchText
;
136 private Button button3
;
137 private Button button2
;
139 protected EventList
<TaxonDistributionDTO
> taxonList
;
140 private String actualNameCache
;
141 protected Map
<UUID
,Map
<NamedArea
,Set
<DescriptionElementBase
>>> taxonDistributionMap
= new HashMap
<>();
143 protected List
<TaxonDistributionDTO
> descriptionsToSave
= new ArrayList
<>();
145 protected SortedSet
<DefinedTermBase
> areas
;
146 protected DistributionEditorPart part
;
147 private BodyLayerStack
<TaxonDistributionDTO
> bodyLayerStack
;
148 private FreezeLayer freezeLayer
;
149 private ConfigRegistry configRegistry
;
150 private AbstractLayer topMostLayer
;
152 private SelectionLayer selectionLayer
;
154 public DistributionEditor(Composite parent
, DistributionEditorPart part
) {
155 super(parent
, SWT
.NULL
);
156 isShowRank
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowRankInDistributionEditor
.getKey());
158 this.setLayout(new GridLayout());
159 GridLayoutFactory
.fillDefaults().applyTo(parent
);
161 Composite topComposite
= new Composite(parent
, SWT
.NONE
);
162 createTopComposite(topComposite
);
164 natTable
= new NatTable(parent
, false);
167 Composite bottomComposite
= new Composite(parent
, SWT
.NONE
);
168 GridLayoutFactory
.fillDefaults().applyTo(bottomComposite
);
169 createStatusBar(bottomComposite
);
172 public boolean isShowRank() {
176 public void setShowRank(boolean isShowRank
) {
177 this.isShowRank
= isShowRank
;
180 public int getFirstDataColumnIndex() {
181 return firstDataColumnIndex
;
184 public void setFirstDataColumnIndex(int firstDataColumnIndex
) {
185 this.firstDataColumnIndex
= firstDataColumnIndex
;
189 public String
getActualNameCache() {
190 return actualNameCache
;
193 public void setActualNameCache(String actualNameCache
) {
194 this.actualNameCache
= actualNameCache
;
197 public LinkedMap
<String
, String
> getPropertyToLabelMap() {
198 return propertyToLabelMap
;
201 public void setPropertyToLabelMap(LinkedMap
<String
, String
> propertyToLabelMap
) {
202 this.propertyToLabelMap
= propertyToLabelMap
;
205 public Map
<Integer
, NamedArea
> getAreaToColumnIndexMap() {
206 return areaToColumnIndexMap
;
209 public void setAreaToColumnIndexMap(Map
<Integer
, NamedArea
> areaToColumnIndexMap
) {
210 this.areaToColumnIndexMap
= areaToColumnIndexMap
;
213 public List
<TaxonDistributionDTO
> getDescriptionsToSave() {
214 return descriptionsToSave
;
217 public void setDescriptionsToSave(List
<TaxonDistributionDTO
> descriptionsToSave
) {
218 this.descriptionsToSave
= descriptionsToSave
;
221 private void createStatusBar(Composite composite
) {
222 GridData gridData
= new GridData();
223 gridData
.horizontalSpan
= 2;
224 gridData
.grabExcessHorizontalSpace
= true;
225 gridData
.horizontalAlignment
= GridData
.FILL
;
226 GridLayout gridLayout
= new GridLayout();
227 gridLayout
.numColumns
= 3;
228 composite
.setLayoutData(gridData
);
229 composite
.setLayout(gridLayout
);
232 gridData
= new GridData();
233 gridData
.horizontalSpan
= 1;
234 gridData
.grabExcessHorizontalSpace
= true;
235 gridData
.horizontalAlignment
= GridData
.FILL
;
237 statusLabel
= new Label(composite
, SWT
.LEFT
);
238 statusLabel
.setText(ELEMENT_COUNT
+ (taxonList
!= null ? taxonList
.size() : UNKNOWN
));
239 statusLabel
.setLayoutData(gridData
);
241 statusLabelSourceReference
= new Label(composite
, SWT
.RIGHT
);
243 statusLabelSourceReference
.setLayoutData(gridData
);
245 if (defaultSource
!= null){
246 statusLabelSourceReference
.setText(Messages
.DistributionEditor_defaultSource
+ (defaultSource
.getAbbrevTitle() != null? defaultSource
.getAbbrevTitle() : defaultSource
.getAbbrevTitleCache()));
249 button3
= new Button(composite
, SWT
.PUSH
);
250 button3
.setEnabled(false);
251 GridData gridData3
= new GridData();
252 gridData3
.horizontalAlignment
= SWT
.RIGHT
;
253 button3
.setLayoutData(gridData3
);
254 //button3.setText(Messages.ChecklistEditor_REMOVE_DEFAULT_SOURCE);
255 button3
.setImage(ImageResources
.getImage(ImageResources
.TRASH_ICON
));
256 button3
.setToolTipText(Messages
.ChecklistEditor_REMOVE_DEFAULT_SOURCE_TOOLTIP
);
257 button3
.addSelectionListener(new SelectionAdapter() {
260 public void widgetSelected(SelectionEvent event
) {
261 defaultSource
= null;
263 String defaultSourceStr
= (defaultSource
== null) ?
"" : Messages
.DistributionEditor_defaultSource
+ defaultSource
.getTitleCache(); //$NON-NLS-1$
264 if (defaultSourceStr
.length()> 100){
265 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "..."; //$NON-NLS-1$
267 statusLabelSourceReference
.setText(defaultSourceStr
);
269 button3
.setBackground(AbstractUtility
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
270 button3
.setEnabled(false);
271 button2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
277 private void applyStyles(){
278 CdmModernNatTableThemeConfiguration configuration
= new CdmModernNatTableThemeConfiguration();
280 // configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
281 // NOTE: Getting the colors and fonts from the GUIHelper ensures that
282 // they are disposed properly (required by SWT)
283 configuration
.cHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
284 configuration
.rHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
285 natTable
.addConfiguration(configuration
);
288 private void configureNatTable(ConfigRegistry configRegistry
,
289 AbstractLayer topMostLayer
) {
293 natTable
.setConfigRegistry(configRegistry
);
295 //add default configuration because autoconfigure is set to false in constructor
296 natTable
.addConfiguration(new DefaultNatTableStyleConfiguration());
299 natTable
.addConfiguration(new DefaultColumnHeaderStyleConfiguration() {
301 TextPainter painter
= new TextPainter();
302 painter
.setCalculateByTextLength(true);
303 painter
.setWrapText(false);
305 cellPainter
= new BeveledBorderDecorator(painter
);
310 // override the default sort configuration and change the mouse bindings
311 // to sort on a single click
313 natTable
.addConfiguration(new SingleClickSortConfiguration());
314 natTable
.addConfiguration(new FilterRowConfiguration(this));
316 // add the header menu configuration for adding the column header menu
317 // with hide/show actions
318 natTable
.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable
));
320 // add custom configuration for data conversion and add column labels to viewport layer
321 topMostLayer
.addConfiguration(new DistributionCellEditorDataConversionConfiguration(this));
324 natTable
.configure();
327 public void createTable(){
336 configureNatTable( configRegistry
, topMostLayer
);
339 * handlers and listeners
341 registerHandlersAndListeners(topMostLayer
);
342 FreezeHelper
.freeze(freezeLayer
, bodyLayerStack
.getViewPortLayer(),
343 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, 0),
344 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, -1));
346 GridDataFactory
.fillDefaults().grab(true, true).applyTo(natTable
);
349 natTable
.doCommand(new ClientAreaResizeCommand(natTable
));
350 // boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
353 private void createLayers() {
355 DistributionColumnAccessor columnPropertyAccessor
= new DistributionColumnAccessor(this);
356 DistributionEditorConfigLabelAccumulator labelAccumulator
= new DistributionEditorConfigLabelAccumulator(this);
358 // bodyLayerStack = new BodyLayerStack<>(taxonList, columnPropertyAccessor, new TaxonDistributionDtoComparator(), labelAccumulator);
359 bodyLayerStack
= new BodyLayerStack
<>(taxonList
, columnPropertyAccessor
, null, labelAccumulator
);
360 bodyDataProvider
= bodyLayerStack
.getBodyDataProvider();
362 propertyToLabelMap
.put(TAXON_COLUMN
, Messages
.ChecklistEditor_TAXON
);
364 propertyToLabelMap
.put(RANK_COLUMN
, Messages
.ChecklistEditor_RANK
);
365 propertyToLabelMap
.put(SYNONYM_COLUMN
, Messages
.ChecklistEditor_SYNONYMS
);
367 propertyToLabelMap
.put(SYNONYM_COLUMN
, Messages
.ChecklistEditor_SYNONYMS
);
369 configRegistry
= new ConfigRegistry();
372 this.selectionLayer
= bodyLayerStack
.getSelectionLayer();
374 freezeLayer
= new FreezeLayer(selectionLayer
);
375 final CompositeFreezeLayer compositeFreezeLayer
= new CompositeFreezeLayer(
376 freezeLayer
, bodyLayerStack
.getViewPortLayer(), selectionLayer
);
378 // as the selection mouse bindings are registered for the region label
380 // we need to set that region label to the viewport so the selection via mouse
381 // is working correctly
382 compositeFreezeLayer
.setRegionName(GridRegion
.BODY
);
384 IDataProvider columnHeaderDataProvider
=
385 new DefaultColumnHeaderDataProvider(propertyToLabelMap
.values().toArray(new String
[] {}), propertyToLabelMap
);
386 DataLayer columnHeaderDataLayer
= new DefaultColumnHeaderDataLayer(columnHeaderDataProvider
);
387 ILayer columnHeaderLayer
= new ColumnHeaderLayer(
388 columnHeaderDataLayer
,
389 compositeFreezeLayer
,
392 FilterRowHeaderComposite
<TaxonDistributionDTO
> filterRowHeaderLayer
=
393 new FilterRowHeaderComposite
<>(
394 new DefaultGlazedListsFilterStrategy
<>(
395 bodyLayerStack
.getFilterList(),
396 columnPropertyAccessor
,
399 columnHeaderDataLayer
.getDataProvider(),
402 // build the row header layer stack
403 IDataProvider rowHeaderDataProvider
= new DefaultRowHeaderDataProvider(bodyDataProvider
);
404 DataLayer rowHeaderDataLayer
= new DefaultRowHeaderDataLayer(rowHeaderDataProvider
);
405 ILayer rowHeaderLayer
= new RowHeaderLayer(
407 compositeFreezeLayer
,
410 IDataProvider cornerDataProvider
=
411 new DefaultCornerDataProvider(
412 columnHeaderDataProvider
,
413 rowHeaderDataProvider
);
414 DataLayer cornerDataLayer
= new DataLayer(cornerDataProvider
);
415 ILayer cornerLayer
= new CornerLayer(
418 filterRowHeaderLayer
);
420 GridLayer gridLayer
= new GridLayer(
421 compositeFreezeLayer
,
422 filterRowHeaderLayer
,
426 natTable
.setLayer(gridLayer
);
427 topMostLayer
= compositeFreezeLayer
;
430 private Text
createSearchBar(Composite parent
) {
432 Button button1
= new Button(parent
, SWT
.PUSH
);
433 GridData gridData2
= new GridData();
434 gridData2
.horizontalSpan
= 1;
435 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
437 button1
.setLayoutData(gridData2
);
439 button1
.setText(Messages
.ChecklistEditor_DIST_STATUS
);
440 button1
.setToolTipText(Messages
.ChecklistEditor_DIST_STATUS_TOOLTIP
);
441 button1
.addSelectionListener(new SelectionAdapter() {
443 public void widgetSelected(SelectionEvent event
) {
444 AvailableDistributionWizard availableDistributionWizard
= new AvailableDistributionWizard();
445 WizardDialog dialog
= new WizardDialog(AbstractUtility
.getShell(),
446 availableDistributionWizard
);
448 int open
= dialog
.open();
455 button2
= new Button(parent
, SWT
.PUSH
);
456 GridData gridData3
= new GridData();
457 gridData3
.horizontalAlignment
= SWT
.RIGHT
;
459 button2
.setLayoutData(gridData3
);
461 button2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
462 button2
.setToolTipText(Messages
.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP
);
463 button2
.addSelectionListener(new SelectionAdapter() {
466 public void widgetSelected(SelectionEvent event
) {
467 defaultSource
= ReferenceSelectionDialog
.select(AbstractUtility
.getShell(), null);
469 String defaultSourceStr
= (defaultSource
== null) ?
"" : Messages
.DistributionEditor_defaultSource
+ defaultSource
.getTitleCache(); //$NON-NLS-1$
470 if (defaultSourceStr
.length()> 100){
471 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "..."; //$NON-NLS-1$
473 statusLabelSourceReference
.setText(defaultSourceStr
);
475 button2
.setBackground(AbstractUtility
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
476 // EventUtility.postEvent(WorkbenchEventConstants.REFRESH_DETAILS, true);
477 button3
.setEnabled(true);
478 button2
.setText(Messages
.ChecklistEditor_SWITCH_DEFAULT_SOURCE
);
486 * This method should only be called for adding new Distribution columns and reloading the table.<br>
487 * It will hide the old distribution column and load the newly added columns.<br>
489 * <b>Notice:</b> for data update please use <b>refresh()</b>
492 public void reload(){
493 this.areaToColumnIndexMap
.clear();
495 this.propertyToLabelMap
.clear();
500 private void createTopComposite(Composite parent
) {
501 GridLayout gridLayout
= new GridLayout(3, false);
502 gridLayout
.marginWidth
= 0;
503 gridLayout
.marginHeight
= 0;
504 GridData gridData2
= new GridData();
505 gridData2
.horizontalSpan
= 1;
506 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
507 gridData2
.horizontalIndent
= 3;
508 parent
.setLayoutData(gridData2
);
509 parent
.setLayout(gridLayout
);
510 searchText
= createSearchBar(parent
);
514 public void loadDistributions(List
<TaxonDistributionDTO
> taxonList
) {
515 if (this.taxonList
== null){
516 this.taxonList
= new BasicEventList
<>();
518 taxonList
.stream().forEach(wrapper
->DistributionEditor
.this.taxonList
.add(wrapper
));
519 statusLabel
.setText(ELEMENT_COUNT
+ taxonList
.size());
520 createTaxonDistributionMap();
523 protected void createTaxonDistributionMap() {
524 Iterator
<TaxonDistributionDTO
> iterator
= this.taxonList
.iterator();
525 while (iterator
.hasNext()){
526 TaxonDistributionDTO dto
= iterator
.next();
527 TaxonDescriptionDTO descriptionDto
= dto
.getDescriptionsWrapper();
528 for (TaxonDescription desc
: descriptionDto
.getDescriptions()){
529 if(this.part
.getCdmEntitySession()!=null){
530 this.part
.getCdmEntitySession().load(desc
, true);
532 for (DescriptionElementBase descElement
: desc
.getElements()){
533 if (descElement
instanceof Distribution
){
534 Map
<NamedArea
, Set
<DescriptionElementBase
>> distributionsMap
= taxonDistributionMap
.get(dto
.getTaxonUuid());
536 if (distributionsMap
== null){
537 distributionsMap
= new HashMap
<>();
538 taxonDistributionMap
.put(dto
.getTaxonUuid(), distributionsMap
);
540 Set
<DescriptionElementBase
> distributions
= distributionsMap
.get(((Distribution
) descElement
).getArea());
541 if (distributions
== null){
542 distributions
= new HashSet
<>();
543 distributionsMap
.put(((Distribution
)descElement
).getArea(), distributions
);
545 distributions
.add(descElement
);
552 private void initLabels() {
561 areas
= new TreeSet
<>();
563 for (DefinedTermBase
<?
> area
: areas
) {
564 this.areaToColumnIndexMap
.put(index
++, (NamedArea
)area
);
566 //TODO: adapt to preference
567 Representation rep
= area
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
568 String label
= rep
.getLabel();
570 label
= area
.getTitleCache();
572 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
573 if (area
.getIdInVocabulary() != null){
574 areaLabel
= area
.getIdInVocabulary();
578 }else if (PreferencesUtil
.isShowSymbol1InChecklistEditor()){
579 if (area
.getSymbol() != null){
580 areaLabel
= area
.getSymbol();
584 }else if (PreferencesUtil
.isShowSymbol2InChecklistEditor()){
585 if (area
.getSymbol2() != null){
586 areaLabel
= area
.getSymbol2();
594 //String areaLabel = area.getLabel();
595 String property
= area
.getUuid().toString();
596 propertyToLabelMap
.put(property
, areaLabel
);
600 private SortedSet
<DefinedTermBase
> loadNamedAreas() {
601 //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
603 String valuesAreas
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey(), true);
604 String values
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey());
605 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
607 List
<String
> listValue
;
608 List
<DefinedTermBase
> termlist
= new ArrayList
<>();
609 if (values
!= null && values
!= "") { //$NON-NLS-1$
610 split
= values
.split(";"); //$NON-NLS-1$
611 listValue
= Arrays
.asList(split
);
614 for(String s
: listValue
){
615 uuid
= UUID
.fromString(s
);
620 List
<TermVocabulary
> vocs
= new ArrayList
<>();
621 IVocabularyService service
= CdmStore
.getService(IVocabularyService
.class);
622 if (uuidList
.isEmpty()){
623 List
<TermVocabulary
<DefinedTermBase
>> vocList
= CdmStore
.getService(IVocabularyService
.class).findByTermType(TermType
.NamedArea
, null);
624 vocs
.addAll(vocList
);
626 vocs
= service
.find(uuidList
);
628 for (TermVocabulary
<?
> voc
: vocs
){
629 termlist
.addAll(service
.getTerms(voc
, null, null, null, null).getRecords());
631 List
<DefinedTermBase
> filteredList
= new ArrayList
<>();
632 if (valuesAreas
!= null && valuesAreas
!= "") {
633 split
= valuesAreas
.split(";"); //$NON-NLS-1$
634 listValue
= Arrays
.asList(split
);
636 for (DefinedTermBase
<?
> area
: termlist
){
637 if (listValue
.contains(area
.getUuid().toString())) {
638 filteredList
.add(area
);
642 filteredList
.addAll(termlist
);
645 TermOrder sortOrder
= PreferencesUtil
.getSortNamedAreasInDistributionEditor();
646 if (sortOrder
.equals(TermOrder
.Natural
)){
647 areas
= getTermsOrderedByVocabularyOrder(filteredList
);
648 } else if (sortOrder
.equals(TermOrder
.IdInVoc
)){
649 areas
= getTermsOrderedByIdInVocabulary(filteredList
);
651 areas
= getTermsOrderedByLabels(filteredList
, CdmStore
.getDefaultLanguage());
657 public SortedSet
<DefinedTermBase
> getTermsOrderedByLabels(List
<DefinedTermBase
> listTerm
,Language language
){
658 TermLanguageComparator
<DefinedTermBase
> comp
= new TermLanguageComparator
<>(Language
.DEFAULT(), language
);
659 SortedSet
<DefinedTermBase
> result
= new TreeSet
<>(comp
);
660 if(listTerm
!= null){
661 result
.addAll(listTerm
);
667 public SortedSet
<DefinedTermBase
> getTermsOrderedByIdInVocabulary(List
<DefinedTermBase
> namedAreas
) {
668 TermIdInVocabularyComparator
<DefinedTermBase
> comp
= new TermIdInVocabularyComparator
<>();
670 SortedSet
<DefinedTermBase
> result
= new TreeSet
<>(comp
);
671 if(namedAreas
!= null){
672 result
.addAll(namedAreas
);
677 public SortedSet
<DefinedTermBase
> getTermsOrderedByVocabularyOrder(List
<DefinedTermBase
> listAreas
){
678 OrderedTermComparator
<DefinedTermBase
> comp
= new OrderedTermComparator
<>();
679 boolean allOrderedTerms
= true;
680 List
<TermVocabulary
> alreadyOrderIndexNull
= new ArrayList
<>();
681 for (DefinedTermBase
<?
> term
: listAreas
){
682 if (!(term
instanceof OrderedTermBase
)){
683 allOrderedTerms
= false;
685 }else if (((OrderedTermBase
<?
>)term
).getOrderIndex() == 0){
686 if(alreadyOrderIndexNull
.contains(term
.getVocabulary())) {
687 allOrderedTerms
= false;
690 alreadyOrderIndexNull
.add(term
.getVocabulary());
696 if (allOrderedTerms
){
697 SortedSet
<DefinedTermBase
> result
= new TreeSet
<>(comp
.reversed());
698 result
.addAll(listAreas
);
701 return getTermsOrderedByLabels(listAreas
, PreferencesUtil
.getGlobalLanguage());
705 private void registerHandlersAndListeners(AbstractLayer topMostLayer
) {
707 E4SelectionListener
<?
> selectionListener
= new DistributionCellSelectionListener(part
.getSelectionService(),
708 selectionLayer
, bodyDataProvider
, part
);
709 selectionLayer
.addLayerListener(selectionListener
);
710 selectionListener
.setFullySelectedRowsOnly(false);
712 //register handler for view configuration menu
713 // natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
716 public IRowDataProvider
<TaxonDistributionDTO
> getBodyDataProvider() {
717 return bodyDataProvider
;
720 public void setDirty() {
725 public Reference
getDefaultSource(){
726 return defaultSource
;
732 // public void reloadDistributions() {
733 // loadDistributions(taxonList);