3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
;
13 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
14 import org
.eclipse
.jface
.viewers
.DelegatingStyledCellLabelProvider
.IStyledLabelProvider
;
15 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
16 import org
.eclipse
.jface
.viewers
.StyledString
;
17 import org
.eclipse
.jface
.viewers
.StyledString
.Styler
;
18 import org
.eclipse
.swt
.graphics
.Image
;
19 import org
.eclipse
.swt
.graphics
.TextStyle
;
20 import org
.eclipse
.ui
.navigator
.IDescriptionProvider
;
21 import org
.hibernate
.LazyInitializationException
;
23 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
24 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.IIdentifiableEntity
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
30 import eu
.etaxonomy
.taxeditor
.security
.RequiredPermissions
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
32 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
35 * <p>TaxonNodeLabelProvider class.</p>
40 public class TaxonNodeLabelProvider
extends ColumnLabelProvider
41 implements ILabelProvider
, IDescriptionProvider
, IStyledLabelProvider
{
44 private Styler notGrantedStyler
= null;
48 public Image
getImage(Object element
) {
54 public String
getText(Object element
) {
55 if (element
instanceof TaxonNode
){
56 TaxonNode taxonNode
= (TaxonNode
) HibernateProxyHelper
.deproxy(element
);
59 Taxon taxon
= (Taxon
) HibernateProxyHelper
.deproxy(taxonNode
.getTaxon());
61 MessagingUtils
.error(getClass(), "The taxon node does not have a taxon attached to it. Please check your import. TaxonNode: " + element
, null);
62 // throw new RuntimeException("The data your are trying to view is corrupt. Please check your import.");
65 return taxon
.getName() != null ?
((IIdentifiableEntity
) HibernateProxyHelper
.deproxy(taxon
.getName())).getTitleCache() : new String();
67 MessagingUtils
.error(getClass(), e
);
70 }catch (LazyInitializationException e
){
71 MessagingUtils
.error(getClass(), e
);
80 public String
getDescription(Object anElement
) {
81 if (anElement
instanceof TaxonNode
) {
82 Taxon data
= ((TaxonNode
) anElement
).getTaxon();
83 return "Taxon: " + (data
!= null ? data
.getTitleCache() : ">NO TAXON<");
90 public StyledString
getStyledText(Object element
) {
91 // determine style base on user grants
93 if(!CdmStore
.currentAuthentiationHasPermission((CdmBase
) element
, RequiredPermissions
.TAXONNODE_EDIT
)){
94 styler
= getNotGrantedStyler();
96 return new StyledString(getText(element
), styler
);
103 private Styler
getNotGrantedStyler() {
104 if (notGrantedStyler
== null) {
105 notGrantedStyler
= new Styler() {
107 public void applyStyles(TextStyle textStyle
) {
108 textStyle
.underline
= false;
109 textStyle
.foreground
= StoreUtil
.getColor(Resources
.COLOR_TEXT_DISABLED
);
113 return notGrantedStyler
;