Project

General

Profile

« Previous | Next » 

Revision 31abf522

Added by Andreas Müller almost 5 years ago

ref #6903 allow preferences for distribution area vocabulary and distribution status

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmSpringContextHelper.java
19 19
import eu.etaxonomy.cdm.api.service.ICommonService;
20 20
import eu.etaxonomy.cdm.api.service.IDescriptionService;
21 21
import eu.etaxonomy.cdm.api.service.INameService;
22
import eu.etaxonomy.cdm.api.service.IPreferenceService;
22 23
import eu.etaxonomy.cdm.api.service.IReferenceService;
23 24
import eu.etaxonomy.cdm.api.service.IService;
24 25
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
......
159 160
        return (IDescriptionService)getCurrent().getBean(IDescriptionService.class);
160 161
    }
161 162

  
163
    public static IPreferenceService getPreferenceService() {
164
        return (IPreferenceService)getCurrent().getBean(IPreferenceService.class);
165
    }
166

  
162 167

  
163 168
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/AreaAndTaxonSettingsConfigWindow.java
15 15
import java.util.Set;
16 16
import java.util.UUID;
17 17

  
18
import com.vaadin.data.Container;
18 19
import com.vaadin.data.Property;
19 20
import com.vaadin.data.Property.ValueChangeEvent;
20 21
import com.vaadin.data.Property.ValueChangeListener;
......
67 68
    private ComboBox distAreaBox;
68 69
    private ListSelect namedAreaList;
69 70
    private TreeTable taxonTree;
70
    IDistributionTableView distributionTableView;
71
    private IDistributionTableView distributionTableView;
71 72

  
72 73
    /**
73 74
     * The constructor should first build the main layout, set the
......
110 111

  
111 112
        //init areas
112 113
        TermVocabulary<NamedArea> chosenAreaVoc = presenter.getChosenAreaVoc();
113
        distAreaBox.setContainerDataSource(presenter.getDistributionContainer());
114
        Container areaContainer = presenter.getAreaContainer();
115
        if (areaContainer.size() == 1){
116
            chosenAreaVoc = (TermVocabulary<NamedArea>)areaContainer.getItemIds().iterator().next();
117
        }
118
        distAreaBox.setContainerDataSource(areaContainer);
114 119
        distAreaBox.setValue(chosenAreaVoc);
115 120
        distAreaBox.addValueChangeListener(this);
116 121

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/AreaAndTaxonSettingsPresenter.java
17 17
import com.vaadin.data.util.IndexedContainer;
18 18
import com.vaadin.server.VaadinSession;
19 19

  
20
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
21 20
import eu.etaxonomy.cdm.model.common.TermType;
22 21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
23 22
import eu.etaxonomy.cdm.model.location.NamedArea;
23
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
24
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
24 25
import eu.etaxonomy.cdm.model.taxon.Classification;
25 26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26 27
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
......
33 34
 */
34 35
public class AreaAndTaxonSettingsPresenter extends SettingsPresenterBase {
35 36

  
36
    private Container distributionContainer;
37
    private Container areaContainer;
37 38
    private UUID areaVocabUUID;
38 39

  
39 40
    /**
......
42 43
     */
43 44
    public AreaAndTaxonSettingsPresenter() {
44 45
        super();
45
        Object selectedVocabularyUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
46
        Object selectedVocabularyUuidString = VaadinSession.getCurrent()
47
                .getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
46 48
        if(selectedVocabularyUuidString!=null){
47 49
            areaVocabUUID = UUID.fromString(selectedVocabularyUuidString.toString());
48 50
        }
49
        distributionContainer = new IndexedContainer(getNamedAreaList());
51
        areaContainer = new IndexedContainer(getNamedAreaList());
50 52
    }
51 53

  
52
    public Container getDistributionContainer() {
53
        return distributionContainer;
54

  
55

  
56
    public Container getAreaContainer() {
57
        return areaContainer;
58
    }
59

  
60
    private List<TermVocabulary<? extends NamedArea>> getNamedAreaList() {
61
        CdmPreference areaVocPref = CdmSpringContextHelper.getPreferenceService()
62
                .findVaadin(PreferencePredicate.AvailableDistributionAreaVocabularies);
63
        if (areaVocPref != null){
64
            List<UUID> uuidList = areaVocPref.getValueUuidList();
65
            return (List)CdmSpringContextHelper.getVocabularyService().load(uuidList, VOCABULARY_INIT_STRATEGY);
66
        }else{
67
            return (List)CdmSpringContextHelper.getVocabularyService().findByTermType(TermType.NamedArea, VOCABULARY_INIT_STRATEGY);
68
        }
54 69
    }
55 70

  
56
    private List<TermVocabulary<DefinedTermBase>> getNamedAreaList() {
57
        List<TermVocabulary<DefinedTermBase>> termList = CdmSpringContextHelper.getVocabularyService().findByTermType(TermType.NamedArea, VOCABULARY_INIT_STRATEGY);
58
        return termList;
71

  
72
    public TermVocabulary<NamedArea> getChosenAreaVoc(){
73
        return CdmSpringContextHelper.getVocabularyService().load(areaVocabUUID);
59 74
    }
60 75

  
76

  
61 77
    public List<TaxonNode> getChosenTaxonNodes(){
62
        List<UUID> nodeUuids = (List<UUID>) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID);
78
        List<UUID> nodeUuids = (List<UUID>) VaadinSession.getCurrent()
79
                .getAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID);
63 80
        if(nodeUuids!=null){
64 81
            return CdmSpringContextHelper.getTaxonNodeService().load(nodeUuids, null);
65 82
        }
......
74 91
        return null;
75 92
    }
76 93

  
77
    public TermVocabulary<NamedArea> getChosenAreaVoc(){
78
        return CdmSpringContextHelper.getVocabularyService().load(areaVocabUUID);
79
    }
80 94

  
81 95
    protected static final List<String> VOCABULARY_INIT_STRATEGY = Arrays.asList(new String []{
82 96
            "$",
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/DistributionStatusSettingsPresenter.java
10 10

  
11 11
import java.util.Arrays;
12 12
import java.util.List;
13
import java.util.UUID;
13 14

  
14 15
import com.vaadin.data.Container;
15 16
import com.vaadin.data.util.IndexedContainer;
16 17

  
17
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
18 18
import eu.etaxonomy.cdm.model.common.TermType;
19
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
20
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
21
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
19 22
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
20 23

  
21 24
/**
......
32 35
     */
33 36
    public DistributionStatusSettingsPresenter() {
34 37
        super();
35
        distributionStatusContainer = new IndexedContainer(getPresenceAbsenceVocabulary());
38
        distributionStatusContainer = new IndexedContainer(getDistributionStatusList());
36 39
    }
37 40

  
38
    private List<DefinedTermBase<?>> getPresenceAbsenceVocabulary(){
39
        return CdmSpringContextHelper.getTermService().listByTermType(
40
                TermType.PresenceAbsenceTerm, null, null, null, DESCRIPTION_INIT_STRATEGY);
41
    private List<PresenceAbsenceTerm> getDistributionStatusList(){
42
        CdmPreference statusPref = CdmSpringContextHelper.getPreferenceService().findVaadin(PreferencePredicate.AvailableDistributionStatus);
43
        if (statusPref != null){
44
            List<UUID> uuidList = statusPref.getValueUuidList();
45
            return (List)CdmSpringContextHelper.getTermService().load(uuidList, TERMS_INIT_STRATEGY);
46
        }else{
47
            return CdmSpringContextHelper.getTermService().listByTermType(
48
                    TermType.PresenceAbsenceTerm, null, null, null, TERMS_INIT_STRATEGY);
49
        }
41 50
    }
42 51

  
43 52

  
53

  
44 54
    public Container getDistributionStatusContainer() {
45 55
        return distributionStatusContainer;
46 56
    }
47 57

  
48
    protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
58
    protected static final List<String> TERMS_INIT_STRATEGY = Arrays.asList(new String []{
49 59
            "$",
50 60
            "representations",
51 61
    });

Also available in: Unified diff