Project

General

Profile

Download (4.63 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
import org.eclipse.e4.ui.di.UISynchronize;
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 DescriptionBase sourceDescription;
42
	private IDescriptionService service;
43
	private UUID targetTaxonUuid;
44

    
45
	private String moveMessage;
46
	private boolean isCopy;
47
	private UISynchronize sync;
48

    
49
	/**
50
	 *
51
	 * @param label
52
	 * @param undoContext
53
	 * @param targetDescription
54
	 * @param descriptionElements
55
	 * @param isCopy
56
	 * @param postOperationEnabled
57
	 */
58
	public MoveDescriptionElementsOperation(String label,
59
			IUndoContext undoContext, DescriptionBase targetDescription, DescriptionBase sourceDescription,
60
			Collection<DescriptionElementBase> descriptionElements, boolean isCopy,
61
			IPostOperationEnabled postOperationEnabled, UISynchronize sync) {
62
		super(label, undoContext, postOperationEnabled);
63
		this.targetDescription = targetDescription;
64
		this.sourceDescription = sourceDescription;
65
		this.descriptionElements = descriptionElements;
66
		this.isCopy = isCopy;
67
		this.sync = sync;
68
		service = CdmStore.getService(IDescriptionService.class);
69
	}
70

    
71
	public MoveDescriptionElementsOperation(String label,
72
	        IUndoContext undoContext, UUID targetTaxonUuid, String moveMessage,
73
	        Collection<DescriptionElementBase> descriptionElements, boolean isCopy,
74
	        IPostOperationEnabled postOperationEnabled, UISynchronize sync) {
75
	    super(label, undoContext, postOperationEnabled);
76
	    this.targetTaxonUuid = targetTaxonUuid;
77
	    this.descriptionElements = descriptionElements;
78
	    this.moveMessage = moveMessage;
79
	    this.isCopy = isCopy;
80
	    this.sync = sync;
81
	    service = CdmStore.getService(IDescriptionService.class);
82
	}
83

    
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86
	 */
87
	@Override
88
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
89
			throws ExecutionException {
90

    
91
		Set<UUID> descriptionElementsUuid = new HashSet<UUID>();
92
		for(DescriptionElementBase deBase : descriptionElements) {
93
		    descriptionElementsUuid.add(deBase.getUuid());
94
		}
95
		UpdateResult result;
96
		if(targetDescription == null){
97
			result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetTaxonUuid, moveMessage, isCopy);
98

    
99
		} else {
100
		    UUID targetDescriptionUuid = targetDescription.getUuid();
101
		    UUID sourceDescriptionUuid = sourceDescription.getUuid();
102
		    if (!targetDescription.isPersited()){
103
		        result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetDescription, isCopy);
104
		    }else{
105
		        result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetDescriptionUuid, isCopy);
106
		    }
107

    
108

    
109
		}
110
		return postExecute(null);
111
	}
112

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

    
123
	/* (non-Javadoc)
124
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
125
	 */
126
	@Override
127
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
128
			throws ExecutionException {
129
		// TODO Auto-generated method stub
130
		return null;
131
	}
132

    
133

    
134

    
135
}
(10-10/11)