Project

General

Profile

Download (3.18 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.editor.definedterm.operation;
10

    
11
import java.util.Collection;
12
import java.util.UUID;
13

    
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.commands.operations.IUndoContext;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.jface.viewers.ViewerDropAdapter;
20

    
21
import eu.etaxonomy.cdm.api.service.ITermService;
22
import eu.etaxonomy.cdm.api.service.TermServiceImpl.TermMovePosition;
23
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
24
import eu.etaxonomy.cdm.persistence.dto.TermDto;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29
/**
30
 * @author l.morris
31
 * @date 10 Jan 2012
32
 *
33
 */
34
public class MoveDefinedTermOperation extends AbstractPostTaxonOperation {
35

    
36
	private final Collection<TermDto> sourceTerms;// the actual DefinedTermBase(s) we are moving
37
	private final AbstractTermDto targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to
38
	private final int currentLocation;
39

    
40
	public MoveDefinedTermOperation(String label,
41
	        IUndoContext undoContext,
42
	        AbstractTermDto target,
43
	        Collection<TermDto> sourceTerms,
44
	        IPostOperationEnabled postOperationEnabled) {
45
	    this(label, undoContext, target, sourceTerms, postOperationEnabled, ViewerDropAdapter.LOCATION_ON);
46
	}
47
	public MoveDefinedTermOperation(String label,
48
	        IUndoContext undoContext,
49
	        AbstractTermDto target,
50
	        Collection<TermDto> sourceTerms,
51
			IPostOperationEnabled postOperationEnabled,
52
			int currentLocation) {
53
		super(label, undoContext, postOperationEnabled);
54

    
55
		this.targetTermOrVocabulary = target;
56
		this.sourceTerms = sourceTerms;
57
		this.currentLocation = currentLocation;
58
	}
59

    
60
	@Override
61
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62
			throws ExecutionException {
63
	    sourceTerms.forEach(term->
64
	    {
65
            UUID parentUuid = targetTermOrVocabulary.getUuid();
66
            TermMovePosition termMovePosition = TermMovePosition.ON;
67
            if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) {
68
                termMovePosition = TermMovePosition.BEFORE;
69
            }
70
            else if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) {
71
                termMovePosition = TermMovePosition.AFTER;
72
            }
73
            CdmStore.getService(ITermService.class).moveTerm(term, parentUuid, termMovePosition);
74
        });
75
		return postExecute(targetTermOrVocabulary);
76
	}
77

    
78
	@Override
79
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
80
			throws ExecutionException {
81
		return null;
82
	}
83

    
84
	@Override
85
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
86
			throws ExecutionException {
87
		return null;
88
	}
89

    
90
}
(4-4/4)