Project

General

Profile

Download (4.12 KB) Statistics
| Branch: | Tag: | Revision:
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

    
92
		if(targetDescription == null){
93
		    UpdateResult result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetTaxonUuid, moveMessage, isCopy);
94

    
95
		} else {
96
		    UUID targetDescriptionUuid = targetDescription.getUuid();
97
		    service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetDescriptionUuid, isCopy);
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)