2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.handler
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.eclipse
.core
.commands
.AbstractHandler
;
19 import org
.eclipse
.core
.commands
.ExecutionEvent
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
23 import org
.eclipse
.ui
.IEditorInput
;
24 import org
.eclipse
.ui
.PartInitException
;
25 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
27 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
28 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
29 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
34 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
35 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
36 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
37 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
38 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToAcceptedTaxonOperation
;
39 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
40 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
41 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
42 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
43 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
46 * <p>ChangeSynonymToAcceptedTaxonHandler class.</p>
51 public class ChangeSynonymToAcceptedTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
52 private static final Logger logger
= Logger
53 .getLogger(ChangeSynonymToAcceptedTaxonHandler
.class);
54 private MultiPageTaxonEditor editor
;
58 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
59 editor
= (MultiPageTaxonEditor
) HandlerUtil
.getActiveEditor(event
);
60 Shell shell
= HandlerUtil
.getActiveShell(event
);
61 IEditorInput input
= editor
.getEditorInput();
63 if (!(input
instanceof TaxonEditorInput
)) {
64 logger
.error("Editor input is not TaxonEditorInput"); //$NON-NLS-1$
68 // Get synonym from selection
69 StructuredSelection selection
= (StructuredSelection
) HandlerUtil
.getCurrentSelection(event
);
70 if (!(selection
.getFirstElement() instanceof Synonym
)) {
71 logger
.error("Selection does not contain a Synonym"); //$NON-NLS-1$
75 Synonym synonym
= (Synonym
) selection
.getFirstElement();
77 // Force user to save taxon - not really necessary though, is it?
78 if (!EditorUtil
.forceUserSave(editor
, shell
)) {
83 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
85 TaxonNode parentNode
= HibernateProxyHelper
.deproxy(((TaxonEditorInput
) input
).getTaxonNode().getParent());
87 List
<UUID
> excludeTaxa
= new ArrayList
<>();
88 //excludeTaxa.add(taxon.getUuid());//there are some cases where the accepted taxon should be the parent of the new created accepted taxon
90 TaxonNode newParentNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), editor
.getConversationHolder(), Messages
.ChangeSynonymToAcceptedTaxonHandler_SELECT_PARENT
, null, null, ((TaxonEditorInput
) input
).getTaxonNode().getClassification());
93 if(newParentNode
!= null){
95 // TODO get synonyms from homotypical group and add them as homotypic synonyms to new accepted taxon
96 // apply confirmation dialog
97 HomotypicalGroup group
= synonym
.getHomotypicGroup();
98 Set
<TaxonName
> namesInGroup
= group
.getTypifiedNames();
99 // FIXME with this implementation we can not create a taxonNode that is a direct child of the classification node
100 AbstractPostOperation operation
= new ChangeSynonymToAcceptedTaxonOperation(Messages
.ChangeSynonymToAcceptedTaxonHandler_CHANGE_SYN_TO_ACC_TAXON
, EditorUtil
.getUndoContext(),
101 taxon
, newParentNode
, synonym
, namesInGroup
, this, editor
, (ICdmEntitySessionEnabled
)editor
.getEditorInput()); //$NON-NLS-1$
103 EditorUtil
.executeOperation(operation
);
111 public boolean postOperation(CdmBase objectAffectedByOperation
) {
113 // Redraw existing editor
114 ((IPostOperationEnabled
) editor
).postOperation(null);
116 editor
.doSave(EditorUtil
.getMonitor());
118 if (objectAffectedByOperation
instanceof TaxonNode
) {
120 // Open new unsaved editor with existing taxon's parent as temporary parent
121 TaxonNode newNode
= (TaxonNode
) objectAffectedByOperation
;
122 // TaxonNode newNode = parentNode.addChild(newTaxon);
127 * This doesn't work b/c newNode hasn't been committed yet, and therefore
128 * CdmStore.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid);
131 EditorUtil
.openTaxonBaseE4(newNode
.getUuid());
133 } catch (PartInitException e
) {
134 // TODO Auto-generated catch block
136 } catch (Exception e
) {
137 MessagingUtils
.warningDialog(Messages
.ChangeSynonymToAcceptedTaxonHandler_CREATE_FAILURE
, this, e
.getMessage());
149 public boolean onComplete() {
150 // TODO Auto-generated method stub