Merge branch 'release/3.12.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / operation / MoveDescriptionElementsOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
12
13 import java.util.Collection;
14 import java.util.HashSet;
15 import java.util.Set;
16 import java.util.UUID;
17
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.commands.operations.IUndoContext;
20 import org.eclipse.core.runtime.IAdaptable;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.IStatus;
23
24 import eu.etaxonomy.cdm.api.service.IDescriptionService;
25 import eu.etaxonomy.cdm.api.service.UpdateResult;
26 import eu.etaxonomy.cdm.model.description.DescriptionBase;
27 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
28 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
29 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
30 import eu.etaxonomy.taxeditor.store.CdmStore;
31
32 /**
33 * @author n.hoffmann
34 * @created Feb 8, 2011
35 * @version 1.0
36 */
37 public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation{
38
39 private Collection<DescriptionElementBase> descriptionElements;
40 private DescriptionBase targetDescription;
41 private IDescriptionService service;
42 private UUID targetTaxonUuid;
43 private String moveMessage;
44 private boolean isCopy;
45
46 /**
47 *
48 * @param label
49 * @param undoContext
50 * @param targetDescription
51 * @param descriptionElements
52 * @param isCopy
53 * @param postOperationEnabled
54 */
55 public MoveDescriptionElementsOperation(String label,
56 IUndoContext undoContext, DescriptionBase targetDescription,
57 Collection<DescriptionElementBase> descriptionElements, boolean isCopy,
58 IPostOperationEnabled postOperationEnabled) {
59 super(label, undoContext, postOperationEnabled);
60 this.targetDescription = targetDescription;
61 this.descriptionElements = descriptionElements;
62 this.isCopy = isCopy;
63
64 service = CdmStore.getService(IDescriptionService.class);
65 }
66
67 public MoveDescriptionElementsOperation(String label,
68 IUndoContext undoContext, UUID targetTaxonUuid,String moveMessage,
69 Collection<DescriptionElementBase> descriptionElements, boolean isCopy,
70 IPostOperationEnabled postOperationEnabled) {
71 super(label, undoContext, postOperationEnabled);
72 this.targetTaxonUuid = targetTaxonUuid;
73 this.descriptionElements = descriptionElements;
74 this.moveMessage = moveMessage;
75 this.isCopy = isCopy;
76
77 service = CdmStore.getService(IDescriptionService.class);
78 }
79
80 /* (non-Javadoc)
81 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82 */
83 @Override
84 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
85 throws ExecutionException {
86
87 Set<UUID> descriptionElementsUuid = new HashSet<UUID>();
88 for(DescriptionElementBase deBase : descriptionElements) {
89 descriptionElementsUuid.add(deBase.getUuid());
90 }
91 UpdateResult result;
92 if(targetDescription == null){
93 result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetTaxonUuid, moveMessage, isCopy);
94
95 } else {
96 UUID targetDescriptionUuid = targetDescription.getUuid();
97 result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetDescriptionUuid, isCopy);
98
99 }
100 return postExecute(targetDescription);
101 }
102
103 /* (non-Javadoc)
104 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
105 */
106 @Override
107 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
108 throws ExecutionException {
109 // TODO Auto-generated method stub
110 return null;
111 }
112
113 /* (non-Javadoc)
114 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 */
116 @Override
117 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
118 throws ExecutionException {
119 // TODO Auto-generated method stub
120 return null;
121 }
122
123
124
125 }