Project

General

Profile

Download (4.76 KB) Statistics
| Branch: | Tag: | Revision:
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.UUID;
14

    
15
import org.apache.commons.collections.CollectionUtils;
16
import org.apache.commons.lang.StringUtils;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.jface.wizard.Wizard;
19

    
20
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
21
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
24
import eu.etaxonomy.cdm.model.location.NamedArea;
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 alex
31
 * @date 21.07.2014
32
 *
33
 */
34
public class AvailableDistributionWizard extends Wizard implements IConversationEnabled {
35

    
36
    private ConversationHolder conversation;
37
    private final AvailableDistributionPage aPage;
38

    
39
    public AvailableDistributionWizard() {
40
        setWindowTitle("Distribution Selection Wizard");
41
        // TODO if preferenceStore has elements checked load elements in wizard
42
        aPage = new AvailableDistributionPage("AvailableDistributionPage");
43
    }
44

    
45
    /*
46
     * (non-Javadoc)
47
     *
48
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
49
     */
50
    @Override
51
    public boolean performFinish() {
52
        // TODO: get Selection and save in EditorPreferences
53
        if (!checkNoneChecked()) {
54
            Object[] checkedElements = aPage.getViewer().getCheckedElements();
55
            Object[] grayedElements = aPage.getViewer().getGrayedElements();
56
            ArrayList checkedList = new ArrayList(Arrays.asList(checkedElements));
57
            ArrayList grayedList = new ArrayList(Arrays.asList(grayedElements));
58
            checkedList = (ArrayList) CollectionUtils.subtract(checkedList, grayedList);
59
            ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
60
            ArrayList<UUID> listUIIDGrayed = new ArrayList<UUID>();
61
            for (Object o : checkedList) {
62
                if (o instanceof NamedArea) {
63
                    NamedArea na = (NamedArea) o;
64
                    listUIIDChecked.add(na.getUuid());
65

    
66
                }else if(o instanceof OrderedTermVocabulary){
67
                    OrderedTermVocabulary otb = (OrderedTermVocabulary) o;
68
                    listUIIDGrayed.add(otb.getUuid());
69
                }
70
            }
71
            for (Object o : grayedList) {
72
                if(o instanceof DefinedTermBase){
73
                    DefinedTermBase dt = (DefinedTermBase) o;
74
                    listUIIDGrayed.add(dt.getUuid());
75
                }else if(o instanceof OrderedTermVocabulary){
76
                    OrderedTermVocabulary otb = (OrderedTermVocabulary) o;
77
                    listUIIDGrayed.add(otb.getUuid());
78
                }
79

    
80
            }
81

    
82
            String saveCheckedElements = StringUtils.join(listUIIDChecked, ",");
83
            String saveGrayedElements = StringUtils.join(listUIIDGrayed, ",");
84
            IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
85
            //ToDo, if whole vocabulary is selected, save the vocabulary not all areas
86
            PreferencesUtil.setPreferredNamedAreasForDistributionEditor(saveCheckedElements, saveGrayedElements, false);
87
//            preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
88
            preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED, saveGrayedElements);
89
            return true;
90
        } else {
91
            return false;
92
        }
93
    }
94

    
95
    @Override
96
    public void addPages() {
97
        addPage(aPage);
98
    }
99

    
100
    private boolean checkNoneChecked() {
101

    
102
        if (aPage.getViewer().getCheckedElements().length == 0) {
103
            aPage.setMessage("Please check at least one item", aPage.WARNING);
104
            return true;
105
        } else {
106
            aPage.setMessage(null);
107
            return false;
108
        }
109
    }
110

    
111
    @Override
112
    public ConversationHolder getConversationHolder() {
113
        if (conversation == null) {
114
            conversation = CdmStore.createConversation();
115
        }
116
        return conversation;
117
    }
118

    
119
    /*
120
     * (non-Javadoc)
121
     *
122
     * @see
123
     * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
124
     * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
125
     */
126
    @Override
127
    public void update(CdmDataChangeMap changeEvents) {
128
        // TODO Auto-generated method stub
129

    
130
    }
131
}
(2-2/4)