Project

General

Profile

Download (2.68 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.bulkeditor.derivedunit.handler;
12

    
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.common.NotDefinedException;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.ui.IEditorInput;
20
import org.eclipse.ui.IEditorPart;
21
import org.eclipse.ui.IWorkbenchPart;
22
import org.eclipse.ui.handlers.HandlerUtil;
23

    
24
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
25
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
26
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
27
import eu.etaxonomy.taxeditor.bulkeditor.derivedunit.operation.AddDerivedUnitFacadeMediaOperation;
28
import eu.etaxonomy.taxeditor.bulkeditor.input.OccurrenceEditorInput;
29
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
30
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
31

    
32
/**
33
 * @author n.hoffmann
34
 * @created Feb 11, 2011
35
 * @version 1.0
36
 */
37
public abstract class AbstractAddDerivedUnitFacadeMediaHandler extends AbstractHandler {
38

    
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
41
	 */
42
	@Override
43
	public Object execute(ExecutionEvent event) throws ExecutionException {
44
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
45
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
46
		
47
		
48
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
49
		IEditorInput input = editor.getEditorInput();
50
		
51
		
52
		if(input instanceof OccurrenceEditorInput){
53
			BulkEditor bulkEditor = (BulkEditor) editor;
54
			ISelection selection = bulkEditor.getSelectionProvider().getSelection();
55
			
56
			if(selection instanceof IStructuredSelection){
57
				Object element = ((IStructuredSelection) selection).getFirstElement();
58
				if(element instanceof DerivedUnit){
59
					
60
					try{
61
						AbstractPostOperation operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(), BulkEditorUtil.getUndoContext(), (DerivedUnit) element, getMode(), postOperationEnabled);
62
						BulkEditorUtil.executeOperation(operation);
63
					} catch (NotDefinedException e) {
64
						BulkEditorUtil.warn(getClass(), "Command name not set.");
65
					}					
66
				}
67
			}
68
		}
69
		return null;
70
	}
71

    
72
	/**
73
	 * @return
74
	 */
75
	protected abstract int getMode();
76

    
77
}
(1-1/3)