Project

General

Profile

Download (2.47 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.view.concept.handler;
11

    
12
import java.util.Iterator;
13

    
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.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.ui.PartInitException;
20
import org.eclipse.ui.handlers.HandlerUtil;
21

    
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
24
import eu.etaxonomy.taxeditor.editor.EditorUtil;
25
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
26
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
27
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28

    
29
/**
30
 * @author n.hoffmann
31
 * @created Jan 25, 2011
32
 * @version 1.0
33
 */
34
public class OpenRelatedConceptHandler extends AbstractHandler {
35

    
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
38
	 */
39
	@Override
40
	public Object execute(ExecutionEvent event) throws ExecutionException {
41
		MultiPageTaxonEditor editor = EditorUtil.getActiveMultiPageTaxonEditor();
42
		
43
		ISelection selection = HandlerUtil.getCurrentSelection(event);
44
		
45
		if(selection instanceof IStructuredSelection){
46
			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
47
			Iterator iterator = structuredSelection.iterator();
48
			
49
			while (iterator.hasNext()){
50
				Object element = iterator.next();
51
				if(element instanceof TaxonRelationship){
52
					Taxon relatedTaxon = getRelatedTaxon((TaxonRelationship) element, editor.getTaxon());
53
					
54
					try {
55
						EditorUtil.openTaxonBase(relatedTaxon.getUuid());
56
					} catch (PartInitException e) {
57
						MessagingUtils.messageDialog(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN, getClass(), 
58
								String.format(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN_MESSAGE ,relatedTaxon), e);
59
					}
60
				}
61
			}
62
		}
63
		
64
		return null;
65
	}
66

    
67
	
68
	private Taxon getRelatedTaxon(TaxonRelationship relationship, Taxon taxon){
69
		if (relationship.getFromTaxon().equals(taxon)){
70
			return relationship.getToTaxon();
71
		}
72
		else if(relationship.getToTaxon().equals(taxon)){
73
			return relationship.getFromTaxon();
74
		}
75
		else{
76
			return null;
77
		}
78
	}
79
}
(8-8/8)