2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.operation
;
11 import java
.util
.Collection
;
12 import java
.util
.HashSet
;
13 import java
.util
.UUID
;
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
;
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
;
40 public class MoveDefinedTermOperation
extends AbstractPostTaxonOperation
{
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
;
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
);
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
);
62 this.targetTermOrVocabulary
= target
;
63 this.sourceTerms
= sourceTerms
;
64 this.currentLocation
= currentLocation
;
65 sourceVocabularies
= new HashSet
<>();
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
;
79 else if(currentLocation
== ViewerDropAdapter
.LOCATION_AFTER
) {
80 termMovePosition
= TermMovePosition
.AFTER
;
82 result
.includeResult(CdmStore
.getService(ITermService
.class).moveTerm(term
, parentUuid
, termMovePosition
));
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
);
91 if (base
instanceof DefinedTermBase
){
92 TermDto dto
= TermDto
.fromTerm((DefinedTermBase
)base
);
93 affectedDtos
.add(dto
);
98 return postExecute(affectedDtos
);
102 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
103 throws ExecutionException
{
108 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
109 throws ExecutionException
{