3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.operation
;
12 import java
.util
.Collection
;
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
.core
.runtime
.Status
;
21 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
22 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
24 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
25 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
33 public class MoveDefinedTermOperation
extends AbstractPostTaxonOperation
{
35 private Collection
<DefinedTermBase
> sourceTerms
;// the actual DefinedTermBase(s) we are moving
36 private TermBase targetTermOrVocabulary
;// the target VOCABULARY or DefinedTerm we are moving these to
41 * @param postOperationEnabled
43 public MoveDefinedTermOperation(String label
, IUndoContext undoContext
, TermBase target
, Collection
<DefinedTermBase
> sourceTerms
,
44 IPostOperationEnabled postOperationEnabled
) {
45 super(label
, undoContext
, postOperationEnabled
);
47 this.targetTermOrVocabulary
= target
;
48 this.sourceTerms
= sourceTerms
;
52 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
55 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
56 throws ExecutionException
{
58 // need to make the moved DefinedTerm part of another DefinedTerm or Vocabulary (target)
59 // and remove it from old associations
61 //TODO move to ITermService
63 for (DefinedTermBase term
: sourceTerms
){
64 // do nothing when moving it on itself
65 if(targetTermOrVocabulary
.equals(term
)){
66 Status status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Term can not be added to itself");
67 StoreUtil
.informationDialog("", status
);
71 if (targetTermOrVocabulary
instanceof TermVocabulary
) {
72 TermVocabulary termVocabulary
= (TermVocabulary
)targetTermOrVocabulary
;
74 // do nothing when term is top level and gets added to the same vocabulary
75 if(term
.getPartOf() == null && termVocabulary
.equals(term
.getVocabulary())){
76 Status status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Term is already in this vocabulary");
77 StoreUtil
.informationDialog("", status
);
82 termVocabulary
.addTerm(term
);
84 } else if (targetTermOrVocabulary
instanceof DefinedTermBase
) {
86 DefinedTermBase targetDefinedTerm
= (DefinedTermBase
) targetTermOrVocabulary
;
87 targetDefinedTerm
.addIncludes(term
);
88 targetDefinedTerm
.getVocabulary().addTerm(term
);
93 return postExecute(targetTermOrVocabulary
);
96 private DefinedTermBase
cleanTerm(DefinedTermBase term
){
98 DefinedTermBase partOf
= term
.getPartOf();
100 partOf
.removeIncludes(term
);
104 TermVocabulary vocabulary
= term
.getVocabulary();
105 if(vocabulary
!= null){
106 vocabulary
.removeTerm(term
);
114 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
117 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
118 throws ExecutionException
{
119 // TODO Auto-generated method stub
124 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
127 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
128 throws ExecutionException
{
129 // TODO Auto-generated method stub