Project

General

Profile

Download (4.42 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.persistence.dto.TermDto;
22
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
23
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
24
import eu.etaxonomy.taxeditor.l10n.Messages;
25
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
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
            String saveGrayedElements = StringUtils.join(listUIIDGrayed, ";"); //$NON-NLS-1$
77
           // IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
78
            //ToDo, if whole vocabulary is selected, save the vocabulary not all areas
79

    
80
           // PreferencesUtil.setPreferredNamedAreasForDistributionEditor(saveCheckedElements, saveGrayedElements, false);
81
            PreferencesUtil.setStringValue(IPreferenceKeys.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
82
            PreferencesUtil.setStringValue(IPreferenceKeys.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED, saveGrayedElements);
83
            return true;
84
        } else {
85
            return false;
86
        }
87
    }
88

    
89
    @Override
90
    public void addPages() {
91
        addPage(aPage);
92
    }
93

    
94
    private boolean checkNoneChecked() {
95

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

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

    
113
    @Override
114
    public void update(CdmDataChangeMap changeEvents) {
115
    }
116
}
(8-8/14)