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
.DescriptionBase
;
24 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
26 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
27 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
28 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
30 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionToOtherTaxonOperation
;
31 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
32 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
33 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
34 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
39 * <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
41 * @author a.kohlbecker
42 * @created Okt. 11, 2013
46 public class MoveDescriptionToOtherTaxonHandler
extends AbstractHandler
47 implements IPostOperationEnabled
{
48 private static final Logger logger
= Logger
49 .getLogger(MoveDescriptionToOtherTaxonHandler
.class);
50 private MoveDescriptionToOtherTaxonOperation operation
;
52 private UUID newAcceptedTaxonNodeUuid
;
53 private TaxonNameEditor editor
;
56 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
60 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
62 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
64 if(selection
instanceof IStructuredSelection
){
66 List
<TaxonDescription
> descriptions
= new ArrayList
<TaxonDescription
>();
68 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
70 for(Object element
: structuredSelection
.toArray()){
72 if (element
instanceof FeatureNodeContainer
){
73 uuid
= ((FeatureNodeContainer
)element
).getDescription().getUuid();
74 } else if (element
instanceof DescriptionBase
){
75 uuid
= ((DescriptionBase
)element
).getUuid();
79 descriptions
.add((TaxonDescription
) CdmStore
.getService(IDescriptionService
.class).load(uuid
, null));
82 if(descriptions
.size() == 0){
86 // Choose the target taxon
87 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
88 editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
89 excludeTaxa
.add(descriptions
.get(0).getTaxon().getUuid());
90 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
91 editor
.getConversationHolder(),
92 "Choose the accepted taxon",
97 if (newAcceptedTaxonNode
== null) {
101 newAcceptedTaxonNodeUuid
= newAcceptedTaxonNode
.getUuid();
104 for(TaxonDescription description
: descriptions
){
105 operation
= new MoveDescriptionToOtherTaxonOperation(event
.getCommand().getName(),
106 editor
.getUndoContext(), description
, newAcceptedTaxonNode
, this, editor
);
107 AbstractUtility
.executeOperation(operation
);
110 } catch (NotDefinedException e
) {
111 logger
.warn("Command name not set");
120 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
124 public boolean postOperation(CdmBase objectAffectedByOperation
) {
125 Display
.getDefault().asyncExec(new Runnable(){
129 AbstractUtility
.close(editor
.getMultiPageTaxonEditor());
132 MultiPageTaxonEditor possibleOpenEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid
);
133 if(possibleOpenEditor
!= null){
134 AbstractUtility
.close(possibleOpenEditor
);
136 EditorUtil
.openTaxonNode(newAcceptedTaxonNodeUuid
);
137 } catch (PartInitException e
) {
138 MessagingUtils
.error(this.getClass(), e
);
139 throw new RuntimeException(e
);
140 } catch (Exception e
) {
141 MessagingUtils
.warningDialog("Could not create Taxon", this, e
.getMessage());
157 public boolean onComplete() {
158 // TODO Auto-generated method stub