Merge branch 'release/5.0.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / operation / CreateNewTaxonHierarchyOperation.java
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.conversation.IConversationEnabled;
20 import eu.etaxonomy.cdm.api.service.IClassificationService;
21 import eu.etaxonomy.cdm.api.service.UpdateResult;
22 import eu.etaxonomy.cdm.model.common.CdmBase;
23 import eu.etaxonomy.cdm.model.taxon.Classification;
24 import eu.etaxonomy.taxeditor.model.MessagingUtils;
25 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
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(Messages.CreateNewTaxonHierarchyOperation_ADD_HIERARCHY,
66 String.format(Messages.CreateNewTaxonHierarchyOperation_ADD_HIERARCHY_MESSAGE,
67 classification2.getTitleCache(), updatedObjects.size(), 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 }