ref #6190 removing svn property place holder in first line of code - java files
[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.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 IConversationEnabled conversationEnabled) {
47 super(label, undoContext, postOperationEnabled, conversationEnabled);
48
49 this.classification = classification;
50 this.service = CdmStore.getService(IClassificationService.class);
51
52 }
53
54 @Override
55 public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
56
57 monitor.worked(20);
58 UpdateResult result = service.createHierarchyInClassification(classification, null);
59 monitor.worked(60);
60 Set<CdmBase> updatedObjects = result.getUpdatedObjects();
61 Set<CdmBase> unchangedObjects = result.getUnchangedObjects();
62 Classification classification2 = CdmBase.deproxy(result.getCdmEntity(), Classification.class);
63
64 MessagingUtils.informationDialog("Add Hierarchy successful", "New classification is "
65 + classification2.getTitleCache() + "\nCreated Genus: " + updatedObjects.size()
66 +"\nCreated Subspecies: " + unchangedObjects.size());
67
68 return postExecute(result.getCdmEntity());
69 }
70
71 @Override
72 public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
73 return null;
74 }
75
76 @Override
77 public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
78 return null;
79 }
80
81 }