3 * Copyright (C) 2007 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.
11 package eu
.etaxonomy
.taxeditor
.operations
;
13 import java
.util
.UUID
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
18 import org
.eclipse
.core
.runtime
.IAdaptable
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
29 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
36 public class CreateTaxonomicTreeOperation
extends AbstractPersistentPostOperation
{
38 private static final Logger logger
= Logger
39 .getLogger(CreateTaxonomicTreeOperation
.class);
40 private String treeLabel
;
41 private UUID referenceUuid
;
42 private String microReference
;
48 public CreateTaxonomicTreeOperation(String label
, IUndoContext undoContext
, String treeLabel
,
49 UUID referenceUuid
, String microReference
,
50 IPostOperationEnabled postOperationEnabled
,
51 IConversationEnabled conversationEnabled
) {
52 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
);
54 this.treeLabel
= treeLabel
;
55 this.referenceUuid
= referenceUuid
;
56 this.microReference
= microReference
;
61 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
64 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
65 throws ExecutionException
{
69 // Start the main progress monitor.
70 IProgressMonitor newMonitor
= StoreUtil
.startMainMonitor(monitor
,"Creating Taxonomic Tree", 4);
78 if(treeLabel
.trim().length() == 0){
79 return Status
.CANCEL_STATUS
;
82 tree
= TaxonomicTree
.NewInstance(treeLabel
);
83 ReferenceBase reference
;
84 if(referenceUuid
== null){
85 reference
= Generic
.NewInstance();
86 reference
.setTitleCache(treeLabel
);
88 reference
= CdmStore
.getReferenceService().load(referenceUuid
);
90 StoreUtil
.isCanceled(newMonitor
, 1);
92 tree
.setReference(reference
);
93 tree
.setMicroReference(microReference
);
94 StoreUtil
.isCanceled(newMonitor
, 1);
96 CdmStore
.getTaxonTreeService().save(tree
);
97 StoreUtil
.isCanceled(newMonitor
, 1);
99 // conversation.commit(true);
103 // Stop the progress monitor.
108 return postExecute(tree
);
112 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
115 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
116 throws ExecutionException
{
117 // TODO Auto-generated method stub
122 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
125 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
126 throws ExecutionException
{
127 // TODO Auto-generated method stub
131 private TaxonomicTree
createTaxonomicTreeIsolated(){
132 // get a new conversation
133 ConversationHolder conversation
= CdmStore
.NewTransactionalConversation();
135 TaxonomicTree tree
= TaxonomicTree
.NewInstance(treeLabel
);
136 ReferenceBase reference
;
137 if(referenceUuid
== null){
138 reference
= Generic
.NewInstance();
139 reference
.setTitleCache(treeLabel
);
141 reference
= CdmStore
.getReferenceService().load(referenceUuid
);
144 tree
.setReference(reference
);
145 tree
.setMicroReference(microReference
);
147 CdmStore
.getTaxonTreeService().save(tree
);
149 conversation
.commit(true);
153 conversation
.close();