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 org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
14 import org
.eclipse
.core
.runtime
.IAdaptable
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.core
.runtime
.Status
;
19 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
22 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
.TermEditorInput
;
23 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
24 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
25 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
33 public class CreateDefinedTermOperation
extends AbstractPostTaxonOperation
{
37 private TermBase parentTermBase
;
38 private 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
);
72 if (parentTermBase
instanceof TermVocabulary
){
73 TermVocabulary vocabulary
= (TermVocabulary
) parentTermBase
;
74 vocabulary
.addTerm(newTerm
);
75 } else if (parentTermBase
instanceof DefinedTermBase
) {
76 DefinedTermBase parent
= (DefinedTermBase
) parentTermBase
;
77 parent
.addIncludes(newTerm
);
78 TermVocabulary vocabulary
= parent
.getVocabulary();
79 vocabulary
.addTerm(newTerm
);
82 return postExecute(newTerm
);
86 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
89 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
90 throws ExecutionException
{
91 // TODO Auto-generated method stub
96 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
99 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
100 throws ExecutionException
{
101 // TODO Auto-generated method stub