2 * Copyright (C) 2017 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.
9 package eu
.etaxonomy
.taxeditor
.util
;
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
.jface
.viewers
.StyledString
.Styler
;
15 import org
.eclipse
.swt
.graphics
.TextStyle
;
16 import org
.hibernate
.LazyInitializationException
;
18 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
23 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
26 import eu
.etaxonomy
.taxeditor
.security
.RequiredPermissions
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
34 public class TaxonTreeNodeLabelProvider
35 extends ColumnLabelProvider
36 implements IStyledLabelProvider
{
38 protected Styler notGrantedStyler
= null;
41 public String
getText(Object element
) {
43 if(element
instanceof Classification
){
44 String text
= ((Classification
) element
).getName().getText();
45 return text
!= null ? text
: "Unnamed Classification";
48 else if (element
instanceof TaxonNode
){
49 TaxonNode taxonNode
= (TaxonNode
) HibernateProxyHelper
.deproxy(element
);
51 Taxon taxon
= HibernateProxyHelper
.deproxy(taxonNode
.getTaxon());
53 String text
= taxonNode
.getClassification().getName() == null ?
null : taxonNode
.getClassification().getName().getText();
55 text
= taxonNode
.getClassification().getTitleCache();
61 if (taxonNode
.getStatus() != null){
62 text
= taxonNode
.getStatus().getSymbol() + " ";
64 if (taxonNode
.getTaxon() != null && !taxonNode
.getTaxon().isPublish()) {
65 text
= text
+ "\\u20ac";
67 text
+= taxon
.getName() != null ? taxon
.getName().getTitleCache() : "";
70 MessagingUtils
.error(getClass(), e
);
73 }catch (LazyInitializationException e
){
74 MessagingUtils
.error(getClass(), e
);
77 else if (element
instanceof TaxonNodeDto
){
78 TaxonNodeDto taxonNode
= (TaxonNodeDto
) element
;
80 if (taxonNode
.getStatus() != null){
81 text
= taxonNode
.getStatus().getSymbol() + " ";
83 if (!taxonNode
.isPublish() ) {
84 text
= text
+ "\u26D4 ";
86 //TODO if symbols contain non-ASCII this may create problems
87 // if so we may use ASCII like text +=Character.toString((char)248) + " ";
89 text
+= taxonNode
.getTitleCache();
96 public StyledString
getStyledText(Object element
) {
98 if(element
instanceof Classification
){
99 return new StyledString(getText(element
), StyledString
.DECORATIONS_STYLER
);
102 else if(element
instanceof TaxonNode
){
103 // determine style base on user grants
104 Styler styler
= null;
105 if(!CdmStore
.currentAuthentiationHasPermission((CdmBase
) element
, RequiredPermissions
.TAXONNODE_EDIT
)){
106 styler
= getNotGrantedStyler();
108 return new StyledString(getText(element
), styler
);
110 return new StyledString(getText(element
));
113 private Styler
getNotGrantedStyler() {
114 if (notGrantedStyler
== null) {
115 notGrantedStyler
= new Styler() {
117 public void applyStyles(TextStyle textStyle
) {
118 textStyle
.underline
= false;
119 textStyle
.foreground
= StoreUtil
.getColor(Resources
.COLOR_TEXT_DISABLED
);
123 return notGrantedStyler
;