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 org
.eclipse
.core
.commands
.ExecutionException
;
12 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
13 import org
.eclipse
.core
.runtime
.IAdaptable
;
14 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
18 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
19 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
21 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
.TermEditorInput
;
22 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
23 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
24 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
33 public class CreateDefinedTermOperation
extends AbstractPostTaxonOperation
{
37 private final TermBase parentTermBase
;
38 private final TermEditorInput definedTermInput
;
43 * @param postOperationEnabled
45 public CreateDefinedTermOperation(String label
,
46 IUndoContext undoContext
,
48 TermEditorInput definedTermInput
,
49 IPostOperationEnabled postOperationEnabled
) {
50 super(label
, undoContext
, postOperationEnabled
);
51 this.parentTermBase
= termBase
;
52 this.definedTermInput
= definedTermInput
;
56 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
60 throws ExecutionException
{
62 DefinedTermBase newTerm
= definedTermInput
.getTermType().getEmptyDefinedTermBase();
63 if (newTerm
== null) {
65 new Status(IStatus
.CANCEL
,
66 StoreUtil
.getPluginId(),
67 "Creation of term corresponding to type '" + definedTermInput
.getTermType().getMessage() + "' is not yet supported");
68 MessagingUtils
.warningDialog("Cannot create term", newTerm
, status
);
71 newTerm
= CdmStore
.getCurrentApplicationConfiguration().getTermService().save(newTerm
);
73 if (parentTermBase
instanceof TermVocabulary
){
74 TermVocabulary vocabulary
= (TermVocabulary
) parentTermBase
;
75 vocabulary
.addTerm(newTerm
);
76 } else if (parentTermBase
instanceof DefinedTermBase
) {
77 DefinedTermBase parent
= (DefinedTermBase
) parentTermBase
;
78 parent
.addIncludes(newTerm
);
79 TermVocabulary vocabulary
= parent
.getVocabulary();
80 vocabulary
.addTerm(newTerm
);
83 return postExecute(newTerm
);
87 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
90 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
91 throws ExecutionException
{
92 // TODO Auto-generated method stub
97 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
100 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
101 throws ExecutionException
{
102 // TODO Auto-generated method stub