ref #7849: remove OVERRIDE constants from IPreferenceKeys and handle it by method
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / wizard / AvailableDistributionPage.java
1 /**
2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.preference.wizard;
10
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;
17 import java.util.Map;
18 import java.util.Set;
19 import java.util.UUID;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.eclipse.swt.widgets.Composite;
23
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;
35
36 /**
37 * @author a.oppermann
38 * @date 21.07.2014
39 *
40 */
41 public class AvailableDistributionPage extends AbstractTermSelectionWizardPage implements ICdmEntitySessionEnabled {
42
43 protected AvailableDistributionPage(String pageName) {
44 super(pageName, TermType.NamedArea);
45 this.localPref = true;
46
47 }
48
49 @Override
50 public void createControl(Composite parent) {
51 setTitle(Messages.AvailableDistributionPage_PAGE_TITLE);
52 setDescription(Messages.AvailableDistributionPage_PAGE_DESCRIPTION);
53
54 super.createControl(parent);
55 }
56
57 @Override
58 protected String getCheckedValuesFromPreferences() {
59 return PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
60 }
61
62 @Override
63 public void dispose() {
64 CdmStore.getCurrentSessionManager().dispose(this);
65 super.dispose();
66 }
67
68 @Override
69 public ICdmEntitySession getCdmEntitySession() {
70 return CdmStore.getCurrentSessionManager().getNullSession();
71 }
72
73 @Override
74 public <T extends CdmBase> Collection<T> getRootEntities() {
75 return null;
76 }
77
78 @Override
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$
83 });
84 propertyPathsMap.put("includes", termsPropertyPaths); //$NON-NLS-1$
85 propertyPathsMap.put("terms", termsPropertyPaths); //$NON-NLS-1$
86 return propertyPathsMap;
87 }
88
89 @Override
90 protected List<TermVocabularyDto> getVocabulariesFromPreference(){
91 List<TermVocabularyDto> vocs = new ArrayList<>();
92
93 if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null && PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()) == null){
94 vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
95 }else{
96 String vocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
97
98 String[] arrayVocs = vocString.split(";"); //$NON-NLS-1$
99
100 Set<UUID> uuidVocs = new HashSet<>();
101 for (String voc: arrayVocs){
102 if (!StringUtils.isBlank(voc)){
103 uuidVocs.add(UUID.fromString(voc));
104 }
105 }
106 List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
107 for (TermVocabulary voc: tempVocs){
108 vocs.add(new TermVocabularyDto(voc.getUuid(), voc.getRepresentations()));
109 }
110
111 }
112 return vocs;
113 }
114
115 }