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
.logging
.log4j
.LogManager
;import org
.apache
.logging
.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
.compare
.term
.TermSymbol1Comparator
;
80 import eu
.etaxonomy
.cdm
.compare
.term
.TermSymbol2Comparator
;
81 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
82 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
83 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
84 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
85 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
86 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
87 import eu
.etaxonomy
.cdm
.model
.metadata
.TermOrder
;
88 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
89 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
90 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermBase
;
91 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
92 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
93 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
94 import eu
.etaxonomy
.taxeditor
.editor
.IDistributionEditor
;
95 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
96 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
97 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
98 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
99 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
100 import eu
.etaxonomy
.taxeditor
.preference
.wizard
.AvailableDistributionWizard
;
101 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
102 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.ReferenceSelectionDialog
;
108 public class DistributionEditor
extends Composite
implements IDistributionEditor
{
110 @SuppressWarnings("unused")
111 private static final Logger logger
= LogManager
.getLogger(DistributionEditor
.class);
113 private static final String DISTRIBUTION_EDITOR
= "Distribution Editor"; //$NON-NLS-1$
114 private static final String LOADING_TAXA
= Messages
.ChecklistEditor_LOAD_TAXA
;
115 private static final String UNKNOWN
= Messages
.ChecklistEditor_UNKNOWN
;
116 private static final String ELEMENT_COUNT
= Messages
.ChecklistEditor_ELEMENT_COUNT
;
117 public static final String TYPE_FILTER_TEXT
= "type filter text"; //$NON-NLS-1$
119 static final String TAXON_COLUMN
= "taxon_column"; //$NON-NLS-1$
120 static final String RANK_COLUMN
= "collector_column";//$NON-NLS-1$
121 static final String SYNONYM_COLUMN
= "synonym_column";//$NON-NLS-1$
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 Text searchText
;
138 private Button button3
;
139 private Button button2
;
141 protected EventList
<TaxonDistributionDTO
> taxonList
;
142 private String actualNameCache
;
143 protected Map
<UUID
,Map
<NamedArea
,Set
<DescriptionElementBase
>>> taxonDistributionMap
= new HashMap
<>();
145 protected List
<TaxonDistributionDTO
> descriptionsToSave
= new ArrayList
<>();
147 protected SortedSet
<NamedArea
> areas
;
148 protected DistributionEditorPart part
;
149 private BodyLayerStack
<TaxonDistributionDTO
> bodyLayerStack
;
150 private FreezeLayer freezeLayer
;
151 private ConfigRegistry configRegistry
;
152 private AbstractLayer topMostLayer
;
154 private SelectionLayer selectionLayer
;
156 public DistributionEditor(Composite parent
, DistributionEditorPart part
) {
157 super(parent
, SWT
.NULL
);
158 isShowRank
= PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowRankInDistributionEditor
.getKey());
160 this.setLayout(new GridLayout());
161 GridLayoutFactory
.fillDefaults().applyTo(parent
);
163 Composite topComposite
= new Composite(parent
, SWT
.NONE
);
164 createTopComposite(topComposite
);
166 natTable
= new NatTable(parent
, false);
169 Composite bottomComposite
= new Composite(parent
, SWT
.NONE
);
170 GridLayoutFactory
.fillDefaults().applyTo(bottomComposite
);
171 createStatusBar(bottomComposite
);
174 public boolean isShowRank() {
178 public void setShowRank(boolean isShowRank
) {
179 this.isShowRank
= isShowRank
;
182 public int getFirstDataColumnIndex() {
183 return firstDataColumnIndex
;
186 public void setFirstDataColumnIndex(int firstDataColumnIndex
) {
187 this.firstDataColumnIndex
= firstDataColumnIndex
;
191 public String
getActualNameCache() {
192 return actualNameCache
;
195 public void setActualNameCache(String actualNameCache
) {
196 this.actualNameCache
= actualNameCache
;
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
;
211 public void setAreaToColumnIndexMap(Map
<Integer
, NamedArea
> areaToColumnIndexMap
) {
212 this.areaToColumnIndexMap
= areaToColumnIndexMap
;
215 public List
<TaxonDistributionDTO
> getDescriptionsToSave() {
216 return descriptionsToSave
;
219 public void setDescriptionsToSave(List
<TaxonDistributionDTO
> descriptionsToSave
) {
220 this.descriptionsToSave
= descriptionsToSave
;
223 private void createStatusBar(Composite composite
) {
224 GridData gridData
= new GridData();
225 gridData
.horizontalSpan
= 2;
226 gridData
.grabExcessHorizontalSpace
= true;
227 gridData
.horizontalAlignment
= GridData
.FILL
;
228 GridLayout gridLayout
= new GridLayout();
229 gridLayout
.numColumns
= 3;
230 composite
.setLayoutData(gridData
);
231 composite
.setLayout(gridLayout
);
234 gridData
= new GridData();
235 gridData
.horizontalSpan
= 1;
236 gridData
.grabExcessHorizontalSpace
= true;
237 gridData
.horizontalAlignment
= GridData
.FILL
;
239 statusLabel
= new Label(composite
, SWT
.LEFT
);
240 statusLabel
.setText(ELEMENT_COUNT
+ (taxonList
!= null ? taxonList
.size() : UNKNOWN
));
241 statusLabel
.setLayoutData(gridData
);
243 statusLabelSourceReference
= new Label(composite
, SWT
.RIGHT
);
245 statusLabelSourceReference
.setLayoutData(gridData
);
247 if (defaultSource
!= null){
248 statusLabelSourceReference
.setText(Messages
.DistributionEditor_defaultSource
+ (defaultSource
.getAbbrevTitle() != null? defaultSource
.getAbbrevTitle() : defaultSource
.getAbbrevTitleCache()));
251 button3
= new Button(composite
, SWT
.PUSH
);
252 button3
.setEnabled(false);
253 GridData gridData3
= new GridData();
254 gridData3
.horizontalAlignment
= SWT
.RIGHT
;
255 button3
.setLayoutData(gridData3
);
256 //button3.setText(Messages.ChecklistEditor_REMOVE_DEFAULT_SOURCE);
257 button3
.setImage(ImageResources
.getImage(ImageResources
.TRASH_ICON
));
258 button3
.setToolTipText(Messages
.ChecklistEditor_REMOVE_DEFAULT_SOURCE_TOOLTIP
);
259 button3
.addSelectionListener(new SelectionAdapter() {
262 public void widgetSelected(SelectionEvent event
) {
263 defaultSource
= null;
265 String defaultSourceStr
= (defaultSource
== null) ?
"" : Messages
.DistributionEditor_defaultSource
+ defaultSource
.getTitleCache(); //$NON-NLS-1$
266 if (defaultSourceStr
.length()> 100){
267 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "..."; //$NON-NLS-1$
269 statusLabelSourceReference
.setText(defaultSourceStr
);
271 button3
.setBackground(AbstractUtility
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
272 button3
.setEnabled(false);
273 button2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
279 private void applyStyles(){
280 CdmModernNatTableThemeConfiguration configuration
= new CdmModernNatTableThemeConfiguration();
282 // configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
283 // NOTE: Getting the colors and fonts from the GUIHelper ensures that
284 // they are disposed properly (required by SWT)
285 configuration
.cHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
286 configuration
.rHeaderBgColor
= GUIHelper
.getColor(211, 211, 211);
287 natTable
.addConfiguration(configuration
);
290 private void configureNatTable(ConfigRegistry configRegistry
,
291 AbstractLayer topMostLayer
) {
295 natTable
.setConfigRegistry(configRegistry
);
297 //add default configuration because autoconfigure is set to false in constructor
298 natTable
.addConfiguration(new DefaultNatTableStyleConfiguration());
301 natTable
.addConfiguration(new DefaultColumnHeaderStyleConfiguration() {
303 TextPainter painter
= new TextPainter();
304 painter
.setCalculateByTextLength(true);
305 painter
.setWrapText(false);
307 cellPainter
= new BeveledBorderDecorator(painter
);
312 // override the default sort configuration and change the mouse bindings
313 // to sort on a single click
315 natTable
.addConfiguration(new SingleClickSortConfiguration());
316 natTable
.addConfiguration(new FilterRowConfiguration(this));
318 // add the header menu configuration for adding the column header menu
319 // with hide/show actions
320 natTable
.addConfiguration(new DistributionEditorHeaderMenuConfiguration(natTable
));
322 // add custom configuration for data conversion and add column labels to viewport layer
323 topMostLayer
.addConfiguration(new DistributionCellEditorDataConversionConfiguration(this));
326 natTable
.configure();
329 public void createTable(){
338 configureNatTable( configRegistry
, topMostLayer
);
341 * handlers and listeners
343 registerHandlersAndListeners(topMostLayer
);
344 FreezeHelper
.freeze(freezeLayer
, bodyLayerStack
.getViewPortLayer(),
345 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, 0),
346 new PositionCoordinate(bodyLayerStack
.getViewPortLayer(), 0, -1));
348 GridDataFactory
.fillDefaults().grab(true, true).applyTo(natTable
);
351 natTable
.doCommand(new ClientAreaResizeCommand(natTable
));
352 // boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
355 private void createLayers() {
357 DistributionColumnAccessor columnPropertyAccessor
= new DistributionColumnAccessor(this);
358 DistributionEditorConfigLabelAccumulator labelAccumulator
= new DistributionEditorConfigLabelAccumulator(this);
360 // bodyLayerStack = new BodyLayerStack<>(taxonList, columnPropertyAccessor, new TaxonDistributionDtoComparator(), labelAccumulator);
361 bodyLayerStack
= new BodyLayerStack
<>(taxonList
, columnPropertyAccessor
, null, labelAccumulator
);
362 bodyDataProvider
= bodyLayerStack
.getBodyDataProvider();
364 propertyToLabelMap
.put(TAXON_COLUMN
, Messages
.ChecklistEditor_TAXON
);
366 propertyToLabelMap
.put(RANK_COLUMN
, Messages
.ChecklistEditor_RANK
);
367 propertyToLabelMap
.put(SYNONYM_COLUMN
, Messages
.ChecklistEditor_SYNONYMS
);
369 propertyToLabelMap
.put(SYNONYM_COLUMN
, Messages
.ChecklistEditor_SYNONYMS
);
371 configRegistry
= new ConfigRegistry();
374 this.selectionLayer
= bodyLayerStack
.getSelectionLayer();
376 freezeLayer
= new FreezeLayer(selectionLayer
);
377 final CompositeFreezeLayer compositeFreezeLayer
= new CompositeFreezeLayer(
378 freezeLayer
, bodyLayerStack
.getViewPortLayer(), selectionLayer
);
380 // as the selection mouse bindings are registered for the region label
382 // we need to set that region label to the viewport so the selection via mouse
383 // is working correctly
384 compositeFreezeLayer
.setRegionName(GridRegion
.BODY
);
386 IDataProvider columnHeaderDataProvider
=
387 new DefaultColumnHeaderDataProvider(propertyToLabelMap
.values().toArray(new String
[] {}), propertyToLabelMap
);
388 DataLayer columnHeaderDataLayer
= new DefaultColumnHeaderDataLayer(columnHeaderDataProvider
);
389 ILayer columnHeaderLayer
= new ColumnHeaderLayer(
390 columnHeaderDataLayer
,
391 compositeFreezeLayer
,
394 FilterRowHeaderComposite
<TaxonDistributionDTO
> filterRowHeaderLayer
=
395 new FilterRowHeaderComposite
<>(
396 new DefaultGlazedListsFilterStrategy
<>(
397 bodyLayerStack
.getFilterList(),
398 columnPropertyAccessor
,
401 columnHeaderDataLayer
.getDataProvider(),
404 // build the row header layer stack
405 IDataProvider rowHeaderDataProvider
= new DefaultRowHeaderDataProvider(bodyDataProvider
);
406 DataLayer rowHeaderDataLayer
= new DefaultRowHeaderDataLayer(rowHeaderDataProvider
);
407 ILayer rowHeaderLayer
= new RowHeaderLayer(
409 compositeFreezeLayer
,
412 IDataProvider cornerDataProvider
=
413 new DefaultCornerDataProvider(
414 columnHeaderDataProvider
,
415 rowHeaderDataProvider
);
416 DataLayer cornerDataLayer
= new DataLayer(cornerDataProvider
);
417 ILayer cornerLayer
= new CornerLayer(
420 filterRowHeaderLayer
);
422 GridLayer gridLayer
= new GridLayer(
423 compositeFreezeLayer
,
424 filterRowHeaderLayer
,
428 natTable
.setLayer(gridLayer
);
429 topMostLayer
= compositeFreezeLayer
;
432 private Text
createSearchBar(Composite parent
) {
434 Button button1
= new Button(parent
, SWT
.PUSH
);
435 GridData gridData2
= new GridData();
436 gridData2
.horizontalSpan
= 1;
437 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
439 button1
.setLayoutData(gridData2
);
441 button1
.setText(Messages
.ChecklistEditor_DIST_STATUS
);
442 button1
.setToolTipText(Messages
.ChecklistEditor_DIST_STATUS_TOOLTIP
);
443 button1
.addSelectionListener(new SelectionAdapter() {
445 public void widgetSelected(SelectionEvent event
) {
446 AvailableDistributionWizard availableDistributionWizard
= new AvailableDistributionWizard();
447 WizardDialog dialog
= new WizardDialog(AbstractUtility
.getShell(),
448 availableDistributionWizard
);
450 int open
= dialog
.open();
457 button2
= new Button(parent
, SWT
.PUSH
);
458 GridData gridData3
= new GridData();
459 gridData3
.horizontalAlignment
= SWT
.RIGHT
;
461 button2
.setLayoutData(gridData3
);
463 button2
.setText(Messages
.ChecklistEditor_DEFAULT_SOURCE
);
464 button2
.setToolTipText(Messages
.ChecklistEditor_DEFAULT_SOURCE_TOOLTIP
);
465 button2
.addSelectionListener(new SelectionAdapter() {
468 public void widgetSelected(SelectionEvent event
) {
469 defaultSource
= ReferenceSelectionDialog
.select(AbstractUtility
.getShell(), null);
471 String defaultSourceStr
= (defaultSource
== null) ?
"" : Messages
.DistributionEditor_defaultSource
+ defaultSource
.getTitleCache(); //$NON-NLS-1$
472 if (defaultSourceStr
.length()> 100){
473 defaultSourceStr
= defaultSourceStr
.substring(0, 98) + "..."; //$NON-NLS-1$
475 statusLabelSourceReference
.setText(defaultSourceStr
);
477 button2
.setBackground(AbstractUtility
.getColor(Resources
.COLOR_CONTROL_SELECTED
));
478 // EventUtility.postEvent(WorkbenchEventConstants.REFRESH_DETAILS, true);
479 button3
.setEnabled(true);
480 button2
.setText(Messages
.ChecklistEditor_SWITCH_DEFAULT_SOURCE
);
488 * This method should only be called for adding new Distribution columns and reloading the table.<br>
489 * It will hide the old distribution column and load the newly added columns.<br>
491 * <b>Notice:</b> for data update please use <b>refresh()</b>
494 public void reload(){
495 this.areaToColumnIndexMap
.clear();
497 this.propertyToLabelMap
.clear();
502 private void createTopComposite(Composite parent
) {
503 GridLayout gridLayout
= new GridLayout(3, false);
504 gridLayout
.marginWidth
= 0;
505 gridLayout
.marginHeight
= 0;
506 GridData gridData2
= new GridData();
507 gridData2
.horizontalSpan
= 1;
508 gridData2
.horizontalAlignment
= SWT
.RIGHT
;
509 gridData2
.horizontalIndent
= 3;
510 parent
.setLayoutData(gridData2
);
511 parent
.setLayout(gridLayout
);
512 searchText
= createSearchBar(parent
);
516 public void loadDistributions(List
<TaxonDistributionDTO
> taxonList
) {
517 if (this.taxonList
== null){
518 this.taxonList
= new BasicEventList
<>();
520 taxonList
.stream().forEach(wrapper
->DistributionEditor
.this.taxonList
.add(wrapper
));
521 statusLabel
.setText(ELEMENT_COUNT
+ taxonList
.size());
522 createTaxonDistributionMap();
525 protected void createTaxonDistributionMap() {
526 Iterator
<TaxonDistributionDTO
> iterator
= this.taxonList
.iterator();
527 while (iterator
.hasNext()){
528 TaxonDistributionDTO dto
= iterator
.next();
529 TaxonDescriptionDTO descriptionDto
= dto
.getDescriptionsWrapper();
530 for (TaxonDescription desc
: descriptionDto
.getDescriptions()){
531 if(this.part
.getCdmEntitySession()!=null){
532 this.part
.getCdmEntitySession().load(desc
, true);
534 for (DescriptionElementBase descElement
: desc
.getElements()){
535 if (descElement
instanceof Distribution
){
536 Map
<NamedArea
, Set
<DescriptionElementBase
>> distributionsMap
= taxonDistributionMap
.get(dto
.getTaxonUuid());
538 if (distributionsMap
== null){
539 distributionsMap
= new HashMap
<>();
540 taxonDistributionMap
.put(dto
.getTaxonUuid(), distributionsMap
);
542 Set
<DescriptionElementBase
> distributions
= distributionsMap
.get(((Distribution
) descElement
).getArea());
543 if (distributions
== null){
544 distributions
= new HashSet
<>();
545 distributionsMap
.put(((Distribution
)descElement
).getArea(), distributions
);
547 distributions
.add(descElement
);
554 private void initLabels() {
563 areas
= new TreeSet
<>();
565 for (DefinedTermBase
<?
> area
: areas
) {
566 this.areaToColumnIndexMap
.put(index
++, (NamedArea
)area
);
568 //TODO: adapt to preference
569 Representation rep
= area
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
570 String label
= rep
.getLabel();
572 label
= area
.getTitleCache();
574 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
575 if (area
.getIdInVocabulary() != null){
576 areaLabel
= area
.getIdInVocabulary();
580 }else if (PreferencesUtil
.isShowSymbol1InChecklistEditor()){
581 if (area
.getSymbol() != null){
582 areaLabel
= area
.getSymbol();
586 }else if (PreferencesUtil
.isShowSymbol2InChecklistEditor()){
587 if (area
.getSymbol2() != null){
588 areaLabel
= area
.getSymbol2();
596 //String areaLabel = area.getLabel();
597 String property
= area
.getUuid().toString();
598 propertyToLabelMap
.put(property
, areaLabel
);
602 private SortedSet
<NamedArea
> loadNamedAreas() {
603 //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
605 String valuesAreas
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey(), true);
606 String values
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey());
607 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
609 List
<String
> listValue
;
610 List
<NamedArea
> termlist
= new ArrayList
<>();
611 if (values
!= null && values
!= "") { //$NON-NLS-1$
612 split
= values
.split(";"); //$NON-NLS-1$
613 listValue
= Arrays
.asList(split
);
616 for(String s
: listValue
){
617 uuid
= UUID
.fromString(s
);
622 List
<TermVocabulary
<NamedArea
>> vocs
= new ArrayList
<>();
623 IVocabularyService service
= CdmStore
.getService(IVocabularyService
.class);
624 if (uuidList
.isEmpty()){
625 List
<TermVocabulary
<NamedArea
>> vocList
= CdmStore
.getService(IVocabularyService
.class).findByTermType(TermType
.NamedArea
, null);
626 vocs
.addAll(vocList
);
628 vocs
= (List
)service
.find(uuidList
);
630 for (TermVocabulary
<NamedArea
> voc
: vocs
){
631 termlist
.addAll((List
)service
.getTerms(voc
, null, null, null, null).getRecords());
633 List
<NamedArea
> filteredList
= new ArrayList
<>();
634 if (valuesAreas
!= null && valuesAreas
!= "") {
635 split
= valuesAreas
.split(";"); //$NON-NLS-1$
636 listValue
= Arrays
.asList(split
);
638 for (NamedArea area
: termlist
){
639 if (listValue
.contains(area
.getUuid().toString())) {
640 filteredList
.add(area
);
644 filteredList
.addAll(termlist
);
647 TermOrder sortOrder
= PreferencesUtil
.getSortNamedAreasInDistributionEditor();
648 if (sortOrder
.equals(TermOrder
.Natural
)){
649 areas
= getTermsOrderedByVocabularyOrder(filteredList
);
650 } else if (sortOrder
.equals(TermOrder
.IdInVoc
)){
651 areas
= getTermsOrderedByIdInVocabulary(filteredList
);
653 areas
= getTermsOrderedByLabels(filteredList
, CdmStore
.getDefaultLanguage());
659 public <T
extends DefinedTermBase
<T
>> SortedSet
<T
> getTermsOrderedByLabels(List
<T
> listTerm
,Language language
){
660 TermLanguageComparator
<T
> comp
= new TermLanguageComparator
<>(Language
.DEFAULT(), language
);
661 SortedSet
<T
> result
= new TreeSet
<>(comp
);
662 if(listTerm
!= null){
663 result
.addAll(listTerm
);
669 public <T
extends DefinedTermBase
<T
>> SortedSet
<T
> getTermsOrderedByIdInVocabulary(List
<T
> namedAreas
) {
670 TermIdInVocabularyComparator
<T
> comp
= new TermIdInVocabularyComparator
<>();
672 SortedSet
<T
> result
= new TreeSet
<>(comp
);
673 if(namedAreas
!= null){
674 result
.addAll(namedAreas
);
679 public <T
extends DefinedTermBase
<T
>> SortedSet
<T
> getTermsOrderedBySymbol(List
<T
> namedAreas
) {
680 TermSymbol1Comparator
<T
> comp
= new TermSymbol1Comparator
<>();
682 SortedSet
<T
> result
= new TreeSet
<>(comp
);
683 if(namedAreas
!= null){
684 result
.addAll(namedAreas
);
689 public <T
extends DefinedTermBase
<T
>> SortedSet
<T
> getTermsOrderedBySymbol2(List
<T
> namedAreas
) {
690 TermSymbol2Comparator
<T
> comp
= new TermSymbol2Comparator
<>();
692 SortedSet
<T
> result
= new TreeSet
<>(comp
);
693 if(namedAreas
!= null){
694 result
.addAll(namedAreas
);
699 public <T
extends DefinedTermBase
<T
>> SortedSet
<T
> getTermsOrderedByVocabularyOrder(List
<T
> listAreas
){
700 OrderedTermComparator
<T
> comp
= new OrderedTermComparator
<>();
701 boolean allOrderedTerms
= true;
702 List
<TermVocabulary
<T
>> alreadyOrderIndexNull
= new ArrayList
<>();
703 for (T term
: listAreas
){
704 if (!(term
instanceof OrderedTermBase
)){
705 allOrderedTerms
= false;
707 }else if (((OrderedTermBase
<?
>)term
).getOrderIndex() == 0){
708 if(alreadyOrderIndexNull
.contains(term
.getVocabulary())) {
709 allOrderedTerms
= false;
712 alreadyOrderIndexNull
.add(term
.getVocabulary());
716 if (allOrderedTerms
){
717 SortedSet
<T
> result
= new TreeSet
<>(comp
);
718 result
.addAll(listAreas
);
721 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());
736 public IRowDataProvider
<TaxonDistributionDTO
> getBodyDataProvider() {
737 return bodyDataProvider
;
740 public void setDirty() {
745 public Reference
getDefaultSource(){
746 return defaultSource
;
752 // public void reloadDistributions() {
753 // loadDistributions(taxonList);