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