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
.Classification
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
28 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
29 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
30 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
32 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionToOtherTaxonOperation
;
33 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
34 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
35 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
36 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
37 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
38 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
39 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
42 * <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
44 * @author a.kohlbecker
45 * @created Okt. 11, 2013
49 public class MoveDescriptionToOtherTaxonHandler
extends AbstractHandler
50 implements IPostOperationEnabled
{
51 private static final Logger logger
= Logger
52 .getLogger(MoveDescriptionToOtherTaxonHandler
.class);
53 private MoveDescriptionToOtherTaxonOperation operation
;
55 private UUID newAcceptedTaxonNodeUuid
;
56 private TaxonNameEditor editor
;
59 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
63 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
65 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
67 if(selection
instanceof IStructuredSelection
){
69 List
<TaxonDescription
> descriptions
= new ArrayList
<TaxonDescription
>();
71 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
73 for(Object element
: structuredSelection
.toArray()){
75 if (element
instanceof FeatureNodeContainer
){
76 uuid
= ((FeatureNodeContainer
)element
).getDescription().getUuid();
77 } else if (element
instanceof DescriptionBase
){
78 uuid
= ((DescriptionBase
)element
).getUuid();
82 descriptions
.add((TaxonDescription
) CdmStore
.getService(IDescriptionService
.class).load(uuid
, null));
85 if(descriptions
.size() == 0){
89 // Choose the target taxon
90 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
91 editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
92 excludeTaxa
.add(descriptions
.get(0).getTaxon().getUuid());
94 //get current taxon node
95 TaxonNode node
= null;
96 Classification classification
= null;
97 MultiPageTaxonEditor taxonEditor
= EditorUtil
.getActiveMultiPageTaxonEditor();
98 if(taxonEditor
!=null){
99 node
= ((TaxonEditorInput
) taxonEditor
.getEditorInput()).getTaxonNode();
100 classification
= node
.getClassification();
102 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
103 editor
.getConversationHolder(),
104 "Choose the accepted taxon",
109 if (newAcceptedTaxonNode
== null) {
113 newAcceptedTaxonNodeUuid
= newAcceptedTaxonNode
.getUuid();
116 for(TaxonDescription description
: descriptions
){
117 operation
= new MoveDescriptionToOtherTaxonOperation(event
.getCommand().getName(),
118 editor
.getUndoContext(),
120 newAcceptedTaxonNode
,
123 (ICdmEntitySessionEnabled
)editor
.getEditorInput());
124 AbstractUtility
.executeOperation(operation
);
127 } catch (NotDefinedException e
) {
128 logger
.warn("Command name not set");
137 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
141 public boolean postOperation(CdmBase objectAffectedByOperation
) {
142 Display
.getDefault().asyncExec(new Runnable(){
146 AbstractUtility
.close(editor
.getMultiPageTaxonEditor());
149 MultiPageTaxonEditor possibleOpenEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid
);
150 if(possibleOpenEditor
!= null){
151 AbstractUtility
.close(possibleOpenEditor
);
153 EditorUtil
.openTaxonNode(newAcceptedTaxonNodeUuid
);
154 } catch (PartInitException e
) {
155 MessagingUtils
.error(this.getClass(), e
);
156 throw new RuntimeException(e
);
157 } catch (Exception e
) {
158 MessagingUtils
.warningDialog("Could not create Taxon", this, e
.getMessage());
174 public boolean onComplete() {
175 // TODO Auto-generated method stub