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
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
23 import org
.eclipse
.ui
.PartInitException
;
24 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
28 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
29 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
30 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
31 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
32 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.SynonymPropertySource
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 import eu
.etaxonomy
.taxeditor
.store
.operations
.SwapSynonymAndAcceptedOperation
;
41 public class SwapSynonymAndAcceptedHandler
extends AbstractHandler
implements
43 private static final Logger logger
= Logger
44 .getLogger(SwapSynonymAndAcceptedHandler
.class);
47 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
49 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
50 MultiPageTaxonEditor multiEditor
= EditorUtil
.getActiveEditor();
52 if (multiEditor
.isDirty()) {
53 if (!MessageDialog
.openConfirm((Shell
) multiEditor
.getAdapter(Shell
.class), "Save before proceeding",
54 "All changes must be saved before proceeding.\n\n" +
55 "Save current changes?")) {
58 multiEditor
.doSave(null);
61 TaxonNameEditor editor
= (TaxonNameEditor
) multiEditor
.getPage(Page
.NAME
);
63 ISelection menuSelection
= HandlerUtil
.getActiveMenuSelection(event
);
64 Synonym synonym
= (Synonym
) ((SynonymPropertySource
) ((StructuredSelection
) menuSelection
).getFirstElement()).getTaxonBase();
67 SwapSynonymAndAcceptedOperation operation
;
70 operation
= new SwapSynonymAndAcceptedOperation(event
.getCommand().getName(), editor
.getUndoContext(),
71 editor
.getTaxon(), synonym
, editor
);
72 EditorUtil
.executeOperation(operation
);
74 // TODO this is all very spooky
75 // After performing the logic we do have to mangle around with the windows
76 Taxon newTaxon
= operation
.getNewTaxon();
78 // save and delete the taxon data
79 CdmStore
.getTaxonService().save(newTaxon
);
80 CdmStore
.getTaxonService().delete(editor
.getTaxon());
82 multiEditor
.doSave(null);
83 EditorUtil
.close(multiEditor
);
85 // open an editor with the new
86 EditorUtil
.open(newTaxon
.getUuid());
88 } catch (NotDefinedException e
) {
89 logger
.warn("Command name not set");
90 } catch (PartInitException e
) {
91 logger
.error("Could not open editor with new taxon", e
);