Revision 9fcf0574
Added by Patrick Plitzner about 7 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/OpenRelatedConceptHandler.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.editor.view.concept.handler; |
11 | 11 |
|
12 |
import java.util.Iterator; |
|
13 |
|
|
14 | 12 |
import org.eclipse.core.commands.AbstractHandler; |
15 | 13 |
import org.eclipse.core.commands.ExecutionEvent; |
16 | 14 |
import org.eclipse.core.commands.ExecutionException; |
17 | 15 |
import org.eclipse.jface.viewers.ISelection; |
18 | 16 |
import org.eclipse.jface.viewers.IStructuredSelection; |
17 |
import org.eclipse.ui.IEditorPart; |
|
19 | 18 |
import org.eclipse.ui.PartInitException; |
20 | 19 |
import org.eclipse.ui.handlers.HandlerUtil; |
21 | 20 |
|
22 | 21 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
22 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
23 | 23 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
24 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
24 | 25 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
25 | 26 |
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; |
26 | 27 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
28 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
29 |
import eu.etaxonomy.taxeditor.model.LineSelection; |
|
27 | 30 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
28 | 31 |
|
29 | 32 |
/** |
... | ... | |
33 | 36 |
*/ |
34 | 37 |
public class OpenRelatedConceptHandler extends AbstractHandler { |
35 | 38 |
|
36 |
/* (non-Javadoc) |
|
37 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
38 |
*/ |
|
39 | 39 |
@Override |
40 | 40 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
41 |
MultiPageTaxonEditor editor = EditorUtil.getActiveMultiPageTaxonEditor(); |
|
42 |
|
|
43 | 41 |
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 |
} |
|
42 |
TaxonBase<?> relatedTaxon = null; |
|
43 |
|
|
44 |
if(selection instanceof IStructuredSelection){ |
|
45 |
IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
|
46 |
Object selectedElement = structuredSelection.getFirstElement(); |
|
47 |
|
|
48 |
if(selectedElement instanceof TaxonRelationship){ |
|
49 |
IEditorPart activeEditor = AbstractUtility.getActiveEditor(); |
|
50 |
if(activeEditor instanceof MultiPageTaxonEditor){ |
|
51 |
relatedTaxon = getRelatedTaxon((TaxonRelationship) selectedElement, ((MultiPageTaxonEditor) activeEditor).getTaxon()); |
|
52 |
} |
|
53 |
else if(activeEditor instanceof BulkEditor){ |
|
54 |
ISelection bulkSelection = ((BulkEditor)activeEditor).getSelectionProvider().getSelection(); |
|
55 |
if(bulkSelection instanceof LineSelection){ |
|
56 |
Object firstElement = ((LineSelection)bulkSelection).getFirstElement(); |
|
57 |
if(firstElement instanceof Taxon){ |
|
58 |
relatedTaxon = getRelatedTaxon((TaxonRelationship) selectedElement, (Taxon) firstElement); |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
if(relatedTaxon==null){ |
|
66 |
MessagingUtils.messageDialog(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN, getClass(), |
|
67 |
String.format(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN_MESSAGE ,relatedTaxon), null); |
|
62 | 68 |
} |
63 |
|
|
69 |
else{ |
|
70 |
openConcept(relatedTaxon); |
|
71 |
} |
|
72 |
|
|
64 | 73 |
return null; |
65 | 74 |
} |
66 | 75 |
|
67 |
|
|
76 |
/** |
|
77 |
* @param relatedTaxon |
|
78 |
*/ |
|
79 |
protected void openConcept(TaxonBase<?> relatedTaxon) { |
|
80 |
try { |
|
81 |
EditorUtil.openTaxonBase(relatedTaxon.getUuid()); |
|
82 |
} catch (PartInitException e) { |
|
83 |
MessagingUtils.messageDialog(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN, getClass(), |
|
84 |
String.format(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN_MESSAGE ,relatedTaxon), e); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
68 | 88 |
private Taxon getRelatedTaxon(TaxonRelationship relationship, Taxon taxon){ |
69 | 89 |
if (relationship.getFromTaxon().equals(taxon)){ |
70 | 90 |
return relationship.getToTaxon(); |
Also available in: Unified diff
ref #5923 "Open in.." menu restructuring for conecpt view