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
.description
.DescriptionElementBase
;
28 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
31 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
32 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionElementsOperation
;
33 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
34 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 import eu
.etaxonomy
.taxeditor
.ui
.dialogs
.filteredSelection
.TaxonBaseSelectionDialog
;
40 * @created Feb 8, 2011
43 public class MoveDescriptionElementsHandler
extends AbstractHandler
{
46 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
49 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
51 // ConversationHolder conversation = CdmStore.createConversation();
53 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
55 if(selection
instanceof IStructuredSelection
){
57 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
59 List
<DescriptionElementBase
> elements
= new ArrayList
<DescriptionElementBase
>();
61 for(Object element
: structuredSelection
.toArray()){
62 if(element
instanceof DescriptionElementBase
){
63 UUID uuid
= ((DescriptionElementBase
) element
).getUuid();
65 elements
.add(CdmStore
.getService(IDescriptionService
.class).loadDescriptionElement(uuid
, null));
69 Taxon targetTaxon
= TaxonBaseSelectionDialog
.selectTaxon(HandlerUtil
.getActiveShell(event
), EditorUtil
.getActiveMultiPageTaxonEditor().getConversationHolder());
71 TaxonDescription targetDescription
= TaxonDescription
.NewInstance(targetTaxon
);
72 targetDescription
.setTitleCache(String
.format("Copied from %s", EditorUtil
.getActiveMultiPageTaxonEditor().getTaxon()), true);
75 AbstractPostOperation operation
= new MoveDescriptionElementsOperation(
76 event
.getCommand().getName(), EditorUtil
.getUndoContext(),
77 targetDescription
, elements
, false, (IPostOperationEnabled
) EditorUtil
.getView(DescriptiveViewPart
.ID
, true));
78 EditorUtil
.executeOperation(operation
);
79 // conversation.commit(true);
80 CdmStore
.getService(ITaxonService
.class).saveOrUpdate(targetTaxon
);
82 } catch (NotDefinedException e
) {
83 EditorUtil
.error(getClass(), e
);