1
|
package eu.etaxonomy.taxeditor.editor.view.derivate;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.Arrays;
|
5
|
import java.util.Collection;
|
6
|
import java.util.Collections;
|
7
|
import java.util.HashMap;
|
8
|
import java.util.HashSet;
|
9
|
import java.util.List;
|
10
|
import java.util.Map;
|
11
|
import java.util.Set;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import javax.annotation.PostConstruct;
|
15
|
import javax.annotation.PreDestroy;
|
16
|
import javax.inject.Inject;
|
17
|
import javax.inject.Named;
|
18
|
|
19
|
import org.eclipse.core.runtime.IProgressMonitor;
|
20
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
21
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
22
|
import org.eclipse.e4.core.di.annotations.Optional;
|
23
|
import org.eclipse.e4.ui.di.Focus;
|
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.services.EMenuService;
|
28
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
29
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
30
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
31
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
32
|
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
33
|
import org.eclipse.jface.viewers.ISelection;
|
34
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
35
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
36
|
import org.eclipse.jface.viewers.StructuredSelection;
|
37
|
import org.eclipse.jface.viewers.TreeNode;
|
38
|
import org.eclipse.jface.viewers.TreeSelection;
|
39
|
import org.eclipse.jface.viewers.TreeViewer;
|
40
|
import org.eclipse.swt.SWT;
|
41
|
import org.eclipse.swt.dnd.DND;
|
42
|
import org.eclipse.swt.dnd.Transfer;
|
43
|
import org.eclipse.swt.layout.GridData;
|
44
|
import org.eclipse.swt.layout.GridLayout;
|
45
|
import org.eclipse.swt.widgets.Composite;
|
46
|
import org.eclipse.swt.widgets.Tree;
|
47
|
import org.eclipse.ui.IMemento;
|
48
|
|
49
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
50
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
51
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
52
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
53
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
54
|
import eu.etaxonomy.cdm.model.molecular.SingleRead;
|
55
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
56
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
57
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
58
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
59
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
60
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
61
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
62
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
63
|
import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
|
64
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
65
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
66
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
67
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
68
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
69
|
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
|
70
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
71
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
72
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
73
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
74
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
75
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
76
|
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
|
77
|
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
|
78
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
79
|
|
80
|
/**
|
81
|
* Displays the derivate hierarchy of the specimen specified in the editor input.
|
82
|
*
|
83
|
*/
|
84
|
public class DerivateView implements IPartContentHasFactualData, IConversationEnabled,
|
85
|
ICdmEntitySessionEnabled, IDirtyMarkable, IPostOperationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
|
86
|
IContextListener, IE4SavablePart {
|
87
|
|
88
|
private static final String SPECIMEN_EDITOR = Messages.DerivateView_SPECIMEN_EDITOR;
|
89
|
|
90
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
|
91
|
public static final String INPUT_ID = ID+".editorInput"; //$NON-NLS-1$
|
92
|
|
93
|
public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE;
|
94
|
public static final String VIEW_HAS_UNSAVED_CHANGES = Messages.DerivateView_UNSAVED_CHANGES;
|
95
|
|
96
|
private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
|
97
|
"descriptions", //$NON-NLS-1$
|
98
|
"annotations", //$NON-NLS-1$
|
99
|
"markers", //$NON-NLS-1$
|
100
|
"credits", //$NON-NLS-1$
|
101
|
"extensions", //$NON-NLS-1$
|
102
|
"rights", //$NON-NLS-1$
|
103
|
"sources", //$NON-NLS-1$
|
104
|
"derivationEvents.derivatives.annotations", //$NON-NLS-1$
|
105
|
"derivationEvents.derivatives.markers", //$NON-NLS-1$
|
106
|
"derivationEvents.derivatives.credits", //$NON-NLS-1$
|
107
|
"derivationEvents.derivatives.extensions", //$NON-NLS-1$
|
108
|
"derivationEvents.derivatives.rights", //$NON-NLS-1$
|
109
|
"derivationEvents.derivatives.sources" //$NON-NLS-1$
|
110
|
});
|
111
|
|
112
|
private static final int WARN_THRESHOLD = 200;
|
113
|
|
114
|
|
115
|
private ConversationHolder conversation;
|
116
|
|
117
|
private TreeViewer viewer;
|
118
|
|
119
|
private final int dndOperations = DND.DROP_MOVE;
|
120
|
|
121
|
private DerivateLabelProvider labelProvider;
|
122
|
|
123
|
private DerivateContentProvider contentProvider;
|
124
|
|
125
|
private DerivateSearchCompositeController derivateSearchCompositeController;
|
126
|
|
127
|
/**
|
128
|
* A map with keys being the derivative entities belonging to the {@link UUID}s passed to the constructor
|
129
|
* and values being the root elements of the hierarchy (may be the same objects as the derivative entities)
|
130
|
*/
|
131
|
private Map<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>> derivateToRootEntityMap;
|
132
|
|
133
|
/**
|
134
|
* The set of root elements
|
135
|
*/
|
136
|
private Set<SpecimenOrObservationBase<?>> rootElements;
|
137
|
|
138
|
private ICdmEntitySession cdmEntitySession;
|
139
|
|
140
|
/**
|
141
|
* <code>true</code> if this view is listening to selection changes
|
142
|
*/
|
143
|
private boolean listenToSelectionChange;
|
144
|
|
145
|
private Taxon selectedTaxon;
|
146
|
|
147
|
@Inject
|
148
|
private ESelectionService selService;
|
149
|
|
150
|
@Inject
|
151
|
private MDirtyable dirty;
|
152
|
|
153
|
private ISelectionChangedListener selectionChangedListener;
|
154
|
|
155
|
@Inject
|
156
|
private MPart thisPart;
|
157
|
|
158
|
/**
|
159
|
* Default constructor
|
160
|
*/
|
161
|
@Inject
|
162
|
public DerivateView() {
|
163
|
}
|
164
|
|
165
|
/**
|
166
|
* {@inheritDoc}
|
167
|
*/
|
168
|
public void init(DerivateViewEditorInput editorInput){
|
169
|
this.derivateToRootEntityMap = new HashMap<>();
|
170
|
this.rootElements = new HashSet<>();
|
171
|
|
172
|
//init tree
|
173
|
Collection<UUID> derivativeUuids = editorInput.getDerivativeUuids();
|
174
|
checkWarnThreshold(derivativeUuids);
|
175
|
updateRootEntities(derivativeUuids);
|
176
|
//set taxon filter
|
177
|
derivateSearchCompositeController.setTaxonFilter(editorInput.getTaxonUuid());
|
178
|
//reset status bar
|
179
|
//TODO e4
|
180
|
// getEditorSite().getActionBars().getStatusLineManager().setMessage(""); //$NON-NLS-1$
|
181
|
}
|
182
|
|
183
|
@PostConstruct
|
184
|
public void createPartControl(Composite parent, EMenuService menuService,
|
185
|
IEclipseContext context) {
|
186
|
if (CdmStore.isActive()){
|
187
|
if(conversation == null){
|
188
|
conversation = CdmStore.createConversation();
|
189
|
}
|
190
|
if(cdmEntitySession!=null){
|
191
|
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
192
|
}
|
193
|
}
|
194
|
else{
|
195
|
return;
|
196
|
}
|
197
|
//listen to context changes
|
198
|
CdmStore.getContextManager().addContextListener(this);
|
199
|
|
200
|
parent.setLayout(new GridLayout());
|
201
|
|
202
|
//---search and filter---
|
203
|
derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
|
204
|
GridData gridDataSearchBar = new GridData();
|
205
|
gridDataSearchBar.horizontalAlignment = GridData.FILL;
|
206
|
gridDataSearchBar.grabExcessHorizontalSpace = true;
|
207
|
derivateSearchCompositeController.setLayoutData(gridDataSearchBar);
|
208
|
derivateSearchCompositeController.setEnabled(CdmStore.isActive());
|
209
|
|
210
|
//---tree viewer---
|
211
|
viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
|
212
|
GridData gridDataTree = new GridData();
|
213
|
gridDataTree.horizontalAlignment = GridData.FILL;
|
214
|
gridDataTree.verticalAlignment = GridData.FILL;
|
215
|
gridDataTree.grabExcessVerticalSpace = true;
|
216
|
gridDataTree.grabExcessHorizontalSpace = true;
|
217
|
viewer.getTree().setLayoutData(gridDataTree);
|
218
|
contentProvider = new DerivateContentProvider();
|
219
|
viewer.setContentProvider(contentProvider);
|
220
|
labelProvider = new DerivateLabelProvider();
|
221
|
labelProvider.setConversation(conversation);
|
222
|
viewer.setLabelProvider(labelProvider);
|
223
|
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
|
224
|
viewer.getTree().setEnabled(CdmStore.isActive());
|
225
|
|
226
|
//propagate selection
|
227
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
228
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
229
|
|
230
|
//create context menu
|
231
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.specimeneditor");
|
232
|
|
233
|
//add drag'n'drop support
|
234
|
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer(),};
|
235
|
viewer.addDragSupport(dndOperations, transfers, new DerivateDragListener(this));
|
236
|
DerivateDropListener dropListener = new DerivateDropListener(this);
|
237
|
ContextInjectionFactory.inject(dropListener, context);
|
238
|
viewer.addDropSupport(dndOperations, transfers, dropListener);
|
239
|
}
|
240
|
|
241
|
public void updateRootEntities() {
|
242
|
updateRootEntities((Collection)null);
|
243
|
}
|
244
|
|
245
|
public void updateRootEntities(Collection<UUID> derivativeUuids) {
|
246
|
if(conversation!=null){
|
247
|
if (!conversation.isBound()) {
|
248
|
conversation.bind();
|
249
|
}
|
250
|
/*
|
251
|
* If the active session is not the session of the Derivative Editor
|
252
|
* then we will save the active session for later, bind temporarily
|
253
|
* to our session and rebind to the original session when we are
|
254
|
* done. This happens e.g. if a selection change happens in the
|
255
|
* taxon editor and "Link with editor" is enabled. The selection
|
256
|
* change event and thus the loading in updateRootEntities() happens
|
257
|
* in the session of the taxon editor.
|
258
|
*/
|
259
|
ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
|
260
|
if(cdmEntitySession != null) {
|
261
|
cdmEntitySession.bind();
|
262
|
}
|
263
|
|
264
|
List<SpecimenOrObservationBase> derivates = null;
|
265
|
if(derivativeUuids!=null){
|
266
|
this.derivateToRootEntityMap = new HashMap<>();
|
267
|
this.rootElements = new HashSet<>();
|
268
|
derivates = CdmStore.getService(IOccurrenceService.class).load(new ArrayList(derivativeUuids), SPECIMEN_INIT_STRATEGY);
|
269
|
}
|
270
|
updateRootEntities(derivates);
|
271
|
if(previousCdmEntitySession!=null){
|
272
|
previousCdmEntitySession.bind();
|
273
|
}
|
274
|
}
|
275
|
}
|
276
|
|
277
|
|
278
|
public void updateRootEntities(List<SpecimenOrObservationBase> derivates) {
|
279
|
if(derivates!=null){
|
280
|
this.derivateToRootEntityMap = new HashMap<>();
|
281
|
this.rootElements = new HashSet<>();
|
282
|
for (SpecimenOrObservationBase derivate : derivates) {
|
283
|
|
284
|
if(derivate instanceof FieldUnit){
|
285
|
derivateToRootEntityMap.put(derivate, derivate);
|
286
|
}
|
287
|
else {
|
288
|
SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
|
289
|
if(topMostDerivate!=null){
|
290
|
derivateToRootEntityMap.put(derivate, topMostDerivate);
|
291
|
}
|
292
|
else{
|
293
|
derivateToRootEntityMap.put(derivate, derivate);
|
294
|
}
|
295
|
}
|
296
|
}
|
297
|
for (SpecimenOrObservationBase<?> specimen : derivateToRootEntityMap.values()) {
|
298
|
rootElements.add(specimen);
|
299
|
}
|
300
|
}
|
301
|
labelProvider.updateLabelCache(rootElements);
|
302
|
viewer.setInput(rootElements);
|
303
|
|
304
|
//TODO e4
|
305
|
// getEditorSite().getActionBars().getStatusLineManager().setMessage(String.format(Messages.DerivateView_CNT_DERIVATIVES_FOUND, rootElements.size()));
|
306
|
|
307
|
//set selection to derivatives if the filter criteria
|
308
|
//taxon assignment or derivative type are set
|
309
|
if(derivates!=null && !derivateSearchCompositeController.isDefaultSearch()){
|
310
|
List<TreeNode> nodesToSelect = new ArrayList<>();
|
311
|
for (SpecimenOrObservationBase specimenOrObservationBase : derivates) {
|
312
|
nodesToSelect.add(new TreeNode(specimenOrObservationBase));
|
313
|
}
|
314
|
setSelection(new StructuredSelection(nodesToSelect));
|
315
|
}
|
316
|
else{
|
317
|
setSelection(null);
|
318
|
}
|
319
|
}
|
320
|
|
321
|
private void setSelection(StructuredSelection selection){
|
322
|
viewer.removeSelectionChangedListener(selectionChangedListener);
|
323
|
viewer.setSelection(selection);
|
324
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
325
|
}
|
326
|
|
327
|
public void updateLabelCache(){
|
328
|
labelProvider.updateLabelCache(rootElements);
|
329
|
}
|
330
|
|
331
|
@Persist
|
332
|
@Override
|
333
|
public void save(IProgressMonitor monitor) {
|
334
|
String taskName = Messages.DerivateView_SAVING_HIERARCHY;
|
335
|
monitor.beginTask(taskName, 3);
|
336
|
if (!conversation.isBound()) {
|
337
|
conversation.bind();
|
338
|
}
|
339
|
monitor.worked(1);
|
340
|
|
341
|
// commit the conversation and start a new transaction immediately
|
342
|
conversation.commit(true);
|
343
|
|
344
|
CdmStore.getService(IOccurrenceService.class).merge(new ArrayList<>(rootElements), true);
|
345
|
|
346
|
monitor.worked(1);
|
347
|
|
348
|
this.setDirty(false);
|
349
|
monitor.worked(1);
|
350
|
monitor.done();
|
351
|
dirty.setDirty(false);
|
352
|
refreshTree();
|
353
|
}
|
354
|
|
355
|
/**
|
356
|
* @param isDirty the isDirty to set
|
357
|
*/
|
358
|
public void setDirty(boolean isDirty) {
|
359
|
dirty.setDirty(isDirty);
|
360
|
}
|
361
|
|
362
|
@Focus
|
363
|
public void setFocus() {
|
364
|
//make sure to bind again if maybe in another view the conversation was unbound
|
365
|
if(conversation!=null && !conversation.isBound()){
|
366
|
conversation.bind();
|
367
|
}
|
368
|
if(cdmEntitySession != null) {
|
369
|
cdmEntitySession.bind();
|
370
|
}
|
371
|
if(viewer!=null && !viewer.getControl().isDisposed()) {
|
372
|
viewer.getControl().setFocus();
|
373
|
selService.setSelection(viewer.getSelection());
|
374
|
}
|
375
|
}
|
376
|
|
377
|
@Override
|
378
|
public void update(CdmDataChangeMap changeEvents) {
|
379
|
}
|
380
|
|
381
|
@Override
|
382
|
public ConversationHolder getConversationHolder() {
|
383
|
return conversation;
|
384
|
}
|
385
|
|
386
|
@Override
|
387
|
public void changed(Object element) {
|
388
|
setDirty(true);
|
389
|
//firePropertyChange(IEditorPart.PROP_DIRTY);
|
390
|
viewer.update(new TreeNode(element), null);
|
391
|
viewer.refresh();
|
392
|
}
|
393
|
|
394
|
@Override
|
395
|
public void forceDirty() {
|
396
|
changed(null);
|
397
|
}
|
398
|
|
399
|
@Override
|
400
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
401
|
List<String> specimenPropertyPaths = Arrays.asList(new String[] {
|
402
|
"descriptions", //$NON-NLS-1$
|
403
|
"derivationEvents.derivates", //$NON-NLS-1$
|
404
|
"annotations", //$NON-NLS-1$
|
405
|
"markers", //$NON-NLS-1$
|
406
|
"credits", //$NON-NLS-1$
|
407
|
"extensions", //$NON-NLS-1$
|
408
|
"rights", //$NON-NLS-1$
|
409
|
"sources" //$NON-NLS-1$
|
410
|
});
|
411
|
Map<Object, List<String>> specimenPropertyPathMap =
|
412
|
new HashMap<>();
|
413
|
specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
|
414
|
return specimenPropertyPathMap;
|
415
|
}
|
416
|
|
417
|
/**
|
418
|
* Refreshes the derivate hierarchy tree and expands the tree
|
419
|
* to show and select the given object.
|
420
|
*
|
421
|
* @param expandTo the object to which the tree should be expanded
|
422
|
*/
|
423
|
public void refreshTree(Object expandTo){
|
424
|
refreshTree();
|
425
|
TreeSelection selection = (TreeSelection) viewer.getSelection();
|
426
|
viewer.expandToLevel(selection.getFirstElement(), 1);
|
427
|
viewer.setSelection(new StructuredSelection(new TreeNode(expandTo)));
|
428
|
}
|
429
|
|
430
|
/**
|
431
|
* Refreshes the derivate hierarchy tree
|
432
|
*/
|
433
|
public void refreshTree(){
|
434
|
if(!viewer.getTree().isDisposed()){
|
435
|
viewer.refresh();
|
436
|
}
|
437
|
}
|
438
|
|
439
|
//FIXME:Remoting hack to make this work for remoting
|
440
|
//This should actually be resolved using remoting post operations
|
441
|
public void remove(Object obj) {
|
442
|
if (obj instanceof TreeNode){
|
443
|
obj = ((TreeNode)obj).getValue();
|
444
|
}
|
445
|
rootElements.remove(obj);
|
446
|
Object o = this.derivateToRootEntityMap.remove(obj);
|
447
|
viewer.setInput(rootElements);
|
448
|
}
|
449
|
|
450
|
/**
|
451
|
* @return a set of {@link SingleRead}s that have multiple parents
|
452
|
*/
|
453
|
public Set<SingleRead> getMultiLinkSingleReads() {
|
454
|
return DerivateLabelProvider.getMultiLinkSingleReads();
|
455
|
}
|
456
|
|
457
|
public Object getSelectionInput() {
|
458
|
return selectedTaxon;
|
459
|
}
|
460
|
|
461
|
public DerivateLabelProvider getLabelProvider() {
|
462
|
return labelProvider;
|
463
|
}
|
464
|
|
465
|
@Override
|
466
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
467
|
refreshTree();
|
468
|
if(objectAffectedByOperation!=null){
|
469
|
changed(objectAffectedByOperation);
|
470
|
}
|
471
|
return true;
|
472
|
}
|
473
|
|
474
|
@Override
|
475
|
public boolean onComplete() {
|
476
|
return true;
|
477
|
}
|
478
|
|
479
|
|
480
|
@Override
|
481
|
public boolean canAttachMedia() {
|
482
|
return true;
|
483
|
}
|
484
|
|
485
|
public void addFieldUnit(FieldUnit fieldUnit) {
|
486
|
rootElements.add(fieldUnit);
|
487
|
derivateToRootEntityMap.put(fieldUnit, fieldUnit);
|
488
|
}
|
489
|
|
490
|
@Override
|
491
|
public ICdmEntitySession getCdmEntitySession() {
|
492
|
return cdmEntitySession;
|
493
|
}
|
494
|
|
495
|
@PreDestroy
|
496
|
public void dispose() {
|
497
|
if(conversation!=null){
|
498
|
conversation.close();
|
499
|
conversation = null;
|
500
|
}
|
501
|
if(cdmEntitySession != null) {
|
502
|
cdmEntitySession.dispose();
|
503
|
cdmEntitySession = null;
|
504
|
}
|
505
|
}
|
506
|
|
507
|
|
508
|
@Inject
|
509
|
@Optional
|
510
|
public void selectionChanged(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection,
|
511
|
@Named(IServiceConstants.ACTIVE_PART) MPart activePart, MPart thisPart)
|
512
|
{
|
513
|
if(activePart == thisPart || viewer==null){
|
514
|
return;
|
515
|
}
|
516
|
if(viewer.getTree().isDisposed()){
|
517
|
return;
|
518
|
}
|
519
|
if(listenToSelectionChange){
|
520
|
selectedTaxon = null;
|
521
|
if(activePart instanceof TaxonNameEditorE4){
|
522
|
selectedTaxon = ((TaxonNameEditorE4) activePart).getTaxon();
|
523
|
}
|
524
|
else if(selection instanceof IStructuredSelection){
|
525
|
Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
|
526
|
if(selectedElement instanceof CdmBase){
|
527
|
if(((CdmBase) selectedElement).isInstanceOf(TaxonNode.class)){
|
528
|
selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, TaxonNode.class).getTaxon();
|
529
|
}
|
530
|
else if(((CdmBase) selectedElement).isInstanceOf(Taxon.class)){
|
531
|
selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, Taxon.class);
|
532
|
}
|
533
|
}
|
534
|
}
|
535
|
if(selectedTaxon!=null){
|
536
|
Collection<SpecimenOrObservationBase> fieldUnits = CdmStore.getService(IOccurrenceService.class).listFieldUnitsByAssociatedTaxon(selectedTaxon, null, null);
|
537
|
Collection<UUID> uuids = new HashSet<>();
|
538
|
for (SpecimenOrObservationBase specimenOrObservationBase : fieldUnits) {
|
539
|
uuids.add(specimenOrObservationBase.getUuid());
|
540
|
}
|
541
|
checkWarnThreshold(uuids);
|
542
|
updateRootEntities(uuids);
|
543
|
|
544
|
thisPart.setLabel(SPECIMEN_EDITOR+": " + selectedTaxon.getName()); //$NON-NLS-1$
|
545
|
}
|
546
|
else{
|
547
|
updateRootEntities((Collection<UUID>)Collections.EMPTY_LIST);
|
548
|
}
|
549
|
}
|
550
|
}
|
551
|
|
552
|
private void checkWarnThreshold(Collection<UUID> uuids) {
|
553
|
if(uuids!=null && uuids.size()>WARN_THRESHOLD){
|
554
|
MessagingUtils.warningDialog(Messages.DerivateView_PERF_WARNING, this.getClass(), String.format(Messages.DerivateView_PERF_WARNING_MESSAGE, uuids.size()));
|
555
|
uuids.clear();
|
556
|
}
|
557
|
}
|
558
|
|
559
|
public TreeViewer getViewer() {
|
560
|
return viewer;
|
561
|
}
|
562
|
|
563
|
/**
|
564
|
* {@inheritDoc}
|
565
|
*/
|
566
|
@Override
|
567
|
public List<SpecimenOrObservationBase<?>> getRootEntities() {
|
568
|
return new ArrayList<>(rootElements);
|
569
|
}
|
570
|
|
571
|
public void toggleListenToSelectionChange(MPart part) {
|
572
|
listenToSelectionChange = !listenToSelectionChange;
|
573
|
derivateSearchCompositeController.setEnabled(!listenToSelectionChange);
|
574
|
if(!listenToSelectionChange){
|
575
|
selectedTaxon = null;
|
576
|
part.setLabel(SPECIMEN_EDITOR);
|
577
|
}
|
578
|
else if(selectedTaxon==null){
|
579
|
part.setLabel(SPECIMEN_EDITOR+Messages.DerivateView_NO_TAXON_SELECTED);
|
580
|
}
|
581
|
}
|
582
|
|
583
|
public boolean isListenToSelectionChange(){
|
584
|
return listenToSelectionChange;
|
585
|
}
|
586
|
|
587
|
/**
|
588
|
* {@inheritDoc}
|
589
|
*/
|
590
|
@Override
|
591
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
592
|
}
|
593
|
|
594
|
/**
|
595
|
* {@inheritDoc}
|
596
|
*/
|
597
|
@Override
|
598
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
599
|
//close view when workbench closes
|
600
|
try{
|
601
|
thisPart.getContext().get(EPartService.class).hidePart(thisPart);
|
602
|
}
|
603
|
catch(Exception e){
|
604
|
//nothing
|
605
|
}
|
606
|
}
|
607
|
|
608
|
/**
|
609
|
* {@inheritDoc}
|
610
|
*/
|
611
|
@Override
|
612
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
613
|
}
|
614
|
|
615
|
/**
|
616
|
* {@inheritDoc}
|
617
|
*/
|
618
|
@Override
|
619
|
public void contextRefresh(IProgressMonitor monitor) {
|
620
|
}
|
621
|
|
622
|
/**
|
623
|
* {@inheritDoc}
|
624
|
*/
|
625
|
@Override
|
626
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
627
|
}
|
628
|
|
629
|
|
630
|
public boolean isDirty() {
|
631
|
return dirty.isDirty();
|
632
|
}
|
633
|
|
634
|
}
|