1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2014 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.preference.wizard;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.commons.collections.CollectionUtils;
|
17
|
import org.apache.commons.lang.StringUtils;
|
18
|
import org.eclipse.jface.preference.IPreferenceStore;
|
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.DefinedTermBase;
|
24
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
25
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
26
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
27
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* @author alex
|
32
|
* @date 21.07.2014
|
33
|
*
|
34
|
*/
|
35
|
public class AvailableDistributionWizard extends Wizard implements IConversationEnabled {
|
36
|
|
37
|
private ConversationHolder conversation;
|
38
|
private final AvailableDistributionPage aPage;
|
39
|
|
40
|
public AvailableDistributionWizard() {
|
41
|
setWindowTitle("Distribution Selection Wizard");
|
42
|
// TODO if preferenceStore has elements checked load elements in wizard
|
43
|
aPage = new AvailableDistributionPage("AvailableDistributionPage");
|
44
|
}
|
45
|
|
46
|
/*
|
47
|
* (non-Javadoc)
|
48
|
*
|
49
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
50
|
*/
|
51
|
@Override
|
52
|
public boolean performFinish() {
|
53
|
// TODO: get Selection and save in EditorPreferences
|
54
|
if (!checkNoneChecked()) {
|
55
|
Object[] checkedElements = aPage.getViewer().getCheckedElements();
|
56
|
Object[] grayedElements = aPage.getViewer().getGrayedElements();
|
57
|
ArrayList checkedList = new ArrayList(Arrays.asList(checkedElements));
|
58
|
ArrayList grayedList = new ArrayList(Arrays.asList(grayedElements));
|
59
|
checkedList = (ArrayList) CollectionUtils.subtract(checkedList, grayedList);
|
60
|
ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
|
61
|
ArrayList<UUID> listUIIDGrayed = new ArrayList<UUID>();
|
62
|
for (Object o : checkedList) {
|
63
|
if (o instanceof NamedArea) {
|
64
|
NamedArea na = (NamedArea) o;
|
65
|
listUIIDChecked.add(na.getUuid());
|
66
|
|
67
|
}else if(o instanceof OrderedTermVocabulary){
|
68
|
OrderedTermVocabulary otb = (OrderedTermVocabulary) o;
|
69
|
listUIIDGrayed.add(otb.getUuid());
|
70
|
}
|
71
|
}
|
72
|
for (Object o : grayedList) {
|
73
|
if(o instanceof DefinedTermBase){
|
74
|
DefinedTermBase dt = (DefinedTermBase) o;
|
75
|
listUIIDGrayed.add(dt.getUuid());
|
76
|
}else if(o instanceof OrderedTermVocabulary){
|
77
|
OrderedTermVocabulary otb = (OrderedTermVocabulary) o;
|
78
|
listUIIDGrayed.add(otb.getUuid());
|
79
|
}
|
80
|
|
81
|
}
|
82
|
|
83
|
String saveCheckedElements = StringUtils.join(listUIIDChecked, ",");
|
84
|
String saveGrayedElements = StringUtils.join(listUIIDGrayed, ",");
|
85
|
IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
|
86
|
preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS, saveCheckedElements);
|
87
|
preferenceStore.setValue(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS_GRAYED, saveGrayedElements);
|
88
|
return true;
|
89
|
} else {
|
90
|
return false;
|
91
|
}
|
92
|
}
|
93
|
|
94
|
@Override
|
95
|
public void addPages() {
|
96
|
addPage(aPage);
|
97
|
}
|
98
|
|
99
|
private boolean checkNoneChecked() {
|
100
|
|
101
|
if (aPage.getViewer().getCheckedElements().length == 0) {
|
102
|
aPage.setMessage("Please check at least one item", aPage.WARNING);
|
103
|
return true;
|
104
|
} else {
|
105
|
aPage.setMessage(null);
|
106
|
return false;
|
107
|
}
|
108
|
}
|
109
|
|
110
|
@Override
|
111
|
public ConversationHolder getConversationHolder() {
|
112
|
if (conversation == null) {
|
113
|
conversation = CdmStore.createConversation();
|
114
|
}
|
115
|
return conversation;
|
116
|
}
|
117
|
|
118
|
/*
|
119
|
* (non-Javadoc)
|
120
|
*
|
121
|
* @see
|
122
|
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
|
123
|
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
124
|
*/
|
125
|
@Override
|
126
|
public void update(CdmDataChangeMap changeEvents) {
|
127
|
// TODO Auto-generated method stub
|
128
|
|
129
|
}
|
130
|
}
|