Project

General

Profile

Download (3.94 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.PreferencesUtil;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

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

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

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

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

    
54

    
55

    
56

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

    
63
        return aPage;
64
    }
65

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

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

    
84

    
85

    
86

    
87

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

    
94
        return "Vocabulary Selection Wizard";
95
    }
96

    
97

    
98

    
99

    
100

    
101

    
102

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

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

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

    
134
           PreferencesUtil.updateDBPreferences();
135
           return true;
136
    }
137

    
138

    
139

    
140

    
141
    /**
142
     * {@inheritDoc}
143
     */
144
    @Override
145
    public void update(CdmDataChangeMap changeEvents) {
146
        // TODO Auto-generated method stub
147

    
148
    }
149

    
150

    
151
    /**
152
     * {@inheritDoc}
153
     */
154
    @Override
155
    public ConversationHolder getConversationHolder() {
156
        if (conversation == null) {
157
            conversation = CdmStore.createConversation();
158
        }
159
        return conversation;
160
    }
161

    
162
}
(9-9/13)