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
.cdm
.model
.description
.DescriptionBase
;
25 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
28 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
35 public class MoveDefinedTermOperation
extends AbstractPostOperation
{
37 private Collection
<DefinedTermBase
> sourceTerms
;// the actual DefinedTermBase(s) we are moving
38 private TermBase targetTermOrVocabulary
;// the target VOCABULARY or DefinedTerm we are moving these to
43 * @param postOperationEnabled
45 public MoveDefinedTermOperation(String label
, IUndoContext undoContext
, TermBase target
, Collection
<DefinedTermBase
> sourceTerms
,
46 IPostOperationEnabled postOperationEnabled
) {
47 super(label
, undoContext
, postOperationEnabled
);
49 this.targetTermOrVocabulary
= target
;
50 this.sourceTerms
= sourceTerms
;
54 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
57 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
58 throws ExecutionException
{
60 // need to make the moved DefinedTerm part of another DefinedTerm or Vocabulary (target)
61 // and remove it from old associations
63 //TODO move to ITermService
65 for (DefinedTermBase term
: sourceTerms
){
66 // do nothing when moving it on itself
67 if(targetTermOrVocabulary
.equals(term
)){
68 Status status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Term can not be added to itself");
69 StoreUtil
.informationDialog("", status
);
73 if (targetTermOrVocabulary
instanceof TermVocabulary
) {
74 TermVocabulary termVocabulary
= (TermVocabulary
)targetTermOrVocabulary
;
76 // do nothing when term is top level and gets added to the same vocabulary
77 if(term
.getPartOf() == null && termVocabulary
.equals(term
.getVocabulary())){
78 Status status
= new Status(IStatus
.CANCEL
, StoreUtil
.getPluginId(), "Term is already in this vocabulary");
79 StoreUtil
.informationDialog("", status
);
84 termVocabulary
.addTerm(term
);
86 } else if (targetTermOrVocabulary
instanceof DefinedTermBase
) {
88 DefinedTermBase targetDefinedTerm
= (DefinedTermBase
) targetTermOrVocabulary
;
89 targetDefinedTerm
.addIncludes(term
);
90 targetDefinedTerm
.getVocabulary().addTerm(term
);
95 return postExecute(targetTermOrVocabulary
);
98 private DefinedTermBase
cleanTerm(DefinedTermBase term
){
100 DefinedTermBase partOf
= term
.getPartOf();
102 partOf
.removeIncludes(term
);
106 TermVocabulary vocabulary
= term
.getVocabulary();
107 if(vocabulary
!= null){
108 vocabulary
.removeTerm(term
);
116 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
119 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
120 throws ExecutionException
{
121 // TODO Auto-generated method stub
126 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
129 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
130 throws ExecutionException
{
131 // TODO Auto-generated method stub