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
.PartInitException
;
22 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
29 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
30 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.SwapSynonymAndAcceptedOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 * <p>SwapSynonymAndAcceptedHandler class.</p>
41 public class SwapSynonymAndAcceptedHandler
extends AbstractHandler
implements
42 IHandler
, IPostOperationEnabled
{
43 private static final Logger logger
= Logger
44 .getLogger(SwapSynonymAndAcceptedHandler
.class);
45 private MultiPageTaxonEditor editor
;
49 * @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(), editor
.getUndoContext(),
65 editor
.getTaxon(), synonym
, this);
67 EditorUtil
.executeOperation(operation
);
69 } catch (NotDefinedException e
) {
70 logger
.warn("Command name not set");
77 * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase, boolean)
80 public boolean postOperation(CdmBase objectAffectedByOperation
) {
81 // Redraw existing editor
82 //((IPostOperationEnabled) editor).postOperation(null);
84 editor
.doSave(EditorUtil
.getMonitor());
87 if (objectAffectedByOperation
instanceof Taxon
) {
89 taxon
= (Taxon
) objectAffectedByOperation
;
97 * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
100 public boolean onComplete() {
101 Display display
= Display
.getCurrent();
102 display
.asyncExec(new Runnable() {
105 EditorUtil
.openTaxonBase(taxon
.getUuid());
107 } catch (Exception e
) {
108 EditorUtil
.warningDialog("Could not open editor for taxon", this, e
.getMessage());