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.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
|
28
|
/**
|
29
|
* @author alex
|
30
|
* @date 21.07.2014
|
31
|
*
|
32
|
*/
|
33
|
public class AvailableDistributionWizard extends Wizard implements IConversationEnabled {
|
34
|
|
35
|
private ConversationHolder conversation;
|
36
|
private final AvailableDistributionPage aPage;
|
37
|
|
38
|
public AvailableDistributionWizard() {
|
39
|
setWindowTitle(Messages.AvailableDistributionWizard_WINDOW_TITLE);
|
40
|
// TODO if preferenceStore has elements checked load elements in wizard
|
41
|
aPage = new AvailableDistributionPage(Messages.AvailableDistributionWizard_PAGE_TITLE);
|
42
|
}
|
43
|
|
44
|
/*
|
45
|
* (non-Javadoc)
|
46
|
*
|
47
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
48
|
*/
|
49
|
@Override
|
50
|
public boolean performFinish() {
|
51
|
// TODO: get Selection and save in EditorPreferences
|
52
|
if (!checkNoneChecked()) {
|
53
|
Object[] checkedElements = aPage.getViewer().getCheckedElements();
|
54
|
Object[] grayedElements = aPage.getViewer().getGrayedElements();
|
55
|
ArrayList checkedList = new ArrayList(Arrays.asList(checkedElements));
|
56
|
ArrayList grayedList = new ArrayList(Arrays.asList(grayedElements));
|
57
|
checkedList = (ArrayList) CollectionUtils.subtract(checkedList, grayedList);
|
58
|
ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
|
59
|
ArrayList<UUID> listUIIDGrayed = new ArrayList<UUID>();
|
60
|
for (Object o : checkedList) {
|
61
|
if (o instanceof TermDto) {
|
62
|
listUIIDChecked.add(((TermDto) o).getUuid());
|
63
|
|
64
|
}else if(o instanceof TermVocabularyDto){
|
65
|
TermVocabularyDto termVocDto = (TermVocabularyDto) o;
|
66
|
listUIIDGrayed.add(termVocDto.getUuid());
|
67
|
}
|
68
|
}
|
69
|
for (Object o : grayedList) {
|
70
|
if (o instanceof TermDto) {
|
71
|
listUIIDChecked.add(((TermDto) o).getUuid());
|
72
|
|
73
|
}else if(o instanceof TermVocabularyDto){
|
74
|
TermVocabularyDto termVocDto = (TermVocabularyDto) o;
|
75
|
listUIIDGrayed.add(termVocDto.getUuid());
|
76
|
}
|
77
|
}
|
78
|
|
79
|
String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
|
80
|
String saveGrayedElements = StringUtils.join(listUIIDGrayed, ";"); //$NON-NLS-1$
|
81
|
// IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
|
82
|
//ToDo, if whole vocabulary is selected, save the vocabulary not all areas
|
83
|
|
84
|
// PreferencesUtil.setPreferredNamedAreasForDistributionEditor(saveCheckedElements, saveGrayedElements, false);
|
85
|
PreferencesUtil.setStringValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
|
86
|
PreferencesUtil.setStringValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED, saveGrayedElements);
|
87
|
return true;
|
88
|
} else {
|
89
|
return false;
|
90
|
}
|
91
|
}
|
92
|
|
93
|
@Override
|
94
|
public void addPages() {
|
95
|
addPage(aPage);
|
96
|
}
|
97
|
|
98
|
private boolean checkNoneChecked() {
|
99
|
|
100
|
if (aPage.getViewer().getCheckedElements().length == 0) {
|
101
|
aPage.setMessage(Messages.AvailableDistributionWizard_CHECK_MESSAGE, aPage.WARNING);
|
102
|
return true;
|
103
|
} else {
|
104
|
aPage.setMessage(null);
|
105
|
return false;
|
106
|
}
|
107
|
}
|
108
|
|
109
|
@Override
|
110
|
public ConversationHolder getConversationHolder() {
|
111
|
if (conversation == null) {
|
112
|
conversation = CdmStore.createConversation();
|
113
|
}
|
114
|
return conversation;
|
115
|
}
|
116
|
|
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
|
}
|