1
|
/**
|
2
|
* Copyright (C) 2018 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.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.commons.lang.StringUtils;
|
16
|
import org.eclipse.jface.viewers.CheckboxTreeViewer;
|
17
|
import org.eclipse.jface.wizard.IWizardPage;
|
18
|
import org.eclipse.jface.wizard.Wizard;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
21
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
22
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
23
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
24
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
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 k.luther
|
31
|
* @since 05.10.2018
|
32
|
*
|
33
|
*/
|
34
|
public class AvailableDistributionStatusWizard extends Wizard implements IConversationEnabled{
|
35
|
private ConversationHolder conversation;
|
36
|
private final AvailableDistributionStatusPage aPage;
|
37
|
CdmPreference pref;
|
38
|
|
39
|
|
40
|
public AvailableDistributionStatusWizard() {
|
41
|
setWindowTitle("Distribution Status Selection Wizard");
|
42
|
// TODO if preferenceStore has elements checked load elements in wizard
|
43
|
pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionStatus);
|
44
|
aPage = new AvailableDistributionStatusPage("AvailableDistributionStatusPage", pref);
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
public void addPages() {
|
49
|
addPage(aPage);
|
50
|
}
|
51
|
|
52
|
|
53
|
|
54
|
|
55
|
/**
|
56
|
* {@inheritDoc}
|
57
|
*/
|
58
|
@Override
|
59
|
public IWizardPage getPage(String pageName) {
|
60
|
|
61
|
return aPage;
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* {@inheritDoc}
|
66
|
*/
|
67
|
@Override
|
68
|
public int getPageCount() {
|
69
|
return 1;
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* {@inheritDoc}
|
74
|
*/
|
75
|
@Override
|
76
|
public IWizardPage[] getPages() {
|
77
|
IWizardPage[] pages = new IWizardPage[1];
|
78
|
pages [0] = aPage;
|
79
|
return pages;
|
80
|
}
|
81
|
|
82
|
|
83
|
|
84
|
|
85
|
|
86
|
/**
|
87
|
* {@inheritDoc}
|
88
|
*/
|
89
|
@Override
|
90
|
public String getWindowTitle() {
|
91
|
|
92
|
return "Distribution Status Selection Wizard";
|
93
|
}
|
94
|
|
95
|
|
96
|
|
97
|
|
98
|
|
99
|
|
100
|
|
101
|
/**
|
102
|
* {@inheritDoc}
|
103
|
*/
|
104
|
@Override
|
105
|
public boolean performCancel() {
|
106
|
// TODO Auto-generated method stub
|
107
|
return true;
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* {@inheritDoc}
|
112
|
*/
|
113
|
@Override
|
114
|
public boolean performFinish() {
|
115
|
Object[] checkedElements = ((CheckboxTreeViewer)aPage.getViewer()).getCheckedElements();
|
116
|
|
117
|
List<UUID> listUIIDChecked = new ArrayList<>();
|
118
|
List<DefinedTermBase> preferredTerms = new ArrayList<>();
|
119
|
for (Object o : checkedElements) {
|
120
|
if(o instanceof DefinedTermBase){
|
121
|
DefinedTermBase otb = (DefinedTermBase) o;
|
122
|
listUIIDChecked.add(otb.getUuid());
|
123
|
preferredTerms.add(otb);
|
124
|
}
|
125
|
}
|
126
|
String saveCheckedElements = StringUtils.join(listUIIDChecked, ";");
|
127
|
pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AvailableDistributionStatus, saveCheckedElements);
|
128
|
|
129
|
PreferencesUtil.setPreferenceToDB(pref);
|
130
|
CdmStore.getTermManager().setPreferredTerms(preferredTerms, aPage.getVocabularies().get(0).getTerms());
|
131
|
PreferencesUtil.firePreferencesChanged(this.getClass());
|
132
|
return true;
|
133
|
}
|
134
|
|
135
|
|
136
|
|
137
|
|
138
|
/**
|
139
|
* {@inheritDoc}
|
140
|
*/
|
141
|
@Override
|
142
|
public void update(CdmDataChangeMap changeEvents) {
|
143
|
// TODO Auto-generated method stub
|
144
|
|
145
|
}
|
146
|
|
147
|
|
148
|
/**
|
149
|
* {@inheritDoc}
|
150
|
*/
|
151
|
@Override
|
152
|
public ConversationHolder getConversationHolder() {
|
153
|
if (conversation == null) {
|
154
|
conversation = CdmStore.createConversation();
|
155
|
}
|
156
|
return conversation;
|
157
|
}
|
158
|
|
159
|
}
|