3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
.name
.handler
;
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
.TaxonNameBase
;
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
.name
.operation
.ChangeSynonymToAcceptedTaxonOperation
;
38 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
39 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
40 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
41 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
44 * <p>ChangeSynonymToAcceptedTaxonHandler class.</p>
50 public class ChangeSynonymToAcceptedTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
51 private static final Logger logger
= Logger
52 .getLogger(ChangeSynonymToAcceptedTaxonHandler
.class);
53 private MultiPageTaxonEditor editor
;
56 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
60 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
61 editor
= (MultiPageTaxonEditor
) HandlerUtil
.getActiveEditor(event
);
62 Shell shell
= HandlerUtil
.getActiveShell(event
);
63 IEditorInput input
= editor
.getEditorInput();
65 if (!(input
instanceof TaxonEditorInput
)) {
66 logger
.error("Editor input is not TaxonEditorInput");
70 // Get synonym from selection
71 StructuredSelection selection
= (StructuredSelection
) HandlerUtil
.getCurrentSelection(event
);
72 if (!(selection
.getFirstElement() instanceof Synonym
)) {
73 logger
.error("Selection does not contain a Synonym");
77 Synonym synonym
= (Synonym
) selection
.getFirstElement();
79 // Force user to save taxon - not really necessary though, is it?
80 if (!EditorUtil
.forceUserSave(editor
, shell
)) {
85 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
87 TaxonNode parentNode
= (TaxonNode
) HibernateProxyHelper
.deproxy(((TaxonEditorInput
) input
).getTaxonNode().getParent());
89 List
<UUID
> excludeTaxa
= null;
91 TaxonNode newParentNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), editor
.getConversationHolder(), "Select parent", excludeTaxa
, null, null);
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
<TaxonNameBase
> 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("Change synonym to accepted taxon", EditorUtil
.getUndoContext(),
101 taxon
, newParentNode
, synonym
, namesInGroup
, this, editor
, editor
); //$NON-NLS-1$
102 EditorUtil
.executeOperation(operation
);
109 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
113 public boolean postOperation(CdmBase objectAffectedByOperation
) {
115 // Redraw existing editor
116 ((IPostOperationEnabled
) editor
).postOperation(null);
118 editor
.doSave(EditorUtil
.getMonitor());
120 if (objectAffectedByOperation
instanceof TaxonNode
) {
122 // Open new unsaved editor with existing taxon's parent as temporary parent
123 TaxonNode newNode
= (TaxonNode
) objectAffectedByOperation
;
124 // TaxonNode newNode = parentNode.addChild(newTaxon);
129 * This doesn't work b/c newNode hasn't been committed yet, and therefore
130 * CdmStore.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid);
133 EditorUtil
.openTaxonNode(newNode
.getUuid());
135 } catch (PartInitException e
) {
136 // TODO Auto-generated catch block
138 } catch (Exception e
) {
139 MessagingUtils
.warningDialog("Could not create Taxon", this, e
.getMessage());
151 public boolean onComplete() {
152 // TODO Auto-generated method stub