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.model.common.DefinedTermBase;
|
24
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
25
|
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
|
26
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
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 l.morris
|
33
|
* @date 10 Jan 2012
|
34
|
*
|
35
|
*/
|
36
|
public class MoveDefinedTermOperation extends AbstractPostTaxonOperation {
|
37
|
|
38
|
private final Collection<TermDto> sourceTerms;// the actual DefinedTermBase(s) we are moving
|
39
|
private final AbstractTermDto targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to
|
40
|
private final int currentLocation;
|
41
|
|
42
|
public MoveDefinedTermOperation(String label,
|
43
|
IUndoContext undoContext,
|
44
|
AbstractTermDto target,
|
45
|
Collection<TermDto> sourceTerms,
|
46
|
IPostOperationEnabled postOperationEnabled,
|
47
|
int currentLocation) {
|
48
|
super(label, undoContext, postOperationEnabled);
|
49
|
|
50
|
this.targetTermOrVocabulary = target;
|
51
|
this.sourceTerms = sourceTerms;
|
52
|
this.currentLocation = currentLocation;
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
57
|
throws ExecutionException {
|
58
|
sourceTerms.forEach(term->
|
59
|
{
|
60
|
UUID parentUuid = targetTermOrVocabulary.getUuid();
|
61
|
boolean isKindOf = term.getKindOfUuid()!=null && term.getKindOfUuid().equals(parentUuid);
|
62
|
TermMovePosition termMovePosition = TermMovePosition.ON;
|
63
|
if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) {
|
64
|
termMovePosition = TermMovePosition.BEFORE;
|
65
|
}
|
66
|
else if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) {
|
67
|
termMovePosition = TermMovePosition.AFTER;
|
68
|
}
|
69
|
CdmStore.getService(ITermService.class).moveTerm(term.getUuid(), parentUuid, isKindOf, termMovePosition);
|
70
|
});
|
71
|
return postExecute(targetTermOrVocabulary);
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
76
|
throws ExecutionException {
|
77
|
return null;
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
82
|
throws ExecutionException {
|
83
|
return null;
|
84
|
}
|
85
|
|
86
|
}
|