Project

General

Profile

Download (4.25 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.model.metadata.CdmPreference;
23
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
24
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
25
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
26
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * @author k.luther
32
 * @since 04.06.2018
33
 *
34
 */
35
public class AvailableVocabularyWizard extends Wizard implements IConversationEnabled {
36

    
37
    private ConversationHolder conversation;
38
    private final AvailableAreaVocabulariesPage aPage;
39
    private boolean localPref = true;
40
    private CdmPreference pref;
41

    
42
    public AvailableVocabularyWizard(boolean localPref, CdmPreference pref, String featureTitle) {
43
        setWindowTitle("Vocabulary Selection Wizard");
44
        // TODO if preferenceStore has elements checked load elements in wizard
45
        this.localPref = localPref;
46
        this.pref = pref;
47
        aPage = new AvailableAreaVocabulariesPage("AvailableDistributionPage", localPref, pref, featureTitle);
48
    }
49

    
50
    @Override
51
    public void addPages() {
52
        addPage(aPage);
53
    }
54

    
55

    
56

    
57

    
58
    /**
59
     * {@inheritDoc}
60
     */
61
    @Override
62
    public IWizardPage getPage(String pageName) {
63

    
64
        return aPage;
65
    }
66

    
67
    /**
68
     * {@inheritDoc}
69
     */
70
    @Override
71
    public int getPageCount() {
72
       return 1;
73
    }
74

    
75
    /**
76
     * {@inheritDoc}
77
     */
78
    @Override
79
    public IWizardPage[] getPages() {
80
        IWizardPage[] pages = new IWizardPage[1];
81
        pages [0] = aPage;
82
        return pages;
83
    }
84

    
85

    
86

    
87

    
88

    
89
    /**
90
     * {@inheritDoc}
91
     */
92
    @Override
93
    public String getWindowTitle() {
94

    
95
        return "Vocabulary Selection Wizard";
96
    }
97

    
98

    
99

    
100

    
101

    
102

    
103

    
104
    /**
105
     * {@inheritDoc}
106
     */
107
    @Override
108
    public boolean performCancel() {
109
        // TODO Auto-generated method stub
110
        return true;
111
    }
112

    
113
    /**
114
     * {@inheritDoc}
115
     */
116
    @Override
117
    public boolean performFinish() {
118
        Object[] checkedElements = ((CheckboxTableViewer)aPage.getViewer()).getCheckedElements();
119

    
120
        ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
121
        for (Object o : checkedElements) {
122
               if(o instanceof TermVocabulary){
123
                    TermVocabulary otb = (TermVocabulary) o;
124
                    listUIIDChecked.add(otb.getUuid());
125
                }
126
            }
127
           String saveCheckedElements = StringUtils.join(listUIIDChecked, ";");
128
           String predicate = null;
129
           if (pref != null){
130
               predicate = pref.getPredicate();
131
           }
132
           if (!localPref){
133
               CdmPreference savePref = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.getByKey(predicate), saveCheckedElements);
134
               savePref.setAllowOverride(pref.isAllowOverride());
135
               PreferencesUtil.setPreferenceToDB(savePref);
136

    
137
               PreferencesUtil.updateDBPreferences();
138
           }else{
139
               PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DISTRIBUTION_VOCABULARIES, saveCheckedElements);
140
           }
141
           return true;
142
    }
143

    
144

    
145

    
146

    
147
    /**
148
     * {@inheritDoc}
149
     */
150
    @Override
151
    public void update(CdmDataChangeMap changeEvents) {
152
        // TODO Auto-generated method stub
153

    
154
    }
155

    
156

    
157
    /**
158
     * {@inheritDoc}
159
     */
160
    @Override
161
    public ConversationHolder getConversationHolder() {
162
        if (conversation == null) {
163
            conversation = CdmStore.createConversation();
164
        }
165
        return conversation;
166
    }
167

    
168
}
(9-9/13)