Project

General

Profile

Download (3.37 KB) Statistics
| Branch: | Tag: | Revision:
1
// $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
import org.eclipse.swt.widgets.Display;
20
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.ui.handlers.HandlerUtil;
22

    
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

    
32
/**
33
 * <p>SwapSynonymAndAcceptedHandler class.</p>
34
 *
35
 * @author n.hoffmann
36
 * @created 21.04.2009
37
 * @version 1.0
38
 */
39
public class SwapSynonymAndAcceptedHandler extends AbstractHandler implements
40
		IHandler, IPostOperationEnabled {
41
	private static final Logger logger = Logger
42
			.getLogger(SwapSynonymAndAcceptedHandler.class);
43
	private MultiPageTaxonEditor editor;
44
	private Taxon taxon;
45

    
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
48
	 */
49
	/** {@inheritDoc} */
50
	@Override
51
    public Object execute(ExecutionEvent event) throws ExecutionException {
52
		editor = EditorUtil.getActiveMultiPageTaxonEditor();
53
		Shell shell = HandlerUtil.getActiveShell(event);
54
		Synonym synonym = (Synonym) EditorUtil.getSelection(event).getFirstElement();
55

    
56

    
57
		// Force user to save taxon - not really necessary though, is it?
58
		if (!EditorUtil.forceUserSave(editor, shell)) {
59
			return null;
60
		}
61

    
62
		try {
63
			SwapSynonymAndAcceptedOperation operation = new SwapSynonymAndAcceptedOperation(event.getCommand().getName(), editor.getUndoContext(),
64
								editor.getTaxon(), synonym, this, editor);
65

    
66
			EditorUtil.executeOperation(operation);
67

    
68
		} catch (NotDefinedException e) {
69
			logger.warn("Command name not set");
70
		}
71

    
72
		return null;
73
	}
74

    
75
	/* (non-Javadoc)
76
	 * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase, boolean)
77
	 */
78
	@Override
79
	public boolean postOperation(CdmBase objectAffectedByOperation) {
80
		// Redraw existing editor
81
		//((IPostOperationEnabled) editor).postOperation(null);
82

    
83
		editor.doSave(EditorUtil.getMonitor());
84
		editor.close(true);
85

    
86
		if (objectAffectedByOperation instanceof Taxon) {
87

    
88
			taxon = (Taxon) objectAffectedByOperation;
89

    
90

    
91
		}
92
		return true;
93
	}
94

    
95
	/* (non-Javadoc)
96
	 * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#onComplete()
97
	 */
98
	@Override
99
	public boolean onComplete() {
100
		Display display = Display.getCurrent();
101
		display.asyncExec(new Runnable() {
102
			@Override
103
            public void run() {
104
				try {
105
					EditorUtil.openTaxonBase(taxon.getUuid());
106

    
107
				} catch (Exception e) {
108
					MessagingUtils.warningDialog("Could not open editor for taxon", this, e.getMessage());
109
				}
110

    
111
			}
112
		});
113
		return true;
114
	}
115
}
(15-15/15)