2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.referencingobjects
;
12 import org
.apache
.commons
.lang3
.StringUtils
;
13 import org
.apache
.logging
.log4j
.LogManager
;import org
.apache
.logging
.log4j
.Logger
;
14 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
15 import org
.eclipse
.jface
.viewers
.LabelProvider
;
16 import org
.eclipse
.swt
.graphics
.Image
;
18 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
20 import eu
.etaxonomy
.cdm
.persistence
.dto
.ReferencingObjectDto
;
21 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
24 * Requires an <code>IReferencingObjectsService</code> to translate the label
25 * elements into displayable text.
30 public class ReferencingObjectsLabelProvider
extends LabelProvider
implements ITableLabelProvider
{
32 @SuppressWarnings("unused")
33 private static final Logger logger
= LogManager
.getLogger(ReferencingObjectsLabelProvider
.class);
36 * <p>Constructor for ReferencingObjectsLabelProvider.</p>
38 public ReferencingObjectsLabelProvider() {
42 public Image
getColumnImage(Object element
, int columnIndex
) {
47 public String
getColumnText(Object element
, int columnIndex
) {
50 }else if (element
instanceof String
){
51 return columnIndex
== 0 ? element
.toString() :"";
52 }else if (element
instanceof ReferencingObjectDto
){
53 ReferencingObjectDto dto
= (ReferencingObjectDto
)element
;
54 if (columnIndex
== 0) {
55 Class
<?
> type
= dto
.getType() != null ? dto
.getType() : dto
.getReferencedEntity() != null? dto
.getReferencedEntity().getClass() : null;
56 return type
== null?
null : CdmUtils
.userFriendlyClassName(type
);
57 }else if (columnIndex
== 1) {
58 return dto
.getTitleCache();
59 }else if (columnIndex
== 2) {
60 return dto
.getUuid() == null ?
null : dto
.getUuid().toString();
61 }else if (columnIndex
== 3) {
62 return String
.valueOf(dto
.getId() == null?
null :dto
.getId());
68 //this should not happen, but just in case
70 Object deproxiedElement
= CdmBase
.deproxy(element
);
71 if (columnIndex
== 0) {
72 text
= CdmUtils
.userFriendlyClassName(deproxiedElement
.getClass());
73 }else if (columnIndex
== 1) {
74 text
= element
.toString();
75 }else if (columnIndex
== 2) {
76 if(element
instanceof CdmBase
){
77 text
= ((CdmBase
) element
).getUuid().toString();
79 }else if (columnIndex
== 3) {
80 if(element
instanceof CdmBase
){
81 text
= String
.valueOf(((CdmBase
) element
).getId());
84 return (StringUtils
.isBlank(text
)) ? Messages
.ReferencingObjectsLabelProvider_No_description_available
: text
;