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
.editor
.view
.descriptive
.handler
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.eclipse
.core
.commands
.AbstractHandler
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
21 import org
.eclipse
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
28 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
31 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
33 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
34 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
35 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionElementsOperation
;
36 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
37 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
38 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
39 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
40 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
41 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonBaseSelectionDialog
;
46 * @created Feb 8, 2011
49 public class MoveDescriptionElementsHandler
extends AbstractHandler
{
52 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
55 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
57 // ConversationHolder conversation = CdmStore.createConversation();
59 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
61 if(selection
instanceof IStructuredSelection
){
63 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
65 List
<DescriptionElementBase
> elements
= new ArrayList
<DescriptionElementBase
>();
67 for(Object element
: structuredSelection
.toArray()){
68 if(element
instanceof DescriptionElementBase
){
69 UUID uuid
= ((DescriptionElementBase
) element
).getUuid();
71 elements
.add(CdmStore
.getService(IDescriptionService
.class).loadDescriptionElement(uuid
, null));
72 } else if(element
instanceof FeatureNodeContainer
){
73 for(DescriptionElementBase de
: ((FeatureNodeContainer
)element
).getDescriptionElements()){
75 (DescriptionElementBase
)CdmStore
.getService(IDescriptionService
.class).loadDescriptionElement(de
.getUuid(), null)
81 if(elements
.size() == 0){
85 Taxon targetTaxon
= TaxonBaseSelectionDialog
.selectTaxon(HandlerUtil
.getActiveShell(event
), EditorUtil
.getActiveMultiPageTaxonEditor().getConversationHolder(), null);
87 if(targetTaxon
== null){
92 TaxonDescription targetDescription
= TaxonDescription
.NewInstance(targetTaxon
);
93 String moveMessage
= String
.format("Elements moved from %s", EditorUtil
.getActiveMultiPageTaxonEditor().getTaxon());
94 targetDescription
.setTitleCache(moveMessage
, true);
95 Annotation annotation
= Annotation
.NewInstance(moveMessage
, Language
.getDefaultLanguage());
96 annotation
.setAnnotationType(AnnotationType
.TECHNICAL());
97 targetDescription
.addAnnotation(annotation
);
100 AbstractPostOperation operation
= new MoveDescriptionElementsOperation(
101 event
.getCommand().getName(), EditorUtil
.getUndoContext(),
102 targetDescription
, elements
, false, (IPostOperationEnabled
) EditorUtil
.getView(DescriptiveViewPart
.ID
, true));
103 EditorUtil
.executeOperation(operation
);
104 // conversation.commit(true);
105 CdmStore
.getService(ITaxonService
.class).saveOrUpdate(targetTaxon
);
107 } catch (NotDefinedException e
) {
108 MessagingUtils
.error(getClass(), e
);