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
.data
.DefaultColumnHeaderDataProvider
;
46 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.data
.DefaultCornerDataProvider
;
47 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.data
.DefaultRowHeaderDataProvider
;
48 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.ColumnHeaderLayer
;
49 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.CornerLayer
;
50 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.DefaultColumnHeaderDataLayer
;
51 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.DefaultRowHeaderDataLayer
;
52 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.GridLayer
;
53 import org
.eclipse
.nebula
.widgets
.nattable
.grid
.layer
.RowHeaderLayer
;
54 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.AbstractLayer
;
55 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.DataLayer
;
56 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.ILayer
;
57 import org
.eclipse
.nebula
.widgets
.nattable
.selection
.SelectionLayer
;
58 import org
.eclipse
.nebula
.widgets
.nattable
.sort
.config
.SingleClickSortConfiguration
;
59 import org
.eclipse
.nebula
.widgets
.nattable
.style
.HorizontalAlignmentEnum
;
60 import org
.eclipse
.nebula
.widgets
.nattable
.style
.theme
.ModernNatTableThemeConfiguration
;
61 import org
.eclipse
.nebula
.widgets
.nattable
.util
.GUIHelper
;
62 import org
.eclipse
.swt
.SWT
;
63 import org
.eclipse
.swt
.events
.SelectionAdapter
;
64 import org
.eclipse
.swt
.events
.SelectionEvent
;
65 import org
.eclipse
.swt
.layout
.GridData
;
66 import org
.eclipse
.swt
.layout
.GridLayout
;
67 import org
.eclipse
.swt
.widgets
.Button
;
68 import org
.eclipse
.swt
.widgets
.Composite
;
69 import org
.eclipse
.swt
.widgets
.Label
;
70 import org
.eclipse
.swt
.widgets
.Text
;
72 import ca
.odell
.glazedlists
.BasicEventList
;
73 import ca
.odell
.glazedlists
.EventList
;
74 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
75 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonDescriptionDTO
;
76 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonDistributionDTO
;
77 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
78 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
79 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermBase
;
80 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermComparator
;
81 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
82 import eu
.etaxonomy
.cdm
.model
.common
.TermIdInVocabularyComparator
;
83 import eu
.etaxonomy
.cdm
.model
.common
.TermLanguageComparator
;
84 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
85 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
86 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
87 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
88 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
89 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
90 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
91 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
92 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
93 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
94 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
95 import eu
.etaxonomy
.taxeditor
.preference
.EditorPreferencePredicate
;
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
.store
.StoreUtil
;
101 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.ReferenceSelectionDialog
;
108 public class DistributionEditor
extends Composite
{
111 private static final String DISTRIBUTION_EDITOR
= "Distribution Editor";
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$
120 private static final Logger logger
= Logger
.getLogger(DistributionEditor
.class);
122 private EMenuService menuService
;
123 private NatTable natTable
;
124 private Label statusLabel
;
125 private Label statusLabelSourceReference
;
126 private Reference defaultSource
;
128 private Map
<Integer
, NamedArea
> areaToColumnIndexMap
= new HashMap();
129 private int firstDataColumnIndex
;
131 private ListDataProvider
<TaxonDistributionDTO
> bodyDataProvider
;
132 private LinkedMap
<String
, String
> propertyToLabelMap
= new LinkedMap
<>();
134 private boolean isShowRank
= false;
135 private Integer countNodes
;
136 private Text searchText
;
138 EventList
<TaxonDistributionDTO
> taxonList
;
139 Map
<UUID
,Map
<NamedArea
,Set
<DescriptionElementBase
>>> taxonDistributionMap
= new HashMap
<>();
141 List
<TaxonDistributionDTO
> descriptionsToSave
= new ArrayList
<>();
144 SortedSet
<DefinedTermBase
> areas
;
145 DistributionEditorPart part
;
146 BodyLayerStack
<TaxonDistributionDTO
> bodyLayerStack
;
147 private FreezeLayer freezeLayer
;
148 private ConfigRegistry configRegistry
;
149 private AbstractLayer topMostLayer
;
151 private SelectionLayer selectionLayer
;
155 // private FixedSummaryRowLayer summaryRowLayer;
162 public DistributionEditor(Composite parent
, DistributionEditorPart part
) {
163 super(parent
, SWT
.NULL
);
165 this.setLayout(new GridLayout());
166 GridLayoutFactory
.fillDefaults().applyTo(parent
);
168 Composite topComposite
= new Composite(parent
, SWT
.NONE
);
169 createTopComposite(topComposite
);
171 Composite bottomComposite
= new Composite(parent
, SWT
.NONE
);
172 GridLayoutFactory
.fillDefaults().applyTo(bottomComposite
);
174 natTable
= new NatTable(parent
, false);
178 // // natTable = new NatTable(parent, viewportLayer);
179 // natTable = new NatTable(parent, false);
181 createStatusBar(parent
);
184 public boolean isShowRank() {
188 public void setShowRank(boolean isShowRank
) {
189 this.isShowRank
= isShowRank
;
192 public int getFirstDataColumnIndex() {
193 return firstDataColumnIndex
;
196 public void setFirstDataColumnIndex(int firstDataColumnIndex
) {
197 this.firstDataColumnIndex
= firstDataColumnIndex
;
200 public LinkedMap
<String
, String
> getPropertyToLabelMap() {
201 return propertyToLabelMap
;
204 public void setPropertyToLabelMap(LinkedMap
<String
, String
> propertyToLabelMap
) {
205 this.propertyToLabelMap
= propertyToLabelMap
;
208 public Map
<Integer
, NamedArea
> getAreaToColumnIndexMap() {
209 return areaToColumnIndexMap
;
213 public void setAreaToColumnIndexMap(Map
<Integer
, NamedArea
> areaToColumnIndexMap
) {
214 this.areaToColumnIndexMap
= areaToColumnIndexMap
;
218 public List
<TaxonDistributionDTO
> getDescriptionsToSave() {
219 return descriptionsToSave
;
222 public void setDescriptionsToSave(List
<TaxonDistributionDTO
> descriptionsToSave
) {
223 this.descriptionsToSave
= descriptionsToSave
;
228 private void createStatusBar(Composite composite
) {
229 GridData gridData
= new GridData();
230 gridData
.horizontalSpan
= 1;
231 gridData
.grabExcessHorizontalSpace
= true;
232 gridData
.horizontalAlignment
= GridData
.FILL
;
234 statusLabel
= new Label(composite
, SWT
.LEFT
);
235 statusLabel
.setText(ELEMENT_COUNT
+ (taxonList
!= null ? taxonList
.size() : UNKNOWN
));
236 statusLabel
.setLayoutData(gridData
);
238 statusLabelSourceReference
= new Label(composite
, SWT
.RIGHT
);
240 statusLabelSourceReference
.setLayoutData(gridData
);
242 if (defaultSource
!= null){
243 statusLabelSourceReference
.setText("Default Source Reference: " + defaultSource
.getAbbrevTitle() != null? defaultSource
.getAbbrevTitle() : defaultSource
.getAbbrevTitleCache());
248 private void applyStyles(){
249 ModernNatTableThemeConfiguration configuration
= new ModernNatTableThemeConfiguration();
250 configuration
.summaryRowHAlign
= HorizontalAlignmentEnum
.CENTER
;
251 // NOTE: Getting the colors and fonts from the GUIHelper ensures that
252 // they are disposed properly (required by SWT)
253 configuration
.cHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
254 configuration
.rHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
255 natTable
.addConfiguration(configuration
);
259 private void configureNatTable(ConfigRegistry configRegistry
,
260 AbstractLayer topMostLayer
) {
264 natTable
.setConfigRegistry(configRegistry
);
268 //add default configuration because autoconfigure is set to false in constructor
269 natTable
.addConfiguration(new DefaultNatTableStyleConfiguration());
273 // override the default sort configuration and change the mouse bindings
274 // to sort on a single click
276 natTable
.addConfiguration(new SingleClickSortConfiguration());
277 natTable
.addConfiguration(new FilterRowConfiguration(this));
279 // add the header menu configuration for adding the column header menu
280 // with hide/show actions
281 natTable
.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable
));
283 // add custom configuration for data conversion and add column labels to viewport layer
284 topMostLayer
.addConfiguration(new DistributionCellEditorDataConversionConfiguration(this));
286 natTable
.configure();
289 public void createTable(){
299 configureNatTable( configRegistry
, topMostLayer
);
302 * handlers and listeners
304 registerHandlersAndListeners(topMostLayer
);
305 FreezeHelper
.freeze(freezeLayer
, bodyLayerStack
.getViewPortLayer(),
306 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, 0),
307 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, -1));
309 GridDataFactory
.fillDefaults().grab(true, true).applyTo(natTable
);
312 // boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
313 // System.out.println(ok);
317 private void createLayers() {
319 DistributionColumnAccessor columnPropertyAccessor
= new DistributionColumnAccessor(this);
321 DistributionEditorConfigLabelAccumulator labelAccumulator
= new DistributionEditorConfigLabelAccumulator(this);
322 bodyLayerStack
= new BodyLayerStack
<>(taxonList
, columnPropertyAccessor
, new TaxonDistributionDtoComparator(), labelAccumulator
);
324 bodyDataProvider
= bodyLayerStack
.getBodyDataProvider();
328 propertyToLabelMap
.put(TAXON_COLUMN
, Messages
.ChecklistEditor_TAXON
);
330 propertyToLabelMap
.put(RANK_COLUMN
, Messages
.ChecklistEditor_RANK
);
332 configRegistry
= new ConfigRegistry();
335 this.selectionLayer
= bodyLayerStack
.getSelectionLayer();
339 freezeLayer
= new FreezeLayer(selectionLayer
);
340 final CompositeFreezeLayer compositeFreezeLayer
= new CompositeFreezeLayer(
341 freezeLayer
, bodyLayerStack
.getViewPortLayer(), selectionLayer
);
343 // as the selection mouse bindings are registered for the region label
345 // we need to set that region label to the viewport so the selection via mouse
346 // is working correctly
347 compositeFreezeLayer
.setRegionName(GridRegion
.BODY
);
350 IDataProvider columnHeaderDataProvider
=
351 new DefaultColumnHeaderDataProvider(propertyToLabelMap
.values().toArray(new String
[] {}), propertyToLabelMap
);
352 DataLayer columnHeaderDataLayer
= new DefaultColumnHeaderDataLayer(columnHeaderDataProvider
);
353 ILayer columnHeaderLayer
= new ColumnHeaderLayer(
354 columnHeaderDataLayer
,
355 compositeFreezeLayer
,
358 FilterRowHeaderComposite
<TaxonDistributionDTO
> filterRowHeaderLayer
=
359 new FilterRowHeaderComposite
<>(
360 new DefaultGlazedListsFilterStrategy
<>(
361 bodyLayerStack
.getFilterList(),
362 columnPropertyAccessor
,
365 columnHeaderDataLayer
.getDataProvider(),
370 // build the row header layer stack
371 IDataProvider rowHeaderDataProvider
= new DefaultRowHeaderDataProvider(bodyDataProvider
);
372 DataLayer rowHeaderDataLayer
= new DefaultRowHeaderDataLayer(rowHeaderDataProvider
);
373 ILayer rowHeaderLayer
= new RowHeaderLayer(
375 compositeFreezeLayer
,
380 IDataProvider cornerDataProvider
=
381 new DefaultCornerDataProvider(
382 columnHeaderDataProvider
,
383 rowHeaderDataProvider
);
384 DataLayer cornerDataLayer
= new DataLayer(cornerDataProvider
);
385 ILayer cornerLayer
= new CornerLayer(
388 filterRowHeaderLayer
);
390 GridLayer gridLayer
= new GridLayer(
391 compositeFreezeLayer
,
392 filterRowHeaderLayer
,
396 natTable
.setLayer(gridLayer
);
398 topMostLayer
= compositeFreezeLayer
;
407 private Text
createSearchBar(Composite parent
) {
409 Button button1
= new Button(parent
, SWT
.PUSH
);
410 GridData gridData2
= new GridData();
411 gridData2
.horizontalSpan
= 1;
412 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
414 button1
.setLayoutData(gridData2
);
417 button1
.setText(Messages
.ChecklistEditor_DIST_STATUS
);
418 button1
.setToolTipText(Messages
.ChecklistEditor_DIST_STATUS_TOOLTIP
);
419 button1
.addSelectionListener(new SelectionAdapter() {
421 public void widgetSelected(SelectionEvent event
) {
422 AvailableDistributionWizard availableDistributionWizard
= new AvailableDistributionWizard();
423 WizardDialog dialog
= new WizardDialog(StoreUtil
.getShell(),
424 availableDistributionWizard
);
426 int open
= dialog
.open();
433 Button button2
= new Button(parent
, SWT
.PUSH
);
434 GridData gridData3
= new GridData();
435 gridData2
.horizontalSpan
= 1;
436 button2
.setLayoutData(gridData3
);
439 button2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
440 button2
.setToolTipText(Messages
.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP
);
441 button2
.addSelectionListener(new SelectionAdapter() {
444 public void widgetSelected(SelectionEvent event
) {
445 defaultSource
= ReferenceSelectionDialog
.select(AbstractUtility
.getShell(), null);
447 String defaultSourceStr
= (defaultSource
== null) ?
"" : "Default Source Reference: " + defaultSource
.getTitleCache();
448 if (defaultSourceStr
.length()> 100){
449 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "...";
451 statusLabelSourceReference
.setText(defaultSourceStr
);
453 button2
.setBackground(EditorUtil
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
462 * This method should only be called for adding new Distribution columns and reloading the table.<br>
463 * It will hide the old distribution column and load the newly added columns.<br>
465 * <b>Notice:</b> for data update please use <b>refresh()</b>
468 @SuppressWarnings({ "unchecked", "rawtypes" })
469 public void reload(){
470 this.areaToColumnIndexMap
.clear();
472 this.propertyToLabelMap
.clear();
480 private void createTopComposite(Composite parent
) {
481 GridLayout gridLayout
= new GridLayout(3, false);
482 gridLayout
.marginWidth
= 0;
483 gridLayout
.marginHeight
= 0;
484 GridData gridData2
= new GridData();
485 gridData2
.horizontalSpan
= 1;
486 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
487 gridData2
.horizontalIndent
= 3;
488 parent
.setLayoutData(gridData2
);
489 parent
.setLayout(gridLayout
);
490 searchText
= createSearchBar(parent
);
494 public void loadDistributions(List
<TaxonDistributionDTO
> taxonList
) {
495 if (this.taxonList
== null){
496 this.taxonList
= new BasicEventList
<>();
498 taxonList
.stream().forEach(wrapper
->DistributionEditor
.this.taxonList
.add(wrapper
));
499 statusLabel
.setText(ELEMENT_COUNT
+ (taxonList
!= null ? taxonList
.size() : UNKNOWN
));
500 createTaxonDistributionMap();
503 protected void createTaxonDistributionMap() {
504 Iterator
<TaxonDistributionDTO
> iterator
= this.taxonList
.iterator();
505 while (iterator
.hasNext()){
506 TaxonDistributionDTO dto
= iterator
.next();
507 TaxonDescriptionDTO descriptionDto
= dto
.getDescriptionsWrapper();
508 for (TaxonDescription desc
: descriptionDto
.getDescriptions()){
509 if(this.part
.getCdmEntitySession()!=null){
510 this.part
.getCdmEntitySession().load(desc
, true);
512 for (DescriptionElementBase descElement
: desc
.getElements()){
513 if (descElement
instanceof Distribution
){
514 Map
<NamedArea
, Set
<DescriptionElementBase
>> distributionsMap
= taxonDistributionMap
.get(dto
.getTaxonUuid());
516 if (distributionsMap
== null){
517 distributionsMap
= new HashMap();
518 taxonDistributionMap
.put(dto
.getTaxonUuid(), distributionsMap
);
520 Set
<DescriptionElementBase
> distributions
= distributionsMap
.get(((Distribution
) descElement
).getArea());
521 if (distributions
== null){
522 distributions
= new HashSet();
523 distributionsMap
.put(((Distribution
)descElement
).getArea(), distributions
);
525 distributions
.add(descElement
);
537 private void initLabels() {
546 areas
= new TreeSet
<>();
548 for (DefinedTermBase area
: areas
) {
549 this.areaToColumnIndexMap
.put(index
++, (NamedArea
)area
);
551 //TODO: adapt to preference
552 Representation rep
= area
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
553 String label
= rep
.getLabel();
555 label
= area
.getTitleCache();
557 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
558 if (area
.getIdInVocabulary() != null){
559 areaLabel
= area
.getIdInVocabulary();
563 }else if (PreferencesUtil
.isShowSymbol1InChecklistEditor()){
564 if (area
.getSymbol() != null){
565 areaLabel
= area
.getSymbol();
569 }else if (PreferencesUtil
.isShowSymbol2InChecklistEditor()){
570 if (area
.getSymbol2() != null){
571 areaLabel
= area
.getSymbol2();
580 //String areaLabel = area.getLabel();
581 String property
= areaLabel
;
582 propertyToLabelMap
.put(property
, areaLabel
);
587 private SortedSet
<DefinedTermBase
> loadNamedAreas() {
588 //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
590 String valuesAreas
= PreferencesUtil
.getStringValue(EditorPreferencePredicate
.AvailableDistributionAreaTerms
.getKey());
591 String values
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey());
592 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
594 List
<String
> listValue
;
595 List
<DefinedTermBase
> termlist
= new ArrayList
<DefinedTermBase
>();
596 if (values
!= null && values
!= "") { //$NON-NLS-1$
597 split
= values
.split(";"); //$NON-NLS-1$
598 listValue
= Arrays
.asList(split
);
602 for(String s
: listValue
){
603 uuid
= UUID
.fromString(s
);
609 List
<TermVocabulary
> vocs
= new ArrayList
<>();
610 IVocabularyService service
= CdmStore
.getService(IVocabularyService
.class);
611 if (uuidList
.isEmpty()){
612 List
<TermVocabulary
<DefinedTermBase
>> vocList
= CdmStore
.getService(IVocabularyService
.class).findByTermType(TermType
.NamedArea
, null);
613 vocs
.addAll(vocList
);
615 vocs
= service
.find(uuidList
);
617 split
= valuesAreas
.split(";");
618 listValue
= Arrays
.asList(split
);
619 for (TermVocabulary voc
: vocs
){
620 termlist
.addAll(service
.getTerms(voc
, null, null, null, null).getRecords());
622 List
<DefinedTermBase
> filteredList
= new ArrayList();
623 for (DefinedTermBase area
: termlist
){
624 if (listValue
.contains(area
.getUuid().toString())) {
625 filteredList
.add(area
);
630 if (PreferencesUtil
.isSortNamedAreaByOrderInVocabulary()){
631 areas
= getTermsOrderedByVocabularyOrder(filteredList
);
632 } else if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
633 areas
= getTermsOrderedByIdInVocabulary(filteredList
);
635 areas
= getTermsOrderedByLabels(filteredList
, CdmStore
.getDefaultLanguage());
641 public SortedSet
<DefinedTermBase
> getTermsOrderedByLabels(List
<DefinedTermBase
> listTerm
,Language language
){
642 TermLanguageComparator
<?
> comp
= new TermLanguageComparator
<>();
643 comp
.setCompareLanguage(language
);
644 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
);
645 if(listTerm
!= null){
646 result
.addAll(listTerm
);
651 public SortedSet
<DefinedTermBase
> getTermsOrderedByIdInVocabulary(List
<DefinedTermBase
> namedAreas
) {
652 TermIdInVocabularyComparator
<?
> comp
= new TermIdInVocabularyComparator
<>();
654 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
);
655 if(namedAreas
!= null){
656 result
.addAll(namedAreas
);
661 public SortedSet
<DefinedTermBase
> getTermsOrderedByVocabularyOrder(List
<DefinedTermBase
> listAreas
){
662 HashMap
<TermVocabulary
<DefinedTermBase
>, List
<DefinedTermBase
>> vocs
= new HashMap
<>();
663 OrderedTermComparator
<?
> comp
= new OrderedTermComparator
<>();
664 boolean allOrderedTerms
= true;
665 List
<TermVocabulary
> alreadyOrderIndexNull
= new ArrayList
<>();
666 for (DefinedTermBase term
: listAreas
){
667 if (!(term
instanceof OrderedTermBase
)){
668 allOrderedTerms
= false;
670 }else if (((OrderedTermBase
)term
).getOrderIndex() == 0){
671 if(alreadyOrderIndexNull
.contains(term
.getVocabulary())) {
672 allOrderedTerms
= false;
675 alreadyOrderIndexNull
.add(term
.getVocabulary());
681 if (allOrderedTerms
){
682 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
.reversed());
683 result
.addAll(listAreas
);
686 return getTermsOrderedByLabels(listAreas
, PreferencesUtil
.getGlobalLanguage());
692 private void registerHandlersAndListeners(AbstractLayer topMostLayer
) {
694 E4SelectionListener selectionListener
= new DistributionCellSelectionListener(part
.getSelectionService(),
695 selectionLayer
, bodyDataProvider
, part
);
696 selectionLayer
.addLayerListener(selectionListener
);
697 selectionListener
.setFullySelectedRowsOnly(false);
699 //register handler for view configuration menu
700 // natTable.registerCommandHandler(toolbar.getDisplayPersistenceDialogCommandHandler());
706 public IRowDataProvider
<TaxonDistributionDTO
> getBodyDataProvider() {
707 return bodyDataProvider
;
710 public void setDirty() {
714 public Reference
getDefaultSource(){
715 return defaultSource
;
721 // public void reloadDistributions() {
722 // loadDistributions(taxonList);