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.viewers.CheckboxTreeViewer;
|
19
|
import org.eclipse.jface.wizard.Wizard;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
22
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
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 = ((CheckboxTreeViewer)aPage.getViewer()).getCheckedElements();
|
55
|
Object[] grayedElements = ((CheckboxTreeViewer)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 NamedAreaWrapper) {
|
63
|
NamedArea na = (NamedArea)((NamedAreaWrapper) o).getNamedArea();
|
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 NamedAreaWrapper) {
|
73
|
NamedArea na = (NamedArea)((NamedAreaWrapper) o).getNamedArea();
|
74
|
listUIIDGrayed.add(na.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
|
|
87
|
// PreferencesUtil.setPreferredNamedAreasForDistributionEditor(saveCheckedElements, saveGrayedElements, false);
|
88
|
preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
|
89
|
preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED, saveGrayedElements);
|
90
|
return true;
|
91
|
} else {
|
92
|
return false;
|
93
|
}
|
94
|
}
|
95
|
|
96
|
@Override
|
97
|
public void addPages() {
|
98
|
addPage(aPage);
|
99
|
}
|
100
|
|
101
|
private boolean checkNoneChecked() {
|
102
|
|
103
|
if (((CheckboxTreeViewer)aPage.getViewer()).getCheckedElements().length == 0) {
|
104
|
aPage.setMessage("Please check at least one item", aPage.WARNING);
|
105
|
return true;
|
106
|
} else {
|
107
|
aPage.setMessage(null);
|
108
|
return false;
|
109
|
}
|
110
|
}
|
111
|
|
112
|
@Override
|
113
|
public ConversationHolder getConversationHolder() {
|
114
|
if (conversation == null) {
|
115
|
conversation = CdmStore.createConversation();
|
116
|
}
|
117
|
return conversation;
|
118
|
}
|
119
|
|
120
|
|
121
|
|
122
|
/*
|
123
|
* (non-Javadoc)
|
124
|
*
|
125
|
* @see
|
126
|
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
|
127
|
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
128
|
*/
|
129
|
@Override
|
130
|
public void update(CdmDataChangeMap changeEvents) {
|
131
|
// TODO Auto-generated method stub
|
132
|
|
133
|
}
|
134
|
}
|