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
|
package eu.etaxonomy.taxeditor.editor.view.descriptive;
|
10
|
|
11
|
import org.eclipse.jface.viewers.ColumnLabelProvider;
|
12
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
13
|
import org.eclipse.jface.viewers.StyledString;
|
14
|
import org.eclipse.swt.SWT;
|
15
|
import org.eclipse.swt.graphics.Color;
|
16
|
import org.eclipse.swt.graphics.Image;
|
17
|
import org.eclipse.swt.widgets.Display;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
20
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
21
|
import eu.etaxonomy.cdm.model.description.DescriptionType;
|
22
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.MatrixUtility;
|
23
|
import eu.etaxonomy.taxeditor.model.DescriptionHelper;
|
24
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
25
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
26
|
|
27
|
/**
|
28
|
* @author p.ciardelli
|
29
|
*/
|
30
|
public class DescriptiveLabelProvider extends ColumnLabelProvider implements IStyledLabelProvider {
|
31
|
|
32
|
private static final String TRUNCATE_SIGN = "..."; //$NON-NLS-1$
|
33
|
private static final int MAX_LENGTH = 150;
|
34
|
|
35
|
@Override
|
36
|
public String getText(Object element) {
|
37
|
String text = DescriptionHelper.getLabel(element);
|
38
|
text = text.replaceAll("[\\r\\n]", " "); //$NON-NLS-1$ //$NON-NLS-2$
|
39
|
if(text.length()>MAX_LENGTH){
|
40
|
text = text.substring(0, MAX_LENGTH)+TRUNCATE_SIGN;
|
41
|
}
|
42
|
return text;
|
43
|
}
|
44
|
|
45
|
@Override
|
46
|
public StyledString getStyledText(Object element) {
|
47
|
return new StyledString(getText(element), StyledString.QUALIFIER_STYLER);
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public Image getImage(Object element) {
|
52
|
if(element instanceof DescriptionBase){
|
53
|
DescriptionBase<?> description = (DescriptionBase<?>)element;
|
54
|
if(description.isComputed()){
|
55
|
return MatrixUtility.getAggregatedDescriptionIcon();
|
56
|
}
|
57
|
else if(description.getTypes().contains(DescriptionType.SECONDARY_DATA)){
|
58
|
return MatrixUtility.getLiteratureDescriptionIcon();
|
59
|
}
|
60
|
else if(description.getTypes().contains(DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION)){
|
61
|
return MatrixUtility.getDefaultDescriptionIcon();
|
62
|
}
|
63
|
else if(description.getTypes().contains(DescriptionType.CLONE_FOR_SOURCE)){
|
64
|
return ImageResources.getImage(ImageResources.COPY_ICON);
|
65
|
}
|
66
|
else if(description.getTypes().contains(DescriptionType.INDIVIDUALS_ASSOCIATION)){
|
67
|
return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
|
68
|
}
|
69
|
}
|
70
|
return null;
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
public Color getForeground(Object element) {
|
75
|
DescriptionBase desc = null;
|
76
|
if (element instanceof DescriptionBase){
|
77
|
desc = (DescriptionBase)element;
|
78
|
}else if (element instanceof DescriptionElementBase){
|
79
|
desc = ((DescriptionElementBase)element).getInDescription();
|
80
|
}else if (element instanceof FeatureNodeContainer){
|
81
|
desc = ((FeatureNodeContainer)element).getDescription();
|
82
|
}
|
83
|
if (desc.isComputed()){
|
84
|
return Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
|
85
|
}
|
86
|
return null;
|
87
|
}
|
88
|
|
89
|
}
|