Project

General

Profile

Download (3.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.name.handler;
11

    
12
import org.apache.log4j.Logger;
13
import org.eclipse.core.commands.AbstractHandler;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.IHandler;
17
import org.eclipse.core.commands.common.NotDefinedException;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.ui.handlers.HandlerUtil;
21

    
22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.cdm.model.taxon.Synonym;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.taxeditor.editor.EditorUtil;
26
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
27
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
28
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
29
import eu.etaxonomy.taxeditor.model.MessagingUtils;
30
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
31
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
32

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

    
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
49
	 */
50
	/** {@inheritDoc} */
51
	@Override
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();
56

    
57

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

    
63
		try {
64
			SwapSynonymAndAcceptedOperation operation = new SwapSynonymAndAcceptedOperation(event.getCommand().getName(),
65
			        editor.getUndoContext(),
66
			        editor.getTaxon(),
67
			        synonym,
68
			        this,
69
			        (ICdmEntitySessionEnabled)editor.getEditorInput());
70

    
71
			EditorUtil.executeOperation(operation);
72

    
73
		} catch (NotDefinedException e) {
74
			logger.warn("Command name not set"); //$NON-NLS-1$
75
		}
76

    
77
		return null;
78
	}
79

    
80
	/* (non-Javadoc)
81
	 * @see eu.etaxonomy.taxeditor.operation.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase, boolean)
82
	 */
83
	@Override
84
	public boolean postOperation(CdmBase objectAffectedByOperation) {
85
		// Redraw existing editor
86
		//((IPostOperationEnabled) editor).postOperation(null);
87

    
88
		editor.doSave(EditorUtil.getMonitor());
89
		editor.close(true);
90

    
91
		if (objectAffectedByOperation instanceof Taxon) {
92

    
93
			taxon = (Taxon) objectAffectedByOperation;
94

    
95

    
96
		}
97
		return true;
98
	}
99

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

    
112
				} catch (Exception e) {
113
					MessagingUtils.warningDialog(Messages.SwapSynonymAndAcceptedHandler_COULD_NOT_OPEN, this, e.getMessage());
114
				}
115

    
116
			}
117
		});
118
		return true;
119
	}
120
}
(15-15/15)