4 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.handler
;
6 import java
.util
.ArrayList
;
10 import javax
.lang
.model
.element
.Element
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.IHandler
;
17 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
18 import org
.eclipse
.jface
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.ui
.PartInitException
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
27 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
29 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
30 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
31 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
32 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
33 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
34 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionToOtherTaxonOperation
;
35 //import eu.etaxonomy.taxeditor.navigator.operation.ChangeAcceptedTaxonToSynonymOperation;
36 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
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 IHandler
, IPostOperationEnabled
{
50 private static final Logger logger
= Logger
51 .getLogger(MoveDescriptionToOtherTaxonHandler
.class);
52 private MoveDescriptionToOtherTaxonOperation operation
;
54 private UUID newAcceptedTaxonNodeUuid
;
55 private TaxonNameEditor editor
;
58 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
61 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
63 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
65 if(selection
instanceof IStructuredSelection
){
67 List
<TaxonDescription
> descriptions
= new ArrayList
<TaxonDescription
>();
69 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
71 for(Object element
: structuredSelection
.toArray()){
72 if (element
instanceof TaxonDescription
){
73 UUID uuid
= ((TaxonDescription
)element
).getUuid();
74 descriptions
.add((TaxonDescription
) CdmStore
.getService(IDescriptionService
.class).load(uuid
, null));
77 if(descriptions
.size() == 0){
81 // Choose the target taxon
82 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
83 editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
84 excludeTaxa
.add(descriptions
.get(0).getTaxon().getUuid());
85 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
86 editor
.getConversationHolder(),
87 "Choose the accepted taxon",
92 if (newAcceptedTaxonNode
== null) {
96 newAcceptedTaxonNodeUuid
= newAcceptedTaxonNode
.getUuid();
99 for(TaxonDescription description
: descriptions
){
100 operation
= new MoveDescriptionToOtherTaxonOperation(event
.getCommand().getName(),
101 editor
.getUndoContext(), description
, newAcceptedTaxonNode
, this, editor
);
102 EditorUtil
.executeOperation(operation
);
105 } catch (NotDefinedException e
) {
106 logger
.warn("Command name not set");
115 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
118 public boolean postOperation(CdmBase objectAffectedByOperation
) {
119 Display
.getDefault().asyncExec(new Runnable(){
122 EditorUtil
.close(editor
.getMultiPageTaxonEditor());
125 MultiPageTaxonEditor possibleOpenEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid
);
126 if(possibleOpenEditor
!= null){
127 EditorUtil
.close(possibleOpenEditor
);
129 EditorUtil
.openTaxonNode(newAcceptedTaxonNodeUuid
);
130 } catch (PartInitException e
) {
131 EditorUtil
.error(this.getClass(), e
);
132 throw new RuntimeException(e
);
133 } catch (Exception e
) {
134 EditorUtil
.warningDialog("Could not create Taxon", this, e
.getMessage());
149 public boolean onComplete() {
150 // TODO Auto-generated method stub