Project

General

Profile

Download (4 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.persistence.dto.TermDto;
20
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
21
import eu.etaxonomy.taxeditor.l10n.Messages;
22
import eu.etaxonomy.taxeditor.preference.EditorPreferencePredicate;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24

    
25
/**
26
 * @author alex
27
 * @date 21.07.2014
28
 *
29
 */
30
public class AvailableDistributionWizard extends Wizard {
31

    
32
   // private ConversationHolder conversation;
33
    private final AvailableDistributionPage aPage;
34

    
35
    public AvailableDistributionWizard() {
36
        setWindowTitle(Messages.AvailableDistributionWizard_WINDOW_TITLE);
37
        // TODO if preferenceStore has elements checked load elements in wizard
38
        aPage = new AvailableDistributionPage(Messages.AvailableDistributionWizard_PAGE_TITLE);
39
    }
40

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

    
56
                }else if(o instanceof TermVocabularyDto){
57
                    TermVocabularyDto termVocDto = (TermVocabularyDto) o;
58
                    listUIIDGrayed.add(termVocDto.getUuid());
59
                }
60
            }
61
            for (Object o : grayedList) {
62
                if (o instanceof TermDto) {
63
                    listUIIDChecked.add(((TermDto) o).getUuid());
64

    
65
                }else if(o instanceof TermVocabularyDto){
66
                    TermVocabularyDto termVocDto = (TermVocabularyDto) o;
67
                    listUIIDGrayed.add(termVocDto.getUuid());
68
                }
69
            }
70

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

    
75
           // PreferencesUtil.setPreferredNamedAreasForDistributionEditor(saveCheckedElements, saveGrayedElements, false);
76
            PreferencesUtil.setStringValue(EditorPreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
77
            return true;
78
        } else {
79
            return false;
80
        }
81
    }
82

    
83
    @Override
84
    public void addPages() {
85
        addPage(aPage);
86
    }
87

    
88
    private boolean checkNoneChecked() {
89

    
90
        if (aPage.getViewer().getCheckedElements().length == 0) {
91
            aPage.setMessage(Messages.AvailableDistributionWizard_CHECK_MESSAGE, aPage.WARNING);
92
            return true;
93
        } else {
94
            aPage.setMessage(null);
95
            return false;
96
        }
97
    }
98
//
99
//    @Override
100
//    public ConversationHolder getConversationHolder() {
101
//        if (conversation == null) {
102
//            conversation = CdmStore.createConversation();
103
//        }
104
//        return conversation;
105
//    }
106
//
107
//    @Override
108
//    public void update(CdmDataChangeMap changeEvents) {
109
//    }
110
}
(9-9/14)