4 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.handler
;
6 import java
.util
.ArrayList
;
10 import org
.apache
.log4j
.Logger
;
11 import org
.eclipse
.core
.commands
.AbstractHandler
;
12 import org
.eclipse
.core
.commands
.ExecutionEvent
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
15 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
16 import org
.eclipse
.jface
.viewers
.ISelection
;
17 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import org
.eclipse
.swt
.widgets
.Display
;
19 import org
.eclipse
.ui
.PartInitException
;
20 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
25 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
28 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
29 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
30 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
31 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionToOtherTaxonOperation
;
32 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
33 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
34 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
35 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
36 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
37 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
41 * <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
43 * @author a.kohlbecker
44 * @created Okt. 11, 2013
48 public class MoveDescriptionToOtherTaxonHandler
extends AbstractHandler
49 implements IPostOperationEnabled
{
50 private static final Logger logger
= Logger
51 .getLogger(MoveDescriptionToOtherTaxonHandler
.class);
52 private MoveDescriptionToOtherTaxonOperation operation
;
54 private UUID newAcceptedTaxonNodeUuid
;
55 private MultiPageTaxonEditor editor
;
58 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
62 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
64 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
65 editor
= EditorUtil
.getActiveMultiPageTaxonEditor();
66 if (this.editor
.isDirty()){
67 boolean proceed
= MessageDialog
.openQuestion(null,
68 "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
70 editor
.doSave(EditorUtil
.getMonitor());
78 if(selection
instanceof IStructuredSelection
){
80 List
<TaxonDescription
> descriptions
= new ArrayList
<TaxonDescription
>();
82 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
84 for(Object element
: structuredSelection
.toArray()){
86 if (element
instanceof FeatureNodeContainer
){
87 uuid
= ((FeatureNodeContainer
)element
).getDescription().getUuid();
88 } else if (element
instanceof DescriptionBase
){
89 uuid
= ((DescriptionBase
)element
).getUuid();
93 descriptions
.add((TaxonDescription
) CdmStore
.getService(IDescriptionService
.class).load(uuid
, null));
96 if(descriptions
.size() == 0){
100 // Choose the target taxon
101 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
104 excludeTaxa
.add(descriptions
.get(0).getTaxon().getUuid());
106 //get current taxon node
107 TaxonNode node
= null;
108 Classification classification
= null;
109 MultiPageTaxonEditor taxonEditor
= EditorUtil
.getActiveMultiPageTaxonEditor();
110 if(taxonEditor
!=null){
111 node
= ((TaxonEditorInput
) taxonEditor
.getEditorInput()).getTaxonNode();
112 classification
= node
.getClassification();
114 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
115 editor
.getConversationHolder(),
116 "Choose the accepted taxon",
121 if (newAcceptedTaxonNode
== null) {
125 newAcceptedTaxonNodeUuid
= newAcceptedTaxonNode
.getUuid();
128 for(TaxonDescription description
: descriptions
){
129 operation
= new MoveDescriptionToOtherTaxonOperation(event
.getCommand().getName(),
130 editor
.getUndoContext(),
132 newAcceptedTaxonNode
,
135 (ICdmEntitySessionEnabled
)editor
.getEditorInput());
136 AbstractUtility
.executeOperation(operation
);
139 } catch (NotDefinedException e
) {
140 logger
.warn("Command name not set");
149 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
153 public boolean postOperation(CdmBase objectAffectedByOperation
) {
154 Display
.getDefault().asyncExec(new Runnable(){
158 AbstractUtility
.close(editor
);
161 MultiPageTaxonEditor possibleOpenEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid
);
162 if(possibleOpenEditor
!= null){
163 AbstractUtility
.close(possibleOpenEditor
);
165 EditorUtil
.openTaxonNode(newAcceptedTaxonNodeUuid
);
166 } catch (PartInitException e
) {
167 MessagingUtils
.error(this.getClass(), e
);
168 throw new RuntimeException(e
);
169 } catch (Exception e
) {
170 MessagingUtils
.warningDialog("Could not create Taxon", this, e
.getMessage());
186 public boolean onComplete() {
187 // TODO Auto-generated method stub