Project

General

Profile

Download (2.76 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.view.concept.handler;
12

    
13
import java.util.HashSet;
14
import java.util.Iterator;
15
import java.util.Set;
16

    
17
import org.eclipse.core.commands.AbstractHandler;
18
import org.eclipse.core.commands.ExecutionEvent;
19
import org.eclipse.core.commands.ExecutionException;
20
import org.eclipse.core.commands.common.NotDefinedException;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.ui.IWorkbenchPart;
24
import org.eclipse.ui.handlers.HandlerUtil;
25

    
26
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
27
import eu.etaxonomy.taxeditor.editor.EditorUtil;
28
import eu.etaxonomy.taxeditor.editor.Page;
29
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
30
import eu.etaxonomy.taxeditor.editor.view.concept.operation.DeleteConceptRelationOperation;
31
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
33
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
34

    
35
/**
36
 * @author n.hoffmann
37
 * @created Jan 25, 2011
38
 * @version 1.0
39
 */
40
public class DeleteConceptRelationHandler extends AbstractHandler {
41

    
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44
	 */
45
	@Override
46
	public Object execute(ExecutionEvent event) throws ExecutionException {
47
		TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
48
				Page.NAME);
49
		
50
		ISelection selection = HandlerUtil.getActiveSite(event).getSelectionProvider().getSelection();
51
		
52
		Set<TaxonRelationship> relations = new HashSet<TaxonRelationship>();
53
		
54
		if(selection instanceof IStructuredSelection){
55
			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
56
			Iterator iterator = structuredSelection.iterator();
57
			
58
			while (iterator.hasNext()){
59
				Object element = iterator.next();
60
				if(element instanceof TaxonRelationship){
61
					relations.add((TaxonRelationship) element);
62
				}
63
			}
64
		}
65
		
66
		IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
67
		IPostOperationEnabled postOperationEnabled = (activePart instanceof IPostOperationEnabled) ? (IPostOperationEnabled) activePart : null;
68
		
69
		try {
70
			AbstractPostOperation operation = new DeleteConceptRelationOperation(event.getCommand().getName(), 
71
					editor.getUndoContext(), editor.getTaxon(), relations, postOperationEnabled);
72
			EditorUtil.executeOperation(operation);
73
		} catch (NotDefinedException e) {
74
			MessagingUtils.warn(getClass(), "Command name not set");
75
		}
76
		
77
		return null;
78
	}
79
}
(7-7/8)