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.editor.view.checklist.e4;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import javax.annotation.PostConstruct;
|
18
|
import javax.annotation.PreDestroy;
|
19
|
import javax.inject.Inject;
|
20
|
|
21
|
import org.eclipse.core.runtime.IProgressMonitor;
|
22
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
23
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
24
|
import org.eclipse.e4.ui.di.Persist;
|
25
|
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
26
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
27
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
28
|
import org.eclipse.swt.custom.StackLayout;
|
29
|
import org.eclipse.swt.widgets.Composite;
|
30
|
|
31
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
32
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
33
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
34
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
35
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
36
|
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
|
37
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
38
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
39
|
import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
|
40
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
41
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
42
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
43
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
44
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
45
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
46
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
47
|
|
48
|
/**
|
49
|
* @author k.luther
|
50
|
* @since 28.11.2018
|
51
|
*
|
52
|
*/
|
53
|
public class DistributionEditorPart implements IE4SavablePart, IConversationEnabled, IDirtyMarkable,
|
54
|
ICdmEntitySessionEnabled, IPartContentHasSupplementalData, IPartContentHasDetails, IDistributionEditor{
|
55
|
|
56
|
private static final List<String> TAXONNODE_PROPERTY_PATH = Arrays.asList(new String[] {
|
57
|
"taxon", //$NON-NLS-1$
|
58
|
"taxon.name", //$NON-NLS-1$
|
59
|
"taxon.name.rank",//$NON-NLS-1$
|
60
|
"taxon.descriptions", //$NON-NLS-1$
|
61
|
"taxon.descriptions.descriptionElements", //$NON-NLS-1$
|
62
|
"taxon.descriptions.descriptionElements.feature", //$NON-NLS-1$
|
63
|
"taxon.descriptions.descriptionElements.sources", //$NON-NLS-1$
|
64
|
"taxon.descriptions.descriptionElements.media" //$NON-NLS-1$
|
65
|
});
|
66
|
|
67
|
private List<TaxonDistributionDTO> taxonList;
|
68
|
private Collection<UpdateResult> updateResults;
|
69
|
|
70
|
private ConversationHolder conversation;
|
71
|
|
72
|
private ICdmEntitySession cdmEntitySession;
|
73
|
|
74
|
@Inject
|
75
|
private ESelectionService selService;
|
76
|
|
77
|
@Inject
|
78
|
private MDirtyable dirty;
|
79
|
|
80
|
@Inject
|
81
|
private MPart thisPart;
|
82
|
|
83
|
private DistributionEditor editor;
|
84
|
|
85
|
private StackLayout stackLayout;
|
86
|
|
87
|
@PostConstruct
|
88
|
public void create(Composite parent, IEclipseContext context) {
|
89
|
if(CdmStore.isActive() && conversation==null){
|
90
|
conversation = CdmStore.createConversation();
|
91
|
}
|
92
|
if(cdmEntitySession == null){
|
93
|
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
94
|
}
|
95
|
else{
|
96
|
return;
|
97
|
}
|
98
|
stackLayout = new StackLayout();
|
99
|
parent.setLayout(stackLayout);
|
100
|
editor = new DistributionEditor(parent, this);
|
101
|
|
102
|
ContextInjectionFactory.inject(editor, context);
|
103
|
}
|
104
|
|
105
|
public void init(UUID parentTaxonUuid) {
|
106
|
this.taxonList = CdmStore.getService(ITaxonNodeService.class).getTaxonDistributionDTOForSubtree(parentTaxonUuid, TAXONNODE_PROPERTY_PATH);
|
107
|
|
108
|
if(taxonList!=null){
|
109
|
editor.loadDistributions(taxonList);
|
110
|
editor.createTable();
|
111
|
editor.pack();
|
112
|
stackLayout.topControl = editor;
|
113
|
editor.getParent().layout();
|
114
|
}
|
115
|
}
|
116
|
public ESelectionService getSelectionService() {
|
117
|
return selService;
|
118
|
}
|
119
|
|
120
|
|
121
|
public DistributionEditor getEditor() {
|
122
|
return editor;
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* {@inheritDoc}
|
127
|
*/
|
128
|
@Override
|
129
|
public void update(CdmDataChangeMap changeEvents) {
|
130
|
// TODO Auto-generated method stub
|
131
|
|
132
|
}
|
133
|
@PreDestroy
|
134
|
public void dispose(){
|
135
|
if (conversation != null) {
|
136
|
conversation.close();
|
137
|
conversation = null;
|
138
|
}
|
139
|
if(cdmEntitySession != null) {
|
140
|
cdmEntitySession.dispose();
|
141
|
cdmEntitySession = null;
|
142
|
}
|
143
|
dirty.setDirty(false);
|
144
|
|
145
|
}
|
146
|
|
147
|
|
148
|
/**
|
149
|
* {@inheritDoc}
|
150
|
*/
|
151
|
@Override
|
152
|
public ICdmEntitySession getCdmEntitySession() {
|
153
|
// TODO Auto-generated method stub
|
154
|
return null;
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* {@inheritDoc}
|
159
|
*/
|
160
|
@Override
|
161
|
public <T extends CdmBase> Collection<T> getRootEntities() {
|
162
|
// TODO Auto-generated method stub
|
163
|
return null;
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* {@inheritDoc}
|
168
|
*/
|
169
|
@Override
|
170
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
171
|
// TODO Auto-generated method stub
|
172
|
return null;
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* {@inheritDoc}
|
177
|
*/
|
178
|
@Override
|
179
|
public void changed(Object element) {
|
180
|
if (element != null){
|
181
|
dirty.setDirty(true);
|
182
|
}
|
183
|
|
184
|
}
|
185
|
|
186
|
/**
|
187
|
* {@inheritDoc}
|
188
|
*/
|
189
|
@Override
|
190
|
public void forceDirty() {
|
191
|
// TODO Auto-generated method stub
|
192
|
|
193
|
}
|
194
|
|
195
|
/**
|
196
|
* {@inheritDoc}
|
197
|
*/
|
198
|
@Override
|
199
|
public ConversationHolder getConversationHolder() {
|
200
|
|
201
|
return conversation;
|
202
|
}
|
203
|
|
204
|
@Persist
|
205
|
@Override
|
206
|
public void save(IProgressMonitor monitor) {
|
207
|
//TODO: merge not save distributions
|
208
|
|
209
|
CdmStore.getService(IDescriptionService.class).merge(editor.getDistributions(), true);
|
210
|
|
211
|
conversation.commit();
|
212
|
updateResults = null;
|
213
|
dirty.setDirty(false);
|
214
|
}
|
215
|
|
216
|
/**
|
217
|
* {@inheritDoc}
|
218
|
*/
|
219
|
@Override
|
220
|
public boolean isDirty() {
|
221
|
return this.dirty.isDirty();
|
222
|
}
|
223
|
|
224
|
public void setDirty() {
|
225
|
this.dirty.setDirty(true);
|
226
|
}
|
227
|
|
228
|
}
|