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
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.core
.commands
.AbstractHandler
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
21 import org
.eclipse
.swt
.widgets
.Shell
;
22 import org
.eclipse
.ui
.IEditorInput
;
23 import org
.eclipse
.ui
.PartInitException
;
24 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
31 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
32 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
33 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
34 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToAcceptedTaxonOperation
;
35 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
36 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
37 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
40 * <p>ChangeSynonymToAcceptedTaxonHandler class.</p>
46 public class ChangeSynonymToAcceptedTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
47 private static final Logger logger
= Logger
48 .getLogger(ChangeSynonymToAcceptedTaxonHandler
.class);
49 private MultiPageTaxonEditor editor
;
52 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
55 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
56 editor
= (MultiPageTaxonEditor
) HandlerUtil
.getActiveEditor(event
);
57 Shell shell
= HandlerUtil
.getActiveShell(event
);
58 IEditorInput input
= editor
.getEditorInput();
60 if (!(input
instanceof TaxonEditorInput
)) {
61 logger
.error("Editor input is not TaxonEditorInput");
65 // Get synonym from selection
66 StructuredSelection selection
= (StructuredSelection
) HandlerUtil
.getCurrentSelection(event
);
67 if (!(selection
.getFirstElement() instanceof Synonym
)) {
68 logger
.error("Selection does not contain a Synonym");
72 Synonym synonym
= (Synonym
) selection
.getFirstElement();
74 // Force user to save taxon - not really necessary though, is it?
75 if (!EditorUtil
.forceUserSave(editor
, shell
)) {
80 Taxon taxon
= ((TaxonEditorInput
) input
).getTaxon();
82 TaxonNode parentNode
= (TaxonNode
) HibernateProxyHelper
.deproxy(((TaxonEditorInput
) input
).getTaxonNode().getParent());
84 List
<UUID
> excludeTaxa
= null;
86 TaxonNode newParentNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), editor
.getConversationHolder(), "Select parent", excludeTaxa
, null, null);
88 if(newParentNode
!= null){
90 // TODO get synonyms from homotypical group and add them as homotypic synonyms to new accepted taxon
91 // apply confirmation dialog
93 // FIXME with this implementation we can not create a taxonNode that is a direct child of the classification node
94 AbstractPostOperation operation
= new ChangeSynonymToAcceptedTaxonOperation("Change synonym to accepted taxon", EditorUtil
.getUndoContext(),
95 taxon
, newParentNode
, synonym
, null, this, editor
); //$NON-NLS-1$
96 EditorUtil
.executeOperation(operation
);
103 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
106 public boolean postOperation(CdmBase objectAffectedByOperation
) {
108 // Redraw existing editor
109 ((IPostOperationEnabled
) editor
).postOperation(null);
111 editor
.doSave(EditorUtil
.getMonitor());
113 if (objectAffectedByOperation
instanceof TaxonNode
) {
115 // Open new unsaved editor with existing taxon's parent as temporary parent
116 TaxonNode newNode
= (TaxonNode
) objectAffectedByOperation
;
117 // TaxonNode newNode = parentNode.addChild(newTaxon);
122 * This doesn't work b/c newNode hasn't been committed yet, and therefore
123 * CdmStore.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid);
126 EditorUtil
.openTaxonNode(newNode
.getUuid());
128 } catch (PartInitException e
) {
129 // TODO Auto-generated catch block
131 } catch (Exception e
) {
132 EditorUtil
.warningDialog("Could not create Taxon", this, e
.getMessage());
143 public boolean onComplete() {
144 // TODO Auto-generated method stub