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 org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
18 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
20 import org
.eclipse
.ui
.IEditorInput
;
21 import org
.eclipse
.ui
.IEditorPart
;
22 import org
.eclipse
.ui
.PartInitException
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.ITreeNode
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
30 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
31 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
32 import eu
.etaxonomy
.taxeditor
.operations
.ChangeSynonymToAcceptedTaxonOperation
;
33 import eu
.etaxonomy
.taxeditor
.operations
.IPostOperationEnabled
;
34 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.SynonymPropertySource
;
41 public class ChangeSynonymToAcceptedTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
42 private static final Logger logger
= Logger
43 .getLogger(ChangeSynonymToAcceptedTaxonHandler
.class);
45 private IEditorPart editor
;
49 private ITreeNode parentNode
;
52 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
54 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
55 editor
= HandlerUtil
.getActiveEditor(event
);
56 Shell shell
= HandlerUtil
.getActiveShell(event
);
57 IEditorInput input
= editor
.getEditorInput();
59 if (!(input
instanceof TaxonEditorInput
)) {
60 logger
.error("Editor input is not TaxonEditorInput");
64 // Get synonym from selection
65 StructuredSelection selection
= (StructuredSelection
) HandlerUtil
.getActiveMenuSelection(event
);
66 if (!(selection
.getFirstElement() instanceof SynonymPropertySource
)) {
67 logger
.error("Expected selection containing SynonymPropertySource");
71 Synonym synonym
= (Synonym
) ((SynonymPropertySource
) selection
.getFirstElement()).getTaxonBase();
73 // Force user to save taxon - not really necessary though, is it?
74 if (!EditorUtil
.forceUserSave(editor
, shell
)) {
79 taxon
= ((TaxonEditorInput
) input
).getTaxon();
80 parentNode
= ((TaxonEditorInput
) input
).getTaxonNode().getParent();
82 // Create new taxon with no parent
83 IUndoableOperation operation
= new ChangeSynonymToAcceptedTaxonOperation("Change synonym to accepted taxon", EditorUtil
.getUndoContext(),
84 taxon
, parentNode
, synonym
, this); //$NON-NLS-1$
85 EditorUtil
.executeOperation(operation
);
91 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
93 public boolean postOperation(CdmBase objectAffectedByOperation
) {
95 // Redraw existing editor
96 ((IPostOperationEnabled
) editor
).postOperation(null);
100 if (objectAffectedByOperation
instanceof TaxonNode
) {
102 // Open new unsaved editor with existing taxon's parent as temporary parent
103 TaxonNode newNode
= (TaxonNode
) objectAffectedByOperation
;
104 // TaxonNode newNode = parentNode.addChild(newTaxon);
109 * This doesn't work b/c newNode hasn't been committed yet, and therefore
110 * CdmStore.getTaxonService().getTaxonNodeByUuid(taxonNodeUuid);
113 IEditorPart newEditor
= EditorUtil
.open(newNode
.getUuid());
115 } catch (PartInitException e
) {
116 // TODO Auto-generated catch block