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;
|
12
|
|
13
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
14
|
import org.eclipse.jface.viewers.LabelProvider;
|
15
|
import org.eclipse.jface.viewers.StyledString;
|
16
|
import org.eclipse.swt.graphics.Image;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.Language;
|
19
|
import eu.etaxonomy.cdm.model.common.Representation;
|
20
|
import eu.etaxonomy.cdm.model.reference.IReference;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
22
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
23
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
24
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
25
|
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
|
26
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
|
29
|
/**
|
30
|
* @author n.hoffmann
|
31
|
* @created Jan 24, 2011
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class ConceptLabelProvider extends LabelProvider implements IStyledLabelProvider {
|
35
|
|
36
|
/* (non-Javadoc)
|
37
|
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
|
38
|
*/
|
39
|
@Override
|
40
|
public Image getImage(Object element) {
|
41
|
if(element instanceof TaxonRelationship){
|
42
|
return getTaxonRelationshipImage((TaxonRelationship) element);
|
43
|
}
|
44
|
return super.getImage(element);
|
45
|
}
|
46
|
|
47
|
/* (non-Javadoc)
|
48
|
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
|
49
|
*/
|
50
|
@Override
|
51
|
public String getText(Object element) {
|
52
|
if(element instanceof TaxonRelationship){
|
53
|
return formatRelationship((TaxonRelationship) element);
|
54
|
}
|
55
|
|
56
|
return "";
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* Creates a string that holds a representation of the {@link TaxonRelationship} in relation to
|
61
|
* the accepted taxon of the currently active {@link MultiPageTaxonEditor}.
|
62
|
*
|
63
|
* @param relationship
|
64
|
* @return a formatted String representation of the relationship
|
65
|
*/
|
66
|
private String formatRelationship(TaxonRelationship relationship){
|
67
|
Taxon acceptedTaxon = EditorUtil.getActiveMultiPageTaxonEditor().getTaxon();
|
68
|
boolean inverse = relationship.getFromTaxon().equals(acceptedTaxon) ? false : true;
|
69
|
|
70
|
TaxonRelationshipType type = relationship.getType();
|
71
|
Representation representation = inverse ? type.getInverseRepresentation(Language.ENGLISH()) : type.getRepresentation(Language.ENGLISH());
|
72
|
|
73
|
Taxon relatedTaxon = inverse ? relationship.getFromTaxon() : relationship.getToTaxon();
|
74
|
|
75
|
String symbol = representation.getAbbreviatedLabel();
|
76
|
|
77
|
String string = String.format("%s %s", symbol, relatedTaxon);
|
78
|
|
79
|
return string;
|
80
|
}
|
81
|
|
82
|
/* (non-Javadoc)
|
83
|
* @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
|
84
|
*/
|
85
|
@Override
|
86
|
public StyledString getStyledText(Object element) {
|
87
|
return new StyledString(getText(element), StyledString.QUALIFIER_STYLER);
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* TODO we will get the proper relationship symbol from the type's abbreviated label as a character.
|
92
|
* The image may be omitted then.
|
93
|
*
|
94
|
* @param type
|
95
|
* @return
|
96
|
*/
|
97
|
private Image getTaxonRelationshipImage(TaxonRelationship relationship) {
|
98
|
TaxonRelationshipType type = (relationship).getType();
|
99
|
return ImageResources.getImage(ImageResources.CONCEPT_ICON);
|
100
|
}
|
101
|
}
|