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
.preference
.wizard
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.commons
.lang3
.StringUtils
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
20 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
21 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
22 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermVocabularyDto
;
23 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.RootElementsOnlyTreeContentProvider
;
24 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
25 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 public class AvailableAreaVocabulariesPage
extends AbstractTermSelectionWizardPage
<TermVocabularyDto
>{
38 public AvailableAreaVocabulariesPage(String pageName
, boolean localPref
, CdmPreference pref
, String featureTitle
) {
39 super(pageName
, TermType
.NamedArea
);
40 this.localPref
= localPref
;
41 this.featureTitle
= featureTitle
;
47 // public AvailableAreaVocabulariesPage(String pageName, boolean localPref, CdmPreference pref, String featureTitle) {
48 // this(pageName, localPref, pref, featureTitle);
53 public void createControl(Composite parent
) {
55 setTitle(String
.format(Messages
.AvailableAreaVocabulariesPage_PAGE_TITLE
, featureTitle
));
56 setDescription(String
.format(Messages
.AvailableAreaVocabulariesPage_PAGE_DESCRIPTION
, featureTitle
));
58 createAllowOverrideButton(parent
);
61 super.createControl(parent
);
63 treeComposite
.getViewer().setContentProvider(new RootElementsOnlyTreeContentProvider());
64 treeComposite
.setAllowTopLevelSelection(true);
70 protected String
getCheckedValuesFromPreferences() {
71 String vocString
= null;
73 vocString
= PreferencesUtil
.getPreferredVocabulariesForDistributionEditor(localPref
);
74 if (StringUtils
.isBlank(vocString
) && pref
!= null){
75 vocString
= pref
.getValue();
77 this.override
= PreferencesUtil
.getOverrideForPreference(pref
.getPredicate());
78 }else if (pref
!= null){
79 vocString
= pref
.getValue();
92 protected List
<TermVocabularyDto
> getVocabulariesFromPreference() {
93 // TODO Auto-generated method stub
97 protected void rememberCheckedValues(String checkedValues
) {
98 initialiseVocabularies();
100 treeComposite
.getViewer().setInput(getVocabularies());
102 if (checkedValues
!= null && checkedValues
!= "") { //$NON-NLS-1$
103 String
[] listChecked
= checkedValues
.split(";"); //$NON-NLS-1$
104 String
[] listCheckedComma
= checkedValues
.split(","); //$NON-NLS-1$
105 List
<String
> checked
= new ArrayList
<>();
106 if (listChecked
!= null ){
107 checked
= Arrays
.asList(listChecked
);
109 if (listCheckedComma
!= null && checkedValues
.contains(",")){ //$NON-NLS-1$
110 checked
= Arrays
.asList(listCheckedComma
);
112 List
<TermVocabularyDto
> termsFromStringValues
= getTermsFromStringValues(checked
);
113 treeComposite
.setCheckedElements(termsFromStringValues
.toArray());
117 treeComposite
.getViewer().setAllChecked(true);
122 protected List
<TermVocabularyDto
> getTermsFromStringValues(List
<String
> listValue
) {
123 List
<TermVocabularyDto
> termlist
= new ArrayList
<>();
124 List
<UUID
> uuidList
= new ArrayList
<>();
125 for (String s
: listValue
) {
126 if (!StringUtils
.isBlank(s
)){
127 UUID uuid
= UUID
.fromString(s
);
131 IVocabularyService vocabularyService
= CdmStore
.getService(IVocabularyService
.class);
133 termlist
= vocabularyService
.findVocabularyDtoByVocabularyUuids(uuidList
);