Project

General

Profile

Download (4.44 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.HashSet;
13
import java.util.UUID;
14

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

    
22
import eu.etaxonomy.cdm.api.service.ITermService;
23
import eu.etaxonomy.cdm.api.service.TermServiceImpl.TermMovePosition;
24
import eu.etaxonomy.cdm.api.service.UpdateResult;
25
import eu.etaxonomy.cdm.model.common.CdmBase;
26
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
27
import eu.etaxonomy.cdm.model.term.TermVocabulary;
28
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
29
import eu.etaxonomy.cdm.persistence.dto.TermDto;
30
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
31
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
32
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34

    
35
/**
36
 * @author l.morris
37
 * @date 10 Jan 2012
38
 *
39
 */
40
public class MoveDefinedTermOperation extends AbstractPostTaxonOperation {
41

    
42
	private final Collection<TermDto> sourceTerms;// the actual DefinedTermBase(s) we are moving
43
	private final Collection<TermVocabularyDto> sourceVocabularies;
44
	private final AbstractTermDto targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to
45
	private final int currentLocation;
46

    
47
	public MoveDefinedTermOperation(String label,
48
	        IUndoContext undoContext,
49
	        AbstractTermDto target,
50
	        Collection<TermDto> sourceTerms,
51
	        IPostOperationEnabled postOperationEnabled) {
52
	    this(label, undoContext, target, sourceTerms, postOperationEnabled, ViewerDropAdapter.LOCATION_ON);
53
	}
54
	public MoveDefinedTermOperation(String label,
55
	        IUndoContext undoContext,
56
	        AbstractTermDto target,
57
	        Collection<TermDto> sourceTerms,
58
			IPostOperationEnabled postOperationEnabled,
59
			int currentLocation) {
60
		super(label, undoContext, postOperationEnabled);
61

    
62
		this.targetTermOrVocabulary = target;
63
		this.sourceTerms = sourceTerms;
64
		this.currentLocation = currentLocation;
65
		sourceVocabularies = new HashSet<>();
66
	}
67

    
68
	@Override
69
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
70
			throws ExecutionException {
71
 	    UpdateResult result = new UpdateResult();
72
	    for(TermDto term:sourceTerms){
73
	        sourceVocabularies.add(term.getVocabularyDto());
74
            UUID parentUuid = targetTermOrVocabulary.getUuid();
75
            TermMovePosition termMovePosition = TermMovePosition.ON;
76
            if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) {
77
                termMovePosition = TermMovePosition.BEFORE;
78
            }
79
            else if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) {
80
                termMovePosition = TermMovePosition.AFTER;
81
            }
82
            result.includeResult(CdmStore.getService(ITermService.class).moveTerm(term, parentUuid, termMovePosition));
83
        }
84
	    Collection<CdmBase> affectedObjects = result.getUpdatedObjects();
85
	    Collection<AbstractTermDto> affectedDtos = new HashSet<>();
86
	    for (CdmBase base: affectedObjects){
87
	        if (base instanceof TermVocabulary){
88
	            TermVocabularyDto dto = new TermVocabularyDto(base.getUuid(), ((TermVocabulary<?>)base).getRepresentations(), ((TermVocabulary)base).getTermType(), ((TermVocabulary)base).getTitleCache(), ((TermVocabulary)base).isAllowDuplicates(), ((TermVocabulary)base).isOrderRelevant(), ((TermVocabulary)base).isFlat());
89
	            affectedDtos.add(dto);
90
	        }
91
	        if (base instanceof DefinedTermBase){
92
	            TermDto dto = TermDto.fromTerm((DefinedTermBase)base);
93
                affectedDtos.add(dto);
94
	        }
95
	    }
96

    
97

    
98
		return postExecute(affectedDtos);
99
	}
100

    
101
	@Override
102
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
103
			throws ExecutionException {
104
		return null;
105
	}
106

    
107
	@Override
108
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
109
			throws ExecutionException {
110
		return null;
111
	}
112

    
113
}
(4-4/4)