import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.handlers.HandlerUtil;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
-import eu.etaxonomy.taxeditor.editor.Page;
-import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
/**
* <p>SwapSynonymAndAcceptedHandler class.</p>
* @version 1.0
*/
public class SwapSynonymAndAcceptedHandler extends AbstractHandler implements
- IHandler {
+ IHandler, IPostOperationEnabled {
private static final Logger logger = Logger
.getLogger(SwapSynonymAndAcceptedHandler.class);
+ private MultiPageTaxonEditor editor;
+ private Taxon taxon;
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
/** {@inheritDoc} */
public Object execute(ExecutionEvent event) throws ExecutionException {
- MultiPageTaxonEditor multiEditor = EditorUtil.getActiveMultiPageTaxonEditor();
-
- TaxonNameEditor editor = (TaxonNameEditor) multiEditor.getPage(Page.NAME);
-
+ editor = EditorUtil.getActiveMultiPageTaxonEditor();
+ Shell shell = HandlerUtil.getActiveShell(event);
Synonym synonym = (Synonym) EditorUtil.getSelection(event).getFirstElement();
-
- SwapSynonymAndAcceptedOperation operation;
+
+ // Force user to save taxon - not really necessary though, is it?
+ if (!EditorUtil.forceUserSave(editor, shell)) {
+ return null;
+ }
try {
- operation = new SwapSynonymAndAcceptedOperation(event.getCommand().getName(), editor.getUndoContext(),
- editor.getTaxon(), synonym, editor);
+ SwapSynonymAndAcceptedOperation operation = new SwapSynonymAndAcceptedOperation(event.getCommand().getName(), editor.getUndoContext(),
+ editor.getTaxon(), synonym, this);
+
EditorUtil.executeOperation(operation);
} catch (NotDefinedException e) {
return null;
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase, boolean)
+ */
+ @Override
+ public boolean postOperation(CdmBase objectAffectedByOperation) {
+ // Redraw existing editor
+ //((IPostOperationEnabled) editor).postOperation(null);
+
+ editor.doSave(EditorUtil.getMonitor());
+ editor.close(true);
+
+ if (objectAffectedByOperation instanceof Taxon) {
+
+ taxon = (Taxon) objectAffectedByOperation;
+
+
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
+ */
+ @Override
+ public boolean onComplete() {
+ Display display = Display.getCurrent();
+ display.asyncExec(new Runnable() {
+ public void run() {
+ try {
+ EditorUtil.openTaxonBase(taxon.getUuid());
+
+ } catch (Exception e) {
+ EditorUtil.warningDialog("Could not open editor for taxon", this, e.getMessage());
+ }
+
+ }
+ });
+ return true;
+ }
}