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
.HashMap
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.apache
.commons
.lang3
.StringUtils
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
25 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
26 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
27 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
28 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
29 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermDto
;
30 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermVocabularyDto
;
31 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
40 public class AvailableDistributionPage
extends AbstractTermSelectionWizardPage
<TermDto
> {
44 public AvailableDistributionPage(String pageName
) {
45 super(pageName
, TermType
.NamedArea
);
46 this.localPref
= true;
53 public void createControl(Composite parent
) {
54 setTitle(Messages
.AvailableDistributionPage_PAGE_TITLE
);
55 setDescription(Messages
.AvailableDistributionPage_PAGE_DESCRIPTION
);
57 super.createControl(parent
);
61 protected String
getCheckedValuesFromPreferences() {
62 String checkedValues
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaTerms
.getKey(), true);
68 protected void rememberCheckedValues(String checkedValues
) {
69 initialiseVocabularies();
71 treeComposite
.getViewer().setInput(getVocabularies());
73 if (checkedValues
!= null && checkedValues
!= "") { //$NON-NLS-1$
74 String
[] listChecked
= checkedValues
.split(";"); //$NON-NLS-1$
75 String
[] listCheckedComma
= checkedValues
.split(","); //$NON-NLS-1$
76 List
<String
> checked
= new ArrayList
<>();
77 if (listChecked
!= null ){
78 checked
= Arrays
.asList(listChecked
);
80 if (listCheckedComma
!= null && checkedValues
.contains(",")){ //$NON-NLS-1$
81 checked
= Arrays
.asList(listCheckedComma
);
83 List
<TermDto
> termsFromStringValues
= getTermsFromStringValues(checked
);
84 treeComposite
.setCheckedElements(termsFromStringValues
.toArray());
90 public void dispose() {
91 // CdmStore.getCurrentSessionManager().dispose(this);
96 // public ICdmEntitySession getCdmEntitySession() {
97 // return CdmStore.getCurrentSessionManager().getNullSession();
101 // public <T extends CdmBase> Collection<T> getRootEntities() {
106 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
107 Map
<Object
, List
<String
>> propertyPathsMap
= new HashMap
<Object
, List
<String
>>();
108 List
<String
> termsPropertyPaths
= Arrays
.asList(new String
[] {
109 "includes" //$NON-NLS-1$
111 propertyPathsMap
.put("includes", termsPropertyPaths
); //$NON-NLS-1$
112 propertyPathsMap
.put("terms", termsPropertyPaths
); //$NON-NLS-1$
113 return propertyPathsMap
;
117 protected List
<TermVocabularyDto
> getVocabulariesFromPreference(){
118 List
<TermVocabularyDto
> vocs
= new ArrayList
<>();
120 if (PreferencesUtil
.getPreferenceFromDB(PreferencePredicate
.AvailableDistributionAreaVocabularies
) == null && PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey()) == null){
121 vocs
= CdmStore
.getService(IVocabularyService
.class).findVocabularyDtoByTermType(type
);
123 String vocString
= PreferencesUtil
.getStringValue(PreferencePredicate
.AvailableDistributionAreaVocabularies
.getKey());
124 if (vocString
== null || vocString
.equals("")){
125 vocs
= CdmStore
.getService(IVocabularyService
.class).findVocabularyDtoByTermType(type
);
128 String
[] arrayVocs
= vocString
.split(";"); //$NON-NLS-1$
130 Set
<UUID
> uuidVocs
= new HashSet
<>();
131 for (String voc
: arrayVocs
){
132 if (!StringUtils
.isBlank(voc
)){
133 uuidVocs
.add(UUID
.fromString(voc
));
136 List
<TermVocabulary
> tempVocs
= CdmStore
.getService(IVocabularyService
.class).find(uuidVocs
);
137 for (TermVocabulary
<?
> voc
: tempVocs
){
138 vocs
.add(new TermVocabularyDto(voc
.getUuid(), voc
.getRepresentations(), voc
.getTermType(), voc
.getTitleCache(), voc
.isAllowDuplicates(), voc
.isOrderRelevant(), voc
.isFlat()));
144 protected void initialiseVocabularies() {
145 if (getVocabularies() != null) {
146 getVocabularies().clear();
148 List
<TermVocabularyDto
> vocs
= new ArrayList
<>();
149 vocs
= getVocabulariesFromPreference();
151 setVocabularies(vocs
);
155 protected List
<TermDto
> getTermsFromStringValues(List
<String
> listValue
) {
157 List
<TermDto
> termlist
= new ArrayList
<>();
158 ITermService termService
= CdmStore
.getService(ITermService
.class);
159 List
<UUID
> uuidList
= new ArrayList
<>();
160 for (String s
: listValue
) {
161 if (!StringUtils
.isBlank(s
)){
162 UUID uuid
= UUID
.fromString(s
);
166 termlist
= new ArrayList
<>(termService
.findByUUIDsAsDto(uuidList
));
169 if (listValue
.isEmpty()){
170 List
<DefinedTermBase
> terms
= CdmStore
.getTermManager().getAllTerms(type
, null);
171 for (DefinedTermBase
<?
> term
: terms
){
172 termlist
.add(TermDto
.fromTerm(term
, true));