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
.operation
.AbstractPostTaxonOperation
;
24 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
25 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
32 public class CreateDefinedTermOperation
extends AbstractPostTaxonOperation
{
36 private TermBase parentTermBase
;
37 private TermEditorInput definedTermInput
;
42 * @param postOperationEnabled
44 public CreateDefinedTermOperation(String label
,
45 IUndoContext undoContext
,
47 TermEditorInput definedTermInput
,
48 IPostOperationEnabled postOperationEnabled
) {
49 super(label
, undoContext
, postOperationEnabled
);
50 this.parentTermBase
= termBase
;
51 this.definedTermInput
= definedTermInput
;
55 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
58 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
59 throws ExecutionException
{
61 DefinedTermBase newTerm
= definedTermInput
.getTermType().getEmptyDefinedTermBase();
62 if (newTerm
== null) {
64 new Status(IStatus
.CANCEL
,
65 StoreUtil
.getPluginId(),
66 "Creation of term corresponding to type '" + definedTermInput
.getTermType().getMessage() + "' is not yet supported");
67 StoreUtil
.warningDialog("Cannot create term", newTerm
, status
);
71 if (parentTermBase
instanceof TermVocabulary
){
72 TermVocabulary vocabulary
= (TermVocabulary
) parentTermBase
;
73 vocabulary
.addTerm(newTerm
);
74 } else if (parentTermBase
instanceof DefinedTermBase
) {
75 DefinedTermBase parent
= (DefinedTermBase
) parentTermBase
;
76 parent
.addIncludes(newTerm
);
77 TermVocabulary vocabulary
= parent
.getVocabulary();
78 vocabulary
.addTerm(newTerm
);
81 return postExecute(newTerm
);
85 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
89 throws ExecutionException
{
90 // TODO Auto-generated method stub
95 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
99 throws ExecutionException
{
100 // TODO Auto-generated method stub