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
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
27 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
34 public class MoveDefinedTermOperation
extends AbstractPostTaxonOperation
{
36 private Collection
<DefinedTermBase
> sourceTerms
;// the actual DefinedTermBase(s) we are moving
37 private TermBase targetTermOrVocabulary
;// the target VOCABULARY or DefinedTerm we are moving these to
42 * @param postOperationEnabled
44 public MoveDefinedTermOperation(String label
, IUndoContext undoContext
, TermBase target
, Collection
<DefinedTermBase
> sourceTerms
,
45 IPostOperationEnabled postOperationEnabled
) {
46 super(label
, undoContext
, postOperationEnabled
);
48 this.targetTermOrVocabulary
= target
;
49 this.sourceTerms
= sourceTerms
;
53 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
56 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
57 throws ExecutionException
{
59 // need to make the moved DefinedTerm part of another DefinedTerm or Vocabulary (target)
60 // and remove it from old associations
62 //TODO move to ITermService
64 for (DefinedTermBase term
: sourceTerms
){
65 // do nothing when moving it on itself
66 if(targetTermOrVocabulary
.equals(term
)){
67 Status status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Term can not be added to itself");
68 MessagingUtils
.informationDialog("", status
);
72 if (targetTermOrVocabulary
instanceof TermVocabulary
) {
73 TermVocabulary termVocabulary
= (TermVocabulary
)targetTermOrVocabulary
;
75 // do nothing when term is top level and gets added to the same vocabulary
76 if(term
.getPartOf() == null && termVocabulary
.equals(term
.getVocabulary())){
77 Status status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Term is already in this vocabulary");
78 MessagingUtils
.informationDialog("", status
);
83 termVocabulary
.addTerm(term
);
85 } else if (targetTermOrVocabulary
instanceof DefinedTermBase
) {
87 DefinedTermBase targetDefinedTerm
= (DefinedTermBase
) targetTermOrVocabulary
;
88 targetDefinedTerm
.addIncludes(term
);
89 targetDefinedTerm
.getVocabulary().addTerm(term
);
94 return postExecute(targetTermOrVocabulary
);
97 private DefinedTermBase
cleanTerm(DefinedTermBase term
){
99 DefinedTermBase partOf
= term
.getPartOf();
101 partOf
.removeIncludes(term
);
105 TermVocabulary vocabulary
= term
.getVocabulary();
106 if(vocabulary
!= null){
107 vocabulary
.removeTerm(term
);
115 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
118 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
119 throws ExecutionException
{
120 // TODO Auto-generated method stub
125 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
128 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
129 throws ExecutionException
{
130 // TODO Auto-generated method stub