Project

General

Profile

Download (4.22 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.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.metadata.PreferencePredicate;
22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
24
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
25
import eu.etaxonomy.taxeditor.l10n.Messages;
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(Messages.AvailableDistributionWizard_WINDOW_TITLE);
41
        // TODO if preferenceStore has elements checked load elements in wizard
42
        aPage = new AvailableDistributionPage(Messages.AvailableDistributionWizard_PAGE_TITLE);
43
    }
44

    
45
    @Override
46
    public boolean performFinish() {
47
        // TODO: get Selection and save in EditorPreferences
48
        if (!checkNoneChecked()) {
49
            Object[] checkedElements = aPage.getViewer().getCheckedElements();
50
            Object[] grayedElements = aPage.getViewer().getGrayedElements();
51
            ArrayList checkedList = new ArrayList(Arrays.asList(checkedElements));
52
            ArrayList grayedList = new ArrayList(Arrays.asList(grayedElements));
53
            checkedList = (ArrayList) CollectionUtils.subtract(checkedList, grayedList);
54
            ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
55
            ArrayList<UUID> listUIIDGrayed = new ArrayList<UUID>();
56
            for (Object o : checkedList) {
57
                if (o instanceof TermDto) {
58
                    listUIIDChecked.add(((TermDto) o).getUuid());
59

    
60
                }else if(o instanceof TermVocabularyDto){
61
                    TermVocabularyDto termVocDto = (TermVocabularyDto) o;
62
                    listUIIDGrayed.add(termVocDto.getUuid());
63
                }
64
            }
65
            for (Object o : grayedList) {
66
                if (o instanceof TermDto) {
67
                    listUIIDChecked.add(((TermDto) o).getUuid());
68

    
69
                }else if(o instanceof TermVocabularyDto){
70
                    TermVocabularyDto termVocDto = (TermVocabularyDto) o;
71
                    listUIIDGrayed.add(termVocDto.getUuid());
72
                }
73
            }
74

    
75
            String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
76
           // IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
77
            //ToDo, if whole vocabulary is selected, save the vocabulary not all areas
78

    
79
           // PreferencesUtil.setPreferredNamedAreasForDistributionEditor(saveCheckedElements, saveGrayedElements, false);
80
            PreferencesUtil.setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
81
            return true;
82
        } else {
83
            return false;
84
        }
85
    }
86

    
87
    @Override
88
    public void addPages() {
89
        addPage(aPage);
90
    }
91

    
92
    private boolean checkNoneChecked() {
93

    
94
        if (aPage.getViewer().getCheckedElements().length == 0) {
95
            aPage.setMessage(Messages.AvailableDistributionWizard_CHECK_MESSAGE, aPage.WARNING);
96
            return true;
97
        } else {
98
            aPage.setMessage(null);
99
            return false;
100
        }
101
    }
102

    
103
    @Override
104
    public ConversationHolder getConversationHolder() {
105
        if (conversation == null) {
106
            conversation = CdmStore.createConversation();
107
        }
108
        return conversation;
109
    }
110

    
111
    @Override
112
    public void update(CdmDataChangeMap changeEvents) {
113
    }
114
}
(8-8/13)