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
.viewers
.ISelection
;
16 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
17 import org
.eclipse
.swt
.widgets
.Display
;
18 import org
.eclipse
.ui
.PartInitException
;
19 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
22 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
27 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
29 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionToOtherTaxonOperation
;
30 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
31 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
33 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
38 * <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
40 * @author a.kohlbecker
41 * @created Okt. 11, 2013
45 public class MoveDescriptionToOtherTaxonHandler
extends AbstractHandler
46 implements IPostOperationEnabled
{
47 private static final Logger logger
= Logger
48 .getLogger(MoveDescriptionToOtherTaxonHandler
.class);
49 private MoveDescriptionToOtherTaxonOperation operation
;
51 private UUID newAcceptedTaxonNodeUuid
;
52 private TaxonNameEditor editor
;
55 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
59 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
61 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
63 if(selection
instanceof IStructuredSelection
){
65 List
<TaxonDescription
> descriptions
= new ArrayList
<TaxonDescription
>();
67 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
69 for(Object element
: structuredSelection
.toArray()){
70 if (element
instanceof TaxonDescription
){
71 UUID uuid
= ((TaxonDescription
)element
).getUuid();
72 descriptions
.add((TaxonDescription
) CdmStore
.getService(IDescriptionService
.class).load(uuid
, null));
75 if(descriptions
.size() == 0){
79 // Choose the target taxon
80 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
81 editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
82 excludeTaxa
.add(descriptions
.get(0).getTaxon().getUuid());
83 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
84 editor
.getConversationHolder(),
85 "Choose the accepted taxon",
90 if (newAcceptedTaxonNode
== null) {
94 newAcceptedTaxonNodeUuid
= newAcceptedTaxonNode
.getUuid();
97 for(TaxonDescription description
: descriptions
){
98 operation
= new MoveDescriptionToOtherTaxonOperation(event
.getCommand().getName(),
99 editor
.getUndoContext(),
101 newAcceptedTaxonNode
,
104 (ICdmEntitySessionEnabled
)editor
.getEditorInput());
105 AbstractUtility
.executeOperation(operation
);
108 } catch (NotDefinedException e
) {
109 logger
.warn("Command name not set");
118 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
122 public boolean postOperation(CdmBase objectAffectedByOperation
) {
123 Display
.getDefault().asyncExec(new Runnable(){
127 AbstractUtility
.close(editor
.getMultiPageTaxonEditor());
130 MultiPageTaxonEditor possibleOpenEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid
);
131 if(possibleOpenEditor
!= null){
132 AbstractUtility
.close(possibleOpenEditor
);
134 EditorUtil
.openTaxonNode(newAcceptedTaxonNodeUuid
);
135 } catch (PartInitException e
) {
136 MessagingUtils
.error(this.getClass(), e
);
137 throw new RuntimeException(e
);
138 } catch (Exception e
) {
139 MessagingUtils
.warningDialog("Could not create Taxon", this, e
.getMessage());
155 public boolean onComplete() {
156 // TODO Auto-generated method stub