1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 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.navigation.operation;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
14
|
import org.eclipse.core.commands.ExecutionException;
|
15
|
import org.eclipse.core.commands.operations.IUndoContext;
|
16
|
import org.eclipse.core.runtime.IAdaptable;
|
17
|
import org.eclipse.core.runtime.IProgressMonitor;
|
18
|
import org.eclipse.core.runtime.IStatus;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
21
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
22
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
23
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
24
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
25
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
26
|
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
|
27
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* @author a.oppermann
|
32
|
* @date 28.04.2015
|
33
|
*
|
34
|
*/
|
35
|
public class CreateNewTaxonHierarchyOperation extends AbstractPersistentPostOperation {
|
36
|
|
37
|
private final Classification classification;
|
38
|
|
39
|
private final IClassificationService service;
|
40
|
|
41
|
/**
|
42
|
* @param label
|
43
|
* @param undoContext
|
44
|
*/
|
45
|
public CreateNewTaxonHierarchyOperation(String label, IUndoContext undoContext, Classification classification,
|
46
|
IPostOperationEnabled postOperationEnabled,
|
47
|
IConversationEnabled conversationEnabled) {
|
48
|
super(label, undoContext, postOperationEnabled, conversationEnabled);
|
49
|
|
50
|
this.classification = classification;
|
51
|
this.service = CdmStore.getService(IClassificationService.class);
|
52
|
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
57
|
|
58
|
monitor.worked(20);
|
59
|
UpdateResult result = service.createHierarchyInClassification(classification, null);
|
60
|
monitor.worked(60);
|
61
|
Set<CdmBase> updatedObjects = result.getUpdatedObjects();
|
62
|
Set<CdmBase> unchangedObjects = result.getUnchangedObjects();
|
63
|
Classification classification2 = CdmBase.deproxy(result.getCdmEntity(), Classification.class);
|
64
|
|
65
|
MessagingUtils.informationDialog("Add Hierarchy successful", "New classification is "
|
66
|
+ classification2.getTitleCache() + "\nCreated Genus: " + updatedObjects.size()
|
67
|
+"\nCreated Subspecies: " + unchangedObjects.size());
|
68
|
|
69
|
return postExecute(result.getCdmEntity());
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
74
|
return null;
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
79
|
return null;
|
80
|
}
|
81
|
|
82
|
}
|