2 * Copyright (C) 2014 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
.preference
.wizard
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.Collection
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
16 import java
.util
.List
;
19 import java
.util
.UUID
;
21 import org
.apache
.commons
.lang
.StringUtils
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
27 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
28 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
29 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermVocabularyDto
;
30 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
31 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
32 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
33 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
41 public class AvailableDistributionPage
extends AbstractTermSelectionWizardPage
implements ICdmEntitySessionEnabled
{
43 protected AvailableDistributionPage(String pageName
) {
44 super(pageName
, TermType
.NamedArea
);
45 this.localPref
= true;
50 public void createControl(Composite parent
) {
51 setTitle(Messages
.AvailableDistributionPage_PAGE_TITLE
);
52 setDescription(Messages
.AvailableDistributionPage_PAGE_DESCRIPTION
);
54 super.createControl(parent
);
58 protected String
getCheckedValuesFromPreferences() {
59 return PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey());
63 public void dispose() {
64 CdmStore
.getCurrentSessionManager().dispose(this);
69 public ICdmEntitySession
getCdmEntitySession() {
70 return CdmStore
.getCurrentSessionManager().getNullSession();
74 public <T
extends CdmBase
> Collection
<T
> getRootEntities() {
79 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
80 Map
<Object
, List
<String
>> propertyPathsMap
= new HashMap
<Object
, List
<String
>>();
81 List
<String
> termsPropertyPaths
= Arrays
.asList(new String
[] {
82 "includes" //$NON-NLS-1$
84 propertyPathsMap
.put("includes", termsPropertyPaths
); //$NON-NLS-1$
85 propertyPathsMap
.put("terms", termsPropertyPaths
); //$NON-NLS-1$
86 return propertyPathsMap
;
90 protected List
<TermVocabularyDto
> getVocabulariesFromPreference(){
91 List
<TermVocabularyDto
> vocs
= new ArrayList
<>();
93 if (PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AvailableDistributionAreaVocabularies
) == null && PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey()) == null){
94 vocs
= CdmStore
.getService(IVocabularyService
.class).findVocabularyDtoByTermType(type
);
96 String vocString
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey());
98 String
[] arrayVocs
= vocString
.split(";"); //$NON-NLS-1$
100 Set
<UUID
> uuidVocs
= new HashSet
<>();
101 for (String voc
: arrayVocs
){
102 if (!StringUtils
.isBlank(voc
)){
103 uuidVocs
.add(UUID
.fromString(voc
));
106 List
<TermVocabulary
> tempVocs
= CdmStore
.getService(IVocabularyService
.class).find(uuidVocs
);
107 for (TermVocabulary voc
: tempVocs
){
108 vocs
.add(new TermVocabularyDto(voc
.getUuid(), voc
.getRepresentations()));