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
.IHandler
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.swt
.widgets
.Display
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
21 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
27 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.SwapSynonymAndAcceptedOperation
;
29 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
30 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
31 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
34 * <p>SwapSynonymAndAcceptedHandler class.</p>
40 public class SwapSynonymAndAcceptedHandler
extends AbstractHandler
implements
41 IHandler
, IPostOperationEnabled
{
42 private static final Logger logger
= Logger
43 .getLogger(SwapSynonymAndAcceptedHandler
.class);
44 private MultiPageTaxonEditor editor
;
48 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
53 editor
= EditorUtil
.getActiveMultiPageTaxonEditor();
54 Shell shell
= HandlerUtil
.getActiveShell(event
);
55 Synonym synonym
= (Synonym
) EditorUtil
.getSelection(event
).getFirstElement();
58 // Force user to save taxon - not really necessary though, is it?
59 if (!EditorUtil
.forceUserSave(editor
, shell
)) {
64 SwapSynonymAndAcceptedOperation operation
= new SwapSynonymAndAcceptedOperation(event
.getCommand().getName(),
65 editor
.getUndoContext(),
69 (ICdmEntitySessionEnabled
)editor
.getEditorInput());
71 EditorUtil
.executeOperation(operation
);
73 } catch (NotDefinedException e
) {
74 logger
.warn("Command name not set");
81 * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase, boolean)
84 public boolean postOperation(CdmBase objectAffectedByOperation
) {
85 // Redraw existing editor
86 //((IPostOperationEnabled) editor).postOperation(null);
88 editor
.doSave(EditorUtil
.getMonitor());
91 if (objectAffectedByOperation
instanceof Taxon
) {
93 taxon
= (Taxon
) objectAffectedByOperation
;
101 * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
104 public boolean onComplete() {
105 Display display
= Display
.getCurrent();
106 display
.asyncExec(new Runnable() {
110 EditorUtil
.openTaxonBase(taxon
.getUuid());
112 } catch (Exception e
) {
113 MessagingUtils
.warningDialog("Could not open editor for taxon", this, e
.getMessage());