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