Project

General

Profile

Download (4.13 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
11

    
12
import java.util.Collection;
13
import java.util.HashSet;
14
import java.util.Set;
15
import java.util.UUID;
16

    
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.core.commands.operations.IUndoContext;
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22

    
23
import eu.etaxonomy.cdm.api.service.IDescriptionService;
24
import eu.etaxonomy.cdm.api.service.UpdateResult;
25
import eu.etaxonomy.cdm.model.description.DescriptionBase;
26
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
27
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

    
31
/**
32
 * @author n.hoffmann
33
 * @created Feb 8, 2011
34
 * @version 1.0
35
 */
36
public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation{
37

    
38
	private Collection<DescriptionElementBase> descriptionElements;
39
	private DescriptionBase targetDescription;
40
	private IDescriptionService service;
41
	private UUID targetTaxonUuid;
42
	private String moveMessage;
43
	private boolean isCopy;
44

    
45
	/**
46
	 *
47
	 * @param label
48
	 * @param undoContext
49
	 * @param targetDescription
50
	 * @param descriptionElements
51
	 * @param isCopy
52
	 * @param postOperationEnabled
53
	 */
54
	public MoveDescriptionElementsOperation(String label,
55
			IUndoContext undoContext, DescriptionBase targetDescription,
56
			Collection<DescriptionElementBase> descriptionElements, boolean isCopy,
57
			IPostOperationEnabled postOperationEnabled) {
58
		super(label, undoContext, postOperationEnabled);
59
		this.targetDescription = targetDescription;
60
		this.descriptionElements = descriptionElements;
61
		this.isCopy = isCopy;
62

    
63
		service = CdmStore.getService(IDescriptionService.class);
64
	}
65

    
66
	public MoveDescriptionElementsOperation(String label,
67
	        IUndoContext undoContext, UUID targetTaxonUuid,String moveMessage,
68
	        Collection<DescriptionElementBase> descriptionElements, boolean isCopy,
69
	        IPostOperationEnabled postOperationEnabled) {
70
	    super(label, undoContext, postOperationEnabled);
71
	    this.targetTaxonUuid = targetTaxonUuid;
72
	    this.descriptionElements = descriptionElements;
73
	    this.moveMessage = moveMessage;
74
	    this.isCopy = isCopy;
75

    
76
	    service = CdmStore.getService(IDescriptionService.class);
77
	}
78

    
79
	/* (non-Javadoc)
80
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
81
	 */
82
	@Override
83
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
84
			throws ExecutionException {
85

    
86
		Set<UUID> descriptionElementsUuid = new HashSet<UUID>();
87
		for(DescriptionElementBase deBase : descriptionElements) {
88
		    descriptionElementsUuid.add(deBase.getUuid());
89
		}
90
		UpdateResult result; 
91
		if(targetDescription == null){
92
			result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetTaxonUuid, moveMessage, isCopy);
93

    
94
		} else {
95
		    UUID targetDescriptionUuid = targetDescription.getUuid();
96
		    result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetDescriptionUuid, isCopy);
97
		    
98
		}
99
		return postExecute(targetDescription);
100
	}
101

    
102
	/* (non-Javadoc)
103
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
104
	 */
105
	@Override
106
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
107
			throws ExecutionException {
108
		// TODO Auto-generated method stub
109
		return null;
110
	}
111

    
112
	/* (non-Javadoc)
113
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
114
	 */
115
	@Override
116
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
117
			throws ExecutionException {
118
		// TODO Auto-generated method stub
119
		return null;
120
	}
121

    
122

    
123

    
124
}
(9-9/10)