d80b4c72b33ee94b733c2a00bfd16682ca9eff16
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / DescriptiveLabelProvider.java
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.graphics.Image;
15
16 import eu.etaxonomy.cdm.model.description.DescriptionBase;
17 import eu.etaxonomy.cdm.model.description.DescriptionType;
18 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.MatrixUtility;
19 import eu.etaxonomy.taxeditor.model.DescriptionHelper;
20
21 /**
22 * @author p.ciardelli
23 * @version $Id: $
24 */
25 public class DescriptiveLabelProvider extends ColumnLabelProvider implements IStyledLabelProvider {
26
27 private static final String TRUNCATE_SIGN = "..."; //$NON-NLS-1$
28 private static final int MAX_LENGTH = 150;
29
30 @Override
31 public String getText(Object element) {
32 String text = DescriptionHelper.getLabel(element);
33 text = text.replaceAll("[\\r\\n]", " "); //$NON-NLS-1$ //$NON-NLS-2$
34 if(text.length()>MAX_LENGTH){
35 text = text.substring(0, MAX_LENGTH)+TRUNCATE_SIGN;
36 }
37 return text;
38 }
39
40 @Override
41 public StyledString getStyledText(Object element) {
42 return new StyledString(getText(element), StyledString.QUALIFIER_STYLER);
43 }
44
45 @Override
46 public Image getImage(Object element) {
47 if(element instanceof DescriptionBase){
48 DescriptionBase description = (DescriptionBase)element;
49 if(description.getTypes().contains(DescriptionType.AGGREGATED_STRUC_DESC)){
50 return MatrixUtility.getAggregatedDescriptionIcon();
51 }
52 else if(description.getTypes().contains(DescriptionType.SECONDARY_DATA)){
53 return MatrixUtility.getLiteratureDescriptionIcon();
54 }
55 else if(description.getTypes().contains(DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION)){
56 return MatrixUtility.getDefaultDescriptionIcon();
57 }
58 }
59 return null;
60 }
61 }