1 |
e8409423
|
n.hoffmann
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2007 EDIT
|
4 |
|
|
* European Distributed Institute of Taxonomy
|
5 |
|
|
* http://www.e-taxonomy.eu
|
6 |
|
|
*
|
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.
|
9 |
|
|
*/
|
10 |
|
|
|
11 |
|
|
package eu.etaxonomy.taxeditor.editor.name.handler;
|
12 |
|
|
|
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 |
641ce9d2
|
l.morris
|
import org.eclipse.swt.widgets.Display;
|
20 |
|
|
import org.eclipse.swt.widgets.Shell;
|
21 |
|
|
import org.eclipse.ui.handlers.HandlerUtil;
|
22 |
e8409423
|
n.hoffmann
|
|
23 |
641ce9d2
|
l.morris
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
24 |
e8409423
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
25 |
641ce9d2
|
l.morris
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
26 |
e8409423
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
27 |
|
|
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
|
28 |
35861667
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
|
29 |
641ce9d2
|
l.morris
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
30 |
e8409423
|
n.hoffmann
|
|
31 |
|
|
/**
|
32 |
3be6ef3e
|
n.hoffmann
|
* <p>SwapSynonymAndAcceptedHandler class.</p>
|
33 |
|
|
*
|
34 |
e8409423
|
n.hoffmann
|
* @author n.hoffmann
|
35 |
|
|
* @created 21.04.2009
|
36 |
|
|
* @version 1.0
|
37 |
|
|
*/
|
38 |
|
|
public class SwapSynonymAndAcceptedHandler extends AbstractHandler implements
|
39 |
641ce9d2
|
l.morris
|
IHandler, IPostOperationEnabled {
|
40 |
e8409423
|
n.hoffmann
|
private static final Logger logger = Logger
|
41 |
|
|
.getLogger(SwapSynonymAndAcceptedHandler.class);
|
42 |
641ce9d2
|
l.morris
|
private MultiPageTaxonEditor editor;
|
43 |
|
|
private Taxon taxon;
|
44 |
e8409423
|
n.hoffmann
|
|
45 |
|
|
/* (non-Javadoc)
|
46 |
|
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
47 |
|
|
*/
|
48 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
49 |
e8409423
|
n.hoffmann
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
50 |
641ce9d2
|
l.morris
|
editor = EditorUtil.getActiveMultiPageTaxonEditor();
|
51 |
|
|
Shell shell = HandlerUtil.getActiveShell(event);
|
52 |
2d9a13f7
|
n.hoffmann
|
Synonym synonym = (Synonym) EditorUtil.getSelection(event).getFirstElement();
|
53 |
e8409423
|
n.hoffmann
|
|
54 |
641ce9d2
|
l.morris
|
|
55 |
|
|
// Force user to save taxon - not really necessary though, is it?
|
56 |
|
|
if (!EditorUtil.forceUserSave(editor, shell)) {
|
57 |
|
|
return null;
|
58 |
|
|
}
|
59 |
e8409423
|
n.hoffmann
|
|
60 |
|
|
try {
|
61 |
641ce9d2
|
l.morris
|
SwapSynonymAndAcceptedOperation operation = new SwapSynonymAndAcceptedOperation(event.getCommand().getName(), editor.getUndoContext(),
|
62 |
|
|
editor.getTaxon(), synonym, this);
|
63 |
|
|
|
64 |
e8409423
|
n.hoffmann
|
EditorUtil.executeOperation(operation);
|
65 |
|
|
|
66 |
|
|
} catch (NotDefinedException e) {
|
67 |
|
|
logger.warn("Command name not set");
|
68 |
8e749f15
|
n.hoffmann
|
}
|
69 |
e8409423
|
n.hoffmann
|
|
70 |
|
|
return null;
|
71 |
|
|
}
|
72 |
641ce9d2
|
l.morris
|
|
73 |
|
|
/* (non-Javadoc)
|
74 |
|
|
* @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase, boolean)
|
75 |
|
|
*/
|
76 |
|
|
@Override
|
77 |
|
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
78 |
|
|
// Redraw existing editor
|
79 |
|
|
//((IPostOperationEnabled) editor).postOperation(null);
|
80 |
|
|
|
81 |
|
|
editor.doSave(EditorUtil.getMonitor());
|
82 |
|
|
editor.close(true);
|
83 |
|
|
|
84 |
|
|
if (objectAffectedByOperation instanceof Taxon) {
|
85 |
|
|
|
86 |
|
|
taxon = (Taxon) objectAffectedByOperation;
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
}
|
90 |
|
|
return true;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
/* (non-Javadoc)
|
94 |
|
|
* @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
|
95 |
|
|
*/
|
96 |
|
|
@Override
|
97 |
|
|
public boolean onComplete() {
|
98 |
|
|
Display display = Display.getCurrent();
|
99 |
|
|
display.asyncExec(new Runnable() {
|
100 |
|
|
public void run() {
|
101 |
|
|
try {
|
102 |
|
|
EditorUtil.openTaxonBase(taxon.getUuid());
|
103 |
|
|
|
104 |
|
|
} catch (Exception e) {
|
105 |
|
|
EditorUtil.warningDialog("Could not open editor for taxon", this, e.getMessage());
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
}
|
109 |
|
|
});
|
110 |
|
|
return true;
|
111 |
|
|
}
|
112 |
e8409423
|
n.hoffmann
|
}
|