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.e4.handler;
|
11
|
|
12
|
import javax.inject.Named;
|
13
|
|
14
|
import org.eclipse.e4.core.di.annotations.Execute;
|
15
|
import org.eclipse.e4.core.di.annotations.Optional;
|
16
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
17
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
18
|
import org.eclipse.jface.viewers.ISelection;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
22
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
23
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
24
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
25
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
26
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
27
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
28
|
import eu.etaxonomy.taxeditor.model.LineSelection;
|
29
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
30
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
* @author pplitzner
|
35
|
* @date 21.08.2017
|
36
|
*
|
37
|
*/
|
38
|
public class OpenRelatedConceptHandlerE4 {
|
39
|
|
40
|
@Execute
|
41
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
42
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION) TaxonRelationship taxonRelationship) {
|
43
|
|
44
|
TaxonNameEditorE4 editor = null;
|
45
|
BulkEditor bulkEditor = null;
|
46
|
|
47
|
ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
|
48
|
|
49
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
|
50
|
if(e4WrappedPart instanceof TaxonNameEditorE4){
|
51
|
editor = (TaxonNameEditorE4) e4WrappedPart;
|
52
|
}
|
53
|
else if(e4WrappedPart instanceof BulkEditor){
|
54
|
bulkEditor = (BulkEditor) e4WrappedPart;
|
55
|
}
|
56
|
TaxonBase<?> relatedTaxon = null;
|
57
|
if(editor!=null){
|
58
|
relatedTaxon = getRelatedTaxon(taxonRelationship, editor.getTaxon());
|
59
|
}
|
60
|
else if(bulkEditor!=null){
|
61
|
ISelection bulkSelection = bulkEditor.getSelectionProvider().getSelection();
|
62
|
if(bulkSelection instanceof LineSelection){
|
63
|
Object firstElement = ((LineSelection)bulkSelection).getFirstElement();
|
64
|
if(firstElement instanceof Taxon){
|
65
|
relatedTaxon = getRelatedTaxon(taxonRelationship, (Taxon) firstElement);
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
|
70
|
if(relatedTaxon==null){
|
71
|
MessagingUtils.messageDialog(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN, getClass(),
|
72
|
String.format(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN_MESSAGE ,relatedTaxon), null);
|
73
|
}
|
74
|
else{
|
75
|
openConcept(relatedTaxon);
|
76
|
}
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* @param relatedTaxon
|
81
|
*/
|
82
|
protected void openConcept(TaxonBase<?> relatedTaxon) {
|
83
|
EditorUtil.openTaxonBaseE4(relatedTaxon.getUuid());
|
84
|
}
|
85
|
|
86
|
private Taxon getRelatedTaxon(TaxonRelationship relationship, Taxon taxon){
|
87
|
if (relationship.getFromTaxon().equals(taxon)){
|
88
|
return relationship.getToTaxon();
|
89
|
}
|
90
|
else if(relationship.getToTaxon().equals(taxon)){
|
91
|
return relationship.getFromTaxon();
|
92
|
}
|
93
|
else{
|
94
|
return null;
|
95
|
}
|
96
|
}
|
97
|
}
|