Project

General

Profile

Download (3.55 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.UUID;
13

    
14
import org.apache.commons.lang.StringUtils;
15
import org.eclipse.jface.viewers.CheckboxTableViewer;
16
import org.eclipse.jface.wizard.IWizardPage;
17
import org.eclipse.jface.wizard.Wizard;
18

    
19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
/**
27
 * @author k.luther
28
 * @since 04.06.2018
29
 *
30
 */
31
public class AvailableVocabularyWizard extends Wizard implements IConversationEnabled {
32

    
33
    private ConversationHolder conversation;
34
    private final AvailableAreaVocabulariesPage aPage;
35
    private boolean localPref = true;
36

    
37
    public AvailableVocabularyWizard(boolean localPref) {
38
        setWindowTitle("Vocabulary Selection Wizard");
39
        // TODO if preferenceStore has elements checked load elements in wizard
40
        this.localPref = localPref;
41
        aPage = new AvailableAreaVocabulariesPage("AvailableDistributionPage", localPref);
42
    }
43

    
44
    @Override
45
    public void addPages() {
46
        addPage(aPage);
47
    }
48

    
49

    
50

    
51

    
52
    /**
53
     * {@inheritDoc}
54
     */
55
    @Override
56
    public IWizardPage getPage(String pageName) {
57

    
58
        return aPage;
59
    }
60

    
61
    /**
62
     * {@inheritDoc}
63
     */
64
    @Override
65
    public int getPageCount() {
66
       return 1;
67
    }
68

    
69
    /**
70
     * {@inheritDoc}
71
     */
72
    @Override
73
    public IWizardPage[] getPages() {
74
        IWizardPage[] pages = new IWizardPage[1];
75
        pages [0] = aPage;
76
        return pages;
77
    }
78

    
79

    
80

    
81

    
82

    
83
    /**
84
     * {@inheritDoc}
85
     */
86
    @Override
87
    public String getWindowTitle() {
88

    
89
        return "Vocabulary Selection Wizard";
90
    }
91

    
92

    
93

    
94

    
95

    
96

    
97

    
98
    /**
99
     * {@inheritDoc}
100
     */
101
    @Override
102
    public boolean performCancel() {
103
        // TODO Auto-generated method stub
104
        return true;
105
    }
106

    
107
    /**
108
     * {@inheritDoc}
109
     */
110
    @Override
111
    public boolean performFinish() {
112
        Object[] checkedElements = ((CheckboxTableViewer)aPage.getViewer()).getCheckedElements();
113

    
114
        ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
115
        for (Object o : checkedElements) {
116
               if(o instanceof TermVocabulary){
117
                    TermVocabulary otb = (TermVocabulary) o;
118
                    listUIIDChecked.add(otb.getUuid());
119
                }
120
            }
121
           String saveCheckedElements = StringUtils.join(listUIIDChecked, ";");
122
          // IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
123
           PreferencesUtil.setPreferredVocabulariesForDistributionEditor(saveCheckedElements, localPref);
124
          // preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_VOCABULARIES, saveCheckedElements);
125
           return true;
126
    }
127

    
128

    
129

    
130

    
131
    /**
132
     * {@inheritDoc}
133
     */
134
    @Override
135
    public void update(CdmDataChangeMap changeEvents) {
136
        // TODO Auto-generated method stub
137

    
138
    }
139

    
140

    
141
    /**
142
     * {@inheritDoc}
143
     */
144
    @Override
145
    public ConversationHolder getConversationHolder() {
146
        if (conversation == null) {
147
            conversation = CdmStore.createConversation();
148
        }
149
        return conversation;
150
    }
151

    
152
}
(5-5/7)